Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,7 @@ public void endVisit(EnhancedForStatement node) {
} else if (loopVariable.asType().getKind().isPrimitive()) {
boxLoopVariable(node, expressionType, loopVariable);
} else {
VariableElement newLoopVariable = GeneratedVariableElement.mutableCopy(loopVariable)
.setTypeQualifiers("__strong");
node.getParameter().setVariableElement(newLoopVariable);
nameTable.setTypeQualifiers(loopVariable, "__strong");
}
}

Expand All @@ -93,10 +91,10 @@ private void handleArrayIteration(EnhancedForStatement node) {
TypeMirror bufferType = new PointerType(componentType);
VariableElement arrayVariable = GeneratedVariableElement.newLocalVar(
"a__", expressionType, null);
VariableElement bufferVariable = GeneratedVariableElement.newLocalVar("b__", bufferType, null)
.setTypeQualifiers("const*");
VariableElement endVariable = GeneratedVariableElement.newLocalVar("e__", bufferType, null)
.setTypeQualifiers("const*");
VariableElement bufferVariable = GeneratedVariableElement.newLocalVar("b__", bufferType, null);
nameTable.setTypeQualifiers(bufferVariable, "const*");
VariableElement endVariable = GeneratedVariableElement.newLocalVar("e__", bufferType, null);
nameTable.setTypeQualifiers(endVariable, "const*");
VariableElement bufferField = GeneratedVariableElement.newField(
"buffer", bufferType, iosArrayType)
.addModifiers(Modifier.PUBLIC);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ public class GeneratedVariableElement extends GeneratedElement implements Variab
private final TypeMirror type;
private boolean nonnull = false;
private boolean isWeak = false;
private String typeQualifiers;

private GeneratedVariableElement(
String name, TypeMirror type, ElementKind kind, Element enclosingElement, boolean synthetic) {
Expand Down Expand Up @@ -105,22 +104,6 @@ public GeneratedVariableElement setIsWeak(boolean value) {
return this;
}

/**
* Sets the qualifiers that should be added to the variable declaration. Use
* an asterisk ('*') to delimit qualifiers that should apply to a pointer from
* qualifiers that should apply to the pointee type. For example setting the
* qualifier as "__strong * const" on a string array will result in a
* declaration of "NSString * __strong * const".
*/
public GeneratedVariableElement setTypeQualifiers(String qualifiers) {
typeQualifiers = qualifiers;
return this;
}

public String getTypeQualifiers() {
return typeQualifiers;
}

@Override
public GeneratedVariableElement addAnnotationMirrors(
Collection<? extends AnnotationMirror> newAnnotations) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -274,11 +274,6 @@ public static boolean isNonnull(VariableElement element) {
&& ((GeneratedVariableElement) element).isNonnull();
}

public static String getTypeQualifiers(VariableElement element) {
return element instanceof GeneratedVariableElement
? ((GeneratedVariableElement) element).getTypeQualifiers() : null;
}

public static boolean isAbstract(Element element) {
return hasModifier(element, Modifier.ABSTRACT);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ public class NameTable {
private final CaptureInfo captureInfo;
private final Options options;
private final Map<VariableElement, String> variableNames = new HashMap<>();
private final Map<VariableElement, String> variableTypeQualifiers = new HashMap<>();
private final Map<ExecutableElement, String> methodSelectorCache = new HashMap<>();
private final Map<TypeElement, String> fullNameCache = new HashMap<>();

Expand Down Expand Up @@ -278,6 +279,20 @@ public String getVariableQualifiedName(VariableElement var) {
return shortName;
}

/**
* Sets the qualifiers that should be added to the variable declaration. Use an asterisk ('*') to
* delimit qualifiers that should apply to a pointer from qualifiers that should apply to the
* pointee type. For example setting the qualifier as "__strong * const" on a string array will
* result in a declaration of "NSString * __strong * const".
*/
public void setTypeQualifiers(VariableElement var, String qualifiers) {
variableTypeQualifiers.put(var, qualifiers);
}

public String getTypeQualifiers(VariableElement var) {
return variableTypeQualifiers.get(var);
}

/**
* Returns the name of an annotation property variable, extracted from its accessor element.
*/
Expand Down Expand Up @@ -828,8 +843,7 @@ public String getObjCType(TypeMirror type) {
}

public String getObjCType(VariableElement var) {
return getObjcTypeInner(
var.asType(), ElementUtil.getTypeQualifiers(var), false, false, null);
return getObjcTypeInner(var.asType(), getTypeQualifiers(var), false, false, null);
}

public String getObjCTypeDeclaration(TypeMirror type) {
Expand Down