private List<Fix> createQualifierFix( CompilationInfo compilationInfo, Element annotation, Element classElement ) { PackageElement packageElement = compilationInfo.getElements() .getPackageOf(classElement); FileObject targetFile = SourceUtils.getFile( ElementHandle.create(classElement), compilationInfo.getClasspathInfo()); return Collections.<Fix> singletonList(new CreateQualifierFix( compilationInfo, annotation.getSimpleName().toString(), packageElement.getQualifiedName().toString(), targetFile)); }
private List<Fix> createInterceptorFix( CompilationInfo compilationInfo, Element annotation, Element classElement ) { PackageElement packageElement = compilationInfo.getElements() .getPackageOf(classElement); FileObject targetFile = SourceUtils.getFile( ElementHandle.create(classElement), compilationInfo.getClasspathInfo()); return Collections.<Fix> singletonList(new CreateInterceptorBinding( compilationInfo, annotation.getSimpleName().toString(), packageElement.getQualifiedName().toString(), targetFile)); }
public static DeclarationLocation getDeclarationLocation(final ClasspathInfo cpInfo, final Element el) { ElementHandle<Element> handle = ElementHandle.create(el); FileObject fo = SourceUtils.getFile(handle, cpInfo); if (fo != null) { return getDeclarationLocation(fo, handle); } return DeclarationLocation.NONE; }
private void update( List<TypeElement> types , Set<TypeElement> disabled, CompilationController controller) { DefaultMutableTreeNode root = new DefaultMutableTreeNode(); for (TypeElement type : types) { FileObject fileObject = SourceUtils.getFile(ElementHandle .create(type), controller.getClasspathInfo()); TypeTreeNode node = new TypeTreeNode(fileObject, type, disabled.contains(type ),controller); root.add( node ); } setRoot(root); }
private void update( Collection<TypeElement> foundDecorators, LinkedHashSet<TypeElement> enabled, CompilationController controller ) { DefaultMutableTreeNode root = new DefaultMutableTreeNode(); LinkedHashSet<TypeElement> allDecorators = new LinkedHashSet<TypeElement>(); allDecorators.addAll( enabled ); allDecorators.addAll( foundDecorators ); for (TypeElement type : allDecorators) { FileObject fileObject = SourceUtils.getFile(ElementHandle .create(type), controller.getClasspathInfo()); TypeTreeNode node = new TypeTreeNode(fileObject, type, !enabled.contains(type ),controller); root.add( node ); } setRoot(root); }
@Override public void run(CompilationController controller) throws IOException { controller.toPhase(JavaSource.Phase.ELEMENTS_RESOLVED); TypeElement typeElement = controller.getElements().getTypeElement(className); if (typeElement != null) { result[0] = SourceUtils.getFile(ElementHandle.create(typeElement), controller.getClasspathInfo()); } } }, true);
public void run(CompilationController c) throws Exception { TypeElement te = c.getElements().getTypeElement(mainClassName); if (te != null) { synchronized (MainClassUpdater.this) { current = SourceUtils.getFile(te, cpInfo); listener = WeakListeners.create(FileChangeListener.class, MainClassUpdater.this, current); if (current != null && sourcePath.contains(current)) { current.addFileChangeListener(listener); } } } }
private static FileObject getFileObjectFromClassName(Project p, String qualifiedClassName) throws IOException { FileObject root = MiscUtilities.findSourceRoot(p); ClasspathInfo cpInfo = ClasspathInfo.create(root); ClassIndex ci = cpInfo.getClassIndex(); int beginIndex = qualifiedClassName.lastIndexOf('.')+1; String simple = qualifiedClassName.substring(beginIndex); Set<ElementHandle<TypeElement>> handles = ci.getDeclaredTypes( simple, ClassIndex.NameKind.SIMPLE_NAME, Collections.singleton(ClassIndex.SearchScope.SOURCE)); if ( handles == null ){ return null; } for (ElementHandle<TypeElement> handle : handles) { if (qualifiedClassName.equals(handle.getQualifiedName())) { return SourceUtils.getFile(handle, cpInfo); } } return null; }
@Override public FileObject getFile(){ return SourceUtils.getFile(getTypeElementHandle(), getHelper().getClasspathInfo()); }
@Override public FileObject getFile(){ return SourceUtils.getFile(getTypeElementHandle(), getHelper().getClasspathInfo()); }
/** * 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); }
private void update( List<VariableElement> vars , CompilationController controller) { DefaultMutableTreeNode root = new DefaultMutableTreeNode(); for (VariableElement var : vars) { FileObject fileObject = SourceUtils.getFile(ElementHandle .create(var), controller.getClasspathInfo()); InjectableTreeNode<Element> node = new InjectableTreeNode<Element>(fileObject, var, (DeclaredType)controller.getElementUtilities(). enclosingTypeElement(var).asType(), false,controller); root.add( node ); } setRoot(root); }
private String getRawCommentFor(Element element) { try { FileObject fo = SourceUtils.getFile(element, cpInfo); if (fo != null) { JavaSource js = JavaSource.forFileObject(fo); if (js != null) { final String[] ret = new String[1]; final ElementHandle<? extends Element> handle = ElementHandle.create(element); js.runUserActionTask(new Task<CompilationController>() { public void run(CompilationController controller) throws Exception { controller.toPhase(Phase.ELEMENTS_RESOLVED); Element e = handle.resolve(controller); if (e != null) ret[0] = controller.getElements().getDocComment(e); } },true); return ret[0] != null ? ret[0] : ""; //NOI18N } } } catch (IOException ex) { Exceptions.printStackTrace(ex); } return ""; //NOI18N }
private void update( List<ExecutableElement> methods , CompilationController controller) { DefaultMutableTreeNode root = new DefaultMutableTreeNode(); Map<Element, InjectableTreeNode<? extends Element>> methodsMap= new LinkedHashMap<Element, InjectableTreeNode<? extends Element>>(); for (ExecutableElement method : methods) { FileObject fileObject = SourceUtils.getFile(ElementHandle .create(method), controller.getClasspathInfo()); MethodTreeNode node = new MethodTreeNode(fileObject, method, (DeclaredType)controller.getElementUtilities(). enclosingTypeElement(method).asType(), false, controller); insertTreeNode( methodsMap , method , node , root , controller); } setRoot(root); }
static void checkForJsr311Bootstrap(TypeElement element, Project project, AnnotationModelHelper helper) { RestSupport restSupport = project.getLookup().lookup(RestSupport.class); if ( restSupport == null || restSupport.isRestSupportOn() ){ return; } if ( isRest(element, helper) ){ // Fix for BZ#201039 - REST configuration dialog appears after expanding a web project with WebLogic target FileObject sourceFile = SourceUtils.getFile(ElementHandle. create(element), helper.getClasspathInfo()); if ( sourceFile == null ){ // the element is not in source , it's binary return; } try { restSupport.ensureRestDevelopmentReady(RestSupport.RestConfig.IDE); } catch (IOException ex) { Exceptions.printStackTrace(ex); } } }
@Override public void run(CompilationController controller) throws Exception { controller.toPhase( Phase.ELEMENTS_RESOLVED ); for( String servletClass : servletClasses){ TypeElement typeElem = controller.getElements(). getTypeElement( servletClass); if ( typeElem == null ){ continue; } ElementHandle<TypeElement> handle = ElementHandle.create( typeElem ); FileObject fileObject = SourceUtils.getFile( handle, controller.getClasspathInfo()); if ( fileObject != null && !Boolean.TRUE.equals( fileObject.getAttribute(IS_SERVLET_FILE))) { fileObject.setAttribute(IS_SERVLET_FILE, Boolean.TRUE); } } } }, true);
private static boolean isIncluded (final ElementHandle<TypeElement> element, final ClasspathInfo cpInfo) { FileObject fobj = getFile (element,cpInfo); if (fobj == null) { //Not source return true; } ClassPath sourcePath = cpInfo.getClassPath(ClasspathInfo.PathKind.SOURCE); for (ClassPath.Entry e : sourcePath.entries()) { FileObject root = e.getRoot (); if (root != null && FileUtil.isParentOf(root,fobj)) { return e.includes(fobj); } } return true; }
@Override public void run(CompilationController controller) throws IOException { controller.toPhase(JavaSource.Phase.ELEMENTS_RESOLVED); TypeElement jc = controller.getElements().getTypeElement(entityClass); arrEntityClassFO[0] = org.netbeans.api.java.source.SourceUtils.getFile(ElementHandle.create(jc), controller.getClasspathInfo()); fieldAccess[0] = JpaControllerUtil.isFieldAccess(jc); for (ExecutableElement method : JpaControllerUtil.getEntityMethods(jc)) { String methodName = method.getSimpleName().toString(); if (methodName.startsWith("get")) { Element f = fieldAccess[0] ? JpaControllerUtil.guessField(method) : method; if (f != null) { if (JpaControllerUtil.isAnnotatedWith(f, "javax.persistence.Id") || JpaControllerUtil.isAnnotatedWith(f, "javax.persistence.EmbeddedId")) { idGetter.add(ElementHandle.create(method)); idProperty[0] = JpaControllerUtil.getPropNameFromMethod(methodName); } else if (JpaControllerUtil.isAnnotatedWith(f, "javax.persistence.OneToOne") || JpaControllerUtil.isAnnotatedWith(f, "javax.persistence.ManyToOne")) { toOneRelMethods.add(ElementHandle.create(method)); } else if (JpaControllerUtil.isAnnotatedWith(f, "javax.persistence.OneToMany") || JpaControllerUtil.isAnnotatedWith(f, "javax.persistence.ManyToMany")) { toManyRelMethods.add(ElementHandle.create(method)); } } } } } }, true);
@Override @CheckForNull protected URL map(@NonNull final FileObject fo) { final String relative = FileObjects.convertFolder2Package( FileObjects.stripExtension(FileObjects.getRelativePath(cacheRoot, FileUtil.toFile(fo))), File.separatorChar); final FileObject sourceFile = SourceUtils.getFile( ElementHandleAccessor.getInstance().create(ElementKind.CLASS, relative), resolveCps); return sourceFile == null ? null : sourceFile.toURL(); } }
FileObject file = SourceUtils.getFile(handle, js.getClasspathInfo()); if (file != null) { return file;