类javax.lang.model.element.QualifiedNameable源码实例Demo

下面列出了怎么用javax.lang.model.element.QualifiedNameable的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: netbeans   文件: ImmutableTreeTranslator.java
public Tree visitMemberSelect(MemberSelectTree tree, Object p) {
    if (tree instanceof QualIdentTree) {
        QualIdentTree qit = (QualIdentTree) tree;
        Element el = qit.sym;

        if (el == null) {
            el = overlay.resolve(model, elements, qit.getFQN());
        } else {
            if (el.getKind().isClass() || el.getKind().isInterface() || el.getKind() == ElementKind.PACKAGE) {
                el = overlay.resolve(model, elements, ((QualifiedNameable) el).getQualifiedName().toString(), el, elements.getModuleOf(el));
            }
        }

        return importAnalysis.resolveImport(tree, el);
    } else {
        return rewriteChildren(tree);
    }
}
 
源代码2 项目: netbeans   文件: ElementOverlay.java
private String fqnFor(Tree t) {
    Element el = ASTService.getElementImpl(t);

    if (el != null) {
        if (el.getKind().isClass() || el.getKind().isInterface() || el.getKind() == ElementKind.PACKAGE) {
            return ((QualifiedNameable) el).getQualifiedName().toString();
        } else {
            Logger.getLogger(ElementOverlay.class.getName()).log(Level.SEVERE, "Not a QualifiedNameable: {0}", el);
            return null;
        }
    } else if (t instanceof QualIdentTree) {
        return ((QualIdentTree) t).getFQN();
    } else if (t.getKind() == Kind.PARAMETERIZED_TYPE) {
        return fqnFor(((ParameterizedTypeTree) t).getType());
    } else {
        Logger.getLogger(ElementOverlay.class.getName()).log(Level.FINE, "No element and no QualIdent");
        return null;
    }
}
 
源代码3 项目: buck   文件: TreeBackedTypeResolutionSimulator.java
@Override
protected TreeBackedResolvedType resolvePackage(
    TreePath referencingPath,
    PackageElement referencedPackage,
    QualifiedNameable canonicalPackage) {
  // PackageElements are not considered to be enclosed by their parent elements, but
  // our logic is a lot simpler if we can pretend they are.
  TreeBackedResolvedType enclosingElement = null;
  String qualifiedName = canonicalPackage.getQualifiedName().toString();
  int lastDot = qualifiedName.lastIndexOf('.');
  if (lastDot > 0) {
    String enclosingPackageQualifiedName = qualifiedName.substring(0, lastDot);
    PackageElement enclosingPackage =
        Objects.requireNonNull(
            MoreElements.getPackageElementEvenIfEmpty(elements, enclosingPackageQualifiedName));
    enclosingElement = resolveEnclosingElement(enclosingPackage);
  }

  return new TreeBackedResolvedType(referencingPath, canonicalPackage, enclosingElement);
}
 
源代码4 项目: buck   文件: InterfaceScannerTest.java
@Override
public void onImport(
    boolean isStatic,
    boolean isStarImport,
    TreePath leafmostElementPath,
    QualifiedNameable leafmostElement,
    Name memberName) {
  if (!isStatic) {
    if (isStarImport) {
      starImportedElements.add(leafmostElement);
    } else {
      importedTypes.add((TypeElement) leafmostElement);
    }
  } else if (!isStarImport) {
    staticImportOwners.put(memberName.toString(), (TypeElement) leafmostElement);
  } else {
    staticStarImports.add((TypeElement) leafmostElement);
  }
}
 
源代码5 项目: auto   文件: TypeSimplifier.java
private static Set<String> ambiguousNames(Types typeUtils, Set<TypeMirror> types) {
  Set<String> ambiguous = new HashSet<>();
  Map<String, Name> simpleNamesToQualifiedNames = new HashMap<>();
  for (TypeMirror type : types) {
    if (type.getKind() == TypeKind.ERROR) {
      throw new MissingTypeException(MoreTypes.asError(type));
    }
    String simpleName = typeUtils.asElement(type).getSimpleName().toString();
    /*
     * Compare by qualified names, because in Eclipse JDT, if Java 8 type annotations are used,
     * the same (unannotated) type may appear multiple times in the Set<TypeMirror>.
     * TODO(emcmanus): investigate further, because this might cause problems elsewhere.
     */
    Name qualifiedName = ((QualifiedNameable) typeUtils.asElement(type)).getQualifiedName();
    Name previous = simpleNamesToQualifiedNames.put(simpleName, qualifiedName);
    if (previous != null && !previous.equals(qualifiedName)) {
      ambiguous.add(simpleName);
    }
  }
  return ambiguous;
}
 
@Override
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
  if (roundEnv.processingOver()) return true;

  // looking for at least one class annotated with @InvokeByteCodePatching
  final Set<? extends Element> elements = roundEnv.getElementsAnnotatedWith(InvokeByteCodePatching.class);
  if (elements.size() <= 0) return false;

  //noinspection LoopStatementThatDoesntLoop
  for (final Element elem : elements) {
    // is invalid to apply this annotation to anything other than a class type
    if (!elem.getKind().isClass() || !(elem instanceof QualifiedNameable)) {
      throw new AnnotationFormatError(elem.toString() + " Java type not supported by " + InvokeByteCodePatching.class);
    }

    InvokeByteCodePatching annotation = elem.getAnnotation(InvokeByteCodePatching.class);
    if (annotation == null) {
      throw new AnnotationFormatError("invalid annotation " + InvokeByteCodePatching.class);
    }

    break; // found a class marked by the @InvokeByteCodePatching annotation
  }

  try {
    final String classesBldDir = System.getProperty("maven.build.classes.dir", "target/classes");
    ValidateAvroSchema.bytecodePatchAvroSchemaClass(new File(classesBldDir));
  } catch (ClassNotFoundException|IOException e) {
    uncheckedExceptionThrow(e);
  }

  return true; // no further processing of this annotation type
}
 
源代码7 项目: buck   文件: TreeBackedTypeResolutionSimulator.java
@Override
protected TreeBackedResolvedType resolveType(
    TreePath referencingPath, TypeElement referencedType, QualifiedNameable canonicalType) {
  if (canonicalType == null) {
    canonicalType = referencedType;
  }
  return new TreeBackedResolvedType(
      referencingPath,
      canonicalType,
      resolveEnclosingElement((QualifiedNameable) canonicalType.getEnclosingElement()));
}
 
源代码8 项目: buck   文件: TreeBackedElements.java
private Name getFullyQualifiedName(
    @Nullable QualifiedNameable enclosingElement, Name simpleName) {
  for (int i = 0; i < simpleName.length(); i++) {
    if (simpleName.charAt(i) == '.') {
      throw new IllegalArgumentException(String.format("%s is not a simple name", simpleName));
    }
  }

  if (enclosingElement == null || enclosingElement.getQualifiedName().length() == 0) {
    return simpleName;
  } else {
    return getName(String.format("%s.%s", enclosingElement.getQualifiedName(), simpleName));
  }
}
 
源代码9 项目: buck   文件: ImportsTrackerTestHelper.java
private static void handleImport(Trees trees, ImportsTracker imports, TreePath importTreePath) {
  ImportTree importTree = (ImportTree) importTreePath.getLeaf();
  MemberSelectTree importedExpression = (MemberSelectTree) importTree.getQualifiedIdentifier();
  TreePath importedExpressionPath = new TreePath(importTreePath, importedExpression);
  Name simpleName = importedExpression.getIdentifier();
  boolean isStarImport = simpleName.contentEquals("*");

  if (!isStarImport && !importTree.isStatic()) {
    TypeElement importedType = (TypeElement) trees.getElement(importedExpressionPath);
    imports.importType(importedType, importedExpressionPath);
  } else {
    ExpressionTree containingElementExpression = importedExpression.getExpression();
    TreePath containingElementExpressionPath =
        new TreePath(importedExpressionPath, containingElementExpression);
    QualifiedNameable containingElement =
        (QualifiedNameable) trees.getElement(containingElementExpressionPath);

    if (importTree.isStatic()) {
      TypeElement containingType = (TypeElement) containingElement;
      if (isStarImport) {
        imports.importStaticMembers((TypeElement) containingElement);
      } else {
        imports.importStatic(containingType, simpleName);
      }
    } else {
      // Normal star import
      imports.importMembers(containingElement, containingElementExpressionPath);
    }
  }
}
 
源代码10 项目: auto   文件: MemoizeExtension.java
/**
 * Returns the fully-qualified name of an annotation-mirror, e.g.
 * "com.google.auto.value.AutoValue".
 */
// TODO(b/122509249): Move code copied from com.google.auto.value.processor to auto-common.
private static String getAnnotationFqName(AnnotationMirror annotation) {
  return ((QualifiedNameable) annotation.getAnnotationType().asElement())
      .getQualifiedName()
      .toString();
}
 
源代码11 项目: spring-analysis-note   文件: TypeHelper.java
private String getQualifiedName(Element element) {
	if (element instanceof QualifiedNameable) {
		return ((QualifiedNameable) element).getQualifiedName().toString();
	}
	return element.toString();
}
 
源代码12 项目: magic-starter   文件: TypeHelper.java
private String getQualifiedName(Element element) {
	if (element instanceof QualifiedNameable) {
		return ((QualifiedNameable) element).getQualifiedName().toString();
	}
	return element.toString();
}
 
源代码13 项目: java-technology-stack   文件: TypeHelper.java
private String getQualifiedName(Element element) {
	if (element instanceof QualifiedNameable) {
		return ((QualifiedNameable) element).getQualifiedName().toString();
	}
	return element.toString();
}
 
源代码14 项目: netbeans   文件: ElementOverlay.java
public void registerClass(String parent, String clazz, ClassTree tree, boolean modified) {
    if (clazz == null) return;
    
    Element myself = ASTService.getElementImpl(tree);

    boolean newOrModified =    myself == null
                            || (!myself.getKind().isClass() && !myself.getKind().isInterface())
                            || !((QualifiedNameable) myself).getQualifiedName().contentEquals(clazz);

    if (newOrModified || class2Enclosed.containsKey(parent)) {
        List<String> c = class2Enclosed.get(parent);

        if (c == null) {
            class2Enclosed.put(parent, c = new ArrayList<String>());
        }

        c.add(clazz);
    }

    if (modified) {
        class2Enclosed.put(clazz, new ArrayList<String>());
    }

    Set<String> superFQNs = superFQNs(tree);

    boolean hadObject = superFQNs.remove("java.lang.Object");

    Set<String> original;

    if (!newOrModified) {
        original = new LinkedHashSet<String>();

        TypeElement tel = (TypeElement) myself;

        if (tel.getSuperclass() != null && tel.getSuperclass().getKind() == TypeKind.DECLARED) {
            original.add(((TypeElement) ((DeclaredType) tel.getSuperclass()).asElement()).getQualifiedName().toString());
        }

        for (TypeMirror intf : tel.getInterfaces()) {
            original.add(((TypeElement) ((DeclaredType) intf).asElement()).getQualifiedName().toString());
        }

        original.remove("java.lang.Object");
    } else {
        original = null;
    }

    if (!superFQNs.equals(original)) {
        if (hadObject) superFQNs.add("java.lang.Object");
        
        Set<Modifier> mods = EnumSet.noneOf(Modifier.class);

        mods.addAll(tree.getModifiers().getFlags());
        classes.put(clazz, mods);
        class2SuperElementTrees.put(clazz, superFQNs);
    }
}
 
源代码15 项目: netbeans   文件: ElementOverlay.java
@Override
public Element getEnclosingElement() {
    return ElementOverlay.this.resolve(ast, elements, ((QualifiedNameable/*XXX*/) delegateTo.getEnclosingElement()).getQualifiedName().toString(), moduleOf(elements, delegateTo));
}
 
源代码16 项目: jasperreports   文件: PropertyProcessor.java
protected CompiledPropertyMetadata toPropertyMetadata(VariableElement element, AnnotationMirror propertyAnnotation)
{
	Map<? extends ExecutableElement, ? extends AnnotationValue> annotationValues = processingEnv.getElementUtils().getElementValuesWithDefaults(propertyAnnotation);
	
	CompiledPropertyMetadata property = new CompiledPropertyMetadata();
	
	String propName = (String) annotationValue(annotationValues, "name").getValue();
	if (propName == null || propName.isEmpty())
	{
		propName = (String) element.getConstantValue();
		if (propName == null)
		{
			processingEnv.getMessager().printMessage(Kind.WARNING, "Failed to read constant value for " + element, 
					element);
			return null;
		}
	}
	property.setName(propName);
	
	boolean deprecated = processingEnv.getElementUtils().isDeprecated(element);
	property.setDeprecated(deprecated);
	
	QualifiedNameable enclosingElement = (QualifiedNameable) element.getEnclosingElement();
	property.setConstantDeclarationClass(enclosingElement.getQualifiedName().toString());
	property.setConstantFieldName(element.getSimpleName().toString());
	
	property.setCategory((String) annotationValue(annotationValues, "category").getValue());
	property.setDefaultValue((String) annotationValue(annotationValues, "defaultValue").getValue());
	property.setSinceVersion((String) annotationValue(annotationValues, "sinceVersion").getValue());
	property.setValueType(((TypeMirror) annotationValue(annotationValues, "valueType").getValue()).toString());
	
	@SuppressWarnings("unchecked")
	List<? extends AnnotationValue> scopeValues = (List<? extends AnnotationValue>) annotationValue(annotationValues, "scopes").getValue();
	List<PropertyScope> propertyScopes = new ArrayList<>(scopeValues.size());
	for (AnnotationValue scopeValue : scopeValues)
	{
		PropertyScope scope = Enum.valueOf(PropertyScope.class, ((VariableElement) scopeValue.getValue()).getSimpleName().toString());
		propertyScopes.add(scope); 
	}
	
	//automatically adding Global if Context is present
	int contextIndex = propertyScopes.indexOf(PropertyScope.CONTEXT);
	if (contextIndex >= 0 && !propertyScopes.contains(PropertyScope.GLOBAL))
	{
		propertyScopes.add(contextIndex, PropertyScope.GLOBAL);
	}
	
	//automatically adding Report if Dataset is present
	int datasetIndex = propertyScopes.indexOf(PropertyScope.DATASET);
	if (datasetIndex >= 0 && !propertyScopes.contains(PropertyScope.REPORT))
	{
		propertyScopes.add(datasetIndex, PropertyScope.REPORT);
	}
	
	property.setScopes(propertyScopes);
	
	@SuppressWarnings("unchecked")
	List<? extends AnnotationValue> scopeQualificationValues = (List<? extends AnnotationValue>) annotationValue(annotationValues, "scopeQualifications").getValue();
	List<String> scopeQualifications = new ArrayList<>(scopeValues.size());
	for (AnnotationValue qualificationValue : scopeQualificationValues)
	{
		String qualification = (String) qualificationValue.getValue();
		scopeQualifications.add(qualification);
	}
	property.setScopeQualifications(scopeQualifications);
	
	return property;
}
 
源代码17 项目: buck   文件: InterfaceValidator.java
@Override
public void onImport(
    boolean isStatic,
    boolean isStarImport,
    TreePath leafmostElementPath,
    QualifiedNameable leafmostElement,
    @Nullable Name memberName) {
  if (leafmostElement.getKind() != ElementKind.PACKAGE) {
    if (isStatic) {
      CompletedType completedType = completer.complete(leafmostElement, true);
      if (completedType != null
          && (completedType.kind == CompletedTypeKind.CRASH
              || completedType.kind == CompletedTypeKind.PARTIALLY_COMPLETED_TYPE)) {
        reportMissingDeps(completedType, leafmostElementPath);
      }
    } else {
      ResolvedType compilerResolvedType = compilerResolver.resolve(leafmostElementPath);
      if (compilerResolvedType != null) {
        switch (compilerResolvedType.kind) {
          case CRASH:
            reportMissingDeps(compilerResolvedType, leafmostElementPath);
            break;
          case RESOLVED_TYPE:
            // Nothing to do; it would resolve fine
            break;
            // $CASES-OMITTED$
          default:
            {
              TreeBackedResolvedType treeBackedResolvedType =
                  treeBackedResolver.resolve(leafmostElementPath);
              if (!treeBackedResolvedType.isCorrect()) {
                if (treeBackedResolvedType.isCorrectable()) {
                  treeBackedResolvedType.reportErrors(messageKind);
                } else {
                  reportMissingDeps(compilerResolvedType, leafmostElementPath);
                }
              }
            }
            break;
        }
      }
    }
  }

  if (!isStatic) {
    if (!isStarImport) {
      imports.importType((TypeElement) leafmostElement, leafmostElementPath);
    } else {
      imports.importMembers(leafmostElement, leafmostElementPath);
    }
  } else if (!isStarImport) {
    imports.importStatic((TypeElement) leafmostElement, Objects.requireNonNull(memberName));
  } else {
    imports.importStaticMembers((TypeElement) leafmostElement);
  }
}
 
源代码18 项目: buck   文件: ImportsTracker.java
public void importMembers(QualifiedNameable typeOrPackage, @Nullable TreePath location) {
  importedOwners.put(typeOrPackage, location);
}
 
源代码19 项目: auto   文件: AutoValueOrOneOfProcessor.java
/**
 * Returns the fully-qualified name of an annotation-mirror, e.g.
 * "com.google.auto.value.AutoValue".
 */
private static String getAnnotationFqName(AnnotationMirror annotation) {
  return ((QualifiedNameable) annotation.getAnnotationType().asElement())
      .getQualifiedName()
      .toString();
}
 
源代码20 项目: buck   文件: InterfaceScanner.java
/**
 * An import statement was encountered.
 *
 * @param isStatic true for static imports
 * @param isStarImport true for star imports
 * @param leafmostElementPath the path of the leafmost known element in the imported type
 *     expression
 * @param leafmostElement the leafmost known element in the imported type expression. For
 *     single-type imports, this is the imported type. For the rest, this is the type or package
 *     enclosing the imported element(s).
 * @param memberName for named static imports, the name of the static members to import.
 *     Otherwise null.
 */
void onImport(
    boolean isStatic,
    boolean isStarImport,
    TreePath leafmostElementPath,
    QualifiedNameable leafmostElement,
    @Nullable Name memberName);