Java Code Examples for org.eclipse.jdt.core.dom.IAnnotationBinding#getAnnotationType()

The following examples show how to use org.eclipse.jdt.core.dom.IAnnotationBinding#getAnnotationType() . 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: JdtBasedTypeFactory.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * @since 2.4
 */
protected JvmAnnotationReference createAnnotationReference(/* @NonNull */ IAnnotationBinding annotation) {
	JvmAnnotationReference annotationReference = TypesFactory.eINSTANCE.createJvmAnnotationReference();
	ITypeBinding annotationType = annotation.getAnnotationType();
	annotationReference.setAnnotation(createAnnotationProxy(annotationType));
	InternalEList<JvmAnnotationValue> values = (InternalEList<JvmAnnotationValue>)annotationReference.getExplicitValues();
	IMemberValuePairBinding[] allMemberValuePairs = annotation.getDeclaredMemberValuePairs();
	for (IMemberValuePairBinding memberValuePair : allMemberValuePairs) {
		IMethodBinding methodBinding = memberValuePair.getMethodBinding();
		if (methodBinding != null) {
			try {
				values.addUnique(createAnnotationValue(annotationType, memberValuePair.getValue(), methodBinding));
			} catch(NullPointerException npe) {
				// memberValuePair#getValue may throw an NPE if the methodBinding has no return type
				if (methodBinding.getReturnType() != null) {
					throw npe;
				} else {
					if (log.isDebugEnabled()) {
						log.debug(npe.getMessage(), npe);
					}
				}
			}
		}
	}
	return annotationReference;
}
 
Example 2
Source File: ValidationSuppressionVisitor.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 6 votes vote down vote up
private void processAnnotationBinding(
    IAnnotationBinding resolvedAnnotationBinding) {
  if (resolvedAnnotationBinding != null) {
    ITypeBinding annotationType = resolvedAnnotationBinding.getAnnotationType();
    if (annotationType != null) {
      if (annotationType.getQualifiedName().equals(
          SuppressWarnings.class.getName())) {
        IMemberValuePairBinding[] allMemberValuePairs = resolvedAnnotationBinding.getAllMemberValuePairs();
        for (IMemberValuePairBinding iMemberValuePairBinding : allMemberValuePairs) {
          if (computeSuppressWarning(iMemberValuePairBinding)) {
            suppressValidation = true;
            break;
          }
        }
      }
    }
  }
}
 
Example 3
Source File: TypeAnnotationRewrite.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
private static IAnnotationBinding findTargetAnnotation(IAnnotationBinding[] metaAnnotations) {
	for (int i= 0; i < metaAnnotations.length; i++) {
		IAnnotationBinding binding= metaAnnotations[i];
		ITypeBinding annotationType= binding.getAnnotationType();
		if (annotationType != null && annotationType.getQualifiedName().equals(Target.class.getName())) {
			return binding;
		}
	}
	return null;
}
 
Example 4
Source File: RedundantNullnessTypeAnnotationsFilter.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
public IAnnotationBinding[] removeUnwantedTypeAnnotations(IAnnotationBinding[] annotations, TypeLocation location, ITypeBinding type) {
	if (location == TypeLocation.OTHER) {
		return NO_ANNOTATIONS;
	}
	if(type.isTypeVariable() || type.isWildcardType()) {
		return annotations;
	}
	boolean excludeAllNullAnnotations = NEVER_NULLNESS_LOCATIONS.contains(location);
	if (excludeAllNullAnnotations || fNonNullByDefaultLocations.contains(location)) {
		ArrayList<IAnnotationBinding> list= new ArrayList<>(annotations.length);
		for (IAnnotationBinding annotation : annotations) {
			ITypeBinding annotationType= annotation.getAnnotationType();
			if (annotationType != null) {
				if (annotationType.getQualifiedName().equals(fNonNullAnnotationName)) {
					// ignore @NonNull
				} else if (excludeAllNullAnnotations && annotationType.getQualifiedName().equals(fNullableAnnotationName)) {
					// also ignore @Nullable
				} else {
					list.add(annotation);
				}
			} else {
				list.add(annotation);
			}
		}
		return list.size() == annotations.length ? annotations : list.toArray(new IAnnotationBinding[list.size()]);
	} else {
		return annotations;
	}
}
 
Example 5
Source File: JavaASTUtils.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Returns the fully-qualified name of an annotation, or <code>null</code> if
 * the annotation's type could not be resolved.
 */
public static String getAnnotationTypeName(Annotation annotation) {
  IAnnotationBinding binding = annotation.resolveAnnotationBinding();
  if (binding != null) {
    ITypeBinding annotationTypeBinding = binding.getAnnotationType();
    if (annotationTypeBinding != null) {
      return annotationTypeBinding.getQualifiedName();
    }
  }
  return null;
}
 
Example 6
Source File: InJavaImporter.java    From jdt2famix with Eclipse Public License 1.0 5 votes vote down vote up
public AnnotationInstance createAnnotationInstanceFromAnnotationBinding(NamedEntity entity,
		IAnnotationBinding annotationInstanceBinding) {
	ITypeBinding annotationTypeBinding = annotationInstanceBinding.getAnnotationType();
	AnnotationInstance annotationInstance = new AnnotationInstance();
	annotationInstance.setAnnotatedEntity(entity);
	if (annotationInstanceBinding != null) {
		createAnnotationInstanceFromAnnotationInstanceBinding(annotationInstanceBinding, annotationTypeBinding,
				annotationInstance);
	}
	repository.add(annotationInstance);
	return annotationInstance;
}