當前位置: 首頁>>代碼示例>>Java>>正文


Java DeclaredType.asElement方法代碼示例

本文整理匯總了Java中javax.lang.model.type.DeclaredType.asElement方法的典型用法代碼示例。如果您正苦於以下問題:Java DeclaredType.asElement方法的具體用法?Java DeclaredType.asElement怎麽用?Java DeclaredType.asElement使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在javax.lang.model.type.DeclaredType的用法示例。


在下文中一共展示了DeclaredType.asElement方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: visitDeclared

import javax.lang.model.type.DeclaredType; //導入方法依賴的package包/類
@Override
public StringBuilder visitDeclared(DeclaredType t, Boolean p) {
    Element e = t.asElement();
    if (e instanceof TypeElement) {
        TypeElement te = (TypeElement)e;
        DEFAULT_VALUE.append((p ? te.getQualifiedName() : te.getSimpleName()).toString());
        Iterator<? extends TypeMirror> it = t.getTypeArguments().iterator();
        if (it.hasNext()) {
            DEFAULT_VALUE.append("<"); //NOI18N
            while(it.hasNext()) {
                visit(it.next(), p);
                if (it.hasNext())
                    DEFAULT_VALUE.append(", "); //NOI18N
            }
            DEFAULT_VALUE.append(">"); //NOI18N
        }
        return DEFAULT_VALUE;
    } else {
        return DEFAULT_VALUE.append(UNKNOWN); //NOI18N
    }
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:22,代碼來源:MethodModelSupport.java

示例2: collectConstructors

import javax.lang.model.type.DeclaredType; //導入方法依賴的package包/類
private void collectConstructors(Collection<IConstructor> constructors, Element element){
    if(element == null || element.getKind()!=ElementKind.CLASS) {
        return;
    }
    TypeElement el = (TypeElement) element;
    for(Element sub: el.getEnclosedElements()){
        if(sub.getKind() == ElementKind.CONSTRUCTOR){
            constructors.add(new Constructor(this, (ExecutableElement)sub));
        } else if ((sub.getKind() == ElementKind.CLASS) && (((TypeElement) sub).getSuperclass() != null)){
            TypeMirror supMirror = ((TypeElement) sub).getSuperclass();
            if (supMirror.getKind() == TypeKind.DECLARED) {
                DeclaredType superclassDeclaredType = (DeclaredType)supMirror;
                Element superclassElement = superclassDeclaredType.asElement();  
                collectConstructors(constructors, superclassElement);
            }
        }
    }
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:19,代碼來源:Type.java

示例3: appendSimpleTypeName

import javax.lang.model.type.DeclaredType; //導入方法依賴的package包/類
private static void appendSimpleTypeName(StringBuilder ret, TypeMirror type) {
    switch (type.getKind()) {
        case DECLARED:
            DeclaredType declared = (DeclaredType) type;
            TypeElement element = (TypeElement) declared.asElement();
            ret.append(element.getSimpleName());
            break;
        case TYPEVAR:
            appendSimpleTypeName(ret, ((TypeVariable) type).getUpperBound());
            break;
        case WILDCARD:
            appendSimpleTypeName(ret, ((WildcardType) type).getExtendsBound());
            break;
        case ARRAY:
            appendSimpleTypeName(ret, ((ArrayType) type).getComponentType());
            ret.append("Array");
            break;
        default:
            ret.append(type);
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:22,代碼來源:PluginGenerator.java

示例4: getErasedType

import javax.lang.model.type.DeclaredType; //導入方法依賴的package包/類
static String getErasedType(TypeMirror type) {
    switch (type.getKind()) {
        case DECLARED:
            DeclaredType declared = (DeclaredType) type;
            TypeElement element = (TypeElement) declared.asElement();
            return element.getQualifiedName().toString();
        case TYPEVAR:
            return getErasedType(((TypeVariable) type).getUpperBound());
        case WILDCARD:
            return getErasedType(((WildcardType) type).getExtendsBound());
        case ARRAY:
            return getErasedType(((ArrayType) type).getComponentType()) + "[]";
        default:
            return type.toString();
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:17,代碼來源:GeneratedPlugin.java

示例5: FactoryAnnotatedClass

import javax.lang.model.type.DeclaredType; //導入方法依賴的package包/類
public FactoryAnnotatedClass(TypeElement classElement) throws IllegalArgumentException {
    this.annotatedClassElement = classElement;
    Factory annotation = classElement.getAnnotation(Factory.class);
    id = annotation.id();

    if (id == null || id.length() == 0) {
        throw new IllegalArgumentException(
                String.format("id() in @%s for class %s is null or empty! that's not allowed",
                        Factory.class.getSimpleName(), classElement.getQualifiedName().toString()));
    }

    // Get the full QualifiedTypeName
    try {
        Class<?> clazz = annotation.type();
        qualifiedSuperClassName = clazz.getCanonicalName();
        simpleTypeName = clazz.getSimpleName();
    } catch (MirroredTypeException mte) {
        DeclaredType classTypeMirror = (DeclaredType) mte.getTypeMirror();
        TypeElement classTypeElement = (TypeElement) classTypeMirror.asElement();
        qualifiedSuperClassName = classTypeElement.getQualifiedName().toString();
        simpleTypeName = classTypeElement.getSimpleName().toString();
    }
}
 
開發者ID:jacklongway,項目名稱:FactoryAnnotation,代碼行數:24,代碼來源:FactoryAnnotatedClass.java

示例6: isSubtypeOfType

import javax.lang.model.type.DeclaredType; //導入方法依賴的package包/類
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;
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:40,代碼來源:ButterKnifeProcessor.java

示例7: createArrayItem

import javax.lang.model.type.DeclaredType; //導入方法依賴的package包/類
@Override
public CI createArrayItem(CompilationInfo info, ArrayType type, int substitutionOffset, ReferencesCount referencesCount, Elements elements) {
    int dim = 0;
    TypeMirror tm = type;
    while(tm.getKind() == TypeKind.ARRAY) {
        tm = ((ArrayType)tm).getComponentType();
        dim++;
    }
    if (tm.getKind().isPrimitive()) {
        String kwd = tm.toString();
        StringBuilder sb = new StringBuilder(kwd);
        for(int i = 0; i < dim; i++) {
            sb.append("[]"); //NOI18N
        }
        return new CI(sb.toString(), 670 - SMART_TYPE, kwd);
    }
    if (tm.getKind() == TypeKind.DECLARED || tm.getKind() == TypeKind.ERROR) {
        DeclaredType dt = (DeclaredType)tm;
        TypeElement elem = (TypeElement)dt.asElement();
        String simpleName = elem.getSimpleName().toString();
        String fqn = elem.getQualifiedName().toString();
        int weight = 50;
        if (fqn.startsWith("java.lang") || fqn.startsWith("java.util")) { // NOI18N
            weight -= 10;
        } else if (fqn.startsWith("org.omg") || fqn.startsWith("org.apache")) { // NOI18N
            weight += 10;
        } else if (fqn.startsWith("com.sun") || fqn.startsWith("com.ibm") || fqn.startsWith("com.apple")) { // NOI18N
            weight += 20;
        } else if (fqn.startsWith("sun") || fqn.startsWith("sunw") || fqn.startsWith("netscape")) { // NOI18N
            weight += 30;
        }
        return new CI(simpleName, 800 - SMART_TYPE, referencesCount != null ? simpleName + '#' + weight + '#' + info.getElementUtilities().getElementName(elem.getEnclosingElement(), true) : simpleName);
    }
    throw new IllegalArgumentException("array element kind=" + tm.getKind());
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:36,代碼來源:CompletionTestBase.java

示例8: AdapterAnnotatedClass

import javax.lang.model.type.DeclaredType; //導入方法依賴的package包/類
public AdapterAnnotatedClass(TypeElement typeElement) {
    annotatedClassName = typeElement.getQualifiedName().toString();
    RecyclerAdapter annotation = typeElement.getAnnotation(RecyclerAdapter.class);
    try {
        Class<?> clazz = annotation.itemType();
        adapterItemType = clazz.getCanonicalName();
    } catch (MirroredTypeException e) {
        DeclaredType classTypeMirror = (DeclaredType) e.getTypeMirror();
        TypeElement classTypeElement = (TypeElement) classTypeMirror.asElement();
        adapterItemType = classTypeElement.getQualifiedName().toString();
    }
}
 
開發者ID:mitrejcevski,項目名稱:gendapter,代碼行數:13,代碼來源:AdapterAnnotatedClass.java

示例9: isSubtypeOfType

import javax.lang.model.type.DeclaredType; //導入方法依賴的package包/類
private 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;
}
 
開發者ID:quangctkm9207,項目名稱:prefpin,代碼行數:40,代碼來源:PrefPinProcessor.java

示例10: obtainScreenClassName

import javax.lang.model.type.DeclaredType; //導入方法依賴的package包/類
private String obtainScreenClassName(TypeElement classElement) {
	RegisterScreen annotation = classElement.getAnnotation(RegisterScreen.class);
	try {
		Class<?> clazz = annotation.value();
		return clazz.getCanonicalName();
	} catch (MirroredTypeException mte) {
		DeclaredType type = (DeclaredType) mte.getTypeMirror();
		TypeElement typeElement = (TypeElement) type.asElement();
		return typeElement.getQualifiedName().toString();
	}
}
 
開發者ID:aartikov,項目名稱:Alligator,代碼行數:12,代碼來源:RegistrationAnnotatedClassCreator.java

示例11: visitDeclared

import javax.lang.model.type.DeclaredType; //導入方法依賴的package包/類
@Override
public Object visitDeclared(DeclaredType t, Object p) {
    Element e = t.asElement();
    if (e == null) {
        unknownDeclaredTypes.add(t);
    } else {
        TypeMirror back = e.asType();
        if (back == null || back.getKind() == TypeKind.ERROR) {
            unknownDeclaredTypes.add(t);
        }
    }
    return super.visitDeclared(t, p);
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:14,代碼來源:TypeErroneous.java

示例12: findAnnotationMirror

import javax.lang.model.type.DeclaredType; //導入方法依賴的package包/類
public static AnnotationMirror findAnnotationMirror(ProcessingEnvironment processingEnv, List<? extends AnnotationMirror> mirrors, Class<?> annotationClass) {
    TypeElement expectedAnnotationType = processingEnv.getElementUtils().getTypeElement(annotationClass.getCanonicalName());
    for (AnnotationMirror mirror : mirrors) {
        DeclaredType annotationType = mirror.getAnnotationType();
        TypeElement actualAnnotationType = (TypeElement) annotationType.asElement();
        if (actualAnnotationType.equals(expectedAnnotationType)) {
            return mirror;
        }
    }
    return null;
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:12,代碼來源:VerifierAnnotationProcessor.java

示例13: isRootObjectType

import javax.lang.model.type.DeclaredType; //導入方法依賴的package包/類
/**
 * Checks whether the given type object represents type
 * {@literal java.lang.Object}.
 * 
 * @param  type  type to be checked
 * @return  {@literal true} if the passed type object represents type
 *          {@literal java.lang.Object}, {@literal false} otherwise
 */
private static boolean isRootObjectType(DeclaredType type) {
    if (type.getKind() != TypeKind.DECLARED) {
        return false;
    }

    TypeElement elem = (TypeElement) type.asElement();
    return (elem.getKind() == ElementKind.CLASS)
           && (elem.getSuperclass().getKind() == TypeKind.NONE);
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:18,代碼來源:AbstractTestGenerator.java

示例14: getSuperClass

import javax.lang.model.type.DeclaredType; //導入方法依賴的package包/類
private TypeElement getSuperClass(TypeElement typeElement) {
    if (!(typeElement.getSuperclass() instanceof DeclaredType)) return null;
    DeclaredType declaredAncestor = (DeclaredType) typeElement.getSuperclass();
    return (TypeElement) declaredAncestor.asElement();
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:6,代碼來源:EasyMVPProcessor.java

示例15: visitDeclared

import javax.lang.model.type.DeclaredType; //導入方法依賴的package包/類
@Override
public Element visitDeclared(DeclaredType t, Void p) {
    return t.asElement();
}
 
開發者ID:foodora,項目名稱:android-auto-mapper,代碼行數:5,代碼來源:MoreTypes.java


注:本文中的javax.lang.model.type.DeclaredType.asElement方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。