List of usage examples for org.eclipse.jdt.internal.core NonJavaResource NonJavaResource
public NonJavaResource(Object parent, IResource resource)
From source file:org.eclipse.jdt.internal.core.PackageFragmentRootInfo.java
License:Open Source License
/** * Starting at this folder, create non-java resources for this package fragment root * and add them to the non-java resources collection. * * @exception JavaModelException The resource associated with this package fragment does not exist */// w w w.jav a 2 s . co m static Object[] computeFolderNonJavaResources(IPackageFragmentRoot root, IContainer folder, char[][] inclusionPatterns, char[][] exclusionPatterns) throws JavaModelException { IResource[] nonJavaResources = new IResource[5]; int nonJavaResourcesCounter = 0; JavaProject project = (JavaProject) root.getJavaProject(); try { // GROOVY start // here, we only care about non-source package roots in Groovy projects boolean isInterestingPackageRoot = LanguageSupportFactory.isInterestingProject(project.getProject()) && root.getRawClasspathEntry().getEntryKind() != IClasspathEntry.CPE_SOURCE; // GROOVY end IClasspathEntry[] classpath = project.getResolvedClasspath(); IResource[] members = folder.members(); int length = members.length; if (length > 0) { String sourceLevel = project.getOption(JavaCore.COMPILER_SOURCE, true); String complianceLevel = project.getOption(JavaCore.COMPILER_COMPLIANCE, true); nextResource: for (int i = 0; i < length; i++) { IResource member = members[i]; switch (member.getType()) { case IResource.FILE: String fileName = member.getName(); // ignore .java files that are not excluded // GROOVY start /* old { if (Util.isValidCompilationUnitName(fileName, sourceLevel, complianceLevel) && !Util.isExcluded(member, inclusionPatterns, exclusionPatterns)) } new */ if ((Util.isValidCompilationUnitName(fileName, sourceLevel, complianceLevel) && !Util.isExcluded(member, inclusionPatterns, exclusionPatterns)) && // we want to show groovy scripts that are coming from class folders !(isInterestingPackageRoot && LanguageSupportFactory.isInterestingSourceFile(fileName))) // GROOVY end continue nextResource; // ignore .class files if (Util.isValidClassFileName(fileName, sourceLevel, complianceLevel)) continue nextResource; // ignore .zip or .jar file on classpath if (isClasspathEntry(member.getFullPath(), classpath)) continue nextResource; break; case IResource.FOLDER: // ignore valid packages or excluded folders that correspond to a nested pkg fragment root if (Util.isValidFolderNameForPackage(member.getName(), sourceLevel, complianceLevel) && (!Util.isExcluded(member, inclusionPatterns, exclusionPatterns) || isClasspathEntry(member.getFullPath(), classpath))) continue nextResource; break; } if (nonJavaResources.length == nonJavaResourcesCounter) { // resize System.arraycopy(nonJavaResources, 0, (nonJavaResources = new IResource[nonJavaResourcesCounter * 2]), 0, nonJavaResourcesCounter); } nonJavaResources[nonJavaResourcesCounter++] = member; } } if (ExternalFoldersManager.isInternalPathForExternalFolder(folder.getFullPath())) { IJarEntryResource[] jarEntryResources = new IJarEntryResource[nonJavaResourcesCounter]; for (int i = 0; i < nonJavaResourcesCounter; i++) { jarEntryResources[i] = new NonJavaResource(root, nonJavaResources[i]); } return jarEntryResources; } else if (nonJavaResources.length != nonJavaResourcesCounter) { System.arraycopy(nonJavaResources, 0, (nonJavaResources = new IResource[nonJavaResourcesCounter]), 0, nonJavaResourcesCounter); } return nonJavaResources; } catch (CoreException e) { throw new JavaModelException(e); } }
From source file:org.eclipse.xtext.ui.tests.core.resource.Storage2UriMapperJdtImplTest.java
License:Open Source License
@Flaky @Test//from w w w. java 2 s . c om public void testBug463258_04() throws Exception { IFolder externalFolder = createExternalFolder("externalFolder"); IJavaProject project = createJavaProject("foo"); addExternalFolderToClasspath(project, externalFolder); Storage2UriMapperJavaImpl impl = getStorage2UriMapper(); IPackageFragmentRoot root = project.getPackageFragmentRoot(externalFolder); IPackageFragment foo = root.getPackageFragment("foo"); NonJavaResource fileInFolder = new NonJavaResource(foo, externalFolder.getFile("foo/does.notexist")); externalFolder.delete(true, null); URI uri = impl.getUri(fileInFolder); assertNull(uri); }
From source file:org.eclipse.xtext.ui.tests.editor.model.JavaClassPathResourceForIEditorInputFactoryTest.java
License:Open Source License
@Test(expected = CoreException.class) public void testBug463258_04() throws Throwable { IFolder externalFolder = createExternalFolder("externalFolder"); IJavaProject project = createJavaProject("foo"); addExternalFolderToClasspath(project, externalFolder); IPackageFragmentRoot root = project.getPackageFragmentRoot(externalFolder); IPackageFragment foo = root.getPackageFragment("foo"); NonJavaResource fileInFolder = new NonJavaResource(foo, externalFolder.getFile("foo/doesNotExist.testlanguage")); externalFolder.delete(true, null);//from w w w.ja va 2 s. co m XtextReadonlyEditorInput editorInput = new XtextReadonlyEditorInput(fileInFolder); try { factory.createResource(editorInput); } catch (WrappedException e) { throw e.getCause(); } }
From source file:org.jboss.tools.common.model.ui.editor.ModelObjectStorageEditorInput.java
License:Open Source License
IJarEntryResource findJarEntryFile() {
XModelObject o = object;//from w w w.j a v a 2s. co m
JarEntryFile f = null;
JarEntryResource current = null;
String packageName = "";
List<String> parts = new ArrayList<String>();
List<XModelObject> os = new ArrayList<XModelObject>();
while (o != null && o.getFileType() != XModelObject.SYSTEM) {
String part = o.getFileType() == XModelObject.FILE ? FileAnyImpl.toFileName(o)
: o.getFileType() == XModelObject.FOLDER ? o.getAttributeValue(XModelObjectConstants.ATTR_NAME)
: null;
if (part != null) {
parts.add(0, part);
os.add(0, o);
if (f == null) {
f = new JarEntryFile(part) {
public InputStream getContents() throws CoreException {
return storage.getContents();
}
};
current = f;
} else {
if (packageName.length() > 0) {
packageName = part + "." + packageName;
} else {
packageName = part;
}
JarEntryDirectory d = new JarEntryDirectory(part);
current.setParent(d);
current = d;
}
}
o = o.getParent();
}
// if(!(o instanceof JarSystemImpl)) return null;
String file = Paths.expand(o.get(XModelObjectConstants.ATTR_NAME_LOCATION), o.getModel().getProperties());
IProject p = EclipseResourceUtil.getProject(o);
IJavaProject jp = EclipseResourceUtil.getJavaProject(p);
if (jp == null)
return null;
IPackageFragmentRoot root = null;
try {
IPackageFragmentRoot[] rs = jp.getAllPackageFragmentRoots();
for (IPackageFragmentRoot r : rs) {
if (r.getResource() != null && r.getResource().exists()
&& r.getResource().getLocation().toString().equals(file)) {
root = r;
} else if (r.getPath() != null && r.getPath().toString().equals(file)) {
root = r;
}
}
} catch (CoreException e) {
ModelUIPlugin.getDefault().logError(e);
}
if (root == null) {
root = jp.getPackageFragmentRoot(file);
}
if (root == null) {
return null;
}
if (current != null && !"META-INF".equalsIgnoreCase(current.getName()) && packageName.length() > 0) {
IPackageFragment pf = root.getPackageFragment(packageName);
f.setParent(pf);
} else {
current.setParent(root);
if (!(o instanceof JarSystemImpl)) {
Object q = root;
NonJavaResource nj = null;
for (int i = 0; i < parts.size(); i++) {
IResource ri = (IResource) os.get(i).getAdapter(IResource.class);
if (ri == null) {
return f;
}
nj = new NonJavaResource(q, ri);
q = nj;
}
if (nj != null) {
return nj;
}
}
}
return f;
}