org.eclipse.jdt.internal.compiler.lookup.AnnotationBinding Java Examples
The following examples show how to use
org.eclipse.jdt.internal.compiler.lookup.AnnotationBinding.
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: Factory.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
@SuppressWarnings("unchecked") // for cast of newProxyInstance() to A private <A extends Annotation> A[] getAnnotations(AnnotationBinding[] annoInstances, Class<A> annotationClass, boolean justTheFirst) { if(annoInstances == null || annoInstances.length == 0 || annotationClass == null ) return null; String annoTypeName = annotationClass.getName(); if(annoTypeName == null ) return null; List<A> list = new ArrayList<A>(annoInstances.length); for(AnnotationBinding annoInstance : annoInstances) { if (annoInstance == null) continue; AnnotationMirrorImpl annoMirror = createAnnotationMirror(annoTypeName, annoInstance); if (annoMirror != null) { list.add((A)Proxy.newProxyInstance(annotationClass.getClassLoader(), new Class[]{ annotationClass }, annoMirror)); if (justTheFirst) break; } } A [] result = (A[]) Array.newInstance(annotationClass, list.size()); return list.size() > 0 ? (A[]) list.toArray(result) : null; }
Example #2
Source File: ASTNode.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
private static TypeBinding mergeAnnotationsIntoType(BlockScope scope, AnnotationBinding[] se8Annotations, long se8nullBits, Annotation se8NullAnnotation, TypeReference typeRef, TypeBinding existingType) { if (existingType == null || !existingType.isValidBinding()) return existingType; TypeReference unionRef = typeRef.isUnionType() ? ((UnionTypeReference) typeRef).typeReferences[0] : null; // for arrays: @T X[] SE7 associates @T to the type, but in SE8 it affects the leaf component type long prevNullBits = existingType.leafComponentType().tagBits & TagBits.AnnotationNullMASK; if (se8nullBits != 0 && prevNullBits != se8nullBits && ((prevNullBits | se8nullBits) == TagBits.AnnotationNullMASK)) { scope.problemReporter().contradictoryNullAnnotations(se8NullAnnotation); } TypeBinding oldLeafType = (unionRef == null) ? existingType.leafComponentType() : unionRef.resolvedType; AnnotationBinding [][] goodies = new AnnotationBinding[typeRef.getAnnotatableLevels()][]; goodies[0] = se8Annotations; // @T X.Y.Z local; ==> @T should annotate X TypeBinding newLeafType = scope.environment().createAnnotatedType(oldLeafType, goodies); if (unionRef == null) { typeRef.resolvedType = existingType.isArrayType() ? scope.environment().createArrayType(newLeafType, existingType.dimensions(), existingType.getTypeAnnotations()) : newLeafType; } else { unionRef.resolvedType = newLeafType; unionRef.bits |= HasTypeAnnotations; } return typeRef.resolvedType; }
Example #3
Source File: Extractor.java From javaide with GNU General Public License v3.0 | 6 votes |
@SuppressWarnings("unused") static boolean hasSourceRetention(@NonNull AnnotationBinding a) { if (new String(a.getAnnotationType().readableName()).equals("java.lang.annotation.Retention")) { ElementValuePair[] pairs = a.getElementValuePairs(); if (pairs == null || pairs.length != 1) { warning("Expected exactly one parameter passed to @Retention"); return false; } ElementValuePair pair = pairs[0]; Object value = pair.getValue(); if (value instanceof FieldBinding) { FieldBinding field = (FieldBinding) value; if ("SOURCE".equals(new String(field.readableName()))) { return true; } } } return false; }
Example #4
Source File: BindingKeyResolver.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
public void consumeAnnotation() { int size = this.types.size(); if (size == 0) return; Binding annotationType = ((BindingKeyResolver) this.types.get(size-1)).compilerBinding; AnnotationBinding[] annotationBindings; if (this.compilerBinding == null && this.typeBinding instanceof ReferenceBinding) { annotationBindings = ((ReferenceBinding) this.typeBinding).getAnnotations(); } else if (this.compilerBinding instanceof MethodBinding) { annotationBindings = ((MethodBinding) this.compilerBinding).getAnnotations(); } else if (this.compilerBinding instanceof VariableBinding) { annotationBindings = ((VariableBinding) this.compilerBinding).getAnnotations(); } else { return; } for (int i = 0, length = annotationBindings.length; i < length; i++) { AnnotationBinding binding = annotationBindings[i]; if (binding.getAnnotationType() == annotationType) { this.annotationBinding = binding; break; } } }
Example #5
Source File: Factory.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
private AnnotationMirrorImpl createAnnotationMirror(String annoTypeName, AnnotationBinding annoInstance) { ReferenceBinding binding = annoInstance.getAnnotationType(); if (binding != null && binding.isAnnotationType() ) { char[] qName; if (binding.isMemberType()) { annoTypeName = annoTypeName.replace('$', '.'); qName = CharOperation.concatWith(binding.enclosingType().compoundName, binding.sourceName, '.'); CharOperation.replace(qName, '$', '.'); } else { qName = CharOperation.concatWith(binding.compoundName, '.'); } if(annoTypeName.equals(new String(qName)) ){ return (AnnotationMirrorImpl)_env.getFactory().newAnnotationMirror(annoInstance); } } return null; }
Example #6
Source File: EcjParser.java From javaide with GNU General Public License v3.0 | 6 votes |
@NonNull @Override public Iterable<ResolvedAnnotation> getAnnotations() { List<ResolvedAnnotation> compiled = null; AnnotationBinding[] annotations = mBinding.getAnnotations(); int count = annotations.length; if (count > 0) { compiled = Lists.newArrayListWithExpectedSize(count); for (AnnotationBinding annotation : annotations) { if (annotation != null) { compiled.add(new EcjResolvedAnnotation(annotation)); } } } // Look for external annotations ExternalAnnotationRepository manager = ExternalAnnotationRepository.get(mClient); Collection<ResolvedAnnotation> external = manager.getAnnotations(this); return merge(compiled, external); }
Example #7
Source File: EcjParser.java From javaide with GNU General Public License v3.0 | 6 votes |
@NonNull @Override public Iterable<ResolvedAnnotation> getAnnotations() { AnnotationBinding[] annotations = mBinding.getAnnotations(); int count = annotations.length; if (count > 0) { List<ResolvedAnnotation> result = Lists.newArrayListWithExpectedSize(count); for (AnnotationBinding annotation : annotations) { if (annotation != null) { result.add(new EcjResolvedAnnotation(annotation)); } } return result; } // No external annotations for variables return Collections.emptyList(); }
Example #8
Source File: RoundEnvImpl.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
/** * Check whether an element has a superclass that is annotated with an @Inherited annotation. * @param element must be a class (not an interface, enum, etc.). * @param anno must be an annotation type, and must be @Inherited * @return true if element has a superclass that is annotated with anno */ private boolean inheritsAnno(ReferenceBinding element, ReferenceBinding anno) { ReferenceBinding searchedElement = element; do { if (searchedElement instanceof ParameterizedTypeBinding) { searchedElement = ((ParameterizedTypeBinding) searchedElement).genericType(); } AnnotationBinding[] annos = Factory.getPackedAnnotationBindings(searchedElement.getAnnotations()); for (AnnotationBinding annoBinding : annos) { if (annoBinding.getAnnotationType() == anno) { //$IDENTITY-COMPARISON$ // element is annotated with anno return true; } } } while (null != (searchedElement = searchedElement.superclass())); return false; }
Example #9
Source File: AnnotationDiscoveryVisitor.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
private void resolveAnnotations(BlockScope scope, Annotation[] annotations, Binding currentBinding) { int length = annotations == null ? 0 : annotations.length; if (length == 0) return; boolean old = scope.insideTypeAnnotation; scope.insideTypeAnnotation = true; ASTNode.resolveAnnotations(scope, annotations, currentBinding); scope.insideTypeAnnotation = old; ElementImpl element = (ElementImpl) _factory.newElement(currentBinding); AnnotationBinding [] annotationBindings = element.getPackedAnnotationBindings(); // discovery is never in terms of repeating annotation. for (AnnotationBinding binding : annotationBindings) { if (binding != null) { // binding should be resolved, but in case it's not, ignore it: it could have been wrapped into a container. TypeElement anno = (TypeElement)_factory.newElement(binding.getAnnotationType()); _annoToElement.put(anno, element); } } }
Example #10
Source File: EcjParser.java From javaide with GNU General Public License v3.0 | 6 votes |
@NonNull @Override public Iterable<ResolvedAnnotation> getAnnotations() { List<ResolvedAnnotation> compiled = null; AnnotationBinding[] annotations = mBinding.getAnnotationType().getAnnotations(); int count = annotations.length; if (count > 0) { compiled = Lists.newArrayListWithExpectedSize(count); for (AnnotationBinding annotation : annotations) { if (annotation != null) { compiled.add(new EcjResolvedAnnotation(annotation)); } } } // Look for external annotations ExternalAnnotationRepository manager = ExternalAnnotationRepository.get(mClient); Collection<ResolvedAnnotation> external = manager.getAnnotations(this); return merge(compiled, external); }
Example #11
Source File: CompilationUnitResolver.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
private void reportBinding(Object key, FileASTRequestor astRequestor, CompilationUnitDeclaration unit) { BindingKeyResolver keyResolver = (BindingKeyResolver) key; Binding compilerBinding = keyResolver.getCompilerBinding(); if (compilerBinding != null) { DefaultBindingResolver resolver = new DefaultBindingResolver(unit.scope, null, this.bindingTables, false, this.fromJavaProject); AnnotationBinding annotationBinding = keyResolver.getAnnotationBinding(); IBinding binding; if (annotationBinding != null) { binding = resolver.getAnnotationInstance(annotationBinding); } else { binding = resolver.getBinding(compilerBinding); } if (binding != null) astRequestor.acceptBinding(keyResolver.getKey(), binding); } }
Example #12
Source File: CompilationUnitResolver.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
private void reportBinding(Object key, ASTRequestor astRequestor, WorkingCopyOwner owner, CompilationUnitDeclaration unit) { BindingKeyResolver keyResolver = (BindingKeyResolver) key; Binding compilerBinding = keyResolver.getCompilerBinding(); if (compilerBinding != null) { DefaultBindingResolver resolver = new DefaultBindingResolver(unit.scope, owner, this.bindingTables, false, this.fromJavaProject); AnnotationBinding annotationBinding = keyResolver.getAnnotationBinding(); IBinding binding; if (annotationBinding != null) { binding = resolver.getAnnotationInstance(annotationBinding); } else { binding = resolver.getBinding(compilerBinding); } if (binding != null) astRequestor.acceptBinding(keyResolver.getKey(), binding); } }
Example #13
Source File: PatchDelegate.java From EasyMPermission with MIT License | 6 votes |
private static void failIfContainsAnnotation(TypeBinding parent, Binding[] bindings) throws DelegateRecursion { if (bindings == null) return; for (Binding b : bindings) { AnnotationBinding[] anns = null; if (b instanceof MethodBinding) anns = ((MethodBinding) b).getAnnotations(); if (b instanceof FieldBinding) anns = ((FieldBinding) b).getAnnotations(); // anns = b.getAnnotations() would make a heck of a lot more sense, but that is a late addition to ecj, so would cause NoSuchMethodErrors! Don't use that! if (anns == null) continue; for (AnnotationBinding ann : anns) { char[][] name = null; try { name = ann.getAnnotationType().compoundName; } catch (Exception ignore) {} if (name == null || name.length < 2 || name.length > 3) continue; if (!Arrays.equals(STRING_LOMBOK, name[0])) continue; if (!Arrays.equals(STRING_DELEGATE, name[name.length - 1])) continue; if (name.length == 3 && !Arrays.equals(STRING_EXPERIMENTAL, name[1])) continue; throw new DelegateRecursion(parent.readableName(), b.readableName()); } } }
Example #14
Source File: Factory.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
public PrimitiveTypeImpl getPrimitiveType(BaseTypeBinding binding) { AnnotationBinding[] annotations = binding.getTypeAnnotations(); if (annotations == null || annotations.length == 0) { return getPrimitiveType(PrimitiveTypeImpl.getKind(binding)); } return new PrimitiveTypeImpl(_env, binding); }
Example #15
Source File: AnnotationMirrorImpl.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
private static boolean equals(AnnotationBinding annotationBinding, AnnotationBinding annotationBinding2) { if (annotationBinding.getAnnotationType() != annotationBinding2.getAnnotationType()) return false; //$IDENTITY-COMPARISON$ final ElementValuePair[] elementValuePairs = annotationBinding.getElementValuePairs(); final ElementValuePair[] elementValuePairs2 = annotationBinding2.getElementValuePairs(); final int length = elementValuePairs.length; if (length != elementValuePairs2.length) return false; loop: for (int i = 0; i < length; i++) { ElementValuePair pair = elementValuePairs[i]; // loop on the given pair to make sure one will match for (int j = 0; j < length; j++) { ElementValuePair pair2 = elementValuePairs2[j]; if (pair.binding == pair2.binding) { if (pair.value == null) { if (pair2.value == null) { continue loop; } return false; } else { if (pair2.value == null) return false; if (pair2.value instanceof Object[] && pair.value instanceof Object[]) { if (!Arrays.equals((Object[]) pair.value, (Object[]) pair2.value)) { return false; } } else if (!pair2.value.equals(pair.value)){ return false; } } continue loop; } } return false; } return true; }
Example #16
Source File: TypeParameterElementImpl.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
private boolean shouldEmulateJavacBug() { if (_env.getLookupEnvironment().globalOptions.emulateJavacBug8031744) { AnnotationBinding [] annotations = getAnnotationBindings(); for (int i = 0, length = annotations.length; i < length; i++) { ReferenceBinding firstAnnotationType = annotations[i].getAnnotationType(); for (int j = i+1; j < length; j++) { ReferenceBinding secondAnnotationType = annotations[j].getAnnotationType(); if (firstAnnotationType == secondAnnotationType) //$IDENTITY-COMPARISON$ return true; } } } return false; }
Example #17
Source File: ArrayTypeImpl.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
protected AnnotationBinding[] getAnnotationBindings() { AnnotationBinding[] oldies = ((ArrayBinding)_binding).getTypeAnnotations(); AnnotationBinding[] newbies = Binding.NO_ANNOTATIONS; // Strip out the annotations on sub arrays for (int i = 0, length = oldies == null ? 0 : oldies.length; i < length; i++) { if (oldies[i] == null) { System.arraycopy(oldies, 0, newbies = new AnnotationBinding[i], 0, i); return newbies; } } return newbies; }
Example #18
Source File: PackageElementImpl.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
@Override protected AnnotationBinding[] getAnnotationBindings() { PackageBinding packageBinding = (PackageBinding) this._binding; char[][] compoundName = CharOperation.arrayConcat(packageBinding.compoundName, TypeConstants.PACKAGE_INFO_NAME); ReferenceBinding type = this._env.getLookupEnvironment().getType(compoundName); AnnotationBinding[] annotations = null; if (type != null && type.isValidBinding()) { annotations = type.getAnnotations(); } return annotations; }
Example #19
Source File: Factory.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
/** * Convert an array of compiler annotation bindings into a list of AnnotationMirror * @return a non-null, possibly empty, unmodifiable list. */ public List<? extends AnnotationMirror> getAnnotationMirrors(AnnotationBinding[] annotations) { if (null == annotations || 0 == annotations.length) { return Collections.emptyList(); } List<AnnotationMirror> list = new ArrayList<AnnotationMirror>(annotations.length); for (AnnotationBinding annotation : annotations) { if (annotation == null) continue; list.add(newAnnotationMirror(annotation)); } return Collections.unmodifiableList(list); }
Example #20
Source File: LambdaExpression.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
private void mergeParameterNullAnnotations(BlockScope currentScope) { LookupEnvironment env = currentScope.environment(); TypeBinding[] ourParameters = this.binding.parameters; TypeBinding[] descParameters = this.descriptor.parameters; int len = Math.min(ourParameters.length, descParameters.length); for (int i = 0; i < len; i++) { long ourTagBits = ourParameters[i].tagBits & TagBits.AnnotationNullMASK; long descTagBits = descParameters[i].tagBits & TagBits.AnnotationNullMASK; if (ourTagBits == 0L) { if (descTagBits != 0L && !ourParameters[i].isBaseType()) { AnnotationBinding [] annotations = descParameters[i].getTypeAnnotations(); for (int j = 0, length = annotations.length; j < length; j++) { AnnotationBinding annotation = annotations[j]; if (annotation != null) { switch (annotation.getAnnotationType().id) { case TypeIds.T_ConfiguredAnnotationNullable : case TypeIds.T_ConfiguredAnnotationNonNull : ourParameters[i] = env.createAnnotatedType(ourParameters[i], new AnnotationBinding [] { annotation }); break; } } } } } else if (ourTagBits != descTagBits) { if (ourTagBits == TagBits.AnnotationNonNull) { // requested @NonNull not provided char[][] inheritedAnnotationName = null; if (descTagBits == TagBits.AnnotationNullable) inheritedAnnotationName = env.getNullableAnnotationName(); currentScope.problemReporter().illegalRedefinitionToNonNullParameter(this.arguments[i], this.descriptor.declaringClass, inheritedAnnotationName); } } } }
Example #21
Source File: ASTNode.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
/** Resolve JSR308 annotations on a type reference, array creation expression or a wildcard. Type parameters go directly to the subroutine, By construction the bindings associated with QTR, PQTR etc get resolved first and then annotations for different levels get resolved and applied at one go. Likewise for multidimensional arrays. @Returns the annotated type binding. */ public static TypeBinding resolveAnnotations(BlockScope scope, Annotation[][] sourceAnnotations, TypeBinding type) { int levels = sourceAnnotations == null ? 0 : sourceAnnotations.length; if (type == null || levels == 0) return type; AnnotationBinding [][] annotationBindings = new AnnotationBinding [levels][]; for (int i = 0; i < levels; i++) { Annotation[] annotations = sourceAnnotations[i]; if (annotations != null && annotations.length > 0) { annotationBindings[i] = resolveAnnotations(scope, annotations, TypeBinding.TYPE_USE_BINDING, false); } } return scope.environment().createAnnotatedType(type, annotationBindings); }
Example #22
Source File: EcjParser.java From javaide with GNU General Public License v3.0 | 5 votes |
@NonNull @Override public Iterable<ResolvedAnnotation> getAnnotations() { List<ResolvedAnnotation> all = Lists.newArrayListWithExpectedSize(2); AnnotationBinding[] annotations = mBinding.getAnnotations(); int count = annotations.length; if (count == 0) { Binding pkgInfo = mBinding.getTypeOrPackage(PACKAGE_INFO_CHARS); if (pkgInfo != null) { annotations = pkgInfo.getAnnotations(); } count = annotations.length; } if (count > 0) { for (AnnotationBinding annotation : annotations) { if (annotation != null) { all.add(new EcjResolvedAnnotation(annotation)); } } } // Merge external annotations ExternalAnnotationRepository manager = ExternalAnnotationRepository.get(mClient); Collection<ResolvedAnnotation> external = manager.getAnnotations(this); if (external != null) { all.addAll(external); } return all; }
Example #23
Source File: EcjParser.java From javaide with GNU General Public License v3.0 | 5 votes |
@NonNull @Override public Iterable<ResolvedAnnotation> getParameterAnnotations(int index) { List<ResolvedAnnotation> all = Lists.newArrayListWithExpectedSize(4); ExternalAnnotationRepository manager = ExternalAnnotationRepository.get(mClient); MethodBinding binding = this.mBinding; while (binding != null) { AnnotationBinding[][] parameterAnnotations = binding.getParameterAnnotations(); if (parameterAnnotations != null && index >= 0 && index < parameterAnnotations.length) { AnnotationBinding[] annotations = parameterAnnotations[index]; int count = annotations.length; if (count > 0) { for (AnnotationBinding annotation : annotations) { if (annotation != null) { all.add(new EcjResolvedAnnotation(annotation)); } } } } // Look for external annotations Collection<ResolvedAnnotation> external = manager.getAnnotations( new EcjResolvedMethod(binding), index); if (external != null) { all.addAll(external); } binding = findSuperMethodBinding(binding); } return all; }
Example #24
Source File: EcjParser.java From javaide with GNU General Public License v3.0 | 5 votes |
@NonNull @Override public Iterable<ResolvedAnnotation> getAnnotations() { List<ResolvedAnnotation> all = Lists.newArrayListWithExpectedSize(4); ExternalAnnotationRepository manager = ExternalAnnotationRepository.get(mClient); MethodBinding binding = this.mBinding; while (binding != null) { AnnotationBinding[] annotations = binding.getAnnotations(); int count = annotations.length; if (count > 0) { for (AnnotationBinding annotation : annotations) { if (annotation != null) { all.add(new EcjResolvedAnnotation(annotation)); } } } // Look for external annotations Collection<ResolvedAnnotation> external = manager.getAnnotations( new EcjResolvedMethod(binding)); if (external != null) { all.addAll(external); } binding = findSuperMethodBinding(binding); } return all; }
Example #25
Source File: TypeParameter.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
public void resolveAnnotations(Scope scope) { BlockScope resolutionScope = Scope.typeAnnotationsResolutionScope(scope); if (resolutionScope != null) { AnnotationBinding [] annotationBindings = resolveAnnotations(resolutionScope, this.annotations, this.binding, false); if (annotationBindings != null && annotationBindings.length > 0) { this.binding.setTypeAnnotations(annotationBindings, scope.environment().globalOptions.isAnnotationBasedNullAnalysisEnabled); scope.referenceCompilationUnit().compilationResult.hasAnnotations = true; if (this.binding != null && this.binding.isValidBinding()) this.binding.evaluateNullAnnotations(scope, this); } } }
Example #26
Source File: ElementImpl.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
public final AnnotationBinding [] getPackedAnnotationBindings() { return Factory.getPackedAnnotationBindings(getAnnotationBindings()); }
Example #27
Source File: TypeParameterElementImpl.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
@Override protected AnnotationBinding[] getAnnotationBindings() { return ((TypeVariableBinding)_binding).getTypeAnnotations(); }
Example #28
Source File: VariableElementImpl.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
@Override protected AnnotationBinding[] getAnnotationBindings() { return ((VariableBinding)_binding).getAnnotations(); }
Example #29
Source File: TypeElementImpl.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
@Override protected AnnotationBinding[] getAnnotationBindings() { return ((ReferenceBinding)_binding).getAnnotations(); }
Example #30
Source File: ExecutableElementImpl.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
@Override protected AnnotationBinding[] getAnnotationBindings() { return ((MethodBinding)_binding).getAnnotations(); }