javax.lang.model.element.TypeElement#getInterfaces ( )源码实例Demo

下面列出了javax.lang.model.element.TypeElement#getInterfaces ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: TencentKona-8   文件: TypeModeler.java
public static TypeElement getDeclaringClassMethod(TypeElement theClass, String methodName, TypeMirror[] args) {

        TypeElement retClass = null;
        if (theClass.getKind().equals(ElementKind.CLASS)) {
            TypeMirror superClass = theClass.getSuperclass();
            if (!superClass.getKind().equals(TypeKind.NONE))
                retClass = getDeclaringClassMethod(superClass, methodName, args);
        }
        if (retClass == null) {
            for (TypeMirror interfaceType : theClass.getInterfaces()) {
                retClass = getDeclaringClassMethod(interfaceType, methodName, args);
            }
        }
        if (retClass == null) {
            Collection<? extends ExecutableElement> methods = ElementFilter.methodsIn(theClass.getEnclosedElements());
            for (ExecutableElement method : methods) {
                if (method.getSimpleName().toString().equals(methodName)) {
                    retClass = theClass;
                    break;
                }
            }
        }
        return retClass;
    }
 
源代码2 项目: data-mediator   文件: OutInterfaceManager.java
/**
 * get the super interface flags for parent
 * @param te the current type element
 * @param pp the log printer
 * @return the flags.
 */
public static int getSuperInterfaceFlagForParent(TypeElement te,
                                                 Elements mElements, Types types, ProcessorPrinter pp){
    final String tag = te.getSimpleName().toString();
    List<? extends TypeMirror> interfaces = te.getInterfaces();
    for(TypeMirror tm: interfaces) {
        // pp.note(TAG, "getSuperInteraceFlagForParent_" + tag, "TypeMirror : " + tm);
        FieldData.TypeCompat tc = new FieldData.TypeCompat(types, tm);
        tc.replaceIfNeed(mElements, pp);
        pp.note(TAG, "getSuperInteraceFlagForParent_" + tag, "TypeMirror : " + tm
                + " , hasAnnotationFields = " + tc.hasAnnotationFields());
        if(tc.hasAnnotationFields()){
            //we want.
            int sum = 0;
            final Set<Integer> flags = getSuperInterfaceFlags(tag,
                    tc.getElementAsType(), types, pp);
            for(Integer val : flags){
                sum += val;
            }
            return sum;
        }
    }
    return 0;
}
 
源代码3 项目: openjdk-jdk8u-backup   文件: WebServiceVisitor.java
protected boolean classImplementsSei(TypeElement classElement, TypeElement interfaceElement) {
    for (TypeMirror interfaceType : classElement.getInterfaces()) {
        if (((DeclaredType) interfaceType).asElement().equals(interfaceElement))
            return true;
    }
    List<ExecutableElement> classMethods = getClassMethods(classElement);
    boolean implementsMethod;
    for (ExecutableElement interfaceMethod : ElementFilter.methodsIn(interfaceElement.getEnclosedElements())) {
        implementsMethod = false;
        for (ExecutableElement classMethod : classMethods) {
            if (sameMethod(interfaceMethod, classMethod)) {
                implementsMethod = true;
                classMethods.remove(classMethod);
                break;
            }
        }
        if (!implementsMethod) {
            builder.processError(WebserviceapMessages.WEBSERVICEAP_METHOD_NOT_IMPLEMENTED(interfaceElement.getSimpleName(), classElement.getSimpleName(), interfaceMethod), interfaceMethod);
            return false;
        }
    }
    return true;
}
 
@Override
public Set<FieldData> getDependFields(TypeElement te) {
    Set<FieldData> list = new HashSet<>();

    List<? extends AnnotationMirror> mirrors = te.getAnnotationMirrors();
    AnnotationMirror expect = null;
    for(AnnotationMirror am : mirrors){
        DeclaredType type = am.getAnnotationType();
        if(type.toString().equals(Fields.class.getName())){
            expect = am;
            break;
        }
    }
    if(expect != null){
        ElementHelper.parseFields(elements, types, expect, list, pp);
    }
    //a depend b, b depend c ,,, etc.
    List<? extends TypeMirror> superInterfaces = te.getInterfaces();
    for(TypeMirror tm : superInterfaces){
        final TypeElement newTe = (TypeElement) ((DeclaredType) tm).asElement();
        list.addAll(getDependFields(newTe)); //recursion
    }
    return list;
}
 
源代码5 项目: javaide   文件: PrintingProcessor.java
private void printInterfaces(TypeElement e) {
    ElementKind kind = e.getKind();

    if(kind != ANNOTATION_TYPE) {
        List<? extends TypeMirror> interfaces = e.getInterfaces();
        if (interfaces.size() > 0) {
            writer.print((kind.isClass() ? " implements" : " extends"));

            boolean first = true;
            for(TypeMirror interf: interfaces) {
                if (!first)
                    writer.print(",");
                writer.print(" ");
                writer.print(interf.toString());
                first = false;
            }
        }
    }
}
 
源代码6 项目: helidon-build-tools   文件: Visitor.java
private boolean implementsCommandExecution(TypeElement type) {
    for (TypeMirror iface : type.getInterfaces()) {
        TypeElement ifaceTypeElt = (TypeElement) env.getTypeUtils().asElement(iface);
        if (CommandExecution.class.getName().equals(ifaceTypeElt.getQualifiedName().toString())) {
            return true;
        }
    }
    TypeMirror parent = type.getSuperclass();
    if (parent != null) {
        return implementsCommandExecution((TypeElement) env.getTypeUtils().asElement(parent));
    }
    env.getMessager().printMessage(Diagnostic.Kind.ERROR,
            String.format("%s does not implement %s", type, CommandExecution.class.getSimpleName()),
            type);
    return false;
}
 
源代码7 项目: hottub   文件: WebServiceVisitor.java
protected boolean classImplementsSei(TypeElement classElement, TypeElement interfaceElement) {
    for (TypeMirror interfaceType : classElement.getInterfaces()) {
        if (((DeclaredType) interfaceType).asElement().equals(interfaceElement))
            return true;
    }
    List<ExecutableElement> classMethods = getClassMethods(classElement);
    boolean implementsMethod;
    for (ExecutableElement interfaceMethod : ElementFilter.methodsIn(interfaceElement.getEnclosedElements())) {
        implementsMethod = false;
        for (ExecutableElement classMethod : classMethods) {
            if (sameMethod(interfaceMethod, classMethod)) {
                implementsMethod = true;
                classMethods.remove(classMethod);
                break;
            }
        }
        if (!implementsMethod) {
            builder.processError(WebserviceapMessages.WEBSERVICEAP_METHOD_NOT_IMPLEMENTED(interfaceElement.getSimpleName(), classElement.getSimpleName(), interfaceMethod), interfaceMethod);
            return false;
        }
    }
    return true;
}
 
源代码8 项目: spring-init   文件: ElementUtils.java
public boolean implementsInterface(TypeElement te, ClassName intface) {
	if (te == null) {
		return false;
	}
	if (ClassName.get(te).equals(intface)) {
		return true;
	}
	for (TypeMirror t : te.getInterfaces()) {
		boolean b = implementsInterface((TypeElement) asElement(t), intface);
		if (b) {
			return true;
		}
	}
	TypeMirror superclass = te.getSuperclass();
	if (superclass == null) {
		return false;
	}
	return implementsInterface((TypeElement) asElement(superclass), intface);
}
 
源代码9 项目: openjdk-jdk9   文件: HtmlDocletWriter.java
/**
 * Add method information.
 *
 * @param method the method to be documented
 * @param dl the content tree to which the method information will be added
 */
private void addMethodInfo(ExecutableElement method, Content dl) {
    TypeElement enclosing = utils.getEnclosingTypeElement(method);
    List<? extends TypeMirror> intfacs = enclosing.getInterfaces();
    ExecutableElement overriddenMethod = utils.overriddenMethod(method);
    // Check whether there is any implementation or overridden info to be
    // printed. If no overridden or implementation info needs to be
    // printed, do not print this section.
    if ((!intfacs.isEmpty()
            && new ImplementedMethods(method, this.configuration).build().isEmpty() == false)
            || overriddenMethod != null) {
        MethodWriterImpl.addImplementsInfo(this, method, dl);
        if (overriddenMethod != null) {
            MethodWriterImpl.addOverridden(this,
                    utils.overriddenType(method),
                    overriddenMethod,
                    dl);
        }
    }
}
 
源代码10 项目: netbeans   文件: JavaOperationsImpl.java
@NonNull
@Override
public final Collection<? extends String> getInterfaces(@NonNull final String cls) throws QueryException {
    final TypeElement te = findClass(cls);
    if (te == null) {
        return null;
    }
    final List<? extends TypeMirror> interfaceTypes = te.getInterfaces();
    final List<String> result = new ArrayList<String>(interfaceTypes.size());
    for (TypeMirror tm : interfaceTypes) {
        if (tm.getKind() == TypeKind.DECLARED) {
            result.add(
                ((TypeElement)((DeclaredType)tm).asElement()).getQualifiedName().toString());
        }
    }
    return Collections.unmodifiableCollection(result);
}
 
源代码11 项目: droitatedDB   文件: EntityAnnotationProcessor.java
private String getHookName(final RoundEnvironment roundEnv, Class<? extends Annotation> hookAnnotation, Class<?> hookInterface) {
	Set<? extends Element> annotated = roundEnv.getElementsAnnotatedWith(hookAnnotation);
	if (annotated.size() == 0) {
		return null;
	}
	if (annotated.size() > 1) {
           messager.printMessage(Kind.ERROR,
                   "Only one " + hookAnnotation.getCanonicalName() + " hook is allowed with the project", annotated.iterator().next());
		return null;
	}
	Element updateElement = annotated.iterator().next();
	TypeElement typeElement = updateElement.accept(new TypeResolvingVisitor(), null);
	boolean implementsDbUpdate = false;
	for (TypeMirror typeMirror : typeElement.getInterfaces()) {
		if (typeMirror.toString().equals(hookInterface.getCanonicalName())) {
			implementsDbUpdate = true;
		}
	}
	if (!implementsDbUpdate) {
           messager.printMessage(Kind.ERROR,
                   "The " + hookAnnotation + " hook has to implement the " + hookInterface.getCanonicalName() + " interface", updateElement);
		return null;
	}
	return typeElement.getQualifiedName().toString();
}
 
源代码12 项目: j2objc   文件: SignatureGenerator.java
/**
 * ClassSignature ::=
 *   OptFormalTypeParameters SuperclassSignature {SuperinterfaceSignature}.
 */
private void genClassSignature(TypeElement type, StringBuilder sb) {
  genOptFormalTypeParameters(type.getTypeParameters(), sb);
  // JDT returns null for an interface's superclass, but signatures expect Object.
  if (type.getKind().isInterface()) {
    sb.append(JAVA_OBJECT_SIGNATURE);
  } else {
    genTypeSignature(type.getSuperclass(), sb);
  }
  for (TypeMirror intrface : type.getInterfaces()) {
    genTypeSignature(intrface, sb);
  }
}
 
源代码13 项目: netbeans   文件: SerializableClass.java
private static boolean extendsFromSerializable(TypeElement subject) {
    for (TypeMirror iface : subject.getInterfaces()) {
        if ("java.io.Serializable".equals(iface.toString())) { //NOI18N
            return true;
        } else if (iface instanceof DeclaredType) {
            DeclaredType iType = (DeclaredType) iface;
            if (extendsFromSerializable((TypeElement) iType.asElement())) {
                return true;
            }
        }
    }
    return false;
}
 
源代码14 项目: vault   文件: Processor.java
private boolean isSubtypeOfType(TypeMirror typeMirror, String otherType) {
  if (otherType.equals(typeMirror.toString())) {
    return true;
  }
  if (!(typeMirror instanceof DeclaredType)) {
    return false;
  }
  DeclaredType declaredType = (DeclaredType) typeMirror;
  List<? extends TypeMirror> typeArguments = declaredType.getTypeArguments();
  if (typeArguments.size() > 0) {
    StringBuilder typeString = new StringBuilder(declaredType.asElement().toString());
    typeString.append('<');
    for (int i = 0; i < typeArguments.size(); i++) {
      if (i > 0) {
        typeString.append(',');
      }
      typeString.append('?');
    }
    typeString.append('>');
    if (typeString.toString().equals(otherType)) {
      return true;
    }
  }
  Element element = declaredType.asElement();
  if (!(element instanceof TypeElement)) {
    return false;
  }
  TypeElement typeElement = (TypeElement) element;
  TypeMirror superType = typeElement.getSuperclass();
  if (isSubtypeOfType(superType, otherType)) {
    return true;
  }
  for (TypeMirror interfaceType : typeElement.getInterfaces()) {
    if (isSubtypeOfType(interfaceType, otherType)) {
      return true;
    }
  }
  return false;
}
 
源代码15 项目: auto   文件: Overrides.java
private ImmutableList<TypeElement> superinterfaces(TypeElement type) {
  ImmutableList.Builder<TypeElement> types = ImmutableList.builder();
  for (TypeMirror sup : type.getInterfaces()) {
    types.add(MoreElements.asType(typeUtils.asElement(sup)));
  }
  return types.build();
}
 
源代码16 项目: openjdk-jdk8u-backup   文件: TypeModeler.java
public static Collection<DeclaredType> collectInterfaces(TypeElement type) {
    @SuppressWarnings({"unchecked"})
    Collection<DeclaredType> interfaces = (Collection<DeclaredType>) type.getInterfaces();
    for (TypeMirror interfaceType : type.getInterfaces()) {
        interfaces.addAll(collectInterfaces(getDeclaration(interfaceType)));
    }
    return interfaces;
}
 
源代码17 项目: openjdk-8   文件: TypeModeler.java
public static Collection<DeclaredType> collectInterfaces(TypeElement type) {
    @SuppressWarnings({"unchecked"})
    Collection<DeclaredType> interfaces = (Collection<DeclaredType>) type.getInterfaces();
    for (TypeMirror interfaceType : type.getInterfaces()) {
        interfaces.addAll(collectInterfaces(getDeclaration(interfaceType)));
    }
    return interfaces;
}
 
源代码18 项目: butterknife   文件: ButterKnifeProcessor.java
static boolean isSubtypeOfType(TypeMirror typeMirror, String otherType) {
  if (isTypeEqual(typeMirror, otherType)) {
    return true;
  }
  if (typeMirror.getKind() != TypeKind.DECLARED) {
    return false;
  }
  DeclaredType declaredType = (DeclaredType) typeMirror;
  List<? extends TypeMirror> typeArguments = declaredType.getTypeArguments();
  if (typeArguments.size() > 0) {
    StringBuilder typeString = new StringBuilder(declaredType.asElement().toString());
    typeString.append('<');
    for (int i = 0; i < typeArguments.size(); i++) {
      if (i > 0) {
        typeString.append(',');
      }
      typeString.append('?');
    }
    typeString.append('>');
    if (typeString.toString().equals(otherType)) {
      return true;
    }
  }
  Element element = declaredType.asElement();
  if (!(element instanceof TypeElement)) {
    return false;
  }
  TypeElement typeElement = (TypeElement) element;
  TypeMirror superType = typeElement.getSuperclass();
  if (isSubtypeOfType(superType, otherType)) {
    return true;
  }
  for (TypeMirror interfaceType : typeElement.getInterfaces()) {
    if (isSubtypeOfType(interfaceType, otherType)) {
      return true;
    }
  }
  return false;
}
 
源代码19 项目: netbeans   文件: ElementScanningTask.java
private String createHtmlHeader(CompilationInfo info, TypeElement e, boolean isDeprecated, boolean isInherited, boolean fqn) {

        StringBuilder sb = new StringBuilder();            
        if ( isDeprecated ) {
            sb.append("<s>"); // NOI18N
        }
        if( isInherited ) {
            sb.append( "<font color=" + ui.getInheritedColor() + ">" ); // NOI18N
        }
        sb.append(Utils.escape(
            fqn?
            e.getQualifiedName().toString():
            e.getSimpleName().toString()));
        if ( isDeprecated ) {
            sb.append("</s>"); // NOI18N
        }
        // sb.append(print(info, e.asType()));
        List<? extends TypeParameterElement> typeParams = e.getTypeParameters();

        //System.out.println("Element " + e + "type params" + typeParams.size() );

        if ( typeParams != null && !typeParams.isEmpty() ) {
            sb.append("&lt;"); // NOI18N

            for( Iterator<? extends TypeParameterElement> it = typeParams.iterator(); it.hasNext(); ) {
                TypeParameterElement tp = it.next();
                sb.append( Utils.escape(tp.getSimpleName().toString()) );                    
                try { // XXX Verry ugly -> file a bug against Javac?
                    List<? extends TypeMirror> bounds = tp.getBounds();
                    //System.out.println( tp.getSimpleName() + "   bounds size " + bounds.size() );
                    if ( !bounds.isEmpty() ) {
                        sb.append(printBounds(info, bounds, fqn));
                    }
                }
                catch ( NullPointerException npe ) {
                    System.err.println("El " + e );
                    npe.printStackTrace();
                }                    
                if ( it.hasNext() ) {
                    sb.append(", "); // NOI18N
                }
            }

            sb.append("&gt;"); // NOI18N
        }

        // Add superclass and implemented interfaces

        TypeMirror sc = e.getSuperclass();
        String scName = print(info, sc, fqn);

        if ( sc == null || 
             e.getKind() == ElementKind.ENUM ||
             e.getKind() == ElementKind.ANNOTATION_TYPE ||
             "Object".equals(scName) || // NOI18N
             "<none>".equals(scName)) { // NOI18N
            scName = null;
        }

        List<? extends TypeMirror> ifaces = e.getInterfaces();

        if ( ( scName != null || !ifaces.isEmpty() ) &&
              e.getKind() != ElementKind.ANNOTATION_TYPE ) {
            sb.append( " :: " ); // NOI18N
            if (scName != null) {                
                sb.append( "<font color=" + ui.getTypeColor() + ">" ); // NOI18N
                sb.append( scName );
                sb.append("</font>"); // NOI18N
            }
            if ( !ifaces.isEmpty() ) {
                if ( scName != null ) {
                    sb.append( " : " ); // NOI18N
                }
                for (Iterator<? extends TypeMirror> it = ifaces.iterator(); it.hasNext();) {
                    TypeMirror typeMirror = it.next();
                    sb.append( "<font color=" + ui.getTypeColor() + ">" ); // NOI18N
                    sb.append( print(info, typeMirror, fqn) );
                    sb.append("</font>"); // NOI18N
                    if ( it.hasNext() ) {
                        sb.append(", "); // NOI18N
                    }
                }

            }
        }

        return sb.toString();            
    }
 
源代码20 项目: reflection-no-reflection   文件: Processor.java
private Class createClass(TypeMirror typeMirror, int level) {
    Class result;
    String className = null;
    boolean isPrimitive = false;
    boolean isArray = false;
    boolean isInterface = false;
    Class component = null;
    Class superClass = null;
    GenericDeclarationImpl declaration = null;
    Class[] superInterfaces = null;

    if (typeMirror instanceof DeclaredType) {
        DeclaredType declaredType = (DeclaredType) typeMirror;
        className = ((TypeElement) declaredType.asElement()).getQualifiedName().toString();
        if (!declaredType.getTypeArguments().isEmpty()) {
            declaration = new GenericDeclarationImpl();
            TypeVariable[] typesVariables = new TypeVariable[declaredType.getTypeArguments().size()];
            int index = 0;
            for (TypeMirror mirror : declaredType.getTypeArguments()) {
                TypeVariableImpl typeVariableImpl = new TypeVariableImpl();
                typesVariables[index] = typeVariableImpl;
                typeVariableImpl.setName(mirror.toString());
                index++;
            }

            declaration.setTypeParameters(typesVariables);
        }
        isInterface = ((com.sun.tools.javac.code.Type) typeMirror).isInterface();
        final int indexOfChevron = className.indexOf('<');
        if (indexOfChevron != -1) {
            className = className.substring(0, indexOfChevron);
        }
        TypeElement typeElement = (TypeElement) declaredType.asElement();
        if (level + 1 <= maxLevel) {
            TypeMirror superclass = typeElement.getSuperclass();
            superClass = createClass(superclass, level + 1);
        }
        if (level + 1 <= maxLevel) {
            superInterfaces = new Class[typeElement.getInterfaces().size()];
            int indexInterface = 0;
            for (TypeMirror superInterface : typeElement.getInterfaces()) {
                superInterfaces[indexInterface++] = createClass(superInterface, level +1);
            }
        }
        if (level + 1 <= maxLevel) {
            final List<? extends Element> enclosedElements = ((TypeElement) declaredType.asElement()).getEnclosedElements();
            for (Element enclosedElement : enclosedElements) {
                mapElementToReflection(enclosedElement, level + 1);
            }
        }
    } else if (typeMirror instanceof ArrayType) {
        //warning, this must come before Primitive as arrays are also primitives (here)
        isArray = true;
        className = ((ArrayType) typeMirror).getComponentType().toString() + "[]";
        component = createClass(((ArrayType) typeMirror).getComponentType(), level);
    } else if (typeMirror instanceof PrimitiveType) {
        isPrimitive = true;
        className = typeMirror.toString();
    }

    result = Class.forNameSafe(className, level);

    if (superClass!=null) {
        result.setSuperclass(superClass);
    }

    if (superInterfaces!=null) {
        result.setInterfaces(superInterfaces);
    }

    if (isArray) {
        result.setIsArray(true);
    }
    if (isPrimitive) {
        result.setIsPrimitive(true);
    }
    if (component != null) {
        result.setComponentType(component);
    }

    if (declaration != null) {
        result.setGenericInfo(declaration);
    }
    if (isInterface) {
        result.setIsInterface(true);
    }
    return result;
}