public JavaSource create(ClasspathInfo cpInfo, PositionConverter binding, Collection<? extends FileObject> files) throws IllegalArgumentException { return JavaSource.create(cpInfo, files); }
private void runClassSeekerUserTask(ClassSeekerTask classSeekerTask) { JavaSource js = JavaSource.create(classSeekerTask.cpi); if (js != null) { try { js.runUserActionTask(classSeekerTask, true); } catch (IOException ex) { Exceptions.printStackTrace(ex); } } }
private JavaSource getJavaSourceFromRequest() { ClasspathInfo pathInfo = getClasspathInfoFromRequest(request); assert pathInfo != null; JavaSource javaSource = JavaSource.create(pathInfo); if (javaSource == null) { LOG.log(Level.FINEST, "Problem retrieving JavaSource from ClassPathInfo, exiting."); return null; } return javaSource; }
private JavaSource getJavaSourceFromRequest() { ClasspathInfo pathInfo = getClasspathInfoFromRequest(context); assert pathInfo != null; JavaSource javaSource = JavaSource.create(pathInfo); if (javaSource == null) { LOG.log(Level.FINEST, "Problem retrieving JavaSource from ClassPathInfo, exiting."); return null; } return javaSource; }
@NonNull public JavaSource createResolver(@NonNull final ClasspathInfo info) { JavaSource src = resolver == null ? null : resolver.get(); if (src == null) { LOG.log(Level.FINE,"Javac resolver created."); //NOI18N src = JavaSource.create(info); resolver = new SoftReference<>(src); } return src; }
private FileObject findFileObject(final String className){ if (cpInfo == null){ return null; } final FileObject[] result = new FileObject[]{null}; try{ JavaSource.create(cpInfo).runUserActionTask(new Task<CompilationController>() { @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); }catch(IOException ex){} return result[0]; } }
public static Object execute(Write task, List<FileObject> fObjs) { JavaSource js = JavaSource.create(ClasspathInfo.create(fObjs.get(0)), fObjs); return execute(task, js); }
@Override protected List<SelectorNode> getConstructorNodes(final ConstructorsNode parent) { final List<SelectorNode> constructorNodes = new ArrayList<SelectorNode>(); try { JavaSource js = JavaSource.create(cpInfo, new org.openide.filesystems.FileObject[0]); js.runUserActionTask(new CancellableTask<CompilationController>() { public void cancel() { } public void run(CompilationController controller) throws Exception { controller.toPhase(JavaSource.Phase.RESOLVED); TypeElement type = typeHandle.resolve(controller); List<ExecutableElement> methods = ElementFilter.constructorsIn(type.getEnclosedElements()); for (ExecutableElement method : methods) { constructorNodes.add(new JavaConstructorNode(cpInfo, method, method.getSimpleName().toString(), parent)); } } }, true); } catch (IllegalArgumentException ex) { ex.printStackTrace(); } catch (IOException ex) { ex.printStackTrace(); } return constructorNodes; } };
public static void createParamsForConverterTemplate(final Map<String, Object> params, final FileObject targetJspFO, final String entityClass, final JpaControllerUtil.EmbeddedPkSupport embeddedPkSupport) throws IOException { JavaSource javaSource = JavaSource.create(EntityClass.createClasspathInfo(targetJspFO)); javaSource.runUserActionTask(new Task<CompilationController>() { public void run(CompilationController controller) throws IOException { controller.toPhase(JavaSource.Phase.ELEMENTS_RESOLVED); TypeElement typeElement = controller.getElements().getTypeElement(entityClass); createParamsForConverterTemplate(params, controller, typeElement, embeddedPkSupport); } }, true); }
private static void runUserActionTask(JTextComponent target, Task<CompilationController> aTask) { FileObject fobj = getFileObject(target); if (fobj == null) { return; } try { JavaSource src = JavaSource.create(ClasspathInfo.create(fobj)); if (src != null) src.runUserActionTask(aTask, false); } catch (IOException e) { Exceptions.printStackTrace(e); } }
public static Map<String, Object> createFieldParameters(FileObject targetJspFO, final String entityClass, final String managedBean, final String managedBeanProperty, final boolean collectionComponent, final boolean initValueGetters, JsfLibrariesSupport jls) throws IOException { final Map<String, Object> params = new HashMap<>(); JavaSource javaSource = JavaSource.create(EntityClass.createClasspathInfo(targetJspFO)); javaSource.runUserActionTask(new Task<CompilationController>() { @Override public void run(CompilationController controller) throws IOException { controller.toPhase(JavaSource.Phase.ELEMENTS_RESOLVED); TypeElement typeElement = controller.getElements().getTypeElement(entityClass); enumerateEntityFields(params, controller, typeElement, managedBeanProperty, collectionComponent, initValueGetters); } }, true); params.put("managedBean", managedBean); // NOI18N params.put("managedBeanProperty", managedBeanProperty); // NOI18N String entityName = entityClass; if (entityName.lastIndexOf(".") != -1) { entityName = entityName.substring(entityClass.lastIndexOf(".")+1); } params.put("entityName", entityName); // NOI18N if (jls != null) { params.put("prefixResolver", new PrefixResolver(jls)); } // namespace location WebModule webModule = WebModule.getWebModule(targetJspFO); params.put("nsLocation", JSFUtils.getNamespaceDomain(webModule)); //NOI18N return params; }
private JavaSource createJavaSource() { FileObject fileObject = info.getSnapshot().getSource().getFileObject(); if (fileObject == null) { return null; } // get the JavaSource for our file. JavaSource javaSource = JavaSource.create(ClasspathInfo.create(fileObject)); if (javaSource == null) { LOG.log(Level.FINEST, "Problem retrieving JavaSource from ClassPathInfo, exiting."); return null; } return javaSource; }
public static Element resolveElement(final AbstractRefactoring refactoring, final TreePathHandle treePathHandle) { final ClasspathInfo cpInfo = refactoring.getContext().lookup(ClasspathInfo.class); final Element[] element = new Element[1]; JavaSource source = JavaSource.create(cpInfo, new FileObject[]{treePathHandle.getFileObject()}); try { source.runUserActionTask(new Task<CompilationController>() { @Override public void run(CompilationController info) throws Exception { info.toPhase(JavaSource.Phase.RESOLVED); element[0] = treePathHandle.resolveElement(info); } }, true); } catch (IOException exception) { LOGGER.log(Level.WARNING, "Exception by refactoring:", exception); //NOI18NN } return element[0]; } }
public JavaConstructorNode(ClasspathInfo cpInfo, final ExecutableElement method, String methodName, ConstructorsNode parent) { super(methodName, parent); this.method = method; final String[] signatureString = new String[1]; JavaSource js = JavaSource.create(cpInfo, new org.openide.filesystems.FileObject[0]); try { js.runUserActionTask(new CancellableTask<CompilationController>() { public void cancel() { } public void run(CompilationController controller) throws Exception { signatureString[0] = SourceUtils.getVMMethodSignature(method, controller); } }, true); } catch (IOException ex) { ex.printStackTrace(); } if (signatureString[0] != null) { signature = new SourceCodeSelection(getEnclosingClass(method).getQualifiedName().toString(), method.getSimpleName().toString(), signatureString[0]); updateDisplayName(formatterFactory.getFormatter().formatMethodName(signature).toFormatted()); modifiers = new HashSet<String>(); for (Modifier modifier : method.getModifiers()) { modifiers.add(modifier.name()); } } }
private JavaSource getJavaSource(SourcePathProvider sp) { String[] roots = sp.getOriginalSourceRoots(); List<FileObject> sourcePathFiles = new ArrayList<FileObject>(); for (String root : roots) { FileObject fo = FileUtil.toFileObject (new java.io.File(root)); if (fo != null && FileUtil.isArchiveFile (fo)) { fo = FileUtil.getArchiveRoot (fo); } sourcePathFiles.add(fo); } ClassPath bootPath = ClassPathSupport.createClassPath(new FileObject[] {}); ClassPath classPath = ClassPathSupport.createClassPath(new FileObject[] {}); ClassPath sourcePath = ClassPathSupport.createClassPath(sourcePathFiles.toArray(new FileObject[] {})); return JavaSource.create(ClasspathInfo.create(bootPath, classPath, sourcePath), new FileObject[] {}); }
private void registerClassPathListener(DesignDocument document) { final Project project = ProjectUtils.getProject(document); final ClasspathInfo info = getClasspathInfo(project); if (info == null) { return; } String projID = document.getDocumentInterface().getProjectID(); if (!registeredProjects.contains(projID)) { Task<CompilationController> ct = new ListenerCancellableTask(info); try { JavaSource.create(info).runUserActionTask(ct, true); registeredProjects.add(projID); } catch (IOException ex) { Debug.warning(ex); } } }
private void registerClassPathListener() { final DesignDocument doc = document.get(); if (doc == null) { return; } final ClasspathInfo info = getClasspathInfo(ProjectUtils.getProject(doc)); if (info == null) { Debug.warning("Can't get ClasspathInfo for project"); // NOI18N return; } try { Task<CompilationController> ct = new Task<CompilationController>() { public void run(CompilationController cc) throws Exception { ClassPath cp = info.getClassPath(ClasspathInfo.PathKind.BOOT); PropertyChangeListener wcl = WeakListeners.propertyChange(MidpJavaSupport.this, cp); cp.addPropertyChangeListener(wcl); } }; JavaSource.create(info).runUserActionTask(ct, true); } catch (IOException ex) { Debug.warning(ex); } }
public static JavaSource getJavaSource(FileObject fileObject) { if (fileObject == null) { return null; } Project project = FileOwnerQuery.getOwner(fileObject); if (project == null) { return null; } // XXX this only works correctly with projects with a single sourcepath, // but we don't plan to support another kind of projects anyway (what about Maven?). SourceGroup[] sourceGroups = ProjectUtils.getSources(project).getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA); for (SourceGroup sourceGroup : sourceGroups) { return JavaSource.create(ClasspathInfo.create(sourceGroup.getRootFolder())); } return null; }
public static JavaSource createJavaSource(WebModule webModule) { Project project = FileOwnerQuery.getOwner(webModule.getDocumentBase()); ClassPathProvider cpp = project.getLookup().lookup(ClassPathProvider.class); ClassPath bootCP = cpp.findClassPath(webModule.getDocumentBase(), ClassPath.BOOT); ClassPath compileCP = cpp.findClassPath(webModule.getDocumentBase(), ClassPath.COMPILE); ClassPath sourceCP = cpp.findClassPath(webModule.getDocumentBase(), ClassPath.SOURCE); return JavaSource.create(ClasspathInfo.create(bootCP, compileCP, sourceCP), Collections.EMPTY_LIST); }
public static JavaSource getJavaSource(Document doc) { FileObject fileObject = NbEditorUtilities.getFileObject(doc); if (fileObject == null) { return null; } Project project = FileOwnerQuery.getOwner(fileObject); if (project == null) { return null; } // XXX this only works correctly with projects with a single sourcepath, // but we don't plan to support another kind of projects anyway (what about Maven?). // mkleint: Maven has just one sourceroot for java sources, the config files are placed under // different source root though. JavaProjectConstants.SOURCES_TYPE_RESOURCES SourceGroup[] sourceGroups = ProjectUtils.getSources(project).getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA); for (SourceGroup sourceGroup : sourceGroups) { return JavaSource.create(ClasspathInfo.create(sourceGroup.getRootFolder())); } return null; }