private static void setVariablePath( Object[] variableAtCaret, CompilationController controller, Element element ) { Element parent = element.getEnclosingElement(); if ( parent instanceof ExecutableElement ){ ElementHandle<ExecutableElement> handle = ElementHandle.create( (ExecutableElement)parent ) ; variableAtCaret[0] = handle; variableAtCaret[1] = element.getSimpleName().toString(); variableAtCaret[2] = InspectActionId.INJECTABLES_CONTEXT; } }
public int compare(ElementHandle arg0, ElementHandle arg1) { return arg0.getQualifiedName().compareTo(arg1.getQualifiedName()); } }
private VariableElement getField(CompilationInfo cinfo, String name) { TypeElement typeElement = typeElementHandle.resolve(cinfo); for(VariableElement var : ElementFilter.fieldsIn(typeElement.getEnclosedElements())) { if(var.getSimpleName().toString().equals(name)) { return var; } } return null; }
public static ErrorDescription createNotification( Severity severity, Element subject , WebBeansModel model, CompilationInfo info , String description, Fix fix ) { ElementHandle<Element> handle = ElementHandle.create( subject ); Element element = handle.resolve(info); if ( element == null){ return null; } Tree elementTree = info.getTrees().getTree(element); return createNotification(severity, elementTree, info, description, fix ); }
/** * Tests if the handle has this same signature as the parameter. * The handles has the same signatures if it is resolved into the same * element in the same {@link javax.tools.JavaCompiler} task, but may be resolved into * the different {@link Element} in the different {@link javax.tools.JavaCompiler} task. * @param element to be checked * @return true if this handle resolves into the same {@link Element} * in the same {@link javax.tools.JavaCompiler} task. */ public boolean signatureEquals (@NonNull final T element) { final ElementKind ek = element.getKind(); final ElementKind thisKind = getKind(); if ((ek != thisKind) && !(thisKind == ElementKind.OTHER && (ek.isClass() || ek.isInterface()))) { return false; } final ElementHandle<T> handle = create (element); return signatureEquals (handle); }
@Override public void run(CompilationController controller) throws Exception { Elements elems = controller.getElements(); TypeElement fxAppElement = elems.getTypeElement(classType); ElementHandle<TypeElement> appHandle = ElementHandle.create(fxAppElement); Set<ElementHandle<TypeElement>> appHandles = classIndex.getElements(appHandle, kinds, scopes); for (ElementHandle<TypeElement> elemHandle : appHandles) { appClassNames.add(elemHandle.getQualifiedName()); } } @Override
insideExpression(env, new TreePath(path, fa.getExpression())); TreePath parentPath = path.getParentPath(); ExpressionTree et = it.next(); if (et == fa || (et.getKind() == Tree.Kind.ASSIGNMENT && ((AssignmentTree) et).getExpression() == fa)) { if (type.getKind() == TypeKind.ERROR && el.getKind().isClass()) { el = controller.getElements().getPackageElement(((TypeElement) el).getQualifiedName()); if (type.getKind() == TypeKind.ERROR && el.getKind().isClass()) { el = controller.getElements().getPackageElement(((TypeElement) el).getQualifiedName()); kinds = EnumSet.of(CLASS, INTERFACE); if (!options.contains(Options.ALL_COMPLETION)) { exs = controller.getTreeUtilities().getUncaughtExceptions(grandParentPath.getParentPath()); break; TypeMirror t = trees.getTypeMirror(new TreePath(path, thr)); for (Iterator<TypeMirror> it = exs.iterator(); it.hasNext();) { if (types.isSubtype(it.next(), t)) { if (type.getKind() == TypeKind.ERROR && el.getKind().isClass()) { el = controller.getElements().getPackageElement(((TypeElement) el).getQualifiedName()); TypeElement te = teHandle.resolve(controller);
return fqn; if (simple.contentEquals(e.getSimpleName())) { if (qName.contentEquals(((TypeElement)e).getQualifiedName())) { return sqName.toString(); } else { if (simple.contentEquals(e.getSimpleName())) { if (qName.contentEquals(e.getQualifiedName())) { return sqName.toString(); } else { final Set<Element> elementsToImport = Collections.singleton(toImport); if (info instanceof WorkingCopy) { CompilationUnitTree nue = (CompilationUnitTree) ((WorkingCopy)info).resolveRewriteTarget(cut); ((WorkingCopy)info).rewrite(info.getCompilationUnit(), GeneratorUtilities.get((WorkingCopy)info).addImports(nue, elementsToImport)); } else { final ElementHandle handle = ElementHandle.create(toImport); SwingUtilities.invokeLater(new Runnable() { @Override JCCompilationUnit unit = (JCCompilationUnit) info.getCompilationUnit(); if (toImport.getKind() == ElementKind.PACKAGE) { StarImportScope importScope = new StarImportScope(unit.packge); importScope.prependSubScope(unit.starImportScope);
if (!compoundType) { TypeElement te = (TypeElement)dt.asElement(); element = ElementHandle.create(te); Element encl = te.getEnclosingElement(); genericOuter = (encl.getKind().isClass() || encl.getKind().isInterface()) && !((TypeElement)encl).getTypeParameters().isEmpty() && !te.getModifiers().contains(Modifier.STATIC); if (te.getTypeParameters().isEmpty() && !genericOuter) break; case TYPEVAR: TypeVariable tv = (TypeVariable)tm; element = ElementHandle.create(tv.asElement()); typeMirrors = new ArrayList<TypeMirrorHandle<? extends TypeMirror>>(); typeMirrors.add(tv.getLowerBound() != null ? create(tv.getLowerBound(), map) : null); case ERROR: ErrorType et = (ErrorType)tm; element = ElementHandle.create(et.asElement()); break; case UNION:
public void run(CompilationController compilationController) throws Exception { compilationController.toPhase(Phase.RESOLVED); Element element = elementHandle.resolve(compilationController); if (element != null && element.getKind() == ElementKind.METHOD) { ExecutableElement executableElement = (ExecutableElement) element; TypeMirror typeMirror = executableElement.getReturnType(); if (typeMirror != null && typeMirror.getKind() == TypeKind.DECLARED) { DeclaredType declaredType = (DeclaredType) typeMirror; TypeElement typeElement = (TypeElement) declaredType.asElement(); if (typeElement.getQualifiedName().toString().equals(finalRefactoringSourceFQN)) { TreePathHandle treePathHandle = TreePathHandle.create(compilationController.getTrees().getPath(element), compilationController); methodRenameRefactoring[0] = new RenameRefactoring(Lookups.fixed(treePathHandle)); methodRenameRefactoring[0].getContext().add(compilationController); } } } } }, true);
TypeElement te = (TypeElement)element.resolve(info); if (te == null) return null; if (typeMirrors == null) return (T)te.asType(); Iterator<TypeMirrorHandle<? extends TypeMirror>> it = typeMirrors.iterator(); Element encl = te.getEnclosingElement(); boolean genericOuter = (encl.getKind().isClass() || encl.getKind().isInterface()) && !((TypeElement)encl).getTypeParameters().isEmpty() && !te.getModifiers().contains(Modifier.STATIC); TypeMirror outer = null; if (genericOuter) { Element e = element.resolve(info); if (!(e instanceof TypeSymbol)) return null; e = element.resolve(info); if (e == null) { String[] signatures = element.getSignature(); assert signatures.length == 1; Context context = info.impl.getJavacTask().getContext();
private List<DeclaredType> getSubtypesOf(Env env, DeclaredType baseType) throws IOException { if (((TypeElement) baseType.asElement()).getQualifiedName().contentEquals(JAVA_LANG_OBJECT)) { return Collections.emptyList(); : Utilities.isCaseSensitive() ? ClassIndex.NameKind.PREFIX : ClassIndex.NameKind.CASE_INSENSITIVE_PREFIX; for (ElementHandle<TypeElement> handle : controller.getClasspathInfo().getClassIndex().getDeclaredTypes(subwordsPattern != null ? subwordsPattern : prefix, kind, EnumSet.allOf(ClassIndex.SearchScope.class))) { TypeElement te = handle.resolve(controller); if (te != null && trees.isAccessible(scope, te) && types.isSubtype(types.getDeclaredType(te), baseType)) { subtypes.add(types.getDeclaredType(te)); continue; if (startsWith(env, elem.getSimpleName().toString())) { subtypes.add(head); boolean isRaw = !tas.iterator().hasNext(); subtypes: for (ElementHandle<TypeElement> eh : index.getElements(ElementHandle.create(elem), EnumSet.of(ClassIndex.SearchKind.IMPLEMENTORS), EnumSet.allOf(ClassIndex.SearchScope.class))) { TypeElement e = eh.resolve(controller); if (e != null) { if (trees.isAccessible(scope, e)) { if (isRaw) { DeclaredType dt = types.getDeclaredType(e); Logger.getLogger("global").log(Level.FINE, String.format("Cannot resolve: %s on bootpath: %s classpath: %s sourcepath: %s\n", eh.toString(), controller.getClasspathInfo().getClassPath(ClasspathInfo.PathKind.BOOT), controller.getClasspathInfo().getClassPath(ClasspathInfo.PathKind.COMPILE),
int dot = strategy.getOffset(component); TreePath tp = controller.getTreeUtilities() .pathFor(dot); Element element = controller.getTrees().getElement(tp ); if ( element == null ){ StatusDisplayer.getDefault().setStatusText( subject[0] = ElementHandle.create(element); subject[1] = element.getSimpleName(); subject[2] = InspectActionId.METHOD_CONTEXT; Element enclosingElement = element.getEnclosingElement(); if ( enclosingElement instanceof ExecutableElement && hasAnnotation(element, OBSERVES_ANNOTATION)) subject[0] = ElementHandle.create(enclosingElement); subject[1] = enclosingElement.getSimpleName(); subject[2] = InspectActionId.METHOD_CONTEXT;
public void run(CompilationController cc) throws Exception { cc.toPhase(Phase.RESOLVED); Element element = oldHandle.resolveElement(cc); if (element == null || element.getKind() != ElementKind.METHOD) { return; } PropertyType type = null; ExecutableElement ee = (ExecutableElement) element; if (JavaUtils.isGetter(ee)) { type = PropertyType.READ_ONLY; } else if (JavaUtils.isSetter(ee)) { type = PropertyType.WRITE_ONLY; } else { return; } // gather and keep all overridden methods plus current method Collection<ElementHandle<ExecutableElement>> methodHandles = JavaUtils.getOverridenMethodsAsHandles(ee, cc); methodHandles = new ArrayList<ElementHandle<ExecutableElement>>(methodHandles); methodHandles.add(ElementHandle.create(ee)); String oldName = JavaUtils.getPropertyName(element.getSimpleName().toString()); element = element.getEnclosingElement(); result[0] = new RenamedProperty(methodHandles, oldName, JavaUtils.getPropertyName(newName), type); } }, true);
TypeElement element = findClassElementByBinaryName(classBinName, cc); while (element != null) { List<ExecutableElement> methods = ElementFilter.methodsIn(element.getEnclosedElements()); for (ExecutableElement method : methods) { this.methodHandle = ElementHandle.create(method); return; TypeMirror superClassMirror = element.getSuperclass(); if (superClassMirror instanceof DeclaredType) { DeclaredType declaredType = (DeclaredType) superClassMirror; Element elem = declaredType.asElement(); if (elem.getKind() == ElementKind.CLASS) { element = (TypeElement) elem;
InjectableTreeNode(FileObject fileObject, T element, DeclaredType parentType, boolean disabled , CompilationInfo compilationInfo) { myFileObject = fileObject; myElementHandle = ElementHandle.create(element); myElementKind = element.getKind(); myModifiers = element.getModifiers(); myCpInfo = compilationInfo.getClasspathInfo(); isDisabled = disabled; setName(element.getSimpleName().toString()); setIcon(ElementIcons.getElementIcon(element.getKind(), element.getModifiers())); setLabel(Utils.format(element, parentType, compilationInfo)); setFQNLabel(Utils.format(element, parentType, compilationInfo , false, true)); setToolTip(Utils.format(element, parentType, compilationInfo, true, WebBeansNavigationOptions.isShowFQN())); }
Element resolve = handle.resolve( myController); if ( resolve!= null) { DeclaredType parent = null; myController.getElementUtilities(). enclosingTypeElement(resolve); parent = (DeclaredType)enclosingTypeElement.asType(); setIcon(ElementIcons.getElementIcon(resolve.getKind(), resolve.getModifiers())); setText(Utils.format(resolve, parent , myController));
TreePath path = controller.getTreeUtilities().pathFor(exactOffset); TreePath parent = path.getParentPath(); if (parent != null) { Tree parentLeaf = parent.getLeaf(); if ( parentLeaf.getKind() == Kind.METHOD_INVOCATION){ ExpressionTree select = ((MethodInvocationTree)parentLeaf). String variableName = caller.getSimpleName().toString(); TypeElement enclosingTypeElement = controller.getElementUtilities(). enclosingTypeElement( method); String fqnMethodClass = enclosingTypeElement. getQualifiedName().toString(); if( EVENT_INTERFACE.equals(fqnMethodClass)){ List<VariableElement> fields = if ( variableName.equals( varName )){ ElementHandle<VariableElement> handle = ElementHandle.create(var); variable[0]= handle; variable[1]= varName;
/** * Returns a {@link FileObject} in which the Element is defined. * @param element for which the {@link FileObject} should be located * @param cpInfo the classpaths context * @return the defining {@link FileObject} or null if it cannot be * found * * @deprecated use {@link getFile(ElementHandle, ClasspathInfo)} */ public static FileObject getFile (Element element, final ClasspathInfo cpInfo) { Parameters.notNull("element", element); //NOI18N Parameters.notNull("cpInfo", cpInfo); //NOI18N Element prev = element.getKind() == ElementKind.PACKAGE ? element : null; while (element.getKind() != ElementKind.PACKAGE) { prev = element; element = element.getEnclosingElement(); } final ElementKind kind = prev.getKind(); if (!(kind.isClass() || kind.isInterface() || kind == ElementKind.PACKAGE)) { return null; } final ElementHandle<? extends Element> handle = ElementHandle.create(prev); return getFile (handle, cpInfo); }
public void run(WorkingCopy workingCopy) throws IOException { workingCopy.toPhase(JavaSource.Phase.RESOLVED); ExecutableElement idGetterElement = idGetter.resolve(workingCopy); idGetterName[0] = idGetterElement.getSimpleName().toString(); TypeMirror idType = idGetterElement.getReturnType(); idClass = (TypeElement) declaredType.asElement(); embeddable[0] = idClass != null && JpaControllerUtil.isEmbeddableClass(idClass); idPropertyType[0] = idClass.getQualifiedName().toString(); } else if (TypeKind.BOOLEAN == idType.getKind()) { idPropertyType[0] = "boolean"; ClassTree classTree = workingCopy.getTrees().getTree(controllerTypeElement); ClassTree modifiedClassTree = classTree; (embeddable[0] ? fieldName + ".s" + idGetterName[0].substring(1) + "(new " + idClass.getSimpleName() + "());\n" : "") + "return \"" + fieldName + "_create\";"; methodInfo = new MethodInfo("createSetup", publicModifier, "java.lang.String", null, null, null, bodyText, null, null); TypeElement entityType = workingCopy.getElements().getTypeElement(entityClass); StringBuffer codeToPopulatePkFields = new StringBuffer(); if (embeddable[0]) { newEntityStringInit = "new" + simpleEntityName + ".s" + idGetterName[0].substring(1) + "(new " + idClass.getSimpleName() + "());\n" + "String " + newEntityStringVar + " = converter.getAsString(FacesContext.getCurrentInstance(), null, new" + simpleEntityName + ");\n";