當前位置: 首頁>>代碼示例>>Java>>正文


Java JavacTask.getElements方法代碼示例

本文整理匯總了Java中com.sun.source.util.JavacTask.getElements方法的典型用法代碼示例。如果您正苦於以下問題:Java JavacTask.getElements方法的具體用法?Java JavacTask.getElements怎麽用?Java JavacTask.getElements使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.sun.source.util.JavacTask的用法示例。


在下文中一共展示了JavacTask.getElements方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: testMethodSignatureFromElement

import com.sun.source.util.JavacTask; //導入方法依賴的package包/類
public void testMethodSignatureFromElement () throws Exception {
InputStream in = this.prepareData(TEST_CLASS);
try {
    JavacTask jt = prepareJavac ();
    Elements elements = jt.getElements();
    TypeElement be = elements.getTypeElement(TEST_CLASS);
    ClassFile cf = new ClassFile (in, true);
    String className = cf.getName().getInternalName().replace('/','.');	 //NOI18N
    List<? extends Element> members = be.getEnclosedElements();
    for (Element e : members) {
	if (e.getKind() == ElementKind.METHOD) {
	    String[] msig = ClassFileUtil.createExecutableDescriptor((ExecutableElement) e);
	    assertEquals (className,msig[0]);
	    assertEquals (e.getSimpleName().toString(),msig[1]);
	    Method m = cf.getMethod(e.getSimpleName().toString(),msig[2]);
	    assertNotNull (m);
	}
    }
} finally {
    in.close ();
}
   }
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:23,代碼來源:CompromiseSATest.java

示例2: testConstructorSignatureFromElement

import com.sun.source.util.JavacTask; //導入方法依賴的package包/類
public void testConstructorSignatureFromElement () throws Exception {	
InputStream in = this.prepareData(TEST_CLASS);
try {
    JavacTask jt = prepareJavac ();
    Elements elements = jt.getElements();
    TypeElement be = elements.getTypeElement(TEST_CLASS);
    ClassFile cf = new ClassFile (in, true);
    String className = cf.getName().getInternalName().replace('/','.'); //NOI18N
    List<? extends Element> members = be.getEnclosedElements();
    for (Element e : members) {
	if (e.getKind() == ElementKind.CONSTRUCTOR) {
	    String[] msig = ClassFileUtil.createExecutableDescriptor((ExecutableElement) e);
	    assertEquals (className,msig[0]);
	    assertEquals (e.getSimpleName().toString(),msig[1]);
	    Method m = cf.getMethod (e.getSimpleName().toString(),msig[2]);
	    assertNotNull (m);
	}
    }
} finally {
    in.close ();
}
   }
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:23,代碼來源:CompromiseSATest.java

示例3: testFieldSignatureFromElement

import com.sun.source.util.JavacTask; //導入方法依賴的package包/類
public void testFieldSignatureFromElement () throws Exception {
InputStream in = this.prepareData(TEST_CLASS);
try {
    JavacTask jt = prepareJavac ();
    Elements elements = jt.getElements();
    TypeElement be = elements.getTypeElement(TEST_CLASS);
    ClassFile cf = new ClassFile (in, true);
    String className = cf.getName().getInternalName().replace('/','.');	    //NOI18N
    List<? extends Element> members = be.getEnclosedElements();
    for (Element e : members) {
	if (e.getKind() == ElementKind.FIELD) {
	    String[] msig = ClassFileUtil.createFieldDescriptor((VariableElement) e);
	    assertEquals (className,msig[0]);
	    assertEquals (e.getSimpleName().toString(),msig[1]);
	    Variable v = cf.getVariable (e.getSimpleName().toString());		    
	    assertNotNull (v);		    
	    assertEquals (v.getDescriptor(), msig[2]);
	}
    }
} finally {
    in.close ();
}
   }
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:24,代碼來源:CompromiseSATest.java

示例4: getSourceElement

import com.sun.source.util.JavacTask; //導入方法依賴的package包/類
private Pair<JavacTask, TreePath> getSourceElement(JavacTask origin, Element el) throws IOException {
    String handle = elementSignature(el);
    Pair<JavacTask, TreePath> cached = signature2Source.get(handle);

    if (cached != null) {
        return cached.fst != null ? cached : null;
    }

    TypeElement type = topLevelType(el);

    if (type == null)
        return null;

    Elements elements = origin.getElements();
    String binaryName = elements.getBinaryName(type).toString();
    ModuleElement module = elements.getModuleOf(type);
    String moduleName = module == null || module.isUnnamed()
            ? null
            : module.getQualifiedName().toString();
    Pair<JavacTask, CompilationUnitTree> source = findSource(moduleName, binaryName);

    if (source == null)
        return null;

    fillElementCache(source.fst, source.snd);

    cached = signature2Source.get(handle);

    if (cached != null) {
        return cached;
    } else {
        signature2Source.put(handle, Pair.of(null, null));
        return null;
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:36,代碼來源:JavadocHelper.java

示例5: runTest

import com.sun.source.util.JavacTask; //導入方法依賴的package包/類
void runTest(Stream<Path> inputs) {
    JavacTool tool = JavacTool.create();
    try (JavacFileManager fm = tool.getStandardFileManager(null, null, null)) {
        Path classes = Paths.get(System.getProperty("test.classes"));
        Iterable<? extends JavaFileObject> reconFiles =
                fm.getJavaFileObjectsFromFiles(inputs.sorted().map(p -> p.toFile()) :: iterator);
        List<String> options = Arrays.asList("-classpath", classes.toAbsolutePath().toString());
        JavacTask reconTask = tool.getTask(null, fm, null, options, null, reconFiles);
        Iterable<? extends CompilationUnitTree> reconUnits = reconTask.parse();
        JavacTrees reconTrees = JavacTrees.instance(reconTask);
        SearchAnnotations scanner = new SearchAnnotations(reconTrees,
                                                          reconTask.getElements());
        List<JavaFileObject> validateFiles = new ArrayList<>();

        reconTask.analyze();
        scanner.scan(reconUnits, null);

        for (CompilationUnitTree cut : reconUnits) {
            validateFiles.add(ClearAnnotations.clearAnnotations(reconTrees, cut));
        }

        Context validateContext = new Context();
        TestDependencies.preRegister(validateContext);
        JavacTask validateTask =
                tool.getTask(null, fm, null, options, null, validateFiles, validateContext);

        validateTask.analyze();

        TestDependencies deps = (TestDependencies) Dependencies.instance(validateContext);

        if (!scanner.topLevel2Expected.equals(deps.topLevel2Completing)) {
            throw new IllegalStateException(  "expected=" + scanner.topLevel2Expected +
                                            "; actual=" + deps.topLevel2Completing);
        }
    } catch (IOException ex) {
        throw new IllegalStateException(ex);
    } finally {
        inputs.close();
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:41,代碼來源:DependenciesTest.java

示例6: runDocTreePath

import com.sun.source.util.JavacTask; //導入方法依賴的package包/類
/**
 * Tests DocTrees.getDocTreePath(PackageElement p, FileObject fo).
 *
 * @param javaFileName the java anchor file
 * @param pkgFileName the package file name
 * @throws Exception e if something goes awry
 */
public void runDocTreePath(String javaFileName, String pkgFileName) throws Exception  {
    List<File> javaFiles = new ArrayList<>();
    javaFiles.add(new File(testSrc, javaFileName));

    List<File> dirs = new ArrayList<>();
    dirs.add(new File(testSrc));

    try (StandardJavaFileManager fm = javac.getStandardFileManager(null, null, null)) {
        fm.setLocation(javax.tools.StandardLocation.SOURCE_PATH, dirs);
        Iterable<? extends JavaFileObject> fos = fm.getJavaFileObjectsFromFiles(javaFiles);

        final JavacTask t = javac.getTask(null, fm, null, null, null, fos);
        final DocTrees trees = DocTrees.instance(t);
        final Elements elementUtils = t.getElements();

        Iterable<? extends Element> elements = t.analyze();

        Element klass = elements.iterator().next();
        PackageElement pkg = elementUtils.getPackageOf(klass);

        FileObject htmlFo = fm.getFileForInput(javax.tools.StandardLocation.SOURCE_PATH,
                t.getElements().getPackageOf(klass).getQualifiedName().toString(),
                "package.html");
        System.out.println();
        DocTreePath treePath = trees.getDocTreePath(htmlFo, pkg);
        DocCommentTree dcTree = treePath.getDocComment();

        StringWriter sw = new StringWriter();
        printer.print(dcTree, sw);
        String found = sw.toString();

        String expected = getExpected(htmlFo.openReader(true));
        astcheck(pkgFileName, expected, found);
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:43,代碼來源:DocCommentTreeApiTester.java


注:本文中的com.sun.source.util.JavacTask.getElements方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。