org.eclipse.jdt.core.IJarEntryResource Java Examples

The following examples show how to use org.eclipse.jdt.core.IJarEntryResource. 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: NonJavaResource.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
public IJarEntryResource[] getChildren() {
	if (this.resource instanceof IContainer) {
		IResource[] members;
		try {
			members = ((IContainer) this.resource).members();
		} catch (CoreException e) {
			Util.log(e, "Could not retrieve children of " + this.resource.getFullPath()); //$NON-NLS-1$
			return NO_CHILDREN;
		}
		int length = members.length;
		if (length == 0)
			return NO_CHILDREN;
		IJarEntryResource[] children = new IJarEntryResource[length];
		for (int i = 0; i < length; i++) {
			children[i] = new NonJavaResource(this, members[i]);
		}
		return children;
	}
	return NO_CHILDREN;
}
 
Example #2
Source File: JarEntryLocator.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * @return a URI for the given jarEntry, can be <code>null</code>.
 */
public URI getURI(IPackageFragmentRoot root, IJarEntryResource jarEntry, TraversalState state) {
	if (root.isArchive()) {
		URI jarURI = JarEntryURIHelper.getUriForPackageFragmentRoot(root);
		URI storageURI = URI.createURI(jarEntry.getFullPath().toString());
		return createJarURI(root.isArchive(), jarURI, storageURI);
	} else if (root instanceof ExternalPackageFragmentRoot) {
		IResource resource = ((ExternalPackageFragmentRoot) root).resource();
		IPath result = resource.getFullPath();
		for(int i = 1; i < state.getParents().size(); i++) {
			Object obj = state.getParents().get(i);
			if (obj instanceof IPackageFragment) {
				result = result.append(new Path(((IPackageFragment) obj).getElementName().replace('.', '/')));
			} else if (obj instanceof IJarEntryResource) {
				result = result.append(((IJarEntryResource) obj).getName());
			}
		}
		result = result.append(jarEntry.getName());
		return URI.createPlatformResourceURI(result.toString(), true);			
	} else {
		throw new IllegalStateException("Unexpeced root type: " + root.getClass().getName());
	}
}
 
Example #3
Source File: PackageFragmentRootWalker.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
protected T traverse(IPackageFragment pack, boolean stopOnFirstResult, TraversalState state) throws JavaModelException {
	T result = null;
	state.push(pack);
	IJavaElement[] children = pack.getChildren();
	for (IJavaElement iJavaElement : children) {
		if (iJavaElement instanceof IPackageFragment) {
			result = traverse((IPackageFragment) iJavaElement, stopOnFirstResult, state);
			if (stopOnFirstResult && result!=null)
				return result;
		}
	}
	Object[] resources = pack.getNonJavaResources();
	for (Object object : resources) {
		if (object instanceof IJarEntryResource) {
			result = traverse((IJarEntryResource) object, stopOnFirstResult, state);
			if (stopOnFirstResult && result!=null)
				return result;
		}
	}
	state.pop();
	return result;
}
 
Example #4
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 #5
Source File: SourceAttachmentPackageFragmentRootWalker.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Converts the physical URI to a logic URI based on the bundle symbolic name.
 */
protected URI getLogicalURI(URI uri, IStorage storage, TraversalState state) {
	if (bundleSymbolicName != null) {
		URI logicalURI = URI.createPlatformResourceURI(bundleSymbolicName, false);
		List<?> parents = state.getParents();
		for (int i = 1; i < parents.size(); i++) {
			Object obj = parents.get(i);
			if (obj instanceof IPackageFragment) {
				logicalURI = logicalURI.appendSegments(((IPackageFragment) obj).getElementName().split("\\."));
			} else if (obj instanceof IJarEntryResource) {
				logicalURI = logicalURI.appendSegment(((IJarEntryResource) obj).getName());
			} else if (obj instanceof IFolder) {
				logicalURI = logicalURI.appendSegment(((IFolder) obj).getName());
			}
		}
		return logicalURI.appendSegment(uri.lastSegment());
	}
	return uri;
}
 
Example #6
Source File: PackageFragmentRootWalkerTest.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
@Test public void testTraversePackageFragmentRoot() throws Exception {
	IJavaProject project = createJavaProject("foo");
	String jarName = "JarWalkerTest.jar";
	IFile file = project.getProject().getFile(jarName);
	file.create(getClass().getResourceAsStream(jarName), true, new NullProgressMonitor());
	addJarToClasspath(project, file);
	
	final Set<IPath> pathes = new HashSet<IPath>();
	PackageFragmentRootWalker<Void> walker = new PackageFragmentRootWalker<Void>() {
		@Override
		protected Void handle(IJarEntryResource jarEntry, TraversalState state) {
			pathes.add(jarEntry.getFullPath());
			return null;
		}
	};
	for (IPackageFragmentRoot root : project.getPackageFragmentRoots()) {
		if (root.getElementName().equals(jarName))
			walker.traverse(root,false);
	}
	assertEquals(3,pathes.size());
}
 
Example #7
Source File: PackageFragmentRootWalker.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
protected T traverse(IJarEntryResource jarEntry, boolean stopOnFirstResult, TraversalState state) {
	T result = null;
	if (jarEntry.isFile()) {
		result = handle(jarEntry, state);
	} else {
		state.push(jarEntry);
		IJarEntryResource[] children = jarEntry.getChildren();
		for (IJarEntryResource child : children) {
			result = traverse(child, stopOnFirstResult, state);
			if (stopOnFirstResult && result!=null)
				return result;
		}
		state.pop();
	}
	return result;
}
 
Example #8
Source File: XbaseBreakpointUtil.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
public IResource getBreakpointResource(IEditorInput input) throws CoreException {
	IResource resource = Adapters.adapt(input, IResource.class);
	if (resource != null)
		return resource;
	if (input instanceof IStorageEditorInput) {
		IStorage storage = ((IStorageEditorInput) input).getStorage();
		if (storage instanceof IResource)
			return (IResource) storage;
		if (storage instanceof IJarEntryResource) {
			IResource underlyingResource = ((IJarEntryResource) storage).getPackageFragmentRoot().getUnderlyingResource();
			if (underlyingResource != null)
				return underlyingResource;
		}
	} else {
		IClassFile classFile = Adapters.adapt(input, IClassFile.class);
		if (classFile != null) {
			return getBreakpointResource(classFile.findPrimaryType());
		}
	}
	return ResourcesPlugin.getWorkspace().getRoot();
}
 
Example #9
Source File: ModuleSelectionDialog.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public String getText(Object element) {
  if (!(element instanceof IModule)) {
    return super.getText(element);
  }
  String text = null;

  IModule module = (IModule) element;
  String packageName = module.getPackageName();

  if (!module.isBinary()) {
    ModuleFile moduleFile = (ModuleFile) module;
    IFile file = moduleFile.getFile();
    String modulePath = file.getFullPath().makeRelative().toString();
    text = packageName + " - " + modulePath;
  } else {
    ModuleJarResource moduleJarResource = (ModuleJarResource) module;
    IJarEntryResource jarEntryResource = moduleJarResource.getJarEntryResource();
    String jarPath = jarEntryResource.getPackageFragmentRoot().getPath().makeRelative().toString();
    text = packageName + " - " + jarPath;
  }

  return text;
}
 
Example #10
Source File: ModuleSelectionDialog.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Helper method to return the absolute workspace path of a GWT Module.
 * 
 * If the module file is located in a JAR, then the absolute path of the JAR
 * on the file system is returned.
 */
private static IPath getPathForModule(IModule module) {

  if (module == null) {
    return null;
  }

  if (!module.isBinary()) {
    ModuleFile moduleFile = (ModuleFile) module;
    IFile file = moduleFile.getFile();
    return file.getFullPath();
  }

  ModuleJarResource moduleJarResource = (ModuleJarResource) module;
  IJarEntryResource jarEntryResource = moduleJarResource.getJarEntryResource();
  return jarEntryResource.getPackageFragmentRoot().getPath();
}
 
Example #11
Source File: PropertyKeyHyperlinkDetector.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private static boolean isEclipseNLSAvailable(IStorageEditorInput editorInput) {
	IStorage storage;
	try {
		storage= editorInput.getStorage();
	} catch (CoreException ex) {
		return false;
	}
	if (!(storage instanceof IJarEntryResource))
		return false;

	IJavaProject javaProject= ((IJarEntryResource) storage).getPackageFragmentRoot().getJavaProject();

	if (javaProject == null || !javaProject.exists())
		return false;

	try {
		return javaProject.findType("org.eclipse.osgi.util.NLS") != null; //$NON-NLS-1$
	} catch (JavaModelException e) {
		return false;
	}
}
 
Example #12
Source File: CopyQualifiedNameAction.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private String getQualifiedName(Object element) throws JavaModelException {
	if (element instanceof IResource)
		return ((IResource)element).getFullPath().toString();

	if (element instanceof IJarEntryResource)
		return ((IJarEntryResource)element).getFullPath().toString();

	if (element instanceof LogicalPackage)
		return ((LogicalPackage)element).getElementName();

	if (element instanceof IJavaProject || element instanceof IPackageFragmentRoot || element instanceof ITypeRoot) {
		IResource resource= ((IJavaElement)element).getCorrespondingResource();
		if (resource != null)
			return getQualifiedName(resource);
	}

	if (element instanceof IBinding)
		return BindingLabelProvider.getBindingLabel((IBinding)element, LABEL_FLAGS);

	return TextProcessor.deprocess(JavaElementLabels.getTextLabel(element, LABEL_FLAGS));
}
 
Example #13
Source File: Storage2UriMapperJavaImpl.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * @since 2.5
 */
@Override
public URI getUri(/* @NonNull */ IStorage storage) {
	if (storage instanceof IJarEntryResource) {
		final IJarEntryResource casted = (IJarEntryResource) storage;
		IPackageFragmentRoot packageFragmentRoot = casted.getPackageFragmentRoot();
		Map<URI, IStorage> data = getAllEntries(packageFragmentRoot);
		for (Map.Entry<URI, IStorage> entry : data.entrySet()) {
			if (entry.getValue().equals(casted))
				return entry.getKey();
		}
		if (packageFragmentRoot.exists() && packageFragmentRoot.isArchive()) {
			IPath jarPath = packageFragmentRoot.getPath();
			URI jarURI;
			if (packageFragmentRoot.isExternal()) {
				jarURI = URI.createFileURI(jarPath.toOSString());
			} else {
				jarURI = URI.createPlatformResourceURI(jarPath.toString(), true);
			}
			URI result = URI.createURI("archive:" + jarURI + "!" + storage.getFullPath());
			return result;
		}
	}
	return null;
}
 
Example #14
Source File: CopyToClipboardAction.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public CopyToClipboardEnablementPolicy(IResource[] resources, IJavaElement[] javaElements, IJarEntryResource[] jarEntryResources) {
	Assert.isNotNull(resources);
	Assert.isNotNull(javaElements);
	Assert.isNotNull(jarEntryResources);
	fResources= resources;
	fJavaElements= javaElements;
	fJarEntryResources= jarEntryResources;
}
 
Example #15
Source File: CopyToClipboardAction.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private void doRun(IResource[] resources, IJavaElement[] javaElements, IJarEntryResource[] jarEntryResources) throws CoreException {
	ClipboardCopier copier= new ClipboardCopier(resources, javaElements, jarEntryResources, getShell(), fAutoRepeatOnFailure);

	if (fClipboard != null) {
		copier.copyToClipboard(fClipboard);
	} else {
		Clipboard clipboard= new Clipboard(getShell().getDisplay());
		try {
			copier.copyToClipboard(clipboard);
		} finally {
			clipboard.dispose();
		}
	}
}
 
Example #16
Source File: JavadocContentAccess2.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private static String getHTMLContent(IJarEntryResource jarEntryResource, String encoding) throws CoreException {
	InputStream in= jarEntryResource.getContents();
	try {
		return getContentsFromInputStream(in, encoding);
	} finally {
		if (in != null) {
			try {
				in.close();
			} catch (IOException e) {
				//ignore
			}
		}
	}
}
 
Example #17
Source File: CopyToClipboardAction.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private ClipboardCopier(IResource[] resources, IJavaElement[] javaElements, IJarEntryResource[] jarEntryResources, Shell shell, boolean autoRepeatOnFailure) {
	Assert.isNotNull(resources);
	Assert.isNotNull(javaElements);
	Assert.isNotNull(jarEntryResources);
	Assert.isNotNull(shell);
	fResources= resources;
	fJavaElements= javaElements;
	fJarEntryResources= jarEntryResources;
	fShell= shell;
	fLabelProvider= createLabelProvider();
	fAutoRepeatOnFailure= autoRepeatOnFailure;
}
 
Example #18
Source File: StandardJavaElementContentProvider.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public Object[] getChildren(Object element) {
	if (!exists(element))
		return NO_CHILDREN;

	try {
		if (element instanceof IJavaModel)
			return getJavaProjects((IJavaModel)element);

		if (element instanceof IJavaProject)
			return getPackageFragmentRoots((IJavaProject)element);

		if (element instanceof IPackageFragmentRoot)
			return getPackageFragmentRootContent((IPackageFragmentRoot)element);

		if (element instanceof IPackageFragment)
			return getPackageContent((IPackageFragment)element);

		if (element instanceof IFolder)
			return getFolderContent((IFolder)element);

		if (element instanceof IJarEntryResource) {
			return ((IJarEntryResource) element).getChildren();
		}

		if (getProvideMembers() && element instanceof ISourceReference && element instanceof IParent) {
			return ((IParent)element).getChildren();
		}
	} catch (CoreException e) {
		return NO_CHILDREN;
	}
	return NO_CHILDREN;
}
 
Example #19
Source File: PackageExplorerPart.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Returns the element's parent.
 * @param element the element
 *
 * @return the parent or <code>null</code> if there's no parent
 */
private Object getParent(Object element) {
	if (element instanceof IJavaElement)
		return ((IJavaElement)element).getParent();
	else if (element instanceof IResource)
		return ((IResource)element).getParent();
	else if (element instanceof IJarEntryResource) {
		return ((IJarEntryResource)element).getParent();
	}
	return null;
}
 
Example #20
Source File: JarEntryEditorInputFactory.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private JarEntryEditorInput createEditorInput(String[] pathSegments, Object[] children) {
	int depth= pathSegments.length;
	segments: for (int i= 0; i < depth; i++) {
		String name= pathSegments[i];
		for (int j= 0; j < children.length; j++) {
			Object child= children[j];
			if (child instanceof IJarEntryResource) {
				IJarEntryResource jarEntryResource= (IJarEntryResource) child;
				if (name.equals(jarEntryResource.getName())) {
					boolean isFile= jarEntryResource.isFile();
					if (isFile) {
						if (i == depth - 1) {
							return new JarEntryEditorInput(jarEntryResource);
						} else {
							return null; // got a file for a directory name
						}
					} else {
						children= jarEntryResource.getChildren();
						continue segments;
					}
				}
			}
		}
		return null; // no child found on this level
	}
	return null;
}
 
Example #21
Source File: JarEntryEditorInput.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public IPersistableElement getPersistable() {
	if (fJarEntryFile instanceof IJarEntryResource) {
		return new IPersistableElement() {
			public void saveState(IMemento memento) {
				JarEntryEditorInputFactory.saveState(memento, (IJarEntryResource) fJarEntryFile);
			}

			public String getFactoryId() {
				return JarEntryEditorInputFactory.FACTORY_ID;
			}
		};
	} else {
		return null;
	}
}
 
Example #22
Source File: JavaModelUtil.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public static boolean isOpenableStorage(Object storage) {
	if (storage instanceof IJarEntryResource) {
		return ((IJarEntryResource) storage).isFile();
	} else {
		return storage instanceof IStorage;
	}
}
 
Example #23
Source File: CopyToClipboardAction.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void run(IStructuredSelection selection) {
	try {
		List<?> elements= selection.toList();
		IResource[] resources= ReorgUtils.getResources(elements);
		IJavaElement[] javaElements= ReorgUtils.getJavaElements(elements);
		IJarEntryResource[] jarEntryResources= ReorgUtils.getJarEntryResources(elements);
		if (elements.size() == resources.length + javaElements.length + jarEntryResources.length && canEnable(resources, javaElements, jarEntryResources))
			doRun(resources, javaElements, jarEntryResources);
	} catch (CoreException e) {
		ExceptionHandler.handle(e, getShell(), ReorgMessages.CopyToClipboardAction_2, ReorgMessages.CopyToClipboardAction_3);
	}
}
 
Example #24
Source File: CopyToClipboardAction.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void selectionChanged(IStructuredSelection selection) {
	List<?> elements= selection.toList();
	IResource[] resources= ReorgUtils.getResources(elements);
	IJavaElement[] javaElements= ReorgUtils.getJavaElements(elements);
	IJarEntryResource[] jarEntryResources= ReorgUtils.getJarEntryResources(elements);
	if (elements.size() != resources.length + javaElements.length + jarEntryResources.length)
		setEnabled(false);
	else
		setEnabled(canEnable(resources, javaElements, jarEntryResources));
}
 
Example #25
Source File: ParentChecker.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public ParentChecker(IResource[] resources, IJavaElement[] javaElements, IJarEntryResource[] jarResources) {
	Assert.isNotNull(resources);
	Assert.isNotNull(javaElements);
	Assert.isNotNull(jarResources);
	fResources= resources;
	fJavaElements= javaElements;
	fJarResources= jarResources;
}
 
Example #26
Source File: ReorgUtils.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Returns the jar entry resources from the list of elements.
 * 
 * @param elements the list of elements
 * @return the array of jar entry resources
 * @since 3.6
 */
public static IJarEntryResource[] getJarEntryResources(List<?> elements) {
	List<IJarEntryResource> resources= new ArrayList<IJarEntryResource>(elements.size());
	for (Iterator<?> iter= elements.iterator(); iter.hasNext();) {
		Object element= iter.next();
		if (element instanceof IJarEntryResource)
			resources.add((IJarEntryResource) element);
	}
	return resources.toArray(new IJarEntryResource[resources.size()]);
}
 
Example #27
Source File: SourceAttachmentPackageFragmentRootWalker.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Delegate to
 * {@link #handle(URI, IStorage, org.eclipse.xtext.ui.resource.PackageFragmentRootWalker.TraversalState)}.
 */
@Override
protected T handle(IJarEntryResource jarEntry, TraversalState state) {
	URI uri = getURI(jarEntry, state);
	if (isValid(uri, jarEntry)) {
		return handle(getLogicalURI(uri, jarEntry, state), jarEntry, state);
	}
	return null;
}
 
Example #28
Source File: StatusBarUpdater.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
protected String formatMessage(ISelection sel) {
	if (sel instanceof IStructuredSelection && !sel.isEmpty()) {
		IStructuredSelection selection= (IStructuredSelection) sel;

		int nElements= selection.size();
		if (nElements > 1) {
			return Messages.format(JavaUIMessages.StatusBarUpdater_num_elements_selected, String.valueOf(nElements));
		} else {
			Object elem= selection.getFirstElement();
			if (elem instanceof IJavaElement) {
				return formatJavaElementMessage((IJavaElement) elem);
			} else if (elem instanceof IResource) {
				return formatResourceMessage((IResource) elem);
			} else if (elem instanceof PackageFragmentRootContainer) {
				PackageFragmentRootContainer container= (PackageFragmentRootContainer) elem;
				return container.getLabel() + JavaElementLabels.CONCAT_STRING + container.getJavaProject().getElementName();
			} else if (elem instanceof IJarEntryResource) {
				IJarEntryResource jarEntryResource= (IJarEntryResource) elem;
				StringBuffer buf= new StringBuffer(BasicElementLabels.getResourceName(jarEntryResource.getName()));
				buf.append(JavaElementLabels.CONCAT_STRING);
				IPath fullPath= jarEntryResource.getFullPath();
				if (fullPath.segmentCount() > 1) {
					buf.append(BasicElementLabels.getPathLabel(fullPath.removeLastSegments(1), false));
					buf.append(JavaElementLabels.CONCAT_STRING);
				}
				buf.append(JavaElementLabels.getElementLabel(jarEntryResource.getPackageFragmentRoot(), JavaElementLabels.ROOT_POST_QUALIFIED));
				return buf.toString();
			} else if (elem instanceof IAdaptable) {
				IWorkbenchAdapter wbadapter= (IWorkbenchAdapter) ((IAdaptable)elem).getAdapter(IWorkbenchAdapter.class);
				if (wbadapter != null) {
					return wbadapter.getLabel(elem);
				}
			}
		}
	}
	return "";  //$NON-NLS-1$
}
 
Example #29
Source File: CopyQualifiedNameAction.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private boolean isValidElement(Object element) {
	if (element instanceof IMember)
		return true;

	if (element instanceof IClassFile)
		return true;

	if (element instanceof ICompilationUnit)
		return true;

	if (element instanceof IPackageDeclaration)
		return true;

	if (element instanceof IImportDeclaration)
		return true;

	if (element instanceof IPackageFragment)
		return true;

	if (element instanceof IPackageFragmentRoot)
		return true;

	if (element instanceof IJavaProject)
		return true;

	if (element instanceof IJarEntryResource)
		return true;

	if (element instanceof IResource)
		return true;

	if (element instanceof LogicalPackage)
		return true;

	return false;
}
 
Example #30
Source File: WorkingSetFilter.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public WorkingSetCompareEntry(IAdaptable a) {
	if (a instanceof IJavaElement) {
		init((IJavaElement) a);
	} else if (a instanceof IResource) {
		init((IResource) a);
	} else if (a instanceof RequiredProjectWrapper) {
		RequiredProjectWrapper wrapper= (RequiredProjectWrapper) a;
		IJavaProject proj= wrapper.getParentClassPathContainer().getJavaProject();
		// the project reference is treated like an internal JAR.
		// that means it will only appear if the parent container project is in the working set
		IResource fakeInternal= proj.getProject().getFile(wrapper.getProject().getElementName() + "-fake-jar.jar"); //$NON-NLS-1$
		init(proj.getPackageFragmentRoot(fakeInternal));
	} else if (a instanceof IJarEntryResource) {
		init((IJarEntryResource)a);
	} else {
		IJavaElement je= (IJavaElement) a.getAdapter(IJavaElement.class);
		if (je != null) {
			init(je);
		} else {
			IResource resource= (IResource) a.getAdapter(IResource.class);
			if (resource != null) {
				init(resource);
			} else {
				fResourcePath= null;
				fJavaElement= null;
			}
		}
	}
}