当前位置: 首页>>代码示例>>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;未经允许,请勿转载。