|
org.netbeans.modules.java.source 0.104.0 23 | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.netbeans.api.java.source.ScanUtils
public final class ScanUtils
Utility methods, which help JavaSource processing tasks to coordinate with the indexing/scanning process.
There are two variants of JavaSource.runUserActionTask(org.netbeans.api.java.source.Task, which support abort and restart of the user task,
if the task indicates incomplete data and the scanning is in progress. The restart is done in a hope that, after scanning
completes, the missing types or elements will appear.
checkElement(org.netbeans.api.java.source.CompilationInfo, T) to assert element's presence and validity
signalIncompleteData(org.netbeans.api.java.source.CompilationInfo, org.netbeans.api.java.source.ElementHandle) to request restart if running parallel to scan
final TreePath tp = ... ; // obtain a tree path
ScanUtils.waitUserActionTask(new Task<CompilationController>() {
public void run(CompilationController ctrl) {
// possibly abort and wait for all info to become available
Element e = ScanUtils.checkElement(tp.resolve(ctrl));
if (!ctrl.getElementUtilities().isErroneous(e)) {
// report the error; element is not found or is otherwise unusable
} else {
// do the really useful work on Element e
}
}
};
| Method Summary | ||
|---|---|---|
static
|
checkElement(CompilationInfo info,
T e)
Checks that the Element is valid, is not erroneous. |
|
static Future<Void> |
postUserActionTask(JavaSource src,
Task<CompilationController> uat)
Runs the user task through JavaSource.runUserActionTask(org.netbeans.api.java.source.Task, and returns Future completion handle for it. |
|
static Future<Void> |
postUserTask(Source src,
UserTask task)
Runs the user task, and returns Future completion handle for it. |
|
static void |
signalIncompleteData(CompilationInfo ci,
ElementHandle handle)
Aborts the user task and calls it again when parsing finishes, if a typename is not available. |
|
static void |
waitUserActionTask(JavaSource src,
Task<CompilationController> uat)
Runs user action over source 'src' using JavaSource.runUserActionTask(org.netbeans.api.java.source.Task and waits for its completion. |
|
static void |
waitUserTask(Source src,
UserTask task)
Runs user action over source 'src' using ParserManager.parse(java.util.Collection and waits for its completion. |
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Method Detail |
|---|
public static Future<Void> postUserActionTask(@NonNull
JavaSource src,
@NonNull
Task<CompilationController> uat)
JavaSource.runUserActionTask(org.netbeans.api.java.source.Task, boolean) , and returns Future completion handle for it.
The executed Task may indicate that it does not have enough data when scan is in progress, through e.g. checkElement(org.netbeans.api.java.source.CompilationInfo, T).
If so, processing of the Task will abort, and will be restarted when the scan finishes.
For more details, see description of postUserTask(org.netbeans.modules.parsing.api.Source, org.netbeans.modules.parsing.api.UserTask).
src - JavaSource to processuat - action task that will be executed
postUserTask(org.netbeans.modules.parsing.api.Source, org.netbeans.modules.parsing.api.UserTask),
JavaSource.runUserActionTask(org.netbeans.api.java.source.Task, boolean)
public static Future<Void> postUserTask(@NonNull
Source src,
@NonNull
UserTask task)
checkElement(org.netbeans.api.java.source.CompilationInfo, T).
If so, processing of the Task will abort, and will be restarted when the scan finishes.
The task may run asynchronously, pay attention to synchronization of task's output
data. The first attempt to run the task MAY execute synchronously. Do not call the method from
Swing EDT, if the task typically takes non-trivial time to complete (see JavaSource.runUserActionTask(org.netbeans.api.java.source.Task, boolean)
for discussion).
As postUserTask may decide to defer the task execution, postUserTask cannot reliably report exceptions thrown
from the parsing infrastructure. The Task itself is responsible for handling exceptions and propagating them
to the caller, the post method will just log the exception.
src - Source to processtask - action task that will be executed
JavaSource.runUserActionTask(org.netbeans.api.java.source.Task, boolean)
public static void waitUserActionTask(@NonNull
JavaSource src,
@NonNull
Task<CompilationController> uat)
throws IOException
JavaSource.runUserActionTask(org.netbeans.api.java.source.Task, boolean) and waits for its completion.
The executed Task may indicate that it does not have enough data when scan is in progress, through e.g. checkElement(org.netbeans.api.java.source.CompilationInfo, T).
If so, processing of the Task will abort, and will be restarted when the scan finishes. The waitUserActionTask method
will wait until the rescheduled task completes.
Unlike postUserActionTask(org.netbeans.api.java.source.JavaSource, org.netbeans.api.java.source.Task) , this method propagates exceptiosn from the Task to the caller, even if the Task
is postponed and waited for.
Calling this method from Swing ED thread is prohibited.
src - java source to processuat - task to execute
IOException - in the case of a failure in the user task, or scheduling failure (propagated from JavaSource.runUserActionTask(org.netbeans.api.java.source.Task, boolean) ,
JavaSource.runWhenScanFinished(org.netbeans.api.java.source.Task, boolean) JavaSource.runUserActionTask(org.netbeans.api.java.source.Task, boolean)
public static void waitUserTask(@NonNull
Source src,
@NonNull
UserTask task)
throws ParseException
ParserManager.parse(java.util.Collection, org.netbeans.modules.parsing.api.UserTask) and waits for its completion.
The executed Task may indicate that it does not have enough data when scan is in progress, through e.g. checkElement(org.netbeans.api.java.source.CompilationInfo, T).
If so, processing of the Task will abort, and will be restarted when the scan finishes. The waitUserTask method
will wait until the rescheduled task completes.
Unlike postUserTask(org.netbeans.modules.parsing.api.Source, org.netbeans.modules.parsing.api.UserTask), this method propagates exceptiosn from the Task to the caller, even if the Task
is postponed and waited for.
Calling this method from Swing ED thread is prohibited.
src - java source to processuat - task to execute
ParseException - in the case of a failure in the user task, or scheduling failure (propagated from JavaSource.runUserActionTask(org.netbeans.api.java.source.Task, boolean) ,
{@link ParserManager#parseWhenScanFinished(java.util.Collection, org.netbeans.modules.parsing.api.UserTask)ParserManager.parse(java.util.Collection, org.netbeans.modules.parsing.api.UserTask),
ParserManager.parseWhenScanFinished(java.util.Collection, org.netbeans.modules.parsing.api.UserTask)
public static <T extends Element> T checkElement(@NonNull
CompilationInfo info,
@NullAllowed
T e)
null or erroneous and
scanning is running, the method throws a RetryWhenScanFinished exception to
indicate that the action should be retried. The method should be only used in code, which
is directly or indirectly executed by waitUserActionTask(org.netbeans.api.java.source.JavaSource, org.netbeans.api.java.source.Task) , otherwise IllegalStateException
will be thrown.
If scan is not running, the method always returns the value of 'e' parameter.
An example usage is as follows:
TreePath tp = ...;
Element e = checkElement(cu.getTrees().getElement(tp));
Note: the method may be only called from within waitUserActionTask(org.netbeans.api.java.source.JavaSource, org.netbeans.api.java.source.Task) , it aborts
the current processing under assumption the user task will be restarted. It is illegal to call the
method if not running as user task - IllegalStateException will be thrown.
e - the Element to checks - the source of the Element
IllegalStateException - if not called from within user task
public static void signalIncompleteData(@NonNull
CompilationInfo ci,
@NullAllowed
ElementHandle handle)
el - the Element which causes the troubles - source of the Element
IllegalStateException - if not called from within waitUserActionTask(org.netbeans.api.java.source.JavaSource, org.netbeans.api.java.source.Task) and the like
|
org.netbeans.modules.java.source 0.104.0 23 | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||