Skip to content

Commit

Permalink
Fixed nullability support when jsr305.jar isn't on build path.
Browse files Browse the repository at this point in the history
	Change on 2017/10/19 by tball <tball@google.com>

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=172758793
  • Loading branch information
tomball committed Oct 19, 2017
1 parent 5cf8de6 commit f19ef67
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
Expand Up @@ -33,18 +33,18 @@
import com.google.devtools.j2objc.types.ExecutablePair;
import com.google.devtools.j2objc.types.GeneratedAnnotationMirror;
import com.google.devtools.j2objc.types.GeneratedExecutableElement;
import com.google.devtools.j2objc.types.GeneratedTypeElement;
import com.google.devtools.j2objc.types.GeneratedVariableElement;
import com.google.devtools.j2objc.types.NativeType;
import com.google.devtools.j2objc.util.ElementUtil;
import com.google.devtools.j2objc.util.ErrorUtil;
import com.google.devtools.j2objc.util.Mappings;
import com.google.devtools.j2objc.util.NameTable;
import com.google.devtools.j2objc.util.TypeUtil;
import javax.lang.model.element.AnnotationMirror;

import javax.lang.model.element.ExecutableElement;
import javax.lang.model.element.Modifier;
import javax.lang.model.element.TypeElement;
import javax.lang.model.type.DeclaredType;
import javax.lang.model.type.TypeMirror;

/**
Expand All @@ -70,7 +70,7 @@ public JavaToIOSMethodTranslator(CompilationUnit unit) {
public boolean visit(MethodDeclaration node) {
ExecutableElement method = node.getExecutableElement();

// Check if @ObjectiveCName is used but is mismatched with an overriden method.
// Check if @ObjectiveCName is used but is mismatched with an overridden method.
String name = NameTable.getMethodNameFromAnnotation(method);
if (name != null) {
String selector = nameTable.selectorForMethodName(method, name);
Expand Down Expand Up @@ -148,9 +148,9 @@ private void addCopyWithZoneMethod(TypeDeclaration node, boolean singleton) {
GeneratedVariableElement zoneParam =
GeneratedVariableElement.newParameter("zone", NSZONE_TYPE, copyElement);
if (options.nullability()) {
TypeMirror nullableType = typeUtil.resolveJavaType("javax.annotation.Nullable").asType();
AnnotationMirror annotation = new GeneratedAnnotationMirror((DeclaredType) nullableType);
zoneParam.addAnnotationMirror(annotation);
TypeElement annotationType =
GeneratedTypeElement.newEmulatedInterface("javax.annotation.Nullable");
zoneParam.addAnnotationMirror(new GeneratedAnnotationMirror(annotationType));
}
copyElement.addParameter(zoneParam);
copyDecl.addParameter(new SingleVariableDeclaration(zoneParam));
Expand Down
Expand Up @@ -19,22 +19,23 @@
import javax.lang.model.element.AnnotationMirror;
import javax.lang.model.element.AnnotationValue;
import javax.lang.model.element.ExecutableElement;
import javax.lang.model.element.TypeElement;
import javax.lang.model.type.DeclaredType;

/**
* Annotation mirror class for annotations created during translation.
*/
public class GeneratedAnnotationMirror implements AnnotationMirror {
private final DeclaredType type;
private final TypeElement element;
private final Map<ExecutableElement, AnnotationValue> values = new HashMap<>();

public GeneratedAnnotationMirror(DeclaredType annotationType) {
this.type = annotationType;
public GeneratedAnnotationMirror(TypeElement annotationElement) {
this.element = annotationElement;
}

@Override
public DeclaredType getAnnotationType() {
return type;
return (DeclaredType) element.asType();
}

@Override
Expand Down

0 comments on commit f19ef67

Please sign in to comment.