Java Code Examples for org.eclipse.jdt.core.IPackageFragmentRoot#getNonJavaResources()

The following examples show how to use org.eclipse.jdt.core.IPackageFragmentRoot#getNonJavaResources() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PackageFragmentRootWalker.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
public T traverse(IPackageFragmentRoot root, boolean stopOnFirstResult) throws JavaModelException {
	T result = null;
	if (root.exists() && existsPhysically(root)) {
		Object[] resources = root.getNonJavaResources();
		TraversalState state = new TraversalState(root);
		for (Object object : resources) {
			if (object instanceof IJarEntryResource) {
				result = traverse((IJarEntryResource) object, stopOnFirstResult, state);
				if (stopOnFirstResult && result != null)
					return result;
			}
		}

		IJavaElement[] children = root.getChildren();
		for (IJavaElement javaElement : children) {
			if (javaElement instanceof IPackageFragment) {
				result = traverse((IPackageFragment) javaElement, stopOnFirstResult, state);
				if (stopOnFirstResult && result != null)
					return result;
			}
		}
	}
	return result;
}
 
Example 2
Source File: XbaseResourceForEditorInputFactoryTest.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testValidationIsDisabled_03() throws Exception {
	IProject project = AbstractXbaseUITestCase.createPluginProject("my.plugin.project");
	IJavaProject jp = JavaCore.create(project);
	boolean wasTested = false;
	for (IPackageFragmentRoot pfr : jp.getAllPackageFragmentRoots()) {
		if (pfr.isArchive()) {
			for (Object o : pfr.getNonJavaResources()) {
				if (o instanceof IStorage) {
					assertTrue(isValidationDisabled((IStorage) o));
					wasTested = true;
				}
			}
		}
	}
	assertTrue(wasTested);
}
 
Example 3
Source File: NLSHintHelper.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
public static IPackageFragment getResourceBundlePackage(IJavaProject javaProject, String packageName, String resourceName) throws JavaModelException {
	IPackageFragmentRoot[] allRoots= javaProject.getAllPackageFragmentRoots();
	for (int i= 0; i < allRoots.length; i++) {
		IPackageFragmentRoot root= allRoots[i];
		if (root.getKind() == IPackageFragmentRoot.K_SOURCE) {
			IPackageFragment packageFragment= root.getPackageFragment(packageName);
			if (packageFragment.exists()) {
				Object[] resources= packageFragment.isDefaultPackage() ? root.getNonJavaResources() : packageFragment.getNonJavaResources();
				for (int j= 0; j < resources.length; j++) {
					Object object= resources[j];
					if (object instanceof IFile) {
						IFile file= (IFile) object;
						if (file.getName().equals(resourceName)) {
							return packageFragment;
						}
					}
				}
			}
		}
	}
	return null;
}
 
Example 4
Source File: NLSHintHelper.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
public static IStorage getResourceBundle(IPackageFragmentRoot root, String packageName, String resourceName) throws JavaModelException {
	IPackageFragment packageFragment= root.getPackageFragment(packageName);
	if (packageFragment.exists()) {
		Object[] resources= packageFragment.isDefaultPackage() ? root.getNonJavaResources() : packageFragment.getNonJavaResources();
		for (int j= 0; j < resources.length; j++) {
			Object object= resources[j];
			if (JavaModelUtil.isOpenableStorage(object)) {
				IStorage storage= (IStorage)object;
				if (storage.getName().equals(resourceName)) {
					return storage;
				}
			}
		}
	}
	return null;
}
 
Example 5
Source File: PackageExplorerContentProvider.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
@Override
protected Object[] getPackageFragmentRootContent(IPackageFragmentRoot root) throws JavaModelException {
	if (fIsFlatLayout) {
		return super.getPackageFragmentRootContent(root);
	}

	// hierarchical package mode
	ArrayList<Object> result= new ArrayList<Object>();
	getHierarchicalPackageChildren(root, null, result);
	if (!isProjectPackageFragmentRoot(root)) {
		Object[] nonJavaResources= root.getNonJavaResources();
		for (int i= 0; i < nonJavaResources.length; i++) {
			result.add(nonJavaResources[i]);
		}
	}
	return result.toArray();
}
 
Example 6
Source File: JdtClasspathUriResolver.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
private Object[] getNonJavaResources(IPackageFragmentRoot packageFragmentRoot, IPackageFragment packageFragment)
		throws JavaModelException {
	Object[] nonJavaResources = null;
	if (packageFragment.isDefaultPackage()) {
		nonJavaResources = packageFragmentRoot.getNonJavaResources();
	} else {
		nonJavaResources = packageFragment.getNonJavaResources();
	}
	return nonJavaResources;
}
 
Example 7
Source File: StandardJavaElementContentProvider.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Evaluates all children of a given {@link IPackageFragmentRoot}. Clients can override this method.
 * @param root The root to evaluate the children for.
 * @return The children of the root
 * @exception JavaModelException if the package fragment root does not exist or if an
 *      exception occurs while accessing its corresponding resource
 *
 * @since 3.3
 */
protected Object[] getPackageFragmentRootContent(IPackageFragmentRoot root) throws JavaModelException {
	IJavaElement[] fragments= root.getChildren();
	if (isProjectPackageFragmentRoot(root)) {
		return fragments;
	}
	Object[] nonJavaResources= root.getNonJavaResources();
	if (nonJavaResources == null)
		return fragments;
	return concatenate(fragments, nonJavaResources);
}