org.eclipse.jdt.internal.compiler.ast.Annotation Java Examples

The following examples show how to use org.eclipse.jdt.internal.compiler.ast.Annotation. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SourceTypeBinding.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
protected boolean checkRedundantNullnessDefaultOne(ASTNode location, Annotation[] annotations, long nullBits, boolean isJdk18) {
	
	if (!isPrototype()) throw new IllegalStateException();
	
	int thisDefault = getNullDefault();
	if (thisDefault != NO_NULL_DEFAULT) {
		boolean isRedundant = isJdk18
				? thisDefault == nullBits
				: (nullBits & TagBits.AnnotationNonNullByDefault) != 0;
		if (isRedundant) {
			this.scope.problemReporter().nullDefaultAnnotationIsRedundant(location, annotations, this);
		}
		return false; // different default means inner default is not redundant -> we're done
	}
	return true;
}
 
Example #2
Source File: PatchExtensionMethod.java    From EasyMPermission with MIT License 6 votes vote down vote up
static List<Extension> getApplicableExtensionMethods(EclipseNode typeNode, Annotation ann, TypeBinding receiverType) {
	List<Extension> extensions = new ArrayList<Extension>();
	if ((typeNode != null) && (ann != null) && (receiverType != null)) {
		BlockScope blockScope = ((TypeDeclaration) typeNode.get()).initializerScope;
		EclipseNode annotationNode = typeNode.getNodeFor(ann);
		AnnotationValues<ExtensionMethod> annotation = createAnnotation(ExtensionMethod.class, annotationNode);
		boolean suppressBaseMethods = false;
		try {
			suppressBaseMethods = annotation.getInstance().suppressBaseMethods();
		} catch (AnnotationValueDecodeFail fail) {
			fail.owner.setError(fail.getMessage(), fail.idx);
		}
		for (Object extensionMethodProvider : annotation.getActualExpressions("value")) {
			if (extensionMethodProvider instanceof ClassLiteralAccess) {
				TypeBinding binding = ((ClassLiteralAccess) extensionMethodProvider).type.resolveType(blockScope);
				if (binding == null) continue;
				if (!binding.isClass() && !binding.isEnum()) continue;
				Extension e = new Extension();
				e.extensionMethods = getApplicableExtensionMethodsDefinedInProvider(typeNode, (ReferenceBinding) binding, receiverType);
				e.suppressBaseMethods = suppressBaseMethods;
				extensions.add(e);
			}
		}
	}
	return extensions;
}
 
Example #3
Source File: RecoveredField.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
public void attach(RecoveredAnnotation[] annots, int annotCount, int mods, int modsSourceStart) {
	if (annotCount > 0) {
		Annotation[] existingAnnotations = this.fieldDeclaration.annotations;
		if (existingAnnotations != null) {
			this.annotations = new RecoveredAnnotation[annotCount];
			this.annotationCount = 0;
			next : for (int i = 0; i < annotCount; i++) {
				for (int j = 0; j < existingAnnotations.length; j++) {
					if (annots[i].annotation == existingAnnotations[j]) continue next;
				}
				this.annotations[this.annotationCount++] = annots[i];
			}
		} else {
			this.annotations = annots;
			this.annotationCount = annotCount;
		}
	}

	if (mods != 0) {
		this.modifiers = mods;
		this.modifiersStart = modsSourceStart;
	}
}
 
Example #4
Source File: LocalTypeBinding.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
protected void checkRedundantNullnessDefaultRecurse(ASTNode location, Annotation[] annotations, long nullBits, boolean isJdk18) {
	
	if (!isPrototype()) throw new IllegalStateException();
	
	long outerDefault = 0;
	if (this.enclosingMethod != null) {
		outerDefault = isJdk18 
				? this.enclosingMethod.defaultNullness 
				: this.enclosingMethod.tagBits & (TagBits.AnnotationNonNullByDefault|TagBits.AnnotationNullUnspecifiedByDefault);
	}
	if (outerDefault != 0) {
		if (outerDefault == nullBits) {
			this.scope.problemReporter().nullDefaultAnnotationIsRedundant(location, annotations, this.enclosingMethod);
		}
		return;
	}
	super.checkRedundantNullnessDefaultRecurse(location, annotations, nullBits, isJdk18);
}
 
Example #5
Source File: HandleConstructor.java    From EasyMPermission with MIT License 6 votes vote down vote up
@Override public void handle(AnnotationValues<RequiredArgsConstructor> annotation, Annotation ast, EclipseNode annotationNode) {
	handleFlagUsage(annotationNode, ConfigurationKeys.REQUIRED_ARGS_CONSTRUCTOR_FLAG_USAGE, "@RequiredArgsConstructor", ConfigurationKeys.ANY_CONSTRUCTOR_FLAG_USAGE, "any @xArgsConstructor");
	
	EclipseNode typeNode = annotationNode.up();
	if (!checkLegality(typeNode, annotationNode, RequiredArgsConstructor.class.getSimpleName())) return;
	RequiredArgsConstructor ann = annotation.getInstance();
	AccessLevel level = ann.access();
	if (level == AccessLevel.NONE) return;
	String staticName = ann.staticName();
	Boolean suppressConstructorProperties = null;
	if (annotation.isExplicit("suppressConstructorProperties")) {
		@SuppressWarnings("deprecation")
		boolean suppress = ann.suppressConstructorProperties();
		suppressConstructorProperties = suppress;
	}
	
	List<Annotation> onConstructor = unboxAndRemoveAnnotationParameter(ast, "onConstructor", "@RequiredArgsConstructor(onConstructor=", annotationNode);
	
	new HandleConstructor().generateConstructor(
			typeNode, level, findRequiredFields(typeNode), staticName, SkipIfConstructorExists.NO,
			suppressConstructorProperties, onConstructor, annotationNode);
}
 
Example #6
Source File: EclipseHandlerUtil.java    From EasyMPermission with MIT License 6 votes vote down vote up
/**
 * Checks if there is a (non-default) constructor. In case of multiple constructors (overloading), only
 * the first constructor decides if EXISTS_BY_USER or EXISTS_BY_LOMBOK is returned.
 * 
 * @param node Any node that represents the Type (TypeDeclaration) to look in, or any child node thereof.
 */
public static MemberExistsResult constructorExists(EclipseNode node) {
	while (node != null && !(node.get() instanceof TypeDeclaration)) {
		node = node.up();
	}
	
	if (node != null && node.get() instanceof TypeDeclaration) {
		TypeDeclaration typeDecl = (TypeDeclaration)node.get();
		if (typeDecl.methods != null) top: for (AbstractMethodDeclaration def : typeDecl.methods) {
			if (def instanceof ConstructorDeclaration) {
				if ((def.bits & ASTNode.IsDefaultConstructor) != 0) continue;
				
				if (def.annotations != null) for (Annotation anno : def.annotations) {
					if (typeMatches(Tolerate.class, node, anno.type)) continue top;
				}
				
				return getGeneratedBy(def) == null ? MemberExistsResult.EXISTS_BY_USER : MemberExistsResult.EXISTS_BY_LOMBOK;
			}
		}
	}
	
	return MemberExistsResult.NOT_EXISTS;
}
 
Example #7
Source File: RecoveredType.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
public void attach(RecoveredAnnotation[] annots, int annotCount, int mods, int modsSourceStart) {
	if (annotCount > 0) {
		Annotation[] existingAnnotations = this.typeDeclaration.annotations;
		if (existingAnnotations != null) {
			this.annotations = new RecoveredAnnotation[annotCount];
			this.annotationCount = 0;
			next : for (int i = 0; i < annotCount; i++) {
				for (int j = 0; j < existingAnnotations.length; j++) {
					if (annots[i].annotation == existingAnnotations[j]) continue next;
				}
				this.annotations[this.annotationCount++] = annots[i];
			}
		} else {
			this.annotations = annots;
			this.annotationCount = annotCount;
		}
	}

	if (mods != 0) {
		this.modifiers = mods;
		this.modifiersStart = modsSourceStart;
	}
}
 
Example #8
Source File: EclipseHandlerUtil.java    From EasyMPermission with MIT License 6 votes vote down vote up
public static void sanityCheckForMethodGeneratingAnnotationsOnBuilderClass(EclipseNode typeNode, EclipseNode errorNode) {
	List<String> disallowed = null;
	for (EclipseNode child : typeNode.down()) {
		if (child.getKind() != Kind.ANNOTATION) continue;
		for (Class<? extends java.lang.annotation.Annotation> annType : INVALID_ON_BUILDERS) {
			if (annotationTypeMatches(annType, child)) {
				if (disallowed == null) disallowed = new ArrayList<String>();
				disallowed.add(annType.getSimpleName());
			}
		}
	}
	
	int size = disallowed == null ? 0 : disallowed.size();
	if (size == 0) return;
	if (size == 1) {
		errorNode.addError("@" + disallowed.get(0) + " is not allowed on builder classes.");
		return;
	}
	StringBuilder out = new StringBuilder();
	for (String a : disallowed) out.append("@").append(a).append(", ");
	out.setLength(out.length() - 2);
	errorNode.addError(out.append(" are not allowed on builder classes.").toString());
}
 
Example #9
Source File: Extractor.java    From javaide with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean visit(TypeDeclaration typeDeclaration, CompilationUnitScope scope) {
    Annotation[] annotations = typeDeclaration.annotations;
    if (hasRelevantAnnotations(annotations)) {
        SourceTypeBinding binding = typeDeclaration.binding;
        if (binding == null) {
            return true;
        }
        String fqn = new String(typeDeclaration.binding.readableName());
        Item item = ClassItem.create(fqn, ClassKind.forType(typeDeclaration));
        addItem(fqn, item);
        addAnnotations(annotations, item);

    }
    return true;
}
 
Example #10
Source File: Extractor.java    From javaide with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean visit(TypeDeclaration memberTypeDeclaration, ClassScope scope) {
    Annotation[] annotations = memberTypeDeclaration.annotations;
    if (hasRelevantAnnotations(annotations)) {
        SourceTypeBinding binding = memberTypeDeclaration.binding;
        if (!(binding instanceof MemberTypeBinding)) {
            return true;
        }
        if (binding.isAnnotationType() || binding.isAnonymousType()) {
            return false;
        }

        String fqn = new String(memberTypeDeclaration.binding.readableName());
        Item item = ClassItem.create(fqn, ClassKind.forType(memberTypeDeclaration));
        addItem(fqn, item);
        addAnnotations(annotations, item);
    }
    return true;
}
 
Example #11
Source File: Extractor.java    From javaide with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean visit(TypeDeclaration localTypeDeclaration, BlockScope scope) {
    Annotation[] annotations = localTypeDeclaration.annotations;
    if (hasRelevantAnnotations(annotations)) {
        SourceTypeBinding binding = localTypeDeclaration.binding;
        if (binding == null) {
            return true;
        }

        String fqn = getFqn(scope);
        if (fqn == null) {
            fqn = new String(localTypeDeclaration.binding.readableName());
        }
        Item item = ClassItem.create(fqn, ClassKind.forType(localTypeDeclaration));
        addItem(fqn, item);
        addAnnotations(annotations, item);

    }
    return true;
}
 
Example #12
Source File: AnnotationDiscoveryVisitor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public boolean visit(Argument argument, BlockScope scope) {
	Annotation[] annotations = argument.annotations;
	ReferenceContext referenceContext = scope.referenceContext();
	if (referenceContext instanceof AbstractMethodDeclaration) {
		MethodBinding binding = ((AbstractMethodDeclaration) referenceContext).binding;
		if (binding != null) {
			TypeDeclaration typeDeclaration = scope.referenceType();
			typeDeclaration.binding.resolveTypesFor(binding);
			if (argument.binding != null) {
				argument.binding = new AptSourceLocalVariableBinding(argument.binding, binding);
			}
		}
		if (annotations != null) {
			this.resolveAnnotations(
					scope,
					annotations,
					argument.binding);
		}
	}
	return false;
}
 
Example #13
Source File: Extractor.java    From javaide with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean visit(ConstructorDeclaration constructorDeclaration, ClassScope scope) {
    Annotation[] annotations = constructorDeclaration.annotations;
    if (hasRelevantAnnotations(annotations)) {
        MethodBinding constructorBinding = constructorDeclaration.binding;
        if (constructorBinding == null) {
            return false;
        }

        String fqn = getFqn(scope);
        ClassKind kind = ClassKind.forType(scope.referenceContext);
        Item item = MethodItem.create(fqn, kind, constructorDeclaration, constructorBinding);
        if (item != null) {
            addItem(fqn, item);
            addAnnotations(annotations, item);
        }
    }

    Argument[] arguments = constructorDeclaration.arguments;
    if (arguments != null) {
        for (Argument argument : arguments) {
            argument.traverse(this, constructorDeclaration.scope);
        }
    }
    return false;
}
 
Example #14
Source File: HandleLog.java    From EasyMPermission with MIT License 6 votes vote down vote up
@Override public Expression createFactoryParameter(ClassLiteralAccess type, Annotation source) {
	int pS = source.sourceStart, pE = source.sourceEnd;
	long p = (long)pS << 32 | pE;
	
	MessageSend factoryParameterCall = new MessageSend();
	setGeneratedBy(factoryParameterCall, source);
	
	factoryParameterCall.receiver = super.createFactoryParameter(type, source);
	factoryParameterCall.selector = "getName".toCharArray();
	
	factoryParameterCall.nameSourcePosition = p;
	factoryParameterCall.sourceStart = pS;
	factoryParameterCall.sourceEnd = factoryParameterCall.statementEnd = pE;
	
	return factoryParameterCall;
}
 
Example #15
Source File: HandleLog.java    From EasyMPermission with MIT License 6 votes vote down vote up
public static TypeReference createTypeReference(String typeName, Annotation source) {
	int pS = source.sourceStart, pE = source.sourceEnd;
	long p = (long)pS << 32 | pE;
	
	TypeReference typeReference;
	if (typeName.contains(".")) {
		
		char[][] typeNameTokens = fromQualifiedName(typeName);
		long[] pos = new long[typeNameTokens.length];
		Arrays.fill(pos, p);
		
		typeReference = new QualifiedTypeReference(typeNameTokens, pos);
	}
	else {
		typeReference = null;
	}
	
	setGeneratedBy(typeReference, source);
	return typeReference;
}
 
Example #16
Source File: HandleBuilder.java    From EasyMPermission with MIT License 6 votes vote down vote up
private void makeSimpleSetterMethodForBuilder(EclipseNode builderType, EclipseNode fieldNode, EclipseNode sourceNode, boolean fluent, boolean chain) {
	TypeDeclaration td = (TypeDeclaration) builderType.get();
	AbstractMethodDeclaration[] existing = td.methods;
	if (existing == null) existing = EMPTY;
	int len = existing.length;
	FieldDeclaration fd = (FieldDeclaration) fieldNode.get();
	char[] name = fd.name;
	
	for (int i = 0; i < len; i++) {
		if (!(existing[i] instanceof MethodDeclaration)) continue;
		char[] existingName = existing[i].selector;
		if (Arrays.equals(name, existingName)) return;
	}
	
	String setterName = fluent ? fieldNode.getName() : HandlerUtil.buildAccessorName("set", fieldNode.getName());
	
	MethodDeclaration setter = HandleSetter.createSetter(td, fieldNode, setterName, chain, ClassFileConstants.AccPublic,
			sourceNode, Collections.<Annotation>emptyList(), Collections.<Annotation>emptyList());
	injectMethod(builderType, setter);
}
 
Example #17
Source File: Extractor.java    From javaide with GNU General Public License v3.0 6 votes vote down vote up
private void addAnnotations(@Nullable Annotation[] annotations, @NonNull Item item) {
    if (annotations != null) {
        for (Annotation annotation : annotations) {
            if (isRelevantAnnotation(annotation)) {
                String fqn = getFqn(annotation);
                if (SUPPORT_KEEP.equals(fqn)) {
                    // Put keep rules in a different place; we don't want to write
                    // these out into the external annotations database, they go
                    // into a special proguard file
                    keepItems.add(item);
                } else {
                    addAnnotation(annotation, fqn, item.annotations);
                }
            }
        }
    }
}
 
Example #18
Source File: EclipseHandlerUtil.java    From EasyMPermission with MIT License 5 votes vote down vote up
public static Annotation[] copyAnnotations(ASTNode source, Annotation[]... allAnnotations) {
	List<Annotation> result = null;
	for (Annotation[] annotations : allAnnotations) {
		if (annotations != null) {
			for (Annotation annotation : annotations) {
				if (result == null) result = new ArrayList<Annotation>();
				result.add(copyAnnotation(annotation, source));
			}
		}
	}
	
	return result == null ? null : result.toArray(new Annotation[0]);
}
 
Example #19
Source File: PatchExtensionMethod.java    From EasyMPermission with MIT License 5 votes vote down vote up
public static Annotation getAnnotation(Class<? extends java.lang.annotation.Annotation> expectedType, EclipseNode node) {
	TypeDeclaration decl = (TypeDeclaration) node.get();
	if (decl.annotations != null) for (Annotation ann : decl.annotations) {
		if (EclipseHandlerUtil.typeMatches(expectedType, node, ann.type)) return ann;
	}
	return null;
}
 
Example #20
Source File: HandleConstructor.java    From EasyMPermission with MIT License 5 votes vote down vote up
public static Annotation[] createConstructorProperties(ASTNode source, Collection<EclipseNode> fields) {
	if (fields.isEmpty()) return null;
	
	int pS = source.sourceStart, pE = source.sourceEnd;
	long p = (long)pS << 32 | pE;
	long[] poss = new long[3];
	Arrays.fill(poss, p);
	QualifiedTypeReference constructorPropertiesType = new QualifiedTypeReference(JAVA_BEANS_CONSTRUCTORPROPERTIES, poss);
	setGeneratedBy(constructorPropertiesType, source);
	SingleMemberAnnotation ann = new SingleMemberAnnotation(constructorPropertiesType, pS);
	ann.declarationSourceEnd = pE;
	
	ArrayInitializer fieldNames = new ArrayInitializer();
	fieldNames.sourceStart = pS;
	fieldNames.sourceEnd = pE;
	fieldNames.expressions = new Expression[fields.size()];
	
	int ctr = 0;
	for (EclipseNode field : fields) {
		char[] fieldName = removePrefixFromField(field);
		fieldNames.expressions[ctr] = new StringLiteral(fieldName, pS, pE, 0);
		setGeneratedBy(fieldNames.expressions[ctr], source);
		ctr++;
	}
	
	ann.memberValue = fieldNames;
	setGeneratedBy(ann, source);
	setGeneratedBy(ann.memberValue, source);
	return new Annotation[] { ann };
}
 
Example #21
Source File: AnnotationDiscoveryVisitor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public boolean visit(TypeDeclaration memberTypeDeclaration, ClassScope scope) {
	SourceTypeBinding binding = memberTypeDeclaration.binding;
	if (binding == null) {
		return false;
	}
	Annotation[] annotations = memberTypeDeclaration.annotations;
	if (annotations != null) {
		this.resolveAnnotations(
				memberTypeDeclaration.staticInitializerScope,
				annotations,
				binding);
	}
	return true;
}
 
Example #22
Source File: HandleEqualsAndHashCode.java    From EasyMPermission with MIT License 5 votes vote down vote up
public void generateEqualsAndHashCodeForType(EclipseNode typeNode, EclipseNode errorNode) {
	if (hasAnnotation(EqualsAndHashCode.class, typeNode)) {
		//The annotation will make it happen, so we can skip it.
		return;
	}
	
	generateMethods(typeNode, errorNode, null, null, null, false, FieldAccess.GETTER, new ArrayList<Annotation>());
}
 
Example #23
Source File: AnnotationDiscoveryVisitor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public boolean visit(ConstructorDeclaration constructorDeclaration, ClassScope scope) {
	Annotation[] annotations = constructorDeclaration.annotations;
	if (annotations != null) {
		MethodBinding constructorBinding = constructorDeclaration.binding;
		if (constructorBinding == null) {
			return false;
		}
		((SourceTypeBinding) constructorBinding.declaringClass).resolveTypesFor(constructorBinding);
		this.resolveAnnotations(
				constructorDeclaration.scope,
				annotations,
				constructorBinding);
	}
	
	TypeParameter[] typeParameters = constructorDeclaration.typeParameters;
	if (typeParameters != null) {
		int typeParametersLength = typeParameters.length;
		for (int i = 0; i < typeParametersLength; i++) {
			typeParameters[i].traverse(this, constructorDeclaration.scope);
		}
	}
	
	Argument[] arguments = constructorDeclaration.arguments;
	if (arguments != null) {
		int argumentLength = arguments.length;
		for (int i = 0; i < argumentLength; i++) {
			arguments[i].traverse(this, constructorDeclaration.scope);
		}
	}
	return false;
}
 
Example #24
Source File: LocalVariableBinding.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public AnnotationBinding[] getAnnotations() {
	if (this.declaringScope == null) {
		if ((this.tagBits & TagBits.AnnotationResolved) != 0) {
			// annotation are already resolved
			if (this.declaration == null) {
				return Binding.NO_ANNOTATIONS;
			}
			Annotation[] annotations = this.declaration.annotations;
			if (annotations != null) {
				int length = annotations.length;
				AnnotationBinding[] annotationBindings = new AnnotationBinding[length];
				for (int i = 0; i < length; i++) {
					AnnotationBinding compilerAnnotation = annotations[i].getCompilerAnnotation();
					if (compilerAnnotation == null) {
						return Binding.NO_ANNOTATIONS;
					}
					annotationBindings[i] = compilerAnnotation;
				}
				return annotationBindings;
			}
		}
		return Binding.NO_ANNOTATIONS;
	}
	SourceTypeBinding sourceType = this.declaringScope.enclosingSourceType();
	if (sourceType == null)
		return Binding.NO_ANNOTATIONS;

	if ((this.tagBits & TagBits.AnnotationResolved) == 0) {
		if (((this.tagBits & TagBits.IsArgument) != 0) && this.declaration != null) {
			Annotation[] annotationNodes = this.declaration.annotations;
			if (annotationNodes != null) {
				ASTNode.resolveAnnotations(this.declaringScope, annotationNodes, this, true);
			}
		}
	}
	return sourceType.retrieveAnnotations(this);
}
 
Example #25
Source File: HandleWither.java    From EasyMPermission with MIT License 5 votes vote down vote up
/**
 * Generates a wither on the stated field.
 * 
 * Used by {@link HandleValue}.
 * 
 * The difference between this call and the handle method is as follows:
 * 
 * If there is a {@code lombok.experimental.Wither} annotation on the field, it is used and the
 * same rules apply (e.g. warning if the method already exists, stated access level applies).
 * If not, the wither is still generated if it isn't already there, though there will not
 * be a warning if its already there. The default access level is used.
 */
public void generateWitherForField(EclipseNode fieldNode, EclipseNode sourceNode, AccessLevel level) {
	for (EclipseNode child : fieldNode.down()) {
		if (child.getKind() == Kind.ANNOTATION) {
			if (annotationTypeMatches(Wither.class, child)) {
				//The annotation will make it happen, so we can skip it.
				return;
			}
		}
	}
	
	List<Annotation> empty = Collections.emptyList();
	createWitherForField(level, fieldNode, sourceNode, false, empty, empty);
}
 
Example #26
Source File: AnnotationDiscoveryVisitor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public boolean visit(TypeParameter typeParameter, BlockScope scope) {
	Annotation[] annotations = typeParameter.annotations;
	if (annotations != null) {
		TypeVariableBinding binding = typeParameter.binding;
		if (binding == null) {
			return false;
		}
		// when we get here, it is guaranteed that class type parameters are connected, but method type parameters may not be.			
		MethodBinding methodBinding = (MethodBinding) binding.declaringElement;
		((SourceTypeBinding) methodBinding.declaringClass).resolveTypesFor(methodBinding);
		this.resolveAnnotations(scope, annotations, binding);
	}
	return false;
}
 
Example #27
Source File: EclipseAST.java    From EasyMPermission with MIT License 5 votes vote down vote up
private EclipseNode buildAnnotation(Annotation annotation, boolean field) {
	if (annotation == null) return null;
	boolean handled = setAndGetAsHandled(annotation);
	if (!field && handled) {
		// @Foo int x, y; is handled in eclipse by putting the same annotation node on 2 FieldDeclarations.
		return null;
	}
	return putInMap(new EclipseNode(this, annotation, null, Kind.ANNOTATION));
}
 
Example #28
Source File: HandleEqualsAndHashCode.java    From EasyMPermission with MIT License 5 votes vote down vote up
@Override public void handle(AnnotationValues<EqualsAndHashCode> annotation, Annotation ast, EclipseNode annotationNode) {
	handleFlagUsage(annotationNode, ConfigurationKeys.EQUALS_AND_HASH_CODE_FLAG_USAGE, "@EqualsAndHashCode");
	
	EqualsAndHashCode ann = annotation.getInstance();
	List<String> excludes = Arrays.asList(ann.exclude());
	List<String> includes = Arrays.asList(ann.of());
	EclipseNode typeNode = annotationNode.up();
	
	List<Annotation> onParam = unboxAndRemoveAnnotationParameter(ast, "onParam", "@EqualsAndHashCode(onParam=", annotationNode);
	checkForBogusFieldNames(typeNode, annotation);
	
	Boolean callSuper = ann.callSuper();
	if (!annotation.isExplicit("callSuper")) callSuper = null;
	if (!annotation.isExplicit("exclude")) excludes = null;
	if (!annotation.isExplicit("of")) includes = null;
	
	if (excludes != null && includes != null) {
		excludes = null;
		annotation.setWarning("exclude", "exclude and of are mutually exclusive; the 'exclude' parameter will be ignored.");
	}
	
	Boolean doNotUseGettersConfiguration = annotationNode.getAst().readConfiguration(ConfigurationKeys.EQUALS_AND_HASH_CODE_DO_NOT_USE_GETTERS);
	boolean doNotUseGetters = annotation.isExplicit("doNotUseGetters") || doNotUseGettersConfiguration == null ? ann.doNotUseGetters() : doNotUseGettersConfiguration;
	FieldAccess fieldAccess = doNotUseGetters ? FieldAccess.PREFER_FIELD : FieldAccess.GETTER;
	
	generateMethods(typeNode, annotationNode, excludes, includes, callSuper, true, fieldAccess, onParam);
}
 
Example #29
Source File: SourceTypeBinding.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private static void rejectTypeAnnotatedVoidMethod(AbstractMethodDeclaration methodDecl) {
	Annotation[] annotations = methodDecl.annotations;
	int length = annotations == null ? 0 : annotations.length;
	for (int i = 0; i < length; i++) {
		ReferenceBinding binding = (ReferenceBinding) annotations[i].resolvedType;
		if (binding != null
				&& (binding.tagBits & TagBits.AnnotationForTypeUse) != 0
				&& (binding.tagBits & TagBits.AnnotationForMethod) == 0) {
			methodDecl.scope.problemReporter().illegalUsageOfTypeAnnotations(annotations[i]);
		}
	}
}
 
Example #30
Source File: AnnotationDiscoveryVisitor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public boolean visit(FieldDeclaration fieldDeclaration, MethodScope scope) {
	Annotation[] annotations = fieldDeclaration.annotations;
	if (annotations != null) {
		FieldBinding fieldBinding = fieldDeclaration.binding;
		if (fieldBinding == null) {
			return false;
		}
		((SourceTypeBinding) fieldBinding.declaringClass).resolveTypeFor(fieldBinding);
		this.resolveAnnotations(scope, annotations, fieldBinding);
	}
	return false;
}