org.eclipse.jdt.internal.compiler.apt.model.TypeElementImpl Java Examples

The following examples show how to use org.eclipse.jdt.internal.compiler.apt.model.TypeElementImpl. 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: RoundEnvImpl.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * From the set of root elements and their enclosed elements, return the subset that are annotated
 * with {@code a}.  If {@code a} is annotated with the {@link java.lang.annotation.Inherited} 
 * annotation, include those elements that inherit the annotation from their superclasses.
 * Note that {@link java.lang.annotation.Inherited} only applies to classes (i.e. TypeElements).
 */
@Override
public Set<? extends Element> getElementsAnnotatedWith(TypeElement a)
{
	if (a.getKind() != ElementKind.ANNOTATION_TYPE) {
		throw new IllegalArgumentException("Argument must represent an annotation type"); //$NON-NLS-1$
	}
	Binding annoBinding = ((TypeElementImpl)a)._binding;
	if (0 != (annoBinding.getAnnotationTagBits() & TagBits.AnnotationInherited)) {
		Set<Element> annotatedElements = new HashSet<Element>(_annoToUnit.getValues(a));
		// For all other root elements that are TypeElements, and for their recursively enclosed
		// types, add each element if it has a superclass are annotated with 'a'
		ReferenceBinding annoTypeBinding = (ReferenceBinding) annoBinding;
		for (TypeElement element : ElementFilter.typesIn(getRootElements())) {
			ReferenceBinding typeBinding = (ReferenceBinding)((TypeElementImpl)element)._binding;
			addAnnotatedElements(annoTypeBinding, typeBinding, annotatedElements);
		}
		return Collections.unmodifiableSet(annotatedElements);
	}
	return Collections.unmodifiableSet(_annoToUnit.getValues(a));
}
 
Example #2
Source File: AnnotationProcessorManager.java    From takari-lifecycle with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Given {@code Element}, returns source file that defines the element. Returns {@code null} if the element is not defined in a source file.
 */
private File getSourceFile(ElementImpl element) {
  TypeElementImpl topLevelType = getTopLevelType(element);
  if (topLevelType == null) {
    // TODO package-info.java annotation?
    return null;
  }
  Binding binding = topLevelType._binding;
  if (binding instanceof SourceTypeBinding) {
    return new File(new String(((SourceTypeBinding) binding).getFileName()));
  }
  return null;
}
 
Example #3
Source File: AnnotationProcessorManager.java    From takari-lifecycle with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Returns enclosing top-level type of the element. Returns {@code null} if the element does not have enclosing top-level type.
 */
private TypeElementImpl getTopLevelType(ElementImpl element) {
  for (; element != null; element = (ElementImpl) element.getEnclosingElement()) {
    if (element instanceof TypeElementImpl && ((TypeElementImpl) element).getNestingKind() == NestingKind.TOP_LEVEL) {
      return (TypeElementImpl) element;
    }
  }
  return null;
}
 
Example #4
Source File: SourceExtraction.java    From immutables with Apache License 2.0 5 votes vote down vote up
public static String getSuperclassString(TypeElement element) {
  if (Compiler.ECJ.isPresent()) {
    if (element instanceof TypeElementImpl) {
      TypeElementImpl elementImpl = ((TypeElementImpl) element);
      if (elementImpl._binding instanceof SourceTypeBinding) {
        return EclipseSourceExtractor.extractSuperclass((SourceTypeBinding) elementImpl._binding).toString();
      }
    }
  }
  return element.getSuperclass().toString();
}