本文整理汇总了Java中org.netbeans.api.java.source.CancellableTask类的典型用法代码示例。如果您正苦于以下问题:Java CancellableTask类的具体用法?Java CancellableTask怎么用?Java CancellableTask使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
CancellableTask类属于org.netbeans.api.java.source包,在下文中一共展示了CancellableTask类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: addPhaseCompletionTask
import org.netbeans.api.java.source.CancellableTask; //导入依赖的package包/类
public void addPhaseCompletionTask (final JavaSource js,
final CancellableTask<CompilationInfo> task,
final JavaSource.Phase phase,
final JavaSource.Priority priority,
final TaskIndexingMode taskIndexingMode) {
final Collection<Source> sources = getSources(js);
assert sources.size() == 1;
final int pp = translatePriority(priority);
if (tasks.keySet().contains(task)) {
throw new IllegalArgumentException(String.format("Task: %s is already scheduled", task.toString())); //NOI18N
}
final ParserResultTask<?> hanz = new CancelableTaskWrapper(task, pp, phase, js, taskIndexingMode);
tasks.put(task, hanz);
Utilities.addParserResultTask(hanz, sources.iterator().next());
}
开发者ID:apache,项目名称:incubator-netbeans,代码行数:17,代码来源:JavaSourceAccessor.java
示例2: initialize
import org.netbeans.api.java.source.CancellableTask; //导入依赖的package包/类
private void initialize() {
final TreePathHandle sourceType = refactoring.getSourceType();
if (sourceType == null) {
return;
}
FileObject fo = sourceType.getFileObject();
JavaSource js = JavaSource.forFileObject(fo);
try {
js.runUserActionTask(new CancellableTask<CompilationController>() {
@Override
public void cancel() {
}
@Override
public void run(CompilationController javac) throws Exception {
javac.toPhase(JavaSource.Phase.RESOLVED);
initializeInTransaction(javac, sourceType);
}
}, true);
} catch (IOException ex) {
throw new IllegalStateException(ex);
}
}
开发者ID:apache,项目名称:incubator-netbeans,代码行数:26,代码来源:ExtractSuperclassPanel.java
示例3: addImport
import org.netbeans.api.java.source.CancellableTask; //导入依赖的package包/类
/** Creates new Class from package
* @param packageName destination
* @param className name
* @throws Exception
* @return
*/
public static void addImport(JavaSource js,final String importText,final boolean isStatic) throws IOException {
CancellableTask task = new CancellableTask<WorkingCopy>() {
public void cancel() {
throw new UnsupportedOperationException("Not supported yet.");
}
public void run(WorkingCopy workingCopy) throws Exception {
workingCopy.toPhase(Phase.RESOLVED);
CompilationUnitTree cut = workingCopy.getCompilationUnit();
TreeMaker make = workingCopy.getTreeMaker();
CompilationUnitTree copy = make.addCompUnitImport(cut,make.Import(make.Identifier(importText), isStatic));
workingCopy.rewrite(cut, copy);
}
};
js.runModificationTask(task).commit();
}
开发者ID:apache,项目名称:incubator-netbeans,代码行数:25,代码来源:Common.java
示例4: setPackage
import org.netbeans.api.java.source.CancellableTask; //导入依赖的package包/类
public static void setPackage(JavaSource js, final String pack) throws IOException {
CancellableTask task = new CancellableTask<WorkingCopy>() {
public void cancel() {
throw new UnsupportedOperationException("Not supported yet.");
}
public void run(WorkingCopy workingCopy) throws Exception {
workingCopy.toPhase(Phase.RESOLVED);
CompilationUnitTree cut = workingCopy.getCompilationUnit();
TreeMaker make = workingCopy.getTreeMaker();
CompilationUnitTree copy = make.CompilationUnit(make.Identifier(pack),cut.getImports(), cut.getTypeDecls(), cut.getSourceFile());
workingCopy.rewrite(cut, copy);
}
};
js.runModificationTask(task).commit();
}
开发者ID:apache,项目名称:incubator-netbeans,代码行数:17,代码来源:Common.java
示例5: addTopLevelClass
import org.netbeans.api.java.source.CancellableTask; //导入依赖的package包/类
public static void addTopLevelClass(JavaSource js) throws IOException {
CancellableTask task = new CancellableTask<WorkingCopy>() {
public void cancel() {
throw new UnsupportedOperationException("Not supported yet.");
}
public void run(WorkingCopy workingCopy) throws Exception {
workingCopy.toPhase(Phase.RESOLVED);
CompilationUnitTree cut = workingCopy.getCompilationUnit();
TreeMaker make = workingCopy.getTreeMaker();
ClassTree clazz = getClassTree(make, workingCopy, "TopLevel", "java.util.List", Collections.<ExpressionTree>emptyList(), EnumSet.noneOf(Modifier.class));
CompilationUnitTree copy = make.addCompUnitTypeDecl(cut, clazz);
workingCopy.rewrite(cut, copy);
}
};
js.runModificationTask(task).commit();
}
开发者ID:apache,项目名称:incubator-netbeans,代码行数:19,代码来源:Common.java
示例6: implement
import org.netbeans.api.java.source.CancellableTask; //导入依赖的package包/类
public ChangeInfo implement(){
CancellableTask<WorkingCopy> task = new CancellableTask<WorkingCopy>(){
public void cancel() {}
public void run(WorkingCopy workingCopy) throws Exception {
workingCopy.toPhase(JavaSource.Phase.RESOLVED);
TypeElement clazz = classHandle.resolve(workingCopy);
if (clazz != null){
ClassTree clazzTree = workingCopy.getTrees().getTree(clazz);
GenerationUtils genUtils = GenerationUtils.newInstance(workingCopy);
ClassTree modifiedClazz = genUtils.addImplementsClause(clazzTree, "java.io.Serializable"); // NOI18N
workingCopy.rewrite(clazzTree, modifiedClazz);
}
}
};
JavaSource javaSource = JavaSource.forFileObject(fileObject);
try{
javaSource.runModificationTask(task).commit();
} catch (IOException e){
JPAProblemFinder.LOG.log(Level.SEVERE, e.getMessage(), e);
}
return null;
}
开发者ID:apache,项目名称:incubator-netbeans,代码行数:27,代码来源:ImplementSerializable.java
示例7: processJavaFile
import org.netbeans.api.java.source.CancellableTask; //导入依赖的package包/类
private static void processJavaFile(final FileObject javaFO, final JavaClassHandler handler) {
try {
JavaSource js = JavaSource.forFileObject(javaFO);
js.runUserActionTask(new CancellableTask<CompilationController>() {
@Override
public void cancel() {
}
@Override
public void run(CompilationController ctrl) throws Exception {
ctrl.toPhase(Phase.ELEMENTS_RESOLVED);
TypeElement clazz = findClass(ctrl, javaFO.getName());
if (clazz != null) {
handler.handle(clazz.getQualifiedName().toString(), isDeclaredAsJavaBean(clazz));
}
}
}, true);
} catch (IOException ex) {
Logger.getLogger(BeanInstaller.class.getClass().getName()).
log(Level.SEVERE, javaFO.toString(), ex);
}
}
开发者ID:apache,项目名称:incubator-netbeans,代码行数:23,代码来源:BeanInstaller.java
示例8: invoke
import org.netbeans.api.java.source.CancellableTask; //导入依赖的package包/类
/**
* This will be invoked when user chooses this Generator from Insert Code
* dialog
*/
@Override
public void invoke() {
Document doc = textComponent.getDocument();
JavaSource javaSource = JavaSource.forDocument(doc);
CancellableTask<WorkingCopy> task = new CodeGeneratorCancellableTask(textComponent) {
@Override
public void generateCode(WorkingCopy workingCopy, TreePath path, int position) {
JavaFxBeanHelper.this.generateCode(workingCopy, path, position, JavaFxBeanHelper.this.fields);
}
};
try {
ModificationResult result = javaSource.runModificationTask(task);
result.commit();
} catch (IOException ex) {
Exceptions.printStackTrace(ex);
}
}
开发者ID:rterp,项目名称:JavaFxPropertyHelperNBPlugin,代码行数:25,代码来源:JavaFxBeanHelper.java
示例9: resolveTreePathHandle
import org.netbeans.api.java.source.CancellableTask; //导入依赖的package包/类
/**
* Resolves the TreePathHandle for the given refactoring.
* @param refactoring the refactoring.
* @return the TreePathHandle or null if no handle could be resolved.
*/
public static TreePathHandle resolveTreePathHandle(AbstractRefactoring refactoring) throws IOException {
Parameters.notNull("refactoring", refactoring); //NO18N
TreePathHandle tph = refactoring.getRefactoringSource().lookup(TreePathHandle.class);
if (tph != null) {
return tph;
}
final TreePathHandle[] result = new TreePathHandle[1];
JavaSource source = JavaSource.forFileObject(refactoring.getRefactoringSource().lookup(FileObject.class));
source.runUserActionTask(new CancellableTask<CompilationController>() {
@Override
public void cancel() {
}
@Override
public void run(CompilationController co) throws Exception {
co.toPhase(JavaSource.Phase.RESOLVED);
CompilationUnitTree cut = co.getCompilationUnit();
result[0] = TreePathHandle.create(TreePath.getPath(cut, cut.getTypeDecls().get(0)), co);
}
}, true);
return result[0];
}
开发者ID:apache,项目名称:incubator-netbeans,代码行数:32,代码来源:RefactoringUtil.java
示例10: getTreePathHandle
import org.netbeans.api.java.source.CancellableTask; //导入依赖的package包/类
/**
* Gets a TreePathHandle for the specified property.
*
* @param fieldName the name of the field.
* @param className the FQN of the class.
* @param file the file object representing the class.
*/
public static TreePathHandle getTreePathHandle(final String fieldName,
final String className, FileObject file) throws IOException{
final TreePathHandle[] result = new TreePathHandle[1];
JavaSource source = JavaSource.forFileObject(file);
source.runUserActionTask(new CancellableTask<CompilationController>() {
@Override
public void cancel() {
}
@Override
public void run(CompilationController info) throws Exception {
info.toPhase(JavaSource.Phase.RESOLVED);
TypeElement te = info.getElements().getTypeElement(className);
for (Element enclosed : te.getEnclosedElements()){
if (enclosed.getSimpleName().contentEquals(fieldName)){
TreePath propertyPath = info.getTrees().getPath(enclosed);
result[0] = TreePathHandle.create(propertyPath, info);
}
}
}
}, true);
return result[0];
}
开发者ID:apache,项目名称:incubator-netbeans,代码行数:36,代码来源:RefactoringUtil.java
示例11: shouldHandle
import org.netbeans.api.java.source.CancellableTask; //导入依赖的package包/类
/**
* Checks whether the given <code>refactoringSource</code> should be handled by
* this refactoring. Override in subclasses as needed, the
* default implementation returns true if the given <code>refactoringSource</code>
* is a class.
* @param refactoringSource the object being refactored.
*
* @return true if the <code>refactoringSource<code> represents a class that
* should be handled by persistence.xml refactorings.
*/
protected boolean shouldHandle(FileObject refactoringSource) {
final boolean[] result = new boolean[]{false};
if (RefactoringUtil.isJavaFile(refactoringSource)) {
JavaSource source = JavaSource.forFileObject(refactoringSource);
try {
source.runUserActionTask(new CancellableTask<CompilationController>() {
public void cancel() {
}
public void run(CompilationController info) throws Exception {
info.toPhase(JavaSource.Phase.RESOLVED);
TreePathHandle treePathHandle = null;
CompilationUnitTree cut = info.getCompilationUnit();
if (!cut.getTypeDecls().isEmpty()) {
treePathHandle = TreePathHandle.create(TreePath.getPath(cut, cut.getTypeDecls().get(0)), info);
}
if (treePathHandle == null) {
result[0] = false;
} else {
Element element = treePathHandle.resolveElement(info);
if (element != null) {
result[0] = element.getKind() == ElementKind.CLASS;
}
}
}
}, true);
} catch (IOException ex) {
Exceptions.printStackTrace(ex);
}
}
return result[0];
}
开发者ID:apache,项目名称:incubator-netbeans,代码行数:46,代码来源:PersistenceXmlRefactoring.java
示例12: testGetTreePathHandle
import org.netbeans.api.java.source.CancellableTask; //导入依赖的package包/类
/**
* TODO, resolve fail
* @throws Exception
*/
// public void testResolveReferences() throws Exception {
// EntityAssociationResolver resolver = new EntityAssociationResolver(getTreePathHandle("customer", ORDER), createModel());
// List<EntityAnnotationReference> result = resolver.resolveReferences();
// assertEquals(1, result.size());
// EntityAnnotationReference reference = result.get(0);
// assertEquals(EntityAssociationResolver.ONE_TO_MANY, reference.getAnnotation());
// assertEquals("entities.Customer", reference.getEntity());
// assertEquals(EntityAssociationResolver.MAPPED_BY, reference.getAttribute());
// assertEquals("customer", reference.getAttributeValue());
//
// }
public void testGetTreePathHandle() throws Exception{
final TreePathHandle handle = RefactoringUtil.getTreePathHandle("orders", CUSTOMER, getJavaFile(CUSTOMER));
JavaSource source = JavaSource.forFileObject(handle.getFileObject());
source.runUserActionTask(new CancellableTask<CompilationController>(){
public void cancel() {
}
public void run(CompilationController parameter) throws Exception {
parameter.toPhase(JavaSource.Phase.RESOLVED);
Element element = handle.resolveElement(parameter);
assertEquals("orders", element.getSimpleName().toString());
for (AnnotationMirror annotation : element.getAnnotationMirrors()){
assertEquals(EntityAssociationResolver.ONE_TO_MANY, annotation.getAnnotationType().toString());
}
}
}, true);
}
开发者ID:apache,项目名称:incubator-netbeans,代码行数:36,代码来源:EntityAssociationResolverTest.java
示例13: generate
import org.netbeans.api.java.source.CancellableTask; //导入依赖的package包/类
protected FileObject generate(FileObject targetFo, final GenerationOptions options) throws IOException{
JavaSource targetSource = JavaSource.forFileObject(targetFo);
CancellableTask task = new CancellableTask<WorkingCopy>() {
public void cancel() {
}
public void run(WorkingCopy workingCopy) throws Exception {
workingCopy.toPhase(Phase.RESOLVED);
CompilationUnitTree cut = workingCopy.getCompilationUnit();
TreeMaker make = workingCopy.getTreeMaker();
for (Tree typeDeclaration : cut.getTypeDecls()){
if (TreeUtilities.CLASS_TREE_KINDS.contains(typeDeclaration.getKind())){
ClassTree clazz = (ClassTree) typeDeclaration;
ClassTree modifiedClazz = getStrategy(workingCopy, make, clazz, options).generate();
workingCopy.rewrite(clazz, modifiedClazz);
}
}
}
};
targetSource.runModificationTask(task).commit();
return targetFo;
}
开发者ID:apache,项目名称:incubator-netbeans,代码行数:31,代码来源:EntityManagerGenerationTestSupport.java
示例14: findController
import org.netbeans.api.java.source.CancellableTask; //导入依赖的package包/类
private CompilationController findController(FileObject fileObj) {
JavaSource javaSource = JavaSource.forFileObject(fileObj);
if (javaSource == null) {
return null;
}
final CompilationController[] result = new CompilationController[1];
result[0] = null;
try {
javaSource.runUserActionTask(new CancellableTask<CompilationController>() {
@Override
public void cancel() {
}
@Override
public void run(CompilationController ci) throws Exception {
if (ci.toPhase(Phase.RESOLVED).compareTo(Phase.RESOLVED) < 0) {
ErrorManager.getDefault().log(ErrorManager.WARNING,
"Unable to resolve "+ci.getFileObject()+" to phase "+Phase.RESOLVED+", current phase = "+ci.getPhase()+
"\nDiagnostics = "+ci.getDiagnostics()+
"\nFree memory = "+Runtime.getRuntime().freeMemory());
return;
}
result[0] = ci;
}
}, true);
} catch (IOException ioex) {
ErrorManager.getDefault().notify(ioex);
return null;
}
return result[0];
}
开发者ID:apache,项目名称:incubator-netbeans,代码行数:31,代码来源:WatchPanel.java
示例15: removePhaseCompletionTask
import org.netbeans.api.java.source.CancellableTask; //导入依赖的package包/类
public void removePhaseCompletionTask (final JavaSource js,
final CancellableTask<CompilationInfo> task) {
final Collection<Source> sources = getSources(js);
assert sources.size() == 1;
final ParserResultTask<?> hanz = tasks.remove(task);
if (hanz == null) {
throw new IllegalArgumentException(String.format("Task: %s is not scheduled", task.toString())); //NOI18N
}
Utilities.removeParserResultTask(hanz, sources.iterator().next());
}
开发者ID:apache,项目名称:incubator-netbeans,代码行数:11,代码来源:JavaSourceAccessor.java
示例16: rescheduleTask
import org.netbeans.api.java.source.CancellableTask; //导入依赖的package包/类
public void rescheduleTask (final JavaSource js,
final CancellableTask<CompilationInfo> task) {
final Collection<Source> sources = getSources(js);
assert sources.size() == 1;
final ParserResultTask<?> hanz = tasks.get(task);
if (hanz != null)
Utilities.rescheduleTask(hanz, sources.iterator().next());
}
开发者ID:apache,项目名称:incubator-netbeans,代码行数:9,代码来源:JavaSourceAccessor.java
示例17: CancelableTaskWrapper
import org.netbeans.api.java.source.CancellableTask; //导入依赖的package包/类
public CancelableTaskWrapper (
@NonNull final CancellableTask<CompilationInfo> task,
final int priority,
@NonNull final Phase phase,
@NonNull final JavaSource javaSource,
@NonNull final TaskIndexingMode taskIndexingMode) {
super (phase, taskIndexingMode);
assert phase != null;
assert javaSource != null;
this.task = task;
this.priority = priority;
this.javaSource = javaSource;
}
开发者ID:apache,项目名称:incubator-netbeans,代码行数:14,代码来源:JavaSourceAccessor.java
示例18: createTask
import org.netbeans.api.java.source.CancellableTask; //导入依赖的package包/类
public CancellableTask<CompilationInfo> createTask(FileObject file) {
filesWithTasks.add(file);
CancellableTask<CompilationInfo> task = file2Task.get(file);
if (task == null) {
System.out.println("WARN: Instantiating empty dummy task");
new DummyCancellableTask<CompilationInfo>();
}
return task;
}
开发者ID:apache,项目名称:incubator-netbeans,代码行数:10,代码来源:JavaSourceTaskFactoryTest.java
示例19: initClasses
import org.netbeans.api.java.source.CancellableTask; //导入依赖的package包/类
private void initClasses() {
classes = new HashMap();
for (int i=0;i<filesToMove.size();i++) {
final int j = i;
try {
JavaSource source = JavaSource.forFileObject(filesToMove.get(i));
source.runUserActionTask(new CancellableTask<CompilationController>() {
public void cancel() {
throw new UnsupportedOperationException("Not supported yet.");
}
public void run(final CompilationController parameter) throws Exception {
parameter.toPhase(JavaSource.Phase.ELEMENTS_RESOLVED);
List<? extends Tree> trees= parameter.getCompilationUnit().getTypeDecls();
for (Tree t: trees) {
if (TreeUtilities.CLASS_TREE_KINDS.contains(t.getKind())) {
if (((ClassTree) t).getSimpleName().toString().equals(filesToMove.get(j).getName())) {
classes.put(filesToMove.get(j), ElementHandle.create(parameter.getTrees().getElement(TreePath.getPath(parameter.getCompilationUnit(), t))));
return ;
}
}
}
}
}, true);
} catch (IOException ex) {
java.util.logging.Logger.getLogger("global").log(java.util.logging.Level.SEVERE, ex.getMessage(), ex);
};
}
}
开发者ID:apache,项目名称:incubator-netbeans,代码行数:34,代码来源:NbMoveRefactoringPlugin.java
示例20: createTask
import org.netbeans.api.java.source.CancellableTask; //导入依赖的package包/类
public synchronized CancellableTask<CompilationInfo> createTask(FileObject file) {
// System.out.println("CREATE TASK FOR " + file.getNameExt() );
if ( ui == null) {
return EMPTY_TASK;
}
else {
ui.showWaitNode();
return ui.getTask();
}
}
开发者ID:apache,项目名称:incubator-netbeans,代码行数:11,代码来源:ClassMemberNavigatorJavaSourceFactory.java
注:本文中的org.netbeans.api.java.source.CancellableTask类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论