Java Code Examples for org.netbeans.api.java.source.JavaSource#runWhenScanFinished()
The following examples show how to use
org.netbeans.api.java.source.JavaSource#runWhenScanFinished() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TestSingleMethodSupport.java From netbeans with Apache License 2.0 | 6 votes |
public static SingleMethod getTestMethod(Document doc, int cursor){ SingleMethod sm = null; if (doc != null) { JavaSource js = JavaSource.forDocument(doc); if(js == null) { return null; } TestClassInfoTask task = new TestClassInfoTask(cursor); try { Future<Void> f = js.runWhenScanFinished(task, true); if (f.isDone() && task.getFileObject() != null && task.getMethodName() != null) { sm = new SingleMethod(task.getFileObject(), task.getMethodName()); } } catch (IOException ex) { LOGGER.log(Level.WARNING, null, ex); } } return sm; }
Example 2
Source File: TestSingleMethodSupport.java From netbeans with Apache License 2.0 | 6 votes |
public static SingleMethod getTestMethod(Document doc, int cursor){ SingleMethod sm = null; if (doc != null){ JavaSource js = JavaSource.forDocument(doc); if(js == null) { return null; } TestClassInfoTask task = new TestClassInfoTask(cursor); try { Future<Void> f = js.runWhenScanFinished(task, true); if (f.isDone() && task.getFileObject() != null && task.getMethodName() != null){ sm = new SingleMethod(task.getFileObject(), task.getMethodName()); } } catch (IOException ex) { LOGGER.log(Level.WARNING, null, ex); } } return sm; }
Example 3
Source File: J2SEActionProvider.java From netbeans with Apache License 2.0 | 6 votes |
private void enqueueDeferred(final Runnable work) { boolean addGuard = false; synchronized (this) { this.deferred.offer(work); if (deferredGuard == 0) { addGuard = true; deferredGuard = 1; } } if (addGuard) { final JavaSource js = createSource(); synchronized (this) { if (deferredGuard == 1) { deferredGuard = 2; try { js.runWhenScanFinished((cc) -> drainDeferred(), true); } catch (IOException ioe) { Exceptions.printStackTrace(ioe); } } } } }
Example 4
Source File: AddBeanPanelVisual.java From netbeans with Apache License 2.0 | 6 votes |
private void validClass() { JavaSource js = JavaSource.create(ClasspathInfo.create(fileObject)); if (js == null) { return; } try { ClassSeeker laterSeeker = new ClassSeeker(); Future<Void> seekingTask = js.runWhenScanFinished(laterSeeker, true); if (seekingTask.isDone()) { classFound.set(laterSeeker.isClassFound()); return; } ClassSeeker promptSeeker = new ClassSeeker(); js.runUserActionTask(promptSeeker, true); classFound.set(promptSeeker.isClassFound()); } catch (IOException ex) { Exceptions.printStackTrace(ex); } }
Example 5
Source File: BaseAnalisysTestCase.java From netbeans with Apache License 2.0 | 6 votes |
protected void runAnalysis( FileObject fileObject , final ResultProcessor processor ) throws IOException { IndexingManager.getDefault().refreshIndexAndWait(srcFO.getURL(), null); JavaSource js = JavaSource.create(myClassPathInfo, fileObject ); final AbstractAnalysisTask task = createTask(); js.runWhenScanFinished( new Task<CompilationController>() { @Override public void run( CompilationController controller ) throws Exception { controller.toPhase( Phase.ELEMENTS_RESOLVED ); task.run( controller ); processor.process((TestProblems)task.getResult()); } }, true); }
Example 6
Source File: ActionProviderSupport.java From netbeans with Apache License 2.0 | 5 votes |
private static void invokeByJavaSource ( @NonNull final Runnable runnable) throws IOException { Parameters.notNull("runnable", runnable); //NOI18N final ClasspathInfo info = ClasspathInfo.create(JavaPlatform.getDefault().getBootstrapLibraries(), ClassPathSupport.createClassPath(new URL[0]), ClassPathSupport.createClassPath(new URL[0])); final JavaSource js = JavaSource.create(info); if (js != null) { js.runWhenScanFinished((final CompilationController controller) -> { runnable.run(); }, true); } }
Example 7
Source File: ManagedBeanCustomizer.java From netbeans with Apache License 2.0 | 5 votes |
public List<String> getManagedBeanPropertyNames(Project project, final String managedBean, final String entityClassName, final String managedBeanName, final boolean collection) { final List<String> res = new ArrayList<String>(); Sources sources = ProjectUtils.getSources(project); SourceGroup[] sourceGroups = sources.getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA); if (sourceGroups.length == 0) { return res; } FileObject root = sourceGroups[0].getRootFolder(); ClasspathInfo classpathInfo = ClasspathInfo.create( ClassPathSupport.createProxyClassPath(ClassPath.getClassPath(root, ClassPath.BOOT)), ClassPathSupport.createProxyClassPath(ClassPath.getClassPath(root, ClassPath.COMPILE)), ClassPathSupport.createProxyClassPath(ClassPath.getClassPath(root, ClassPath.SOURCE))); JavaSource js = JavaSource.create(classpathInfo); try { Future<Void> searchingTask = js.runWhenScanFinished( new SearchTask(managedBean, entityClassName, managedBeanName, res, false), true); if (searchingTask.isDone()) { return res; } js.runUserActionTask(new SearchTask(managedBean, entityClassName, managedBeanName, res, true), true); } catch (IOException ex) { Exceptions.printStackTrace(ex); } return res; }
Example 8
Source File: EJBActionGroup.java From netbeans with Apache License 2.0 | 5 votes |
protected boolean enable(final org.openide.nodes.Node[] activatedNodes) { if (activatedNodes.length != 1) { return false; } final FileObject fileObject = activatedNodes[0].getLookup().lookup(FileObject.class); if (fileObject == null) { return false; } JavaSource javaSource = JavaSource.forFileObject(fileObject); if (javaSource == null) { return false; } // The following code atomically checks that the scan is not running and posts a JavaSource task // which is expected to run synchronously. If the task does not run synchronously, // then we cancel it and return false from this method. final AtomicBoolean enabled = new AtomicBoolean(false); try { Future<Void> future = javaSource.runWhenScanFinished(new Task<CompilationController>() { public void run(CompilationController controller) throws Exception { String className = null; ElementHandle<TypeElement> elementHandle = _RetoucheUtil.getJavaClassFromNode(activatedNodes[0]); if (elementHandle != null) { className = elementHandle.getQualifiedName(); } EjbMethodController ejbMethodController = null; if (className != null) { ejbMethodController = EjbMethodController.createFromClass(fileObject, className); } enabled.set(ejbMethodController != null); } }, true); // Cancel the task if it has not run yet (it will run asynchronously at a later point in time // which is too late for us -- we need the result now). If it has already run, the cancel() call is a no-op. future.cancel(true); } catch (IOException e) { Exceptions.printStackTrace(e); } return enabled.get(); }
Example 9
Source File: MdbLocationPanelVisual.java From netbeans with Apache License 2.0 | 5 votes |
@NbBundle.Messages({ "MdbLocationPanel.warn.scanning.in.progress=Scanning in progress, parial results shown..." }) private MdbLocationPanelVisual(Project project, J2eeModuleProvider provider, Set<MessageDestination> moduleDestinations, Set<MessageDestination> serverDestinations) { initComponents(); projectDestinationsCombo.setModel(new ProjectDestinationsComboModel(projectDestinationsCombo.getEditor())); this.project = project; this.provider = provider; this.moduleDestinations = moduleDestinations; this.serverDestinations = serverDestinations; isDestinationCreationSupportedByServerPlugin = provider.getConfigSupport().supportsCreateMessageDestination(); // scanning in progress? if (!SourceUtils.isScanInProgress()) { scanningLabel.setVisible(false); } else { ClasspathInfo classPathInfo = MdbLocationPanel.getClassPathInfo(project); JavaSource javaSource = JavaSource.create(classPathInfo); try { javaSource.runWhenScanFinished(new Task<CompilationController>() { @Override public void run(CompilationController parameter) throws Exception { fire(true); } }, true); } catch (IOException ex) { Exceptions.printStackTrace(ex); } } }
Example 10
Source File: MainClassUpdater.java From netbeans with Apache License 2.0 | 5 votes |
private void addFileChangeListener () { synchronized (MainClassUpdater.this) { if (current != null && listener != null) { current.removeFileChangeListener(listener); current = null; listener = null; } } final String mainClassName = MainClassUpdater.this.eval.getProperty(mainClassPropName); if (mainClassName != null) { try { FileObject[] roots = sourcePath.getRoots(); if (roots.length>0) { ClassPath bootCp = ClassPath.getClassPath(roots[0], ClassPath.BOOT); ClassPath compileCp = ClassPath.getClassPath(roots[0], ClassPath.COMPILE); final ClasspathInfo cpInfo = ClasspathInfo.create(bootCp, compileCp, sourcePath); JavaSource js = JavaSource.create(cpInfo); js.runWhenScanFinished(new Task<CompilationController>() { 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); } } } } }, true); } } catch (IOException ioe) { } } }
Example 11
Source File: ClientJavaSourceHelper.java From netbeans with Apache License 2.0 | 4 votes |
private static void addJerseyClient ( final JavaSource source, final String className, final String resourceUri, final RestServiceDescription restServiceDesc, final WadlSaasResource saasResource, final PathFormat pf, final Security security, final ClientGenerationStrategy strategy ) { try { final Task<WorkingCopy> task = new AbstractTask<WorkingCopy>() { @Override public void run(WorkingCopy copy) throws java.io.IOException { copy.toPhase(JavaSource.Phase.RESOLVED); ClassTree tree = JavaSourceHelper.getTopLevelClassTree(copy); ClassTree modifiedTree = null; if (className == null) { modifiedTree = modifyJerseyClientClass(copy, tree, resourceUri, restServiceDesc, saasResource, pf, security, strategy ); } else { modifiedTree = addJerseyClientClass(copy, tree, className, resourceUri, restServiceDesc, saasResource, pf, security, strategy); } copy.rewrite(tree, modifiedTree); } }; ModificationResult result = source.runModificationTask(task); if ( SourceUtils.isScanInProgress() ){ source.runWhenScanFinished( new Task<CompilationController>(){ @Override public void run(CompilationController controller) throws Exception { source.runModificationTask(task).commit(); } }, true); } else { result.commit(); } } catch (java.io.IOException ex) { if (ex.getCause() instanceof GuardedException) { DialogDisplayer.getDefault().notify( new NotifyDescriptor.Message( NbBundle.getMessage(ClientJavaSourceHelper.class, "ERR_CannotApplyGuarded"), // NOI18N NotifyDescriptor.ERROR_MESSAGE)); Logger.getLogger(ClientJavaSourceHelper.class.getName()). log(Level.FINE, null, ex); } else { Logger.getLogger(ClientJavaSourceHelper.class.getName()). log(Level.WARNING, null, ex); } } }