当前位置: 首页>>代码示例>>Java>>正文


Java Task类代码示例

本文整理汇总了Java中org.netbeans.api.java.source.Task的典型用法代码示例。如果您正苦于以下问题:Java Task类的具体用法?Java Task怎么用?Java Task使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


Task类属于org.netbeans.api.java.source包,在下文中一共展示了Task类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testImportClashWithJavaLang

import org.netbeans.api.java.source.Task; //导入依赖的package包/类
public void testImportClashWithJavaLang() throws IOException {
    testFile = getFile(getSourceDir(), getSourcePckg() + "ImportsTest9.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);
            ExpressionTree type = make.QualIdent(workingCopy.getElements().getTypeElement("java.awt.geom.Point2D.Double"));
            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("testImportClashWithJavaLang.pass");
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:19,代码来源:ImportAnalysisTest.java

示例2: findAndOpenJavaClass

import org.netbeans.api.java.source.Task; //导入依赖的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(JPAEditorUtil.class, "LBL_SourceNotFound", classBinaryName);
                        StatusDisplayer.getDefault().setStatusText(msg);
                    }
                }
                }, false);
        } catch (IOException ex) {
            Logger.getLogger("global").log(Level.SEVERE, ex.getMessage(), ex);
        }
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:24,代码来源:JPAEditorUtil.java

示例3: performErrorsCorrectTest

import org.netbeans.api.java.source.Task; //导入依赖的package包/类
private void performErrorsCorrectTest(String code, String sourceLevel, String... errors) throws Exception {
    prepareTest();

    FileObject src = FileUtil.createData(sourceRoot, "test/Test.java");

    TestUtilities.copyStringToFile(src, code);
    SourceUtilsTestUtil.setSourceLevel(src, sourceLevel);
    JavaSource javaSource = JavaSource.forFileObject(src);
    final Set<String> actual = new HashSet<String>();
    javaSource.runUserActionTask(new Task<CompilationController>() {
        public void run(CompilationController controller) throws IOException {
            controller.toPhase(Phase.RESOLVED);
            for (Diagnostic<?> d : controller.getDiagnostics()) {
                actual.add(d.getPosition() + ":" + d.getCode());
            }
        }
    }, true);
    
    assertEquals(new HashSet<String>(Arrays.asList(errors)), actual);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:21,代码来源:PostFlowAnalysisTest.java

示例4: testIssue247469

import org.netbeans.api.java.source.Task; //导入依赖的package包/类
public void testIssue247469() throws IOException {
    final JavaPlatform jp = JavaPlatformManager.getDefault().getDefaultPlatform();
    assertNotNull(jp);
    final ClasspathInfo cpInfo = ClasspathInfo.create(jp.getBootstrapLibraries(), ClassPath.EMPTY, ClassPath.EMPTY);
    assertNotNull(cpInfo);
    final JavaSource js = JavaSource.create(cpInfo);
    js.runUserActionTask(new Task<CompilationController>() {
        @Override
        public void run(final CompilationController cc) throws Exception {
            final PackageElement packageElement = cc.getElements().getPackageElement("java.lang"); // NOI18N
            for (Element elem : packageElement.getEnclosedElements()) {
                if ("ProcessBuilder$1".equals(elem.getSimpleName().toString())) { // NOI18N
                    TypeElement te = (TypeElement) elem;
                    assertEquals(NestingKind.ANONYMOUS, te.getNestingKind());
                    break;
                }
            }
        }
    }, true);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:21,代码来源:CtSymArchiveTest.java

示例5: testAddImport3

import org.netbeans.api.java.source.Task; //导入依赖的package包/类
public void testAddImport3() throws IOException {
    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.List");
            TypeElement collection = workingCopy.getElements().getTypeElement("java.util.Collection");
            Types types = workingCopy.getTypes();
            TypeMirror tm = types.getDeclaredType(list, types.erasure(collection.asType()));
            stats.add(make.Variable(make.Modifiers(Collections.<Modifier>emptySet()), "utilList", make.Type(tm), null));
            workingCopy.rewrite(body, make.Block(stats, false));
        }
    };
    src.runModificationTask(task).commit();
    assertFiles("testAddImport3.pass");
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:27,代码来源:ImportAnalysisTest.java

示例6: testWrapMethod2

import org.netbeans.api.java.source.Task; //导入依赖的package包/类
public void testWrapMethod2() throws Exception {
    String code = "package hierbas.del.litoral;\n\n" +
        "import java.util.concurrent.atomic.AtomicBoolean;\n\n" +
        "public class Test {\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);
            ExpressionTree parsed = workingCopy.getTreeUtilities().parseExpression("new Object() { private void test(int a, int b, int c) throws java.io.FileNotFoundException, java.net.MalformedURLException { } }", new SourcePositions[1]);
            parsed = GeneratorUtilities.get(workingCopy).importFQNs(parsed);
            MethodTree method = (MethodTree) ((NewClassTree) parsed).getClassBody().getMembers().get(0);
            workingCopy.rewrite(clazz, make.addClassMember(clazz, method));
        }
    },
    FmtOptions.wrapMethodParams, WrapStyle.WRAP_ALWAYS.name(),
    FmtOptions.wrapThrowsKeyword, WrapStyle.WRAP_ALWAYS.name(),
    FmtOptions.wrapThrowsList, WrapStyle.WRAP_ALWAYS.name());
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:22,代码来源:WrappingTest.java

示例7: testMoveFirst

import org.netbeans.api.java.source.Task; //导入依赖的package包/类
public void testMoveFirst() 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());
            ImportTree oneImport = imports.remove(0);
            imports.add(3, oneImport);
            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("testMoveFirst_ImportFormatTest.pass");
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:27,代码来源:ImportFormatTest.java

示例8: testDefaultPackage1

import org.netbeans.api.java.source.Task; //导入依赖的package包/类
public void testDefaultPackage1() throws IOException {
    testFile = getFile(getSourceDir(), "ImportAnalysisDefaultPackage1.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 exc = workingCopy.getElements().getTypeElement("ImportAnalysisDefaultPackage2");
            stats.add(make.Variable(make.Modifiers(Collections.<Modifier>emptySet()), "s", make.QualIdent(exc), null));
            workingCopy.rewrite(body, make.Block(stats, false));
        }
    };
    src.runModificationTask(task).commit();
    assertFiles("testDefaultPackage1.pass");
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:25,代码来源:ImportAnalysisTest.java

示例9: performUseSuperType

import org.netbeans.api.java.source.Task; //导入依赖的package包/类
private void performUseSuperType(FileObject source, final int position, Problem... expectedProblems) throws Exception {
    final UseSuperTypeRefactoring[] r = new UseSuperTypeRefactoring[1];

    JavaSource.forFileObject(source).runUserActionTask(new Task<CompilationController>() {

        @Override
        public void run(CompilationController parameter) throws Exception {
            parameter.toPhase(JavaSource.Phase.RESOLVED);
            CompilationUnitTree cut = parameter.getCompilationUnit();

            ClassTree classTree = (ClassTree) cut.getTypeDecls().get(0);
            TreePath tp = TreePath.getPath(cut, classTree);
            r[0] = new UseSuperTypeRefactoring(TreePathHandle.create(tp, parameter));
            r[0].setTargetSuperType(r[0].getCandidateSuperTypes()[position]);
        }
    }, true);

    RefactoringSession rs = RefactoringSession.create("Session");
    List<Problem> problems = new LinkedList<Problem>();

    addAllProblems(problems, r[0].preCheck());
    addAllProblems(problems, r[0].prepare(rs));
    addAllProblems(problems, rs.doRefactoring(true));

    assertProblems(Arrays.asList(expectedProblems), problems);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:27,代码来源:UseSuperTypeTest.java

示例10: test157566b

import org.netbeans.api.java.source.Task; //导入依赖的package包/类
public void test157566b() 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.b.String");
            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("testImports157566b.pass");
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:20,代码来源:ImportAnalysisTest.java

示例11: test162485b

import org.netbeans.api.java.source.Task; //导入依赖的package包/类
public void test162485b() throws Exception {
    testFile = new File(getWorkDir(), "Test.java");
    TestUtilities.copyStringToFile(testFile, 
        "package hierbas.del.litoral;\n" +
        "\n" +
        "public class Test {\n" +
        "    Object test = new int[] {};\n" +
        "}\n"
        );
    String golden =
        "package hierbas.del.litoral;\n" +
        "\n" +
        "public class Test {\n" +
        "    Object test = {{1}};\n" +
        "}\n";
    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);
            VariableTree var = (VariableTree) clazz.getMembers().get(1);
            NewArrayTree nat = (NewArrayTree) var.getInitializer();
            NewArrayTree dim2 = make.NewArray(null, Collections.<ExpressionTree>emptyList(), Collections.singletonList(make.Literal(Integer.valueOf(1))));
            NewArrayTree newTree = make.NewArray(null, Collections.<ExpressionTree>emptyList(), Collections.<ExpressionTree>singletonList(dim2));
            workingCopy.rewrite(nat, newTree);
        }

    };
    src.runModificationTask(task).commit();
    String res = TestUtilities.copyFileToString(testFile);
    System.err.println(res);
    assertEquals(golden, res);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:37,代码来源:ArraysTest.java

示例12: testAddSecondLambdaParam

import org.netbeans.api.java.source.Task; //导入依赖的package包/类
public void testAddSecondLambdaParam() throws Exception {
    testFile = new File(getWorkDir(), "Test.java");
    TestUtilities.copyStringToFile(testFile, 
        "package hierbas.del.litoral;\n\n" +
        "public class Test {\n" +
        "    public static void taragui() {\n" +
        "        ChangeListener l = (e) -> {};\n" + 
        "    }\n" +
        "}\n"
        );
    String golden =
        "package hierbas.del.litoral;\n\n" +
        "public class Test {\n" +
        "    public static void taragui() {\n" +
        "        ChangeListener l = (e, f) -> {};\n" + 
        "    }\n" +
        "}\n";
    JavaSource src = getJavaSource(testFile);
    
    Task<WorkingCopy> task = new Task<WorkingCopy>() {

        public void run(final WorkingCopy workingCopy) throws IOException {
            workingCopy.toPhase(Phase.RESOLVED);
            final TreeMaker make = workingCopy.getTreeMaker();
            new ErrorAwareTreeScanner<Void, Void>() {
                @Override public Void visitLambdaExpression(LambdaExpressionTree node, Void p) {
                    workingCopy.rewrite(node, make.addLambdaParameter(node, make.Variable(make.Modifiers(EnumSet.noneOf(Modifier.class)), "f", null, null)));
                    return super.visitLambdaExpression(node, p);
                }
            }.scan(workingCopy.getCompilationUnit(), null);
        }

    };
    src.runModificationTask(task).commit();
    String res = TestUtilities.copyFileToString(testFile);
    System.err.println(res);
    assertEquals(golden, res);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:39,代码来源:LambdaTest.java

示例13: runModificationTask

import org.netbeans.api.java.source.Task; //导入依赖的package包/类
private static ModificationResult runModificationTask(FileObject javaFile, final Task<WorkingCopy> taskToTest) throws Exception {
    JavaSource javaSource = JavaSource.forFileObject(javaFile);
    return javaSource.runModificationTask(new Task<WorkingCopy>() {
        public void run(WorkingCopy controller) throws Exception {
            controller.toPhase(Phase.RESOLVED);
            taskToTest.run(controller);
        }
    });
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:10,代码来源:GenerationUtilsTest.java

示例14: testCreateAnnotation

import org.netbeans.api.java.source.Task; //导入依赖的package包/类
public void testCreateAnnotation() throws Exception {
    TestUtilities.copyStringToFileObject(testFO,
            "package foo;" +
            "public class TestClass {" +
            "}");
    runModificationTask(testFO, new Task<WorkingCopy>() {
        public void run(WorkingCopy copy) throws Exception {
            GenerationUtils genUtils = GenerationUtils.newInstance(copy);
            ClassTree classTree = (ClassTree)copy.getCompilationUnit().getTypeDecls().get(0);
            AnnotationTree annotationTree = genUtils.createAnnotation("java.lang.SuppressWarnings",
                    Collections.singletonList(genUtils.createAnnotationArgument(null, "unchecked")));
            ClassTree newClassTree = genUtils.addAnnotation(classTree, annotationTree);
            annotationTree = genUtils.createAnnotation("java.lang.annotation.Retention",
                    Collections.singletonList(genUtils.createAnnotationArgument(null, "java.lang.annotation.RetentionPolicy", "RUNTIME")));
            newClassTree = genUtils.addAnnotation(newClassTree, annotationTree);
            copy.rewrite(classTree, newClassTree);
        }
    }).commit();
    runUserActionTask(testFO, new Task<CompilationController>() {
        public void run(CompilationController controller) throws Exception {
            TypeElement typeElement = SourceUtils.getPublicTopLevelElement(controller);
            assertEquals(2, typeElement.getAnnotationMirrors().size());
            SuppressWarnings suppressWarnings = typeElement.getAnnotation(SuppressWarnings.class);
            assertNotNull(suppressWarnings);
            assertEquals(1, suppressWarnings.value().length);
            assertEquals("unchecked", suppressWarnings.value()[0]);
            Retention retention = typeElement.getAnnotation(Retention.class);
            assertNotNull(retention);
            assertEquals(RetentionPolicy.RUNTIME, retention.value());
        }
    });
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:33,代码来源:GenerationUtilsTest.java

示例15: testRenameInImpl2

import org.netbeans.api.java.source.Task; //导入依赖的package包/类
public void testRenameInImpl2() throws Exception {
    testFile = new File(getWorkDir(), "Test.java");
    TestUtilities.copyStringToFile(testFile, 
        "package hierbas.del.litoral;\n\n" +
        "import java.util.*;\n\n" +
        "public class Test<E> extends Object implements PropertyChangeListener, List {\n" +
        "    public void taragui() {\n" +
        "    }\n" +
        "}\n"
        );
    String golden =
        "package hierbas.del.litoral;\n\n" +
        "import java.util.*;\n\n" +
        "public class Test<E> extends Object implements PropertyChangeListener, Seznam {\n" +
        "    public void taragui() {\n" +
        "    }\n" +
        "}\n";
    
    JavaSource src = getJavaSource(testFile);
    Task task = new Task<WorkingCopy>() {

        public void run(WorkingCopy workingCopy) throws IOException {
            workingCopy.toPhase(Phase.RESOLVED);
            CompilationUnitTree cut = workingCopy.getCompilationUnit();
            TreeMaker make = workingCopy.getTreeMaker();
            for (Tree typeDecl : cut.getTypeDecls()) {
                // should check kind, here we can be sure!
                ClassTree clazz = (ClassTree) typeDecl;
                IdentifierTree ident = (IdentifierTree) clazz.getImplementsClause().get(1);
                workingCopy.rewrite(ident, make.setLabel(ident, "Seznam"));
            }
        }
    
    };
    src.runModificationTask(task).commit();
    String res = TestUtilities.copyFileToString(testFile);
    System.err.println(res);
    assertEquals(golden, res);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:40,代码来源:ClassImplementsTest.java


注:本文中的org.netbeans.api.java.source.Task类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。