if (typeTree == null) { TypeMirror typeMirror = copy.getTreeUtilities().parseType(typeName, scope); typeTree = make.Type(typeMirror);
String type = parameters.substring(lastParamStart, paramIndex).replace("...", "[]"); types.add(info.getTypes().erasure(info.getTreeUtilities().parseType(type, info.getTopLevelElements().get(0)/*XXX*/))); lastParamStart = paramIndex + 1;
private void addAttributeValues(Env env, Element element, AnnotationMirror annotation, ExecutableElement member) throws IOException { CompilationController controller = env.getController(); TreeUtilities tu = controller.getTreeUtilities(); ElementUtilities eu = controller.getElementUtilities(); for (javax.annotation.processing.Completion completion : SourceUtils.getAttributeValueCompletions(controller, element, annotation, member, env.getPrefix())) { String value = completion.getValue().trim(); if (value.length() > 0 && startsWith(env, value)) { TypeMirror type = member.getReturnType(); TypeElement typeElement = null; while (type.getKind() == TypeKind.ARRAY) { type = ((ArrayType) type).getComponentType(); } if (type.getKind() == TypeKind.DECLARED) { CharSequence fqn = ((TypeElement) ((DeclaredType) type).asElement()).getQualifiedName(); if (JAVA_LANG_CLASS.contentEquals(fqn)) { String name = value.endsWith(".class") ? value.substring(0, value.length() - 6) : value; //NOI18N TypeMirror tm = tu.parseType(name, eu.outermostTypeElement(element)); typeElement = tm != null && tm.getKind() == TypeKind.DECLARED ? (TypeElement) ((DeclaredType) tm).asElement() : null; if (typeElement != null && startsWith(env, typeElement.getSimpleName().toString())) { env.addToExcludes(typeElement); } } } results.add(itemFactory.createAttributeValueItem(env.getController(), value, completion.getMessage(), typeElement, anchorOffset, env.getReferencesCount())); } } }
/** * Finds whether the given <code>TypeElement</code> is the subtype of a * given supertype. This is a convenience method for * {@link javax.lang.model.util.Types#isSubtype}. * * @param controller a <code>CompilationController</code>. * @param subtype the presumed subtype. * @param supertype the presumed supertype. * @return true if <code>subtype</code> if a subtype of </code>supertype</code>, * false otherwise. */ public static boolean isSubtype(CompilationController controller, TypeElement subtype, String supertype) { Parameters.notNull("controller", controller); // NOI18N Parameters.notNull("subtype", subtype); // NOI18N Parameters.notNull("supertype", supertype); // NOI18N if (controller.getElements().getTypeElement(supertype) != null) { TypeMirror typeMirror = controller.getTreeUtilities().parseType(supertype, subtype); if (typeMirror != null) { return controller.getTypes().isSubtype(subtype.asType(), typeMirror); } } return false; }
/** * Creates a new Tree for a given String type specification. * * @param type String type specification * @see com.sun.source.tree.ExpressionTree * @since 0.65 */ public @NonNull Tree Type(@NonNull String type) { Parameters.notNull("type", type); Tree typeTree = copy.getTreeUtilities().parseType(type); final Map<Tree, Tree> translate = new HashMap<Tree, Tree>(); new TreeScanner<Void, Void>() { @Override public Void visitMemberSelect(MemberSelectTree node, Void p) { translate.put(node, QualIdent(node.toString())); return null; } @Override public Void visitIdentifier(IdentifierTree node, Void p) { translate.put(node, QualIdent(node.toString())); return null; } }.scan(typeTree, null); return copy.getTreeUtilities().translate(typeTree, translate); }
TypeElement toExclude = null; if (nc.getIdentifier().getKind() == Tree.Kind.IDENTIFIER && prefix != null) { TypeMirror tm = controller.getTreeUtilities().parseType(prefix, env.getScope().getEnclosingClass()); if (tm != null && tm.getKind() == TypeKind.DECLARED) { TypeElement te = (TypeElement) ((DeclaredType) tm).asElement();
if (parent.getKind() == Tree.Kind.NEW_CLASS && ((NewClassTree) parent).getIdentifier() == fa && prefix != null) { String typeName = controller.getElementUtilities().getElementName(el, true) + "." + prefix; //NOI18N TypeMirror tm = controller.getTreeUtilities().parseType(typeName, env.getScope().getEnclosingClass()); if (tm != null && tm.getKind() == TypeKind.DECLARED) { addMembers(env, tm, ((DeclaredType) tm).asElement(), EnumSet.of(CONSTRUCTOR), null, inImport, insideNew, false); if (parent.getKind() == Tree.Kind.NEW_CLASS && ((NewClassTree) parent).getIdentifier() == fa && prefix != null) { String typeName = controller.getElementUtilities().getElementName(el, true) + "." + prefix; //NOI18N TypeMirror tm = controller.getTreeUtilities().parseType(typeName, env.getScope().getEnclosingClass()); if (tm != null && tm.getKind() == TypeKind.DECLARED) { addMembers(env, tm, ((DeclaredType) tm).asElement(), EnumSet.of(CONSTRUCTOR), null, inImport, insideNew, false);