本文整理汇总了Java中org.netbeans.api.java.classpath.ClassPath类的典型用法代码示例。如果您正苦于以下问题:Java ClassPath类的具体用法?Java ClassPath怎么用?Java ClassPath使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ClassPath类属于org.netbeans.api.java.classpath包,在下文中一共展示了ClassPath类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getFlags
import org.netbeans.api.java.classpath.ClassPath; //导入依赖的package包/类
@Override
@NonNull
public Set<ClassPath.Flag> getFlags() {
Set<ClassPath.Flag> res;
synchronized (this) {
res = flagsCache;
}
if (res == null) {
res = getActiveClassPath().getFlags();
assert res != null;
synchronized (this) {
if (flagsCache == null) {
flagsCache = res;
} else {
res = flagsCache;
}
}
}
return res;
}
示例2: testAddToPreprocessorPath
import org.netbeans.api.java.classpath.ClassPath; //导入依赖的package包/类
public void testAddToPreprocessorPath() throws Exception {
assertNotNull("Project not created!",prj); //NOI18N
final FileObject libRoot = prj.getProjectDirectory().createFolder("mylib");
assertNotNull("Library not created!",libRoot); //NOI18N
assertNotNull("No src folder in the proj dir!",src); //NOI18N
SourceGroup srcGrp = null;
for (SourceGroup sg : ProjectUtils.getSources(prj).getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA)) {
FileObject root = sg.getRootFolder();
if (root == src) {
srcGrp = sg;
break;
}
}
assertNotNull("No sources group found!",srcGrp); //NOI18N
final ClassPath cp = ClassPath.getClassPath(srcGrp.getRootFolder(), JavaClassPathConstants.PROCESSOR_PATH);
assertFalse(Arrays.asList(cp.getRoots()).contains(libRoot));
ProjectClassPathModifier.addRoots(
new URI[] {libRoot.toURI()},
srcGrp.getRootFolder(),
JavaClassPathConstants.PROCESSOR_PATH);
assertTrue("No lib on processor path!", Arrays.asList(cp.getRoots()).contains(libRoot)); //NOI18N
}
示例3: pathToString
import org.netbeans.api.java.classpath.ClassPath; //导入依赖的package包/类
@NonNull
private static String pathToString(@NonNull final ClassPath path) {
final StringBuilder cpBuilder = new StringBuilder();
for (ClassPath.Entry entry : path.entries()) {
final URL u = entry.getURL();
boolean folder = "file".equals(u.getProtocol());
File f = FileUtil.archiveOrDirForURL(u);
if (f != null) {
if (cpBuilder.length() > 0) {
cpBuilder.append(File.pathSeparatorChar);
}
cpBuilder.append(f.getAbsolutePath());
if (folder) {
cpBuilder.append(File.separatorChar);
}
}
}
return cpBuilder.toString();
}
示例4: testTypeMirrorHandle
import org.netbeans.api.java.classpath.ClassPath; //导入依赖的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);
}
示例5: getPanel
import org.netbeans.api.java.classpath.ClassPath; //导入依赖的package包/类
@Override
public CustomRefactoringPanel getPanel(ChangeListener parent) {
if (panel == null) {
String pkgName = null;
if (targetFolder != null) {
ClassPath cp = ClassPath.getClassPath(targetFolder, ClassPath.SOURCE);
if (cp != null) {
pkgName = cp.getResourceName(targetFolder, '.', false);
}
}
panel = new MoveClassPanel (parent,
pkgName != null ? pkgName : getDOPackageName(javaObjects.iterator().next().getParent()),
getString("LBL_MoveClassesHeadline"),
getString("LBL_MoveWithoutReferences"),
targetFolder != null ? targetFolder : javaObjects.iterator().next(),
disable, getNodes()
);
}
return panel;
}
示例6: createResources
import org.netbeans.api.java.classpath.ClassPath; //导入依赖的package包/类
@Override
protected List<PathResourceImplementation> createResources() {
ArrayList<PathResourceImplementation> result = new ArrayList<> ();
boolean[] includeJDK = { true };
boolean[] includeFX = { false };
result.addAll(ecpImpl.getResources(includeJDK, includeFX));
lastHintValue = project.getAuxProps().get(Constants.HINT_JDK_PLATFORM, true);
if (includeJDK[0]) {
JavaPlatform pat = findActivePlatform();
boolean hasFx = false;
for (ClassPath.Entry entry : pat.getBootstrapLibraries().entries()) {
if (entry.getURL().getPath().endsWith("/jfxrt.jar!/")) {
hasFx = true;
}
result.add(ClassPathSupport.createResource(entry.getURL()));
}
if (includeFX[0] && !hasFx) {
PathResourceImplementation fxcp = createFxCPImpl(pat);
if (fxcp != null) {
result.add(fxcp);
}
}
result.addAll(nbPlatformJavaFxCp(project, pat));
}
return result;
}
示例7: getFiles
import org.netbeans.api.java.classpath.ClassPath; //导入依赖的package包/类
@Override
@NonNull
public Iterable<JavaFileObject> getFiles(
@NonNull String folderName,
@NullAllowed final ClassPath.Entry entry,
@NullAllowed final Set<JavaFileObject.Kind> kinds,
@NullAllowed final JavaFileFilterImplementation filter,
final boolean recursive) throws IOException {
if (separator != FileObjects.NBFS_SEPARATOR_CHAR) {
folderName = folderName.replace(FileObjects.NBFS_SEPARATOR_CHAR, separator);
}
final Path target = root.resolve(folderName);
final List<JavaFileObject> res = new ArrayList<>();
try (final Stream<Path> s = recursive ? Files.walk(target, FileVisitOption.FOLLOW_LINKS) : Files.list(target)) {
s.filter((p)->{
return (kinds == null || kinds.contains(FileObjects.getKind(FileObjects.getExtension(p.getFileName().toString()))))
&& Files.isRegularFile(p);
})
.forEach((p)->{res.add(FileObjects.pathFileObject(p, root, rootURI, null));});
}
return Collections.unmodifiableCollection(res);
}
示例8: remove
import org.netbeans.api.java.classpath.ClassPath; //导入依赖的package包/类
boolean remove() {
final ClassPathModifier cpm = project.getLookup().lookup(ClassPathModifier.class);
boolean success = false;
if (cpm != null) {
try {
cpm.removeAntArtifacts(
new AntArtifact[]{onArt},
new URI[] {onLoc},
root,
ClassPath.COMPILE);
success = true;
} catch (IOException | UnsupportedOperationException ex) {
LOG.log(
Level.INFO,
"Cannot fix dependencies in project: {0}", //NOI18N
ProjectUtils.getInformation(project).getDisplayName());
}
}
return success;
}
示例9: testAPIIsSelfContained
import org.netbeans.api.java.classpath.ClassPath; //导入依赖的package包/类
public void testAPIIsSelfContained() throws Exception {
FileObject root = makeScratchDir(this);
final ClassPath bootPath = ClassPathSupport.createClassPath(SourceUtilsTestUtil.getBootClassPath().toArray(new URL[0]));//ClassPath.getClassPath(source, ClassPath.BOOT);
final ClassPath compilePath = ClassPathSupport.createClassPath(prepareClasspath());
final ClassPath srcPath = ClassPathSupport.createClassPath(new URL[0]);
JavaSource js = JavaSource.create(ClasspathInfo.create(bootPath, compilePath, srcPath)/*, source*/);
js.runUserActionTask(new Task<CompilationController>() {
public void run(CompilationController copy) throws Exception {
PackageElement apiPackage = copy.getElements().getPackageElement("org.netbeans.api.java.source");
verifySelfContainedAPI(apiPackage);
apiPackage = copy.getElements().getPackageElement("org.netbeans.api.java.source.support");
verifySelfContainedAPI(apiPackage);
}
},true);
assertTrue(violations.toString(), violations.isEmpty());
}
示例10: setUp
import org.netbeans.api.java.classpath.ClassPath; //导入依赖的package包/类
@Override
protected void setUp() throws Exception {
ClassPathProvider cpp = new ClassPathProvider() {
@Override
public ClassPath findClassPath(FileObject file, String type) {
if (type.equals(ClassPath.SOURCE)) {
return ClassPathSupport.createClassPath(new FileObject[]{FileUtil.toFileObject(getDataDir())});
}
if (type.equals(ClassPath.COMPILE)) {
return ClassPathSupport.createClassPath(new FileObject[0]);
}
if (type.equals(ClassPath.BOOT)) {
return createClassPath(System.getProperty("sun.boot.class.path"));
}
return null;
}
};
SharedClassObject loader = JavaDataLoader.findObject(JavaDataLoader.class, true);
SourceUtilsTestUtil.prepareTest(new String[]{"org/netbeans/modules/java/source/resources/layer.xml","org/netbeans/modules/java/source/base/layer.xml"}, new Object[]{loader/*, cpp*/});
JEditorPane.registerEditorKitForContentType("text/x-java", "org.netbeans.modules.editor.java.JavaKit");
File cacheFolder = new File(getWorkDir(), "var/cache/index");
cacheFolder.mkdirs();
IndexUtil.setCacheFolder(cacheFolder);
}
示例11: getProjectClassPath
import org.netbeans.api.java.classpath.ClassPath; //导入依赖的package包/类
/**
* Returns the project classpath including project build paths.
* Can be used to set classpath for custom classloader.
*
* @param project the current project.
* @return List of java.net.URL objects representing each entry on the classpath.
*/
public static List<URL> getProjectClassPath(Project project) {
List<URL> projectClassPathEntries = new ArrayList<URL>();
for (SourceGroup sourceGroup : getSourceGroups(project)) {
if (sourceGroup == null) {
continue;
}
ClassPath cp = ClassPath.getClassPath(sourceGroup.getRootFolder(), ClassPath.COMPILE);
for (ClassPath.Entry cpEntry : cp.entries()) {
projectClassPathEntries.add(cpEntry.getURL());
}
}
return projectClassPathEntries;
}
示例12: computeHints
import org.netbeans.api.java.classpath.ClassPath; //导入依赖的package包/类
@Override
public Collection<? extends HintDescription> computeHints(final ClassPath cp, AtomicBoolean cancel) {
final AtomicReference<Collection<? extends FileObject>> foundFiles = new AtomicReference<>();
Task task = ASYNCHRONOUS.post(new Runnable() {
@Override public void run() {
foundFiles.set(findFiles(cp));
}
});
while ((cancel == null || !cancel.get()) && !task.isFinished()) {
try {
task.waitFinished(1);
} catch (InterruptedException ex) {
LOG.log(Level.FINE, null, ex);
}
}
Collection<? extends FileObject> files = foundFiles.get();
if (files == null || (cancel != null && cancel.get())) return null;
return join(readHints(files));
}
示例13: testOraculumLibrarySourceWithoutRootWithSourcePath
import org.netbeans.api.java.classpath.ClassPath; //导入依赖的package包/类
public void testOraculumLibrarySourceWithoutRootWithSourcePath() {
Lookup.getDefault().lookup(CPP.class).add(
root1,
ClassPath.SOURCE,
ClassPathSupport.createClassPath(root1));
final ClasspathInfo cpInfo = new ClasspathInfo.Builder(ClassPath.EMPTY).build();
final JavacParser parser = new JavacParser(Collections.emptyList(), true);
final JavacTaskImpl impl = JavacParser.createJavacTask(
javaFile1,
null,
cpInfo,
parser,
null,
false);
assertNotNull(impl);
final Options opts = Options.instance(impl.getContext());
assertNotNull(opts);
assertEquals("Test", opts.get("-XD-Xmodule:")); //NOI18N
}
示例14: testWrongClassPathWhileParsingClassFile
import org.netbeans.api.java.classpath.ClassPath; //导入依赖的package包/类
public void testWrongClassPathWhileParsingClassFile() throws Exception {
final FileObject wd = FileUtil.toFileObject(getWorkDir());
final ClassPath boot = createBootPath();
final ClassPath compile = ClassPathSupport.createClassPath(FileUtil.createFolder(wd, "libka"));
final ClasspathInfo cpInfo = ClasspathInfo.create(boot, compile, null);
final FileObject jlObject = boot.findResource("java/lang/Object.class");
assertNotNull(jlObject);
final JavaSource js = JavaSource.create(cpInfo, jlObject);
assertNotNull(js);
js.runUserActionTask(
new Task<CompilationController>(){
@Override
public void run(CompilationController control) throws Exception {
final ClasspathInfo cpInfoInTask = control.getClasspathInfo();
assertNotNull(cpInfoInTask);
assertEquals(compile.entries(), cpInfoInTask.getClassPath(ClasspathInfo.PathKind.COMPILE).entries());
}
},true);
}
示例15: findClassPath
import org.netbeans.api.java.classpath.ClassPath; //导入依赖的package包/类
@Override
public ClassPath findClassPath(
FileObject file,
String type) {
for (FileObject srcRoot : srcPath.getRoots()) {
if (srcRoot.equals(file) || FileUtil.isParentOf(srcRoot, file)) {
if (type == ClassPath.SOURCE) {
return srcPath;
} else if (type == ClassPath.BOOT) {
return bootPath;
} else if (type == ClassPath.COMPILE) {
return compilePath;
}
}
}
return null;
}