本文整理汇总了Java中org.netbeans.api.java.source.JavaSource.Phase类的典型用法代码示例。如果您正苦于以下问题:Java Phase类的具体用法?Java Phase怎么用?Java Phase使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Phase类属于org.netbeans.api.java.source.JavaSource包,在下文中一共展示了Phase类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: testAddImport17
import org.netbeans.api.java.source.JavaSource.Phase; //导入依赖的package包/类
public void testAddImport17() throws IOException {
testFile = getFile(getSourceDir(), getSourcePckg() + "ImportsTest6.java");
JavaSource src = getJavaSource(testFile);
Task<WorkingCopy> task = new Task<WorkingCopy>() {
public void run(WorkingCopy workingCopy) throws IOException {
workingCopy.toPhase(Phase.RESOLVED);
CompilationUnitTree cut = workingCopy.getCompilationUnit();
TreeMaker make = workingCopy.getTreeMaker();
ClassTree clazz = (ClassTree) cut.getTypeDecls().get(0);
MethodTree node = (MethodTree) clazz.getMembers().get(0);
BlockTree body = node.getBody();
List<StatementTree> stats = new ArrayList<StatementTree>();
for (StatementTree st : body.getStatements()) {
stats.add(st);
}
TypeElement list = workingCopy.getElements().getTypeElement("java.lang.String");
Types types = workingCopy.getTypes();
TypeMirror tm = types.getArrayType(types.erasure(list.asType()));
stats.add(make.Variable(make.Modifiers(Collections.<Modifier>emptySet()), "s", make.Type(tm), null));
workingCopy.rewrite(body, make.Block(stats, false));
}
};
src.runModificationTask(task).commit();
assertFiles("testAddImport17.pass");
}
开发者ID:apache,项目名称:incubator-netbeans,代码行数:27,代码来源:ImportAnalysisTest.java
示例2: run
import org.netbeans.api.java.source.JavaSource.Phase; //导入依赖的package包/类
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;
EntityManagerGenerationStrategySupport strategy =
(EntityManagerGenerationStrategySupport) getStrategy(workingCopy, make, clazz, new GenerationOptions());
doAsserts(strategy);
} else {
fail("No class found"); // should not happen
}
}
}
开发者ID:apache,项目名称:incubator-netbeans,代码行数:18,代码来源:EntityManagerGenerationStrategySupportTest.java
示例3: getTopLevelClassNames
import org.netbeans.api.java.source.JavaSource.Phase; //导入依赖的package包/类
public static List<String> getTopLevelClassNames(FileObject fo) throws IOException {
JavaSource javaSource = JavaSource.forFileObject(fo);
if (javaSource == null) {
return Collections.emptyList();
}
final List<String> result = new ArrayList<String>(1);
javaSource.runUserActionTask(new Task<CompilationController>() {
public void run(CompilationController cc) throws IOException {
cc.toPhase(Phase.ELEMENTS_RESOLVED);
for (TypeElement typeElement : cc.getTopLevelElements()) {
result.add(ElementUtilities.getBinaryName(typeElement));
}
}
}, true);
return result;
}
开发者ID:apache,项目名称:incubator-netbeans,代码行数:18,代码来源:HibernateRefactoringUtil.java
示例4: testAddImportOrder1
import org.netbeans.api.java.source.JavaSource.Phase; //导入依赖的package包/类
public void testAddImportOrder1() throws IOException {
testFile = getFile(getSourceDir(), getSourcePckg() + "ImportsTest7.java");
JavaSource src = getJavaSource(testFile);
Task<WorkingCopy> task = new Task<WorkingCopy>() {
public void run(WorkingCopy workingCopy) throws IOException {
workingCopy.toPhase(Phase.RESOLVED);
CompilationUnitTree cut = workingCopy.getCompilationUnit();
TreeMaker make = workingCopy.getTreeMaker();
ClassTree clazz = (ClassTree) cut.getTypeDecls().get(0);
MethodTree node = (MethodTree) clazz.getMembers().get(0);
BlockTree body = node.getBody();
List<StatementTree> stats = new ArrayList<StatementTree>();
for (StatementTree st : body.getStatements()) {
stats.add(st);
}
TypeElement list = workingCopy.getElements().getTypeElement("java.util.LinkedList");
Types types = workingCopy.getTypes();
TypeMirror tm = types.getArrayType(types.erasure(list.asType()));
stats.add(make.Variable(make.Modifiers(Collections.<Modifier>emptySet()), "s", make.Type(tm), null));
workingCopy.rewrite(body, make.Block(stats, false));
}
};
src.runModificationTask(task).commit();
assertFiles("testAddImportOrder1.pass");
}
开发者ID:apache,项目名称:incubator-netbeans,代码行数:27,代码来源:ImportAnalysisTest.java
示例5: addImport
import org.netbeans.api.java.source.JavaSource.Phase; //导入依赖的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
示例6: getRawCommentFor
import org.netbeans.api.java.source.JavaSource.Phase; //导入依赖的package包/类
private String getRawCommentFor(Element element) {
try {
FileObject fo = SourceUtils.getFile(element, cpInfo);
if (fo != null) {
JavaSource js = JavaSource.forFileObject(fo);
if (js != null) {
final String[] ret = new String[1];
final ElementHandle<? extends Element> handle = ElementHandle.create(element);
js.runUserActionTask(new Task<CompilationController>() {
public void run(CompilationController controller) throws Exception {
controller.toPhase(Phase.ELEMENTS_RESOLVED);
Element e = handle.resolve(controller);
if (e != null)
ret[0] = controller.getElements().getDocComment(e);
}
},true);
return ret[0] != null ? ret[0] : ""; //NOI18N
}
}
} catch (IOException ex) {
Exceptions.printStackTrace(ex);
}
return ""; //NOI18N
}
开发者ID:apache,项目名称:incubator-netbeans,代码行数:25,代码来源:JavadocEnv.java
示例7: testAddImportThroughMethod1
import org.netbeans.api.java.source.JavaSource.Phase; //导入依赖的package包/类
public void testAddImportThroughMethod1() throws IOException {
JavaSource testSource = JavaSource.forFileObject(FileUtil.toFileObject(testFile));
Task<WorkingCopy> task = new Task<WorkingCopy>() {
public void run(WorkingCopy workingCopy) throws java.io.IOException {
workingCopy.toPhase(Phase.RESOLVED);
TreeMaker make = workingCopy.getTreeMaker();
ClassTree clazz = (ClassTree) workingCopy.getCompilationUnit().getTypeDecls().get(0);
MethodTree node = (MethodTree) clazz.getMembers().get(0);
int offset = (int) (workingCopy.getTrees().getSourcePositions().getStartPosition(workingCopy.getCompilationUnit(), node) + 1);
TreePath context = workingCopy.getTreeUtilities().pathFor(offset);
try {
assertEquals("List", SourceUtils.resolveImport(workingCopy, context, "java.util.List"));
assertEquals("java.awt.List", SourceUtils.resolveImport(workingCopy, context, "java.awt.List"));
} catch (IOException e) {
throw new IllegalStateException(e);
}
}
};
testSource.runModificationTask(task).commit();
String res = TestUtilities.copyFileToString(testFile);
System.err.println(res);
assertFiles("testAddImportThroughMethod1.pass");
}
开发者ID:apache,项目名称:incubator-netbeans,代码行数:25,代码来源:ImportAnalysisTest.java
示例8: testTypeMirrorHandle
import org.netbeans.api.java.source.JavaSource.Phase; //导入依赖的package包/类
public void testTypeMirrorHandle() throws Exception {
prepareTest();
writeIntoFile(testSource, "package test; public class Test<T> {}");
ClassPath empty = ClassPathSupport.createClassPath(new URL[0]);
JavaSource js = JavaSource.create(ClasspathInfo.create(ClassPathSupport.createClassPath(SourceUtilsTestUtil.getBootClassPath().toArray(new URL[0])), empty, empty), testSource);
js.runUserActionTask(new Task<CompilationController>() {
public void run(CompilationController info) throws Exception {
info.toPhase(Phase.RESOLVED);
testCase(info, "java.util.Map");
testCase(info, "java.util.Map<java.lang.Object, java.util.List>");
testCase(info, "java.util.Map<java.lang.Object, java.util.List<java.lang.String>>");
testCase(info, "int[]");
// testCaseEnum(info); IZ #111876.
}
}, true);
}
开发者ID:apache,项目名称:incubator-netbeans,代码行数:19,代码来源:TypeMirrorHandleTest.java
示例9: testHandleForNewClass
import org.netbeans.api.java.source.JavaSource.Phase; //导入依赖的package包/类
public void testHandleForNewClass() throws Exception {
FileObject file = FileUtil.createData(sourceRoot, "test/test.java");
writeIntoFile(file, "package test; public class test {public test() {new Runnable() {public void run() {}};}}");
JavaSource js = JavaSource.forFileObject(file);
CompilationInfo info = SourceUtilsTestUtil.getCompilationInfo(js, Phase.RESOLVED);
assertTrue(info.getDiagnostics().toString(), info.getDiagnostics().isEmpty());
TreePath tp = info.getTreeUtilities().pathFor(55).getParentPath();
TreePathHandle handle = TreePathHandle.create(tp, info);
TreePath resolved = handle.resolve(info);
assertNotNull(resolved);
assertTrue(tp.getLeaf() == resolved.getLeaf());
}
开发者ID:apache,项目名称:incubator-netbeans,代码行数:18,代码来源:TreePathHandleTest.java
示例10: run
import org.netbeans.api.java.source.JavaSource.Phase; //导入依赖的package包/类
public void run(CompilationController controller) throws Exception {
if (controller.toPhase(JavaSource.Phase.RESOLVED).compareTo(Phase.RESOLVED) < 0) {
return ;
}
Document doc = controller.getDocument();
if (doc == null) {
return;
}
for (PositionRefresherHelper h : refreshers) {
if (ctx.isCanceled()) {
return;
}
List errors = h.getErrorDescriptionsAt(controller, ctx, doc);
if (errors == null) continue;
eds.put(h.getKey(), errors);
}
}
开发者ID:apache,项目名称:incubator-netbeans,代码行数:24,代码来源:JavaHintsPositionRefresher.java
示例11: testAddImport18
import org.netbeans.api.java.source.JavaSource.Phase; //导入依赖的package包/类
public void testAddImport18() throws IOException {
testFile = getFile(getSourceDir(), getSourcePckg() + "ImportsTest6.java");
JavaSource src = getJavaSource(testFile);
Task<WorkingCopy> task = new Task<WorkingCopy>() {
public void run(WorkingCopy workingCopy) throws IOException {
workingCopy.toPhase(Phase.RESOLVED);
CompilationUnitTree node = workingCopy.getCompilationUnit();
TreeMaker make = workingCopy.getTreeMaker();
ExpressionTree pack = node.getPackageName();
PackageElement pe = workingCopy.getElements().getPackageElement("org.netbeans.test");
ExpressionTree nuePack = make.QualIdent(pe);
workingCopy.rewrite(pack, nuePack);
}
};
src.runModificationTask(task).commit();
assertFiles("testAddImport18.pass");
}
开发者ID:apache,项目名称:incubator-netbeans,代码行数:20,代码来源:ImportAnalysisTest.java
示例12: test157566a
import org.netbeans.api.java.source.JavaSource.Phase; //导入依赖的package包/类
public void test157566a() throws IOException {
testFile = getFile(getSourceDir(), "org/netbeans/test/codegen/imports157566/b/Test.java");
JavaSource src = getJavaSource(testFile);
Task<WorkingCopy> task = new Task<WorkingCopy>() {
public void run(WorkingCopy workingCopy) throws IOException {
workingCopy.toPhase(Phase.RESOLVED);
CompilationUnitTree cut = workingCopy.getCompilationUnit();
TreeMaker make = workingCopy.getTreeMaker();
ClassTree clazz = (ClassTree) cut.getTypeDecls().get(0);
final TypeElement foo = workingCopy.getElements().getTypeElement("org.netbeans.test.codegen.imports157566.a.C");
assertNotNull(foo);
Tree type = make.QualIdent(foo);
VariableTree vt = make.Variable(make.Modifiers(EnumSet.noneOf(Modifier.class)), "test", type, null);
workingCopy.rewrite(clazz, make.addClassMember(clazz, vt));
}
};
src.runModificationTask(task).commit();
assertFiles("testImports157566a.pass");
}
开发者ID:apache,项目名称:incubator-netbeans,代码行数:20,代码来源:ImportAnalysisTest.java
示例13: testLocVar
import org.netbeans.api.java.source.JavaSource.Phase; //导入依赖的package包/类
public void testLocVar() throws Exception {
FileObject file = FileUtil.createData(sourceRoot, "test/test.java");
String code = "package test;\n" +
"public class Test {\n" +
" private void test() {\n" +
" int aa;\n" +
" }\n" +
"}";
writeIntoFile(file,code);
SourceUtilsTestUtil.compileRecursively(sourceRoot);
JavaSource js = JavaSource.forFileObject(file);
CompilationInfo info = SourceUtilsTestUtil.getCompilationInfo(js, Phase.RESOLVED);
TreePath tp = info.getTreeUtilities().pathFor(code.indexOf("aa") + 1);
TreePathHandle handle = TreePathHandle.create(tp, info);
TreePath resolved = handle.resolve(info);
assertNotNull(resolved);
assertTrue(tp.getLeaf() == resolved.getLeaf());
assertNotNull(handle.resolveElement(info));
}
开发者ID:apache,项目名称:incubator-netbeans,代码行数:26,代码来源:TreePathHandleTest.java
示例14: getTopLevelClasses
import org.netbeans.api.java.source.JavaSource.Phase; //导入依赖的package包/类
@Override
@NonNull
public Collection<? extends String> getTopLevelClasses() throws QueryException {
try {
if (control.toPhase(Phase.ELEMENTS_RESOLVED) != Phase.ELEMENTS_RESOLVED) {
throw new QueryException("Cannot resolve file: " + //NOI18N
Optional.ofNullable(control.getFileObject())
.map((fo) -> FileUtil.getFileDisplayName(fo))
.orElse("<unkown>")); //NOI18N
}
} catch (IOException ioe) {
throw new QueryException(ioe);
}
final Collection<? extends Element> topLevels = control.getTopLevelElements();
final List<String> result = new ArrayList<String>(topLevels.size());
for (Element topLevel : topLevels) {
result.add(((TypeElement)topLevel).getQualifiedName().toString());
}
return result;
}
开发者ID:apache,项目名称:incubator-netbeans,代码行数:21,代码来源:JavaOperationsImpl.java
示例15: run
import org.netbeans.api.java.source.JavaSource.Phase; //导入依赖的package包/类
@Override
public void run(CompilationController cc) throws Exception {
if (cancelled) {
return;
}
cc.toPhase(Phase.RESOLVED);
if (cancelled) {
return;
}
this.cc = cc;
try {
TreePath path = new TreePath (cc.getCompilationUnit());
scan (path, toFind);
} finally {
this.cc = null;
}
}
开发者ID:apache,项目名称:incubator-netbeans,代码行数:18,代码来源:JavaRefactoringUtils.java
示例16: testVariableInitWrapped
import org.netbeans.api.java.source.JavaSource.Phase; //导入依赖的package包/类
public void testVariableInitWrapped() throws Exception {
String code = "package hierbas.del.litoral;\n\n" +
"import java.util.concurrent.atomic.AtomicBoolean;\n\n" +
"public class Test {\n" +
" public void t() {\n" +
" new AtomicBoolean();\n" +
" }\n" +
"}\n";
runWrappingTest(code, new Task<WorkingCopy>() {
public void run(WorkingCopy workingCopy) throws IOException {
workingCopy.toPhase(Phase.RESOLVED);
CompilationUnitTree cut = workingCopy.getCompilationUnit();
TreeMaker make = workingCopy.getTreeMaker();
ClassTree clazz = (ClassTree) cut.getTypeDecls().get(0);
MethodTree method = (MethodTree) clazz.getMembers().get(1);
ExpressionStatementTree init = (ExpressionStatementTree) method.getBody().getStatements().get(0);
VariableTree nue = make.Variable(make.Modifiers(EnumSet.noneOf(Modifier.class)), "ab", make.Type("java.util.concurrent.atomic.AtomicBoolean"), init.getExpression());
workingCopy.rewrite(init, nue);
}
}, FmtOptions.wrapAssignOps, WrapStyle.WRAP_IF_LONG.name());
}
开发者ID:apache,项目名称:incubator-netbeans,代码行数:22,代码来源:WrappingTest.java
示例17: testRemoveInnerImport
import org.netbeans.api.java.source.JavaSource.Phase; //导入依赖的package包/类
public void testRemoveInnerImport() throws IOException, FileStateInvalidException {
JavaSource src = getJavaSource(testFile);
Task<WorkingCopy> task = new Task<WorkingCopy>() {
public void run(WorkingCopy workingCopy) throws IOException {
workingCopy.toPhase(Phase.RESOLVED);
CompilationUnitTree cut = workingCopy.getCompilationUnit();
TreeMaker make = workingCopy.getTreeMaker();
List<ImportTree> imports = new ArrayList<ImportTree>(cut.getImports());
imports.remove(1);
CompilationUnitTree unit = make.CompilationUnit(
cut.getPackageName(),
imports,
cut.getTypeDecls(),
cut.getSourceFile()
);
workingCopy.rewrite(cut, unit);
}
};
src.runModificationTask(task).commit();
String res = TestUtilities.copyFileToString(testFile);
System.err.println(res);
assertFiles("testRemoveInnerImport_ImportFormatTest.pass");
}
开发者ID:apache,项目名称:incubator-netbeans,代码行数:26,代码来源:ImportFormatTest.java
示例18: testSynteticDefaultConstructor
import org.netbeans.api.java.source.JavaSource.Phase; //导入依赖的package包/类
public void testSynteticDefaultConstructor() throws Exception {
performTest("SynteticDefaultConstructor");
source.runModificationTask(new Task<WorkingCopy>() {
public void run(WorkingCopy copy) throws IOException {
copy.toPhase(Phase.RESOLVED);
ClassTree topLevel = findTopLevelClass(copy);
SourceUtilsTestUtil2.run(copy, new AddSimpleField(), topLevel);
}
}).commit();
JavaSourceAccessor.getINSTANCE().revalidate(source);
CompilationInfo check = SourceUtilsTestUtil.getCompilationInfo(source, Phase.RESOLVED);
CompilationUnitTree cu = check.getCompilationUnit();
assertEquals(check.getDiagnostics().toString(), 0, check.getDiagnostics().size());
ClassTree newTopLevel = findTopLevelClass(check);
Element clazz = check.getTrees().getElement(TreePath.getPath(cu, newTopLevel));
Element pack = clazz.getEnclosingElement();
assertEquals(ElementKind.PACKAGE, pack.getKind());
assertEquals("test", ((PackageElement) pack).getQualifiedName().toString());
assertEquals(clazz.getEnclosedElements().toString(), 2 + 1/*syntetic default constructor*/, clazz.getEnclosedElements().size());
}
开发者ID:apache,项目名称:incubator-netbeans,代码行数:27,代码来源:MemberAdditionTest.java
示例19: testAddImport13
import org.netbeans.api.java.source.JavaSource.Phase; //导入依赖的package包/类
public void testAddImport13() throws IOException {
testFile = getFile(getSourceDir(), getSourcePckg() + "ImportsTest2.java");
JavaSource src = getJavaSource(testFile);
Task<WorkingCopy> task = new Task<WorkingCopy>() {
public void run(WorkingCopy workingCopy) throws IOException {
workingCopy.toPhase(Phase.RESOLVED);
CompilationUnitTree cut = workingCopy.getCompilationUnit();
TreeMaker make = workingCopy.getTreeMaker();
ClassTree clazz = (ClassTree) cut.getTypeDecls().get(0);
MethodTree node = (MethodTree) clazz.getMembers().get(0);
BlockTree body = node.getBody();
List<StatementTree> stats = new ArrayList<StatementTree>();
for (StatementTree st : body.getStatements()) {
stats.add(st);
}
TypeElement list = workingCopy.getElements().getTypeElement("java.util.Map.Entry");
Types types = workingCopy.getTypes();
TypeMirror tm = types.getArrayType(types.erasure(list.asType()));
stats.add(make.Variable(make.Modifiers(Collections.<Modifier>emptySet()), "entry", make.Type(tm), null));
workingCopy.rewrite(body, make.Block(stats, false));
}
};
src.runModificationTask(task).commit();
assertFiles("testAddImport13.pass");
}
开发者ID:apache,项目名称:incubator-netbeans,代码行数:27,代码来源:ImportAnalysisTest.java
示例20: testImportAddedAfterThrows
import org.netbeans.api.java.source.JavaSource.Phase; //导入依赖的package包/类
public void testImportAddedAfterThrows() throws IOException {
testFile = getFile(getSourceDir(), getSourcePckg() + "ImportsTest7.java");
JavaSource src = getJavaSource(testFile);
Task<WorkingCopy> task = new Task<WorkingCopy>() {
public void run(WorkingCopy workingCopy) throws IOException {
workingCopy.toPhase(Phase.RESOLVED);
CompilationUnitTree cut = workingCopy.getCompilationUnit();
TreeMaker make = workingCopy.getTreeMaker();
ClassTree clazz = (ClassTree) cut.getTypeDecls().get(0);
MethodTree node = (MethodTree) clazz.getMembers().get(0);
TypeElement exc = workingCopy.getElements().getTypeElement("javax.swing.text.BadLocationException");
MethodTree nueMethod = make.addMethodThrows(node, (ExpressionTree) make.Type(exc.asType()));
workingCopy.rewrite(node, nueMethod);
}
};
src.runModificationTask(task).commit();
assertFiles("testImportAddedAfterThrows.pass");
}
开发者ID:apache,项目名称:incubator-netbeans,代码行数:20,代码来源:ImportAnalysisTest.java
注:本文中的org.netbeans.api.java.source.JavaSource.Phase类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论