当前位置: 首页>>代码示例>>Java>>正文


Java TypeElement.getQualifiedName方法代码示例

本文整理汇总了Java中javax.lang.model.element.TypeElement.getQualifiedName方法的典型用法代码示例。如果您正苦于以下问题:Java TypeElement.getQualifiedName方法的具体用法?Java TypeElement.getQualifiedName怎么用?Java TypeElement.getQualifiedName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.lang.model.element.TypeElement的用法示例。


在下文中一共展示了TypeElement.getQualifiedName方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: from

import javax.lang.model.element.TypeElement; //导入方法依赖的package包/类
static AttributeTypeKind from(TypeMirror type) {
  if (type.getKind() == TypeKind.DECLARED) {
    TypeElement typeElement = toElement(type);
    if (typeElement.getKind() == ElementKind.ENUM) {
      return ENUM;
    }
    if (typeElement.getKind() == ElementKind.ANNOTATION_TYPE) {
      return ANNOTATION;
    }
    Name qualifiedName = typeElement.getQualifiedName();
    if (qualifiedName.contentEquals(Class.class.getName())) {
      return TYPE;
    }
    if (qualifiedName.contentEquals(String.class.getName())) {
      return STRING;
    }
  } else if (type.getKind().isPrimitive()) {
    return PRIMITIVE;
  }
  throw new AssertionError();
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:22,代码来源:Mirrors.java

示例2: visitNewClass

import javax.lang.model.element.TypeElement; //导入方法依赖的package包/类
@Override
public Boolean visitNewClass(NewClassTree node, Void p) {
    TypeMirror tm = ci.getTrees().getTypeMirror(getCurrentPath());
    if (tm == null || tm.getKind() != TypeKind.DECLARED) {
        return false;
    }
    TypeElement el = (TypeElement)((DeclaredType)tm).asElement();
    if (el == null) {
        return false;
    }
    Name n = el.getQualifiedName();
    boolean res = n.contentEquals("java.lang.StringBuilder") || n.contentEquals("java.lang.StringBuffer"); // NOI18N
    // check if there is some initial contents
    if (node.getArguments().size() == 1 && 
            Utilities.isJavaString(ci, ci.getTrees().getTypeMirror(new TreePath(getCurrentPath(), node.getArguments().get(0))))) {
        hasContents = true;
    }
    return res;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:20,代码来源:ReplaceBufferByString.java

示例3: target2String

import javax.lang.model.element.TypeElement; //导入方法依赖的package包/类
public static String target2String(TypeElement target) {
    final Name qualifiedName = target.getQualifiedName(); //#130759
    if (qualifiedName == null) {
        Logger.getLogger(Utilities.class.getName()).warning("Target qualified name could not be resolved."); //NOI18N
        return ""; //NOI18N
    } else {
        String qnString = qualifiedName.toString();
        if (qnString.length() == 0) {
            //probably an anonymous class
            qnString = target.asType().toString();
        }

        try {
            qnString = XMLUtil.toElementContent(qnString);
        } catch (CharConversionException ex) {
            Logger.getLogger(Utilities.class.getName()).log(Level.FINE, null, ex);
        }

        return qnString;
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:22,代码来源:Utilities.java

示例4: isSystemExit

import javax.lang.model.element.TypeElement; //导入方法依赖的package包/类
/**
 * Determines if the element corresponds to never-returning, terminating method.
 * System.exit, Runtime.exit, Runtime.halt are checked. The passed element is
 * usually a result of {@code CompilationInfo.getTrees().getElement(path)}.
 * 
 * @param info context
 * @param e element to check
 * @return true, if the element corrresponds to a VM-exiting method
 */
public static boolean isSystemExit(CompilationInfo info, Element e) {
    if (e == null || e.getKind() != ElementKind.METHOD) {
        return false;
    }
    ExecutableElement ee = (ExecutableElement)e;
    Name n = ee.getSimpleName();
    if (n.contentEquals("exit") || n.contentEquals("halt")) { // NOI18N
        TypeElement tel = info.getElementUtilities().enclosingTypeElement(e);
        if (tel == null) {
            return false;
        }
        Name ofqn = tel.getQualifiedName();
        if (ofqn.contentEquals("java.lang.System") || ofqn.contentEquals("java.lang.Runtime")) { // NOI18N
            return true;
        }
    }
    return false;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:28,代码来源:Utilities.java

示例5: extractClass

import javax.lang.model.element.TypeElement; //导入方法依赖的package包/类
/** Extract reflection Class<?> information from type element. */
@NonNull
public static Class<?> extractClass(@NonNull final TypeElement te) throws ClassNotFoundException {
    final Name name;

    if (te instanceof Symbol.ClassSymbol) {
        final Symbol.ClassSymbol cs = (Symbol.ClassSymbol) te;

        // this method is more accurate for nested classes
        name = cs.flatName();
    } else {
        name = te.getQualifiedName();
    }

    final String className = name.toString();

    try {
        return Class.forName(className).asSubclass(Annotation.class);
    } catch (ClassNotFoundException ex) {
        // it can be sub-type, try another approach bellow
    }

    final int dot = className.lastIndexOf(".");
    final String innerFix2 = className.substring(0, dot) + "$" + className.substring(dot + 1);
    return Class.forName(innerFix2).asSubclass(Annotation.class);
}
 
开发者ID:OleksandrKucherenko,项目名称:autoproxy,代码行数:27,代码来源:CommonClassGenerator.java

示例6: ClassEntity

import javax.lang.model.element.TypeElement; //导入方法依赖的package包/类
/**
 * @param elementUtils
 * @param typeUtils
 * @param element      current anntated class
 */
public ClassEntity(Elements elementUtils, Types typeUtils, TypeElement element) {
    elementWeakCache = new WeakReference<TypeElement>(element);
    this.classPackageName = elementUtils.getPackageOf(element).getQualifiedName().toString();
    this.modifierSet = element.getModifiers();
    this.className = element.toString();
    annotationMirrors = element.getAnnotationMirrors();
    this.classSimpleName = element.getSimpleName();
    this.classQualifiedName = element.getQualifiedName();
    if ("java.lang.Object".equals(element.getSuperclass().toString())){
        this.superclass = null;
    }else{
        this.superclass = element.getSuperclass().toString();
    }
    List<? extends TypeMirror> interfaces = element.getInterfaces();

    for (TypeMirror anInterface : interfaces){
        this.interfaces.add(typeUtils.asElement(anInterface).toString());
    }
}
 
开发者ID:simplezhli,项目名称:RxPay,代码行数:25,代码来源:ClassEntity.java

示例7: categories

import javax.lang.model.element.TypeElement; //导入方法依赖的package包/类
/**
 * Categories field, find his papa.
 *
 * @param elements Field need autowired
 */
private void categories(Set<? extends Element> elements) throws IllegalAccessException {
    if (CollectionUtils.isNotEmpty(elements)) {
        for (Element element : elements) {
            TypeElement enclosingElement = (TypeElement) element.getEnclosingElement();

            if (element.getModifiers().contains(Modifier.PRIVATE)) {
                throw new IllegalAccessException("The autowired fields CAN NOT BE 'private'!!! please check field ["
                        + element.getSimpleName() + "] in class [" + enclosingElement.getQualifiedName() + "]");
            }

            if (parentAndChild.containsKey(enclosingElement)) { // Has categries
                parentAndChild.get(enclosingElement).add(element);
            } else {
                List<Element> childs = new ArrayList<>();
                childs.add(element);
                parentAndChild.put(enclosingElement, childs);
            }
        }

        logger.info("categories finished.");
    }
}
 
开发者ID:luojilab,项目名称:DDComponentForAndroid,代码行数:28,代码来源:AutowiredProcessor.java

示例8: writeProviderFile

import javax.lang.model.element.TypeElement; //导入方法依赖的package包/类
private void writeProviderFile(TypeElement serviceProvider, String interfaceName) {
    String filename = "META-INF/providers/" + serviceProvider.getQualifiedName();
    try {
        FileObject file = processingEnv.getFiler().createResource(StandardLocation.CLASS_OUTPUT, "", filename, serviceProvider);
        PrintWriter writer = new PrintWriter(new OutputStreamWriter(file.openOutputStream(), "UTF-8"));
        writer.println(interfaceName);
        writer.close();
    } catch (IOException e) {
        processingEnv.getMessager().printMessage(isBug367599(e) ? Kind.NOTE : Kind.ERROR, e.getMessage(), serviceProvider);
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:12,代码来源:ServiceProviderProcessor.java

示例9: getTargetType

import javax.lang.model.element.TypeElement; //导入方法依赖的package包/类
/**
    * Returns the target type of the specified type element representing a parameter converter class.
    * @param converterElement
    * @throws ModelException
    */
String getTargetType(TypeElement converterElement) throws ModelException {
       for (AnnotationMirror am : converterElement.getAnnotationMirrors()) {
           Element ae = typeUtils.asElement(am.getAnnotationType());
           if (ae.equals(converterAnnotation))
               for (Map.Entry<? extends ExecutableElement,? extends AnnotationValue> e : am.getElementValues().entrySet())
                   if ("targetType".equals(e.getKey().getSimpleName().toString()))
                       return e.getValue().toString();
       }
       throw new ModelException("cannot read target type for converter: " + converterElement.getQualifiedName());
}
 
开发者ID:Bibliome,项目名称:alvisnlp,代码行数:16,代码来源:ModelContext.java

示例10: parseBindView

import javax.lang.model.element.TypeElement; //导入方法依赖的package包/类
private void parseBindView(Element element, Map<TypeElement, BindingSet.Builder> builderMap,
    Set<TypeElement> erasedTargetNames) {
  TypeElement enclosingElement = (TypeElement) element.getEnclosingElement();

  // Start by verifying common generated code restrictions.
  boolean hasError = isInaccessibleViaGeneratedCode(BindView.class, "fields", element)
      || isBindingInWrongPackage(BindView.class, element);

  // Verify that the target type extends from View.
  TypeMirror elementType = element.asType();
  if (elementType.getKind() == TypeKind.TYPEVAR) {
    TypeVariable typeVariable = (TypeVariable) elementType;
    elementType = typeVariable.getUpperBound();
  }
  Name qualifiedName = enclosingElement.getQualifiedName();
  Name simpleName = element.getSimpleName();
  if (!isSubtypeOfType(elementType, VIEW_TYPE) && !isInterface(elementType)) {
    if (elementType.getKind() == TypeKind.ERROR) {
      note(element, "@%s field with unresolved type (%s) "
              + "must elsewhere be generated as a View or interface. (%s.%s)",
          BindView.class.getSimpleName(), elementType, qualifiedName, simpleName);
    } else {
      error(element, "@%s fields must extend from View or be an interface. (%s.%s)",
          BindView.class.getSimpleName(), qualifiedName, simpleName);
      hasError = true;
    }
  }

  if (hasError) {
    return;
  }

  // Assemble information on the field.
  int id = element.getAnnotation(BindView.class).value();

  BindingSet.Builder builder = builderMap.get(enclosingElement);
  QualifiedId qualifiedId = elementToQualifiedId(element, id);
  if (builder != null) {
    String existingBindingName = builder.findExistingBindingName(getId(qualifiedId));
    if (existingBindingName != null) {
      error(element, "Attempt to use @%s for an already bound ID %d on '%s'. (%s.%s)",
          BindView.class.getSimpleName(), id, existingBindingName,
          enclosingElement.getQualifiedName(), element.getSimpleName());
      return;
    }
  } else {
    builder = getOrCreateBindingBuilder(builderMap, enclosingElement);
  }

  String name = simpleName.toString();
  TypeName type = TypeName.get(elementType);
  boolean required = isFieldRequired(element);

  builder.addField(getId(qualifiedId), new FieldViewBinding(name, type, required));

  // Add the type-erased version to the valid binding targets set.
  erasedTargetNames.add(enclosingElement);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:59,代码来源:ButterKnifeProcessor.java

示例11: generatePresenterBinderClass

import javax.lang.model.element.TypeElement; //导入方法依赖的package包/类
private static String generatePresenterBinderClass(final String builder, String targetClass, final Field field) {
	TypeElement clazz = (TypeElement) ((DeclaredType) field.getClazz()).asElement();
	String s = "\tpublic class " + field.getGeneratedClassName() + " extends PresenterField {\n" +
	           "\t\tpublic " + field.getGeneratedClassName() + "() {\n" +
	           "\t\t\tsuper(" + field.getTag() + ", PresenterType." + field.getType().name() + ", " + field.getPresenterId() + ", " + clazz + ".class);\n" +
	           "\t\t}\n" +
	           "\n" +
	           "\t\[email protected]\n" +
	           "\t\tpublic void bind(Object target, MvpPresenter presenter) {\n" +
	           "\t\t\t((" + targetClass + ") target)." + field.getName() + " = (" + clazz.getQualifiedName() + ") presenter;\n" +
	           "\t\t}\n";

		s += "\n" +
		     "\t\[email protected]\n" +
		     "\t\tpublic MvpPresenter<?> providePresenter(Object delegated) {\n";
	if (field.getPresenterProviderMethodName() != null) {
		s+= "\t\t\treturn ((" + targetClass + ") delegated)." + field.getPresenterProviderMethodName() + "();\n";
	} else {
		boolean hasEmptyConstructor = false;
		List<? extends Element> enclosedElements = clazz.getEnclosedElements();
		for (Element enclosedElement : enclosedElements) {
			if (enclosedElement.getKind() == ElementKind.CONSTRUCTOR) {
				List<? extends VariableElement> parameters = ((ExecutableElement) enclosedElement).getParameters();
				if (parameters == null || parameters.isEmpty()) {
					hasEmptyConstructor = true;
					break;
				}
			}
		}
		if (hasEmptyConstructor) {
		s += "\t\t\treturn new " + clazz.getQualifiedName() + "();\n";
		} else {
		s += "\t\t\tthrow new IllegalStateException(\"" + clazz.getSimpleName() + " has not default constructor. You can apply @ProvidePresenter to some method which will construct Presenter. Also you can make it default constructor\");\n";
		}
	}
	    s += "\t\t}\n";

	if (field.getPresenterTagProviderMethodName() != null) {
		s += "\n" +
		     "\t\[email protected]\n" +
		     "\t\tpublic String getTag(Object delegated) {\n" +
		     "\t\t\treturn String.valueOf(((" + targetClass + ") delegated)." + field.getPresenterTagProviderMethodName() + "());\n" +
		     "\t\t}\n";
	}

	s += "\t}\n" +
	     "\n";
	return builder + s;
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:50,代码来源:PresenterBinderClassGenerator.java

示例12: CachingTypeElement

import javax.lang.model.element.TypeElement; //导入方法依赖的package包/类
CachingTypeElement(TypeElement delegate) {
  super(delegate);
  this.delegate = delegate;
  this.qualifiedName = delegate.getQualifiedName();
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:6,代码来源:CachingElements.java

示例13: checkThatIsPublic

import javax.lang.model.element.TypeElement; //导入方法依赖的package包/类
private void checkThatIsPublic(TypeElement classElement) throws ProcessingException {
	if (!classElement.getModifiers().contains(Modifier.PUBLIC)) {
		throw new ProcessingException(classElement, "The class %s is not public.", classElement.getQualifiedName());
	}
}
 
开发者ID:aartikov,项目名称:Alligator,代码行数:6,代码来源:RegistrationAnnotatedClassCreator.java

示例14: getAnnotationQualifiedName

import javax.lang.model.element.TypeElement; //导入方法依赖的package包/类
public static String getAnnotationQualifiedName(AnnotationMirror annotationMirror) {
    DeclaredType annotationDeclaredType = annotationMirror.getAnnotationType();
    TypeElement annotationTypeElement = (TypeElement) annotationDeclaredType.asElement();
    Name name = annotationTypeElement.getQualifiedName();
    return name.toString();
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:7,代码来源:JpaControllerUtil.java

示例15: interfaceName

import javax.lang.model.element.TypeElement; //导入方法依赖的package包/类
public Content interfaceName(TypeElement typeElement, boolean qual) {
    Content name = new StringContent((qual)
            ? typeElement.getQualifiedName()
            : utils.getSimpleName(typeElement));
    return (utils.isInterface(typeElement)) ?  HtmlTree.SPAN(HtmlStyle.interfaceName, name) : name;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:7,代码来源:HtmlDocletWriter.java


注:本文中的javax.lang.model.element.TypeElement.getQualifiedName方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。