• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java ClasspathInfo类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: testGetFirstTypeArgument

import org.netbeans.api.java.source.ClasspathInfo; //导入依赖的package包/类
public void testGetFirstTypeArgument() throws Exception {
    ClasspathInfo cpi = ClasspathInfo.create(srcFO);
    final AnnotationModelHelper helper = AnnotationModelHelper.create(cpi);
    helper.runJavaSourceTask(new Runnable() {
        public void run() {
            Elements elements = helper.getCompilationController().getElements();
            Types types = helper.getCompilationController().getTypes();
            TypeElement typeElement = elements.getTypeElement("java.util.Collection");
            // Collection<E>
            assertNull(EntityMappingsUtilities.getFirstTypeArgument(typeElement.asType()));
            // Collection
            assertNull(EntityMappingsUtilities.getFirstTypeArgument(types.erasure(typeElement.asType())));
            // Collection<String>
            TypeMirror stringType = elements.getTypeElement("java.lang.String").asType();
            TypeElement argTypeElement = EntityMappingsUtilities.getFirstTypeArgument(types.getDeclaredType(typeElement, stringType));
            assertTrue(argTypeElement.getQualifiedName().contentEquals("java.lang.String"));
        }
    });
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:20,代码来源:EntityMappingsUtilitiesTest.java


示例2: getJavaSource

import org.netbeans.api.java.source.ClasspathInfo; //导入依赖的package包/类
public static JavaSource getJavaSource(Document doc) {
    FileObject fileObject = NbEditorUtilities.getFileObject(doc);
    if (fileObject == null) {
        return null;
    }
    Project project = FileOwnerQuery.getOwner(fileObject);
    if (project == null) {
        return null;
    }
    // XXX this only works correctly with projects with a single sourcepath,
    // but we don't plan to support another kind of projects anyway (what about Maven?).
    // mkleint: Maven has just one sourceroot for java sources, the config files are placed under
    // different source root though. JavaProjectConstants.SOURCES_TYPE_RESOURCES
    SourceGroup[] sourceGroups = ProjectUtils.getSources(project).getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA);
    for (SourceGroup sourceGroup : sourceGroups) {
        return JavaSource.create(ClasspathInfo.create(sourceGroup.getRootFolder()));
    }
    return null;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:20,代码来源:JPAEditorUtil.java


示例3: findImplementorsResolved

import org.netbeans.api.java.source.ClasspathInfo; //导入依赖的package包/类
public static Set<TypeElement> findImplementorsResolved(final ClasspathInfo cpInfo, final ElementHandle<TypeElement> baseType) {
    final Set<TypeElement> implementors = new HashSet<TypeElement>();
    final Set<ElementHandle<TypeElement>> implHandles = findImplementors(cpInfo, baseType);
    
    if (!implHandles.isEmpty()) {
        ParsingUtils.invokeScanSensitiveTask(cpInfo, new ScanSensitiveTask<CompilationController>(true) {
            public void run(CompilationController controller)
                    throws Exception {
                if (controller.toPhase(Phase.ELEMENTS_RESOLVED).compareTo(Phase.ELEMENTS_RESOLVED) < 0) {
                    return;
                }

                for(ElementHandle<TypeElement> eh : implHandles) {
                    implementors.add(eh.resolve(controller));
                }

            }
        });
    }

    return implementors;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:23,代码来源:ElementUtilitiesEx.java


示例4: testGoToAnnonymousInnerClass

import org.netbeans.api.java.source.ClasspathInfo; //导入依赖的package包/类
public void testGoToAnnonymousInnerClass() throws Exception {
    final boolean[] wasCalled = new boolean[1];

    performTest("package test; public class Test {public void test() {new Runnable() {public void run(){}};} }", 61, new OrigUiUtilsCaller() {
        public void open(FileObject fo, int pos) {
            fail("Should not be called.");
        }
        public void beep() {
            fail("Should not be called.");
        }
        public void open(ClasspathInfo info, Element el) {
            assertEquals(ElementKind.INTERFACE, el.getKind());
            assertEquals("java.lang.Runnable", ((TypeElement) el).getQualifiedName().toString());
            wasCalled[0] = true;
        }
    }, false);

    assertTrue(wasCalled[0]);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:20,代码来源:GoToSupportTest.java


示例5: getFileObjectFromClassName

import org.netbeans.api.java.source.ClasspathInfo; //导入依赖的package包/类
public static FileObject getFileObjectFromClassName(String qualifiedClassName, Project project) throws IOException {
    FileObject root = findSourceRoot(project);
    ClasspathInfo cpInfo = ClasspathInfo.create(root);
    ClassIndex ci = cpInfo.getClassIndex();
    int beginIndex = qualifiedClassName.lastIndexOf('.')+1;
    String simple = qualifiedClassName.substring(beginIndex);
    Set<ElementHandle<TypeElement>> handles = ci.getDeclaredTypes(
            simple, ClassIndex.NameKind.SIMPLE_NAME, 
            Collections.singleton(ClassIndex.SearchScope.SOURCE));
    for (ElementHandle<TypeElement> handle : handles) {
        if (qualifiedClassName.equals(handle.getQualifiedName())) {
            return SourceUtils.getFile(handle, cpInfo);
        }
    }
    return null;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:17,代码来源:SourceGroupSupport.java


示例6: testGoToStaticImport

import org.netbeans.api.java.source.ClasspathInfo; //导入依赖的package包/类
public void testGoToStaticImport() throws Exception {
    final boolean[] wasCalled = new boolean[1];
    String code = "package test; import static java.awt.Color.BLACK; public class Test {}";

    performTest(code, code.indexOf("BLACK") + 1, new OrigUiUtilsCaller() {
        public void open(FileObject fo, int pos) {
            fail("Should not be called.");
        }
        public void beep() {
            fail("Should not be called.");
        }
        public void open(ClasspathInfo info, Element el) {
            assertEquals(ElementKind.FIELD, el.getKind());
            assertEquals("java.awt.Color.BLACK",
                    ((TypeElement) el.getEnclosingElement()).getQualifiedName().toString() + '.' + el);
            wasCalled[0] = true;
        }
    }, false);

    assertTrue(wasCalled[0]);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:22,代码来源:GoToSupportTest.java


示例7: operationMethod

import org.netbeans.api.java.source.ClasspathInfo; //导入依赖的package包/类
public static MethodCustomizer operationMethod(String title, MethodModel method, ClasspathInfo cpInfo, Collection<MethodModel> existingMethods) {
    return new MethodCustomizer(
            title,
            method,
            cpInfo,
            true, // doesn't matter? interfaces selections is disabled
            true, // doesn't matter? interfaces selections is disabled
            true, // doesn't matter? interfaces selections is disabled
            true, // doesn't matter? interfaces selections is disabled
            true,  // return type
            null,  // EJB QL
            false, // finder cardinality
            true,  // exceptions
            false, // interfaces
            null,  // prefix
            existingMethods
            );
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:19,代码来源:MethodCustomizerFactory.java


示例8: isClassEjb31Bean

import org.netbeans.api.java.source.ClasspathInfo; //导入依赖的package包/类
private static boolean isClassEjb31Bean(WorkingCopy wc, TypeElement srcClass) {
    ClassPath cp = wc.getClasspathInfo().getClassPath(ClasspathInfo.PathKind.COMPILE);
    if (cp == null || cp.findResource("javax/ejb/embeddable/EJBContainer.class") == null) {
        // if EJBContainer class is not available on classpath then it is not EJB 3.1
        return false;
    }
    List<? extends AnnotationMirror> annotations = wc.getElements().getAllAnnotationMirrors(srcClass);
    for (AnnotationMirror am : annotations) {
        String annotation = ((TypeElement)am.getAnnotationType().asElement()).getQualifiedName().toString();
        if (annotation.equals("javax.ejb.Singleton") || // NOI18N
            annotation.equals("javax.ejb.Stateless") || // NOI18N
            annotation.equals("javax.ejb.Stateful")) { // NOI18N
            // class is an EJB
            return true;
        }
    }
    return false;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:19,代码来源:AbstractTestGenerator.java


示例9: testInterrupted

import org.netbeans.api.java.source.ClasspathInfo; //导入依赖的package包/类
public void testInterrupted() throws Exception {
    IndexingManager.getDefault().refreshIndexAndWait(srcFO.getURL(), null);
    ClasspathInfo cpi = ClasspathInfo.create(srcFO);
    final AnnotationModelHelper helper = AnnotationModelHelper.create(cpi);
    helper.runJavaSourceTask(new Runnable() {
        public void run() {
            // first checking that the manager does not (for any reason) initialize temporarily
            ObjectProvider<PersistentObject> provider = new InterruptibleObjectProviderImpl(false);
            PersistentObjectManager<PersistentObject> manager = helper.createPersistentObjectManager(provider);
            manager.getObjects();
            assertFalse(manager.temporary);
            // now checking that the manager initializes temporarily when ObjectProvider.createInitialObjects throws InterruptedException
            provider = new InterruptibleObjectProviderImpl(true);
            manager = helper.createPersistentObjectManager(provider);
            manager.getObjects();
            assertTrue(manager.temporary);
        }
    });
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:20,代码来源:PersistentObjectManagerInterruptedTest.java


示例10: testGoToClass

import org.netbeans.api.java.source.ClasspathInfo; //导入依赖的package包/类
public void testGoToClass() throws Exception {
    final boolean[] wasCalled = new boolean[1];

    performTest("package test; public class Test { public static void main(String[] args) {TT tt} } class TT { }", 75, new OrigUiUtilsCaller() {
        public void open(FileObject fo, int pos) {
            assertTrue(source == fo);
            assertEquals(83, pos);
            wasCalled[0] = true;
        }
        public void beep() {
            fail("Should not be called.");
        }
        public void open(ClasspathInfo info, Element el) {
            fail("Should not be called.");
        }
    }, false);

    assertTrue(wasCalled[0]);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:20,代码来源:GoToSupportTest.java


示例11: completeFromRoots

import org.netbeans.api.java.source.ClasspathInfo; //导入依赖的package包/类
/**
 * Completes an 'absolute' pathname (anchored at the root of the classpath)
 */
private void completeFromRoots() {
    String folderName;
    String fileMatch;
    int lastSlash = valPrefix.lastIndexOf('/');
    if (lastSlash == 0) {
        folderName = "";
        fileMatch = valPrefix.substring(1);
    } else {
        folderName = valPrefix.substring(1, lastSlash);
        fileMatch = valPrefix.substring(lastSlash + 1);
    }

    Set<String> names = new HashSet<String>();
    List<FileObject> files = new ArrayList<FileObject>();

    collectFromClasspath(context.getClasspathInfo().getClassPath(ClasspathInfo.PathKind.SOURCE), 
            folderName, files, names, fileMatch, extMatch);
    collectFromClasspath(context.getClasspathInfo().getClassPath(ClasspathInfo.PathKind.COMPILE), 
            folderName, files, names, fileMatch, extMatch);
    
    toCompletionItems(folderName, files);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:26,代码来源:ResourcePathCompleter.java


示例12: getPackages

import org.netbeans.api.java.source.ClasspathInfo; //导入依赖的package包/类
private static Collection<String> getPackages(FileObject root) {
    ClasspathInfo cpi = ClasspathInfo.create(root);
    // create CPI from just the single source root, to avoid packages from other
    // modules
    ClasspathInfo rootCpi = new ClasspathInfo.Builder(
            cpi.getClassPath(PathKind.BOOT)).
            setClassPath(cpi.getClassPath(PathKind.COMPILE)).
            setModuleSourcePath(cpi.getClassPath(PathKind.MODULE_SOURCE)).
            setModuleCompilePath(cpi.getClassPath(PathKind.MODULE_COMPILE)).
            setSourcePath(
                ClassPathSupport.createClassPath(root)
            ).build();
    
    Collection<String> pkgs = new HashSet<>(rootCpi.getClassIndex().getPackageNames("", false, 
            Collections.singleton(SearchScope.SOURCE)));
    pkgs.remove(""); // NOI18N
    return pkgs;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:19,代码来源:ShellProjectUtils.java


示例13: getClasspathInfo

import org.netbeans.api.java.source.ClasspathInfo; //导入依赖的package包/类
/**
 * Get {@link ClasspathInfo} for project. In most cases, you are interested in {@link ClassIndex} you can retrieve using
 * {@link ClasspathInfo#getClassIndex() }.
 * If you need to owner project of some file, use {@link FileOwnerQuery}.
 * @param project What project should I use to determine classpath?
 * @return classpath for project that contains {@link ClassPath#BOOT}, {@link ClassPath#COMPILE}, and {@link ClassPath#SOURCE}
 */
protected final ClasspathInfo getClasspathInfo(Project project) {
    ClassPathProvider cpp = project.getLookup().lookup(ClassPathProvider.class);
    assert cpp != null;
    
    // FIXME: should I use sources of project? TEST!!! What about multiple sources?
    Sources sources = project.getLookup().lookup(Sources.class);
    assert sources != null;
    
    SourceGroup[] groups = sources.getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA);
    assert groups.length != 0;
    SourceGroup group = groups[0];
    
    ClassPath bootPath = cpp.findClassPath(group.getRootFolder(), ClassPath.BOOT);
    ClassPath compilePath = cpp.findClassPath(group.getRootFolder(), ClassPath.COMPILE);
    ClassPath srcPath = cpp.findClassPath(group.getRootFolder(), ClassPath.SOURCE);

    return ClasspathInfo.create(bootPath, compilePath, srcPath);

}
 
开发者ID:kefik,项目名称:Pogamut3,代码行数:27,代码来源:AbstractCrawler.java


示例14: browseButtonActionPerformed

import org.netbeans.api.java.source.ClasspathInfo; //导入依赖的package包/类
private void browseButtonActionPerformed(ActionEvent evt) {
    SwingUtilities.invokeLater(new Runnable() {

        @Override
        public void run() {
            final ElementHandle<TypeElement> handle = TypeElementFinder.find(null, new TypeElementFinder.Customizer() {

                @Override
                public Set<ElementHandle<TypeElement>> query(ClasspathInfo classpathInfo, String textForQuery, NameKind nameKind, Set<SearchScope> searchScopes) {
                    return classpathInfo.getClassIndex().getDeclaredTypes(textForQuery, nameKind, searchScopes);
                }

                @Override
                public boolean accept(ElementHandle<TypeElement> typeHandle) {
                    return true;
                }
            });

            if (handle != null) {
                txtClassName.setText(handle.getQualifiedName());
            }
        }
    });

}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:26,代码来源:HibernateMappingWizardPanel.java


示例15: testGoToSuperMethod2

import org.netbeans.api.java.source.ClasspathInfo; //导入依赖的package包/类
public void testGoToSuperMethod2() throws Exception {
    //try to go to "super" in super.methodInParent():
    final boolean[] wasCalled = new boolean[1];

    performTest("package test; public class Test extends Base { public void test() {super.methodInParent();} } class Base {public void methodInParent() {}}", 70, new OrigUiUtilsCaller() {
        public void open(FileObject fo, int pos) {
            fail("Should not be called.");
        }
        public void beep() {
            wasCalled[0] = true;
        }
        public void open(ClasspathInfo info, Element el) {
            fail("Should not be called.");
        }
    }, false);

    assertTrue(wasCalled[0]);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:19,代码来源:GoToSupportTest.java


示例16: finderMethod

import org.netbeans.api.java.source.ClasspathInfo; //导入依赖的package包/类
public static MethodCustomizer finderMethod(String title, MethodModel method, ClasspathInfo cpInfo, boolean remote, boolean local, boolean selectLocal, boolean selectRemote, String ejbql, Collection<MethodModel> existingMethods) {
    return new MethodCustomizer(
            title,
            method,
            cpInfo,
            local,
            remote,
            selectLocal,
            selectRemote,
            false,  // return type
            ejbql,  // EJB QL
            true,   // finder cardinality
            false,  // exceptions
            true,   // interfaces
            "find", // prefix
            existingMethods
            );
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:19,代码来源:MethodCustomizerFactory.java


示例17: parsePackage

import org.netbeans.api.java.source.ClasspathInfo; //导入依赖的package包/类
@NonNull
private static String parsePackage(FileObject file) {
    String pkg = "";    //NOI18N
        final JavacTaskImpl jt = JavacParser.createJavacTask(
                new ClasspathInfo.Builder(ClassPath.EMPTY).build(),
                null,
                null,
                null,
                null,
                null,
                null,
                null,
                Collections.singletonList(FileObjects.fileObjectFileObject(
                file,
                file.getParent(),
                null,
                FileEncodingQuery.getEncoding(file))));
        final CompilationUnitTree cu =  jt.parse().iterator().next();
        pkg = Optional.ofNullable(cu.getPackage())
                .map((pt) -> pt.getPackageName())
                .map((xt) -> xt.toString())
                .orElse(pkg);
    return pkg;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:25,代码来源:ModuleOraculum.java


示例18: JavacPackageInfo

import org.netbeans.api.java.source.ClasspathInfo; //导入依赖的package包/类
public JavacPackageInfo(ClasspathInfo cpInfo, ClasspathInfo indexInfo, String simpleName, String fqn, Scope scope) {
    super(simpleName, fqn, scope);
    this.cpInfo = cpInfo;
    this.indexInfo = indexInfo;
    
    switch (scope) {
        case SOURCE: {
            sScope= EnumSet.of(ClassIndex.SearchScope.SOURCE);
            break;
        }
        case DEPENDENCIES: {
            sScope = EnumSet.of(ClassIndex.SearchScope.DEPENDENCIES);
            break;
        }
        default: {
            sScope = Collections.EMPTY_SET;
        }
    }
    
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:21,代码来源:JavacPackageInfo.java


示例19: testGoToParameter

import org.netbeans.api.java.source.ClasspathInfo; //导入依赖的package包/类
public void testGoToParameter() throws Exception {
    final boolean[] wasCalled = new boolean[1];

    performTest("package test; public class Test {public void test(int xx) {xx = 0;}}", 60, new OrigUiUtilsCaller() {
        public void open(FileObject fo, int pos) {
            assertTrue(source == fo);
            assertEquals(50, pos);
            wasCalled[0] = true;
        }
        public void beep() {
            fail("Should not be called.");
        }
        public void open(ClasspathInfo info, Element el) {
            fail("Should not be called.");
        }
    }, false);

    assertTrue(wasCalled[0]);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:20,代码来源:GoToSupportTest.java


示例20: testNearlyMatchingMethod1

import org.netbeans.api.java.source.ClasspathInfo; //导入依赖的package包/类
public void testNearlyMatchingMethod1() throws Exception {
    final boolean[] wasCalled = new boolean[1];
    String code = "package test; public class Test { public void x() {Object o = null; test(o);} public void test(int i, float f) {} public void test(Integer i) {} }";

    performTest(code, code.indexOf("test(") + 1, new OrigUiUtilsCaller() {
        public void open(FileObject fo, int pos) {
            assertTrue(source == fo);
            assertEquals(114, pos);
            wasCalled[0] = true;
        }
        public void beep() {
            fail("Should not be called.");
        }
        public void open(ClasspathInfo info, Element el) {
            fail("Should not be called.");
        }
    }, false);

    assertTrue(wasCalled[0]);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:21,代码来源:GoToSupportTest.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java BoundedStatsDeque类代码示例发布时间:2022-05-22
下一篇:
Java CollinsHeadFinder类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap