本文整理汇总了Java中org.netbeans.api.java.source.JavaSource.runUserActionTask方法的典型用法代码示例。如果您正苦于以下问题:Java JavaSource.runUserActionTask方法的具体用法?Java JavaSource.runUserActionTask怎么用?Java JavaSource.runUserActionTask使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.netbeans.api.java.source.JavaSource
的用法示例。
在下文中一共展示了JavaSource.runUserActionTask方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: test171340
import org.netbeans.api.java.source.JavaSource; //导入方法依赖的package包/类
public void test171340() throws Exception {
prepareTest();
FileObject src1 = FileUtil.createData(sourceRoot, "test/Test1.java");
FileObject src2 = FileUtil.createData(sourceRoot, "test/Test2.java");
TestUtilities.copyStringToFile(src1,
"package test;\n" +
"public class Test1 {}");
TestUtilities.copyStringToFile(src2,
"package test;\n" +
"public class Test2 {" +
" public void test() {}" +
"}");
SourceUtilsTestUtil.compileRecursively(sourceRoot);
JavaSource javaSource = JavaSource.forFileObject(src1);
javaSource.runUserActionTask(new Task<CompilationController>() {
public void run(CompilationController controller) throws IOException {
controller.toPhase(Phase.RESOLVED);
TypeElement typeElement = controller.getElements().getTypeElement("test.Test2");
assertNotNull(typeElement);
ExecutableElement method = (ExecutableElement) typeElement.getEnclosedElements().get(1);
assertNotNull(controller.getTrees().getPath(method));
}
}, true);
}
示例2: initialize
import org.netbeans.api.java.source.JavaSource; //导入方法依赖的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);
}
}
示例3: getRenamedClassName
import org.netbeans.api.java.source.JavaSource; //导入方法依赖的package包/类
public static RenamedClassName getRenamedClassName(final TreePathHandle oldHandle, final JavaSource javaSource, final String newName) throws IOException {
final RenamedClassName[] result = { null };
javaSource.runUserActionTask(new Task<CompilationController>() {
public void run(CompilationController cc) throws IOException {
cc.toPhase(Phase.RESOLVED);
Element element = oldHandle.resolveElement(cc);
if (element == null || element.getKind() != ElementKind.CLASS) {
return;
}
String oldBinaryName = ElementUtilities.getBinaryName((TypeElement)element);
String oldSimpleName = element.getSimpleName().toString();
String newBinaryName = null;
element = element.getEnclosingElement();
if (element.getKind() == ElementKind.CLASS) {
newBinaryName = ElementUtilities.getBinaryName((TypeElement)element) + '$' + newName;
} else if (element.getKind() == ElementKind.PACKAGE) {
String packageName = ((PackageElement)element).getQualifiedName().toString();
newBinaryName = createQualifiedName(packageName, newName);
} else {
LOGGER.log(Level.WARNING, "Enclosing element of {0} was neither class nor package", oldHandle);
}
result[0] = new RenamedClassName(oldSimpleName, oldBinaryName, newBinaryName);
}
}, true);
return result[0];
}
示例4: findAndOpenJavaClass
import org.netbeans.api.java.source.JavaSource; //导入方法依赖的package包/类
public static void findAndOpenJavaClass(final String classBinaryName, Document doc) {
final JavaSource js = getJavaSource(doc);
if (js != null) {
try {
js.runUserActionTask(new Task<CompilationController>() {
public void run(CompilationController cc) throws Exception {
boolean opened = false;
TypeElement element = findClassElementByBinaryName(classBinaryName, cc);
if (element != null) {
opened = ElementOpen.open(js.getClasspathInfo(), element);
}
if (!opened) {
String msg = NbBundle.getMessage(HibernateEditorUtil.class, "LBL_SourceNotFound", classBinaryName);
StatusDisplayer.getDefault().setStatusText(msg);
}
}
}, false);
} catch (IOException ex) {
Logger.getLogger("global").log(Level.SEVERE, ex.getMessage(), ex);
}
}
}
示例5: resolveTreePathHandle
import org.netbeans.api.java.source.JavaSource; //导入方法依赖的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];
}
示例6: testGetTreePathHandle
import org.netbeans.api.java.source.JavaSource; //导入方法依赖的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);
}
示例7: crawl
import org.netbeans.api.java.source.JavaSource; //导入方法依赖的package包/类
@Override
public final synchronized void crawl() {
ClasspathInfo cpi = getClasspathInfo(project);
ClassIndex ci = cpi.getClassIndex();
ElementHandle<TypeElement> ancestor = getTypeOfClass(ci, fqn);
// if ancestor in not on the classpath, don't do anything.
if (ancestor == null) {
return;
}
notifyStarted();
// get all implementors
Set<ElementHandle<TypeElement>> list = getAllSubtypes(ci, ancestor);
JavaSource js = JavaSource.create(cpi);
try {
FilterAbstract filter = new FilterAbstract(list);
// Filter will remove some elements from list (inplace)
js.runUserActionTask(filter, true);
// notify listeners about new data
notifyCrawledData(filter.getResult());
notifyFinished(false);
return;
} catch (IOException ex) {
// TODO: What exact error?
list.clear();
notifyFinished(true);
return;
}
}
示例8: getModuleName
import org.netbeans.api.java.source.JavaSource; //导入方法依赖的package包/类
@CheckForNull
private static String getModuleName(@NonNull final FileObject moduleInfo) {
try {
final String[] res = new String[1];
final JavaSource src = JavaSource.forFileObject(moduleInfo);
if (src != null) {
src.runUserActionTask((cc) -> {
cc.toPhase(JavaSource.Phase.PARSED);
final CompilationUnitTree cu = cc.getCompilationUnit();
for (Tree decl : cu.getTypeDecls()) {
if (decl.getKind().name().equals("MODULE")) {
res[0] = ((ModuleTree)decl).getName().toString();
break;
}
}
}, true);
}
return res[0];
} catch (IOException ioe) {
LOG.log(
Level.WARNING,
"Cannot read module declaration in: {0} due to: {1}", //NOI18N
new Object[]{
FileUtil.getFileDisplayName(moduleInfo),
ioe.getMessage()
});
return null;
}
}
示例9: compute
import org.netbeans.api.java.source.JavaSource; //导入方法依赖的package包/类
@Override
protected void compute(final CompletionContext context) throws IOException {
final FileObject fileObject = context.getFileObject();
JavaSource javaSource = JavaUtils.getJavaSource(fileObject);
if (javaSource == null) {
return;
}
final String typedPrefix = context.getTypedPrefix();
javaSource.runUserActionTask(new Task<CompilationController>() {
public void run(CompilationController cc) throws Exception {
Map<String, String> tagAttributes = SpringXMLConfigEditorUtils.getTagAttributes(context.getTag());
String beanClassName = new BeanClassFinder(tagAttributes, fileObject).findImplementationClass(true);
if (beanClassName == null) {
return;
}
TypeElement beanType = JavaUtils.findClassElementByBinaryName(beanClassName, cc);
if (beanType == null) {
return;
}
FieldNamesCalculator calculator = new FieldNamesCalculator(beanType.getSimpleName().toString(), getForbiddenNames(fileObject));
List<String> names = calculator.calculate();
int i = 10;
for (String name : names) {
if (name.startsWith(typedPrefix)) {
SpringXMLConfigCompletionItem item = SpringXMLConfigCompletionItem.createBeanNameItem(getAnchorOffset(), name, i);
addCacheItem(item);
i += 10;
}
}
}
}, true);
}
示例10: isEntity
import org.netbeans.api.java.source.JavaSource; //导入方法依赖的package包/类
public static boolean isEntity(JavaSource source) {
final boolean[] isBoolean = new boolean[1];
try {
source.runUserActionTask(new AbstractTask<CompilationController>() {
public void run(CompilationController controller) throws IOException {
controller.toPhase(JavaSource.Phase.ELEMENTS_RESOLVED);
TypeElement classElement = getTopLevelClassElement(controller);
if (classElement == null) {
return;
}
List<? extends AnnotationMirror> annotations = controller.getElements().getAllAnnotationMirrors(classElement);
for (AnnotationMirror annotation : annotations) {
if (annotation.toString().equals("@javax.persistence.Entity")) {
//NOI18N
isBoolean[0] = true;
break;
}
}
}
}, true);
} catch (IOException ex) {
}
return isBoolean[0];
}
示例11: rescan
import org.netbeans.api.java.source.JavaSource; //导入方法依赖的package包/类
void rescan(){
JavaSource javaSrc = JavaSource.forFileObject(file);
if (javaSrc != null){
try{
javaSrc.runUserActionTask(new ProblemFinderCompControl(file), true);
} catch (IOException e){
// IOE can happen legitimatelly, see #103453
LOG.log(Level.FINE, e.getMessage(), e);
}
}
}
示例12: openTestsuite
import org.netbeans.api.java.source.JavaSource; //导入方法依赖的package包/类
public void openTestsuite(TestsuiteNode node) {
Children childrens = node.getChildren();
if (childrens != null) {
Node child = childrens.getNodeAt(0);
if ((child != null) && (child instanceof MavenJUnitTestMethodNode)) {
final FileObject fo = ((MavenJUnitTestMethodNode) child).getTestcaseFileObject();
if (fo != null) {
final long[] line = new long[]{0};
JavaSource javaSource = JavaSource.forFileObject(fo);
if (javaSource != null) {
try {
javaSource.runUserActionTask(new Task<CompilationController>() {
@Override
public void run(CompilationController compilationController) throws Exception {
compilationController.toPhase(Phase.ELEMENTS_RESOLVED);
Trees trees = compilationController.getTrees();
CompilationUnitTree compilationUnitTree = compilationController.getCompilationUnit();
List<? extends Tree> typeDecls = compilationUnitTree.getTypeDecls();
for (Tree tree : typeDecls) {
Element element = trees.getElement(trees.getPath(compilationUnitTree, tree));
if (element != null && element.getKind() == ElementKind.CLASS && element.getSimpleName().contentEquals(fo.getName())) {
long pos = trees.getSourcePositions().getStartPosition(compilationUnitTree, tree);
line[0] = compilationUnitTree.getLineMap().getLineNumber(pos);
break;
}
}
}
}, true);
} catch (IOException ioe) {
ErrorManager.getDefault().notify(ioe);
}
}
UIJavaUtils.openFile(fo, (int) line[0]);
}
}
}
}
示例13: getTypeElement
import org.netbeans.api.java.source.JavaSource; //导入方法依赖的package包/类
public static TypeElement getTypeElement(JavaSource source) throws IOException {
final TypeElement[] results = new TypeElement[1];
source.runUserActionTask(new AbstractTask<CompilationController>() {
public void run(CompilationController controller) throws IOException {
controller.toPhase(JavaSource.Phase.ELEMENTS_RESOLVED);
results[0] = getTopLevelClassElement(controller);
}
}, true);
return results[0];
}
示例14: testCursorInClass2
import org.netbeans.api.java.source.JavaSource; //导入方法依赖的package包/类
public void testCursorInClass2() throws Exception {
JavaSource src = JavaSource.forFileObject(getTestFO());
TestClassInfoTask task = new TestClassInfoTask(0);
src.runUserActionTask(task, true);
assertNull(task.getMethodName());
assertEquals("Test", task.getClassName());
assertEquals("sample.pkg", task.getPackageName());
}
示例15: getPropertyOccurrences
import org.netbeans.api.java.source.JavaSource; //导入方法依赖的package包/类
public static List<Occurrence> getPropertyOccurrences(final RenamedProperty renamedProperty, JavaSource js, final SpringScope scope) throws IOException {
final List<Occurrence> result = new ArrayList<Occurrence>();
final Set<File> processed = new HashSet<File>();
js.runUserActionTask(new Task<CompilationController>() {
@Override
public void run(final CompilationController cc) throws Exception {
cc.toPhase(JavaSource.Phase.ELEMENTS_RESOLVED);
for (SpringConfigModel model : scope.getAllConfigModels()) {
model.runDocumentAction(new Action<DocumentAccess>() {
public void run(DocumentAccess docAccess) {
File file = docAccess.getFile();
if (processed.contains(file)) {
return;
}
processed.add(file);
try {
new PropertyRefFinder(docAccess, cc, renamedProperty).addOccurrences(result);
} catch (BadLocationException ex) {
Exceptions.printStackTrace(ex);
}
}
});
}
}
}, true);
return result;
}