org.eclipse.jdt.core.IJavaModel Java Examples

The following examples show how to use org.eclipse.jdt.core.IJavaModel. 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: JavaNavigatorContentProvider.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Converts the shape modification to use Java elements.
 *
 *
 * @param modification
 *            the shape modification to convert
 * @return returns true if the conversion took place
 */
private boolean convertToJavaElements(PipelinedShapeModification modification) {
	Object parent = modification.getParent();
	// As of 3.3, we no longer re-parent additions to IProject.
	if (parent instanceof IContainer) {
		IJavaElement element = JavaCore.create((IContainer) parent);
		if (element != null && element.exists()) {
			// we don't convert the root
			if( !(element instanceof IJavaModel) && !(element instanceof IJavaProject))
				modification.setParent(element);
			return convertToJavaElements(modification.getChildren());

		}
	}
	return false;
}
 
Example #2
Source File: CompilationUnitDocumentProvider.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Fuzzy search for Java project in the workspace that matches
 * the given path.
 *
 * @param path the path to match
 * @return the matching Java project or <code>null</code>
 * @since 3.2
 */
private IJavaProject findJavaProject(IPath path) {
	if (path == null)
		return null;

	String[] pathSegments= path.segments();
	IJavaModel model= JavaCore.create(JavaPlugin.getWorkspace().getRoot());
	IJavaProject[] projects;
	try {
		projects= model.getJavaProjects();
	} catch (JavaModelException e) {
		return null; // ignore - use default JRE
	}
	for (int i= 0; i < projects.length; i++) {
		IPath projectPath= projects[i].getProject().getFullPath();
		String projectSegment= projectPath.segments()[0];
		for (int j= 0; j < pathSegments.length; j++)
			if (projectSegment.equals(pathSegments[j]))
				return projects[i];
	}
	return null;
}
 
Example #3
Source File: GWTRuntimeTest.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Tests that we find an {@link com.google.gdt.eclipse.core.sdk.Sdk} on the
 * gwt-user project.
 *
 * @throws Exception
 */
public void testFindSdkFor_GwtUserProject() throws Exception {
  GwtRuntimeTestUtilities.importGwtSourceProjects();
  try {
    IJavaModel javaModel = JavaCore.create(ResourcesPlugin.getWorkspace().getRoot());
    IJavaProject javaProject = javaModel.getJavaProject("gwt-user");
    GwtSdk sdk = GwtSdk.findSdkFor(javaProject);
    IClasspathEntry gwtUserEntry =
        JavaCore.newSourceEntry(
            javaModel.getJavaProject("gwt-user").getPath().append("core/src"),
            new IPath[] {new Path("**/super/**")});
    /*
     * NOTE: Passing null for the IClasspathAttribute array tickles a bug in
     * eclipse 3.3.
     */
    IClasspathEntry gwtDevEntry =
        JavaCore.newProjectEntry(javaModel.getJavaProject("gwt-dev").getPath(), null, false,
            new IClasspathAttribute[0] /* */, false);
    IClasspathEntry[] expected = new IClasspathEntry[] {gwtUserEntry, gwtDevEntry};
    assertEquals(expected, sdk.getClasspathEntries());
  } finally {
    GwtRuntimeTestUtilities.removeGwtSourceProjects();
  }
}
 
Example #4
Source File: JavaElementResourceMapping.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
public static ResourceMapping create(IJavaElement element) {
	switch (element.getElementType()) {
		case IJavaElement.TYPE:
			return create((IType)element);
		case IJavaElement.COMPILATION_UNIT:
			return create((ICompilationUnit)element);
		case IJavaElement.CLASS_FILE:
			return create((IClassFile)element);
		case IJavaElement.PACKAGE_FRAGMENT:
			return create((IPackageFragment)element);
		case IJavaElement.PACKAGE_FRAGMENT_ROOT:
			return create((IPackageFragmentRoot)element);
		case IJavaElement.JAVA_PROJECT:
			return create((IJavaProject)element);
		case IJavaElement.JAVA_MODEL:
			return create((IJavaModel)element);
		default:
			return null;
	}

}
 
Example #5
Source File: JavaModelMerger.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Returns the dependent projects of the specified project.
 *
 * @param set
 *            the project set
 * @param project
 *            the project to get its dependent projects
 */
private void getDependentProjects(final Set<IProject> set, final IProject project) {
	Assert.isNotNull(set);
	Assert.isNotNull(project);
	final IJavaModel model= JavaCore.create(ResourcesPlugin.getWorkspace().getRoot());
	if (model != null) {
		try {
			final String name= project.getName();
			final IJavaProject[] projects= model.getJavaProjects();
			for (int index= 0; index < projects.length; index++) {
				final String[] names= projects[index].getRequiredProjectNames();
				for (int offset= 0; offset < names.length; offset++) {
					if (name.equals(names[offset]))
						set.add(projects[index].getProject());
				}
			}
		} catch (JavaModelException exception) {
			JavaPlugin.log(exception);
		}
	}
}
 
Example #6
Source File: RefactoringAvailabilityTester.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
public static boolean isDeleteAvailable(final IJavaElement element) {
	if (!element.exists())
		return false;
	if (element instanceof IJavaModel || element instanceof IJavaProject)
		return false;
	if (element.getParent() != null && element.getParent().isReadOnly())
		return false;
	if (element instanceof IPackageFragmentRoot) {
		IPackageFragmentRoot root= (IPackageFragmentRoot) element;
		if (root.isExternal() || Checks.isClasspathDelete(root)) // TODO: rename isClasspathDelete
			return false;

		if (root.getResource().equals(root.getJavaProject().getProject()))
			return false;
	}
	if (element.getResource() == null && !RefactoringAvailabilityTester.isWorkingCopyElement(element))
		return false;
	if (element instanceof IMember && ((IMember) element).isBinary())
		return false;
	return true;
}
 
Example #7
Source File: VariableBlock.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private boolean doesChangeRequireFullBuild(List<String> removed, List<String> changed) {
	try {
		IJavaModel model= JavaCore.create(ResourcesPlugin.getWorkspace().getRoot());
		IJavaProject[] projects= model.getJavaProjects();
		for (int i= 0; i < projects.length; i++) {
			IClasspathEntry[] entries= projects[i].getRawClasspath();
			for (int k= 0; k < entries.length; k++) {
				IClasspathEntry curr= entries[k];
				if (curr.getEntryKind() == IClasspathEntry.CPE_VARIABLE) {
					String var= curr.getPath().segment(0);
					if (removed.contains(var) || changed.contains(var)) {
						return true;
					}
				}
			}
		}
	} catch (JavaModelException e) {
		return true;
	}
	return false;
}
 
Example #8
Source File: ReorgPolicyFactory.java    From eclipse.jdt.ls with Eclipse Public License 2.0 6 votes vote down vote up
@Override
protected RefactoringStatus verifyDestination(IJavaElement javaElement) throws JavaModelException {
	Assert.isNotNull(javaElement);
	if (!fCheckDestination) {
		return new RefactoringStatus();
	}
	if (!javaElement.exists()) {
		return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ReorgPolicyFactory_cannot1);
	}
	if (javaElement instanceof IJavaModel) {
		return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ReorgPolicyFactory_jmodel);
	}
	IPackageFragmentRoot destRoot= getDestinationAsPackageFragmentRoot(javaElement);
	if (!ReorgUtils.isSourceFolder(destRoot)) {
		return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ReorgPolicyFactory_packages);
	}
	return new RefactoringStatus();
}
 
Example #9
Source File: ReorgPolicyFactory.java    From eclipse.jdt.ls with Eclipse Public License 2.0 6 votes vote down vote up
@Override
protected RefactoringStatus verifyDestination(IJavaElement javaElement) throws JavaModelException {
	Assert.isNotNull(javaElement);
	if (!fCheckDestination) {
		return new RefactoringStatus();
	}
	if (!javaElement.exists()) {
		return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ReorgPolicyFactory_cannot1);
	}
	if (javaElement instanceof IJavaModel) {
		return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ReorgPolicyFactory_jmodel);
	}
	if (!(javaElement instanceof IJavaProject)) {
		return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ReorgPolicyFactory_src2proj);
	}
	if (javaElement.isReadOnly()) {
		return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ReorgPolicyFactory_src2writable);
	}
	if (ReorgUtils.isPackageFragmentRoot(javaElement.getJavaProject())) {
		return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ReorgPolicyFactory_src2nosrc);
	}
	return new RefactoringStatus();
}
 
Example #10
Source File: PostfixLabelProvider.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private String getQualification(Object element) {
	StringBuffer res= new StringBuffer();

	ITreeContentProvider provider= (ITreeContentProvider) fPage.getViewer().getContentProvider();
	Object visibleParent= provider.getParent(element);
	Object realParent= fContentProvider.getParent(element);
	Object lastElement= element;
	while (realParent != null && !(realParent instanceof IJavaModel) && !realParent.equals(visibleParent)) {
		if (!isSameInformation(realParent, lastElement))  {
			res.append(JavaElementLabels.CONCAT_STRING).append(internalGetText(realParent));
		}
		lastElement= realParent;
		realParent= fContentProvider.getParent(realParent);
	}
	return res.toString();
}
 
Example #11
Source File: CategoryFilterActionGroup.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private boolean collectCategories(IJavaElement element, IResultCollector collector) {//HashSet result, int max, LinkedHashMap lruList) {
	try {
		if (element instanceof IMember) {
			IMember member= (IMember)element;
			collector.accept(member.getCategories());
			return processChildren(member.getChildren(), collector);
		} else if (element instanceof ICompilationUnit) {
			return processChildren(((ICompilationUnit)element).getChildren(), collector);
		} else if (element instanceof IClassFile) {
			return processChildren(((IClassFile)element).getChildren(), collector);
		} else if (element instanceof IJavaModel) {
			return processChildren(((IJavaModel)element).getChildren(), collector);
		} else if (element instanceof IJavaProject) {
			return processChildren(((IJavaProject)element).getChildren(), collector);
		} else if (element instanceof IPackageFragment) {
			return processChildren(((IPackageFragment)element).getChildren(), collector);
		} else if (element instanceof IPackageFragmentRoot)	 {
			return processChildren(((IPackageFragmentRoot)element).getChildren(), collector);
		}
		return false;
	} catch (JavaModelException e) {
		JavaPlugin.log(e);
		return true;
	}
}
 
Example #12
Source File: RefreshAction.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private void refreshJavaElements(IStructuredSelection selection, IProgressMonitor monitor) throws JavaModelException {
	Object[] selectedElements= selection.toArray();
	ArrayList<IJavaElement> javaElements= new ArrayList<IJavaElement>();
	for (int i= 0; i < selectedElements.length; i++) {
		Object curr= selectedElements[i];
		if (curr instanceof IPackageFragmentRoot) {
			javaElements.add((IPackageFragmentRoot) curr);
		} else if (curr instanceof PackageFragmentRootContainer) {
			javaElements.addAll(Arrays.asList(((PackageFragmentRootContainer) curr).getPackageFragmentRoots()));
		} else if (curr instanceof IWorkingSet) {
			IAdaptable[] members= ((IWorkingSet) curr).getElements();
			for (int k= 0; k < members.length; k++) {
				IJavaElement adapted= (IJavaElement)members[k].getAdapter(IJavaElement.class);
				if (adapted instanceof IPackageFragmentRoot) {
					javaElements.add(adapted);
				}
			}
		}
		}
	if (!javaElements.isEmpty()) {
		IJavaModel model= JavaCore.create(ResourcesPlugin.getWorkspace().getRoot());
		model.refreshExternalArchives(javaElements.toArray(new IJavaElement[javaElements.size()]), monitor);
	}
}
 
Example #13
Source File: ReorgPolicyFactory.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
@Override
protected RefactoringStatus verifyDestination(IJavaElement javaElement) throws JavaModelException {
	Assert.isNotNull(javaElement);
	if (!fCheckDestination)
		return new RefactoringStatus();
	if (!javaElement.exists())
		return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ReorgPolicyFactory_cannot1);
	if (javaElement instanceof IJavaModel)
		return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ReorgPolicyFactory_jmodel);
	if (!(javaElement instanceof IJavaProject))
		return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ReorgPolicyFactory_src2proj);
	if (javaElement.isReadOnly())
		return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ReorgPolicyFactory_src2writable);
	if (ReorgUtils.isPackageFragmentRoot(javaElement.getJavaProject()))
		return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ReorgPolicyFactory_src2nosrc);
	return new RefactoringStatus();
}
 
Example #14
Source File: JavaElementResourceMapping.java    From eclipse.jdt.ls with Eclipse Public License 2.0 6 votes vote down vote up
public static ResourceMapping create(IJavaElement element) {
	switch (element.getElementType()) {
		case IJavaElement.TYPE:
			return create((IType)element);
		case IJavaElement.COMPILATION_UNIT:
			return create((ICompilationUnit)element);
		case IJavaElement.CLASS_FILE:
			return create((IClassFile)element);
		case IJavaElement.PACKAGE_FRAGMENT:
			return create((IPackageFragment)element);
		case IJavaElement.PACKAGE_FRAGMENT_ROOT:
			return create((IPackageFragmentRoot)element);
		case IJavaElement.JAVA_PROJECT:
			return create((IJavaProject)element);
		case IJavaElement.JAVA_MODEL:
			return create((IJavaModel)element);
		default:
			return null;
	}

}
 
Example #15
Source File: JavaWorkingSetPageContentProvider.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public Object[] getChildren(Object parentElement) {
	try {
		if (parentElement instanceof IJavaModel)
			return concatenate(super.getChildren(parentElement), getNonJavaProjects((IJavaModel)parentElement));

		if (parentElement instanceof IProject) {
			IProject project= (IProject) parentElement;
			if (project.isAccessible()) {
				return project.members();
			}
			return NO_CHILDREN;
		}
		return super.getChildren(parentElement);
	} catch (CoreException e) {
		return NO_CHILDREN;
	}
}
 
Example #16
Source File: JavaProjectClasspathChangeAnalyzer.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * retrieves all Java Projects whose classpath was effected by the given delta
 * 
 * @param delta the delta to analyze
 * @return a Set of the affected Java Projects
 */
public Set<IJavaProject> getJavaProjectsWithClasspathChange(IJavaElementDelta delta) {
	IJavaElement element = delta.getElement();
	if (element instanceof IPackageFragmentRoot) {
		if (isRelevantPackageFragmentRootChange(delta)) {
			IPackageFragmentRoot root = (IPackageFragmentRoot) element;
			return Collections.singleton(root.getJavaProject());
		}
	} else if (element instanceof IJavaModel) {
		return getJavaProjectsWithClasspathChange(delta.getAffectedChildren());
	} else if (element instanceof IJavaProject) {
		if (isClasspathChangeOnProject(delta)) {
			// filter out IJavaElementDelta.F_SOURCEATTACHED | IJavaElementDelta.F_SOURCEDETACHED only
			if (isAttachmentChangeOnly(delta)) {
				return  Collections.emptySet();
			}
			return Collections.singleton((IJavaProject) element);
		}
		return getJavaProjectsWithClasspathChange(delta.getAffectedChildren());
	}
	return Collections.emptySet();
}
 
Example #17
Source File: AbstractJavaProjectsState.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
private boolean isAffectingPackageFragmentRoots(IJavaElementDelta delta) {
	IJavaElement element = delta.getElement();
	if (element instanceof IPackageFragmentRoot) {
		if (javaProjectClasspathChangeAnalyzer.isRelevantPackageFragmentRootChange(delta)) {
			return true;
		}
	} else if (element instanceof IJavaModel) {
		return isAffectingPackageFragmentRoots(delta.getAffectedChildren());
	} else if (element instanceof IJavaProject) {
		if (javaProjectClasspathChangeAnalyzer.isClasspathChangeOnProject(delta)) {
			// filter out IJavaElementDelta.F_SOURCEATTACHED | IJavaElementDelta.F_SOURCEDETACHED only
			if (javaProjectClasspathChangeAnalyzer.isAttachmentChangeOnly(delta)) {
				return  false;
			}
			return true;
		}
		return isAffectingPackageFragmentRoots(delta.getAffectedChildren());
	}
	return false;
}
 
Example #18
Source File: Storage2UriMapperJavaImpl.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
private Set<IJavaElementDelta> getProjectDeltas(IJavaElementDelta delta) {
	IJavaElement element = delta.getElement();
	if(delta.getElement().getElementType() == IJavaElement.JAVA_PROJECT) {
		return Collections.singleton(delta);
	}
	Set<IJavaElementDelta> result = null;
	if(element instanceof IJavaModel) {
		for(IJavaElementDelta child: delta.getAffectedChildren()) {
			Set<IJavaElementDelta> projectDeltas = getProjectDeltas(child);
			if(!projectDeltas.isEmpty()) {
				if(result == null)
					result = newLinkedHashSet(); 
				result.addAll(projectDeltas);
			}
		}
	}
	return result == null ? Collections.<IJavaElementDelta>emptySet() : result;
}
 
Example #19
Source File: DestinationContentProvider.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public Object[] getChildren(Object element) {
	try {
		if (element instanceof IJavaModel) {
			return concatenate(getJavaProjects((IJavaModel)element), getOpenNonJavaProjects((IJavaModel)element));
		} else {
			Object[] children= doGetChildren(element);
			ArrayList<Object> result= new ArrayList<Object>(children.length);
			for (int i= 0; i < children.length; i++) {
				IReorgDestination destination= ReorgDestinationFactory.createDestination(children[i]);
				if (fValidator.canElementBeDestination(destination) || fValidator.canChildrenBeDestinations(destination))
					result.add(children[i]);
			}
			return result.toArray();
		}
	} catch (JavaModelException e) {
		JavaPlugin.log(e);
		return new Object[0];
	}
}
 
Example #20
Source File: PackageExplorerContentProvider.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public Object[] getChildren(Object parentElement) {
	try {
		if (parentElement instanceof IJavaModel)
			return concatenate(getJavaProjects((IJavaModel)parentElement), getNonJavaProjects((IJavaModel)parentElement));

		if (parentElement instanceof PackageFragmentRootContainer)
			return getContainerPackageFragmentRoots((PackageFragmentRootContainer)parentElement);

		if (parentElement instanceof IProject) {
			IProject project= (IProject) parentElement;
			if (project.isAccessible())
				return project.members();
			return NO_CHILDREN;
		}

		return super.getChildren(parentElement);
	} catch (CoreException e) {
		return NO_CHILDREN;
	}
}
 
Example #21
Source File: JavaEditorBreadcrumb.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Returns all accessible projects of the given Java model.
 *
 * @param model the Java model
 * @return the accessible projects of the given model
 */
private Object[] getAccessibleProjects(IJavaModel model) {
	IJavaProject[] javaProjects;
	Object[] nonJavaResources;
	try {
		javaProjects= model.getJavaProjects();
		nonJavaResources= model.getNonJavaResources();
	} catch (JavaModelException e) {
		return fParent.getChildren(model);
	}
	ArrayList<IAdaptable> result= new ArrayList<IAdaptable>(javaProjects.length + nonJavaResources.length);
	for (int i= 0; i < nonJavaResources.length; i++) {
		IProject project= (IProject)nonJavaResources[i];
		if (project.isAccessible())
			result.add(project);
	}
	for (int i= 0; i < javaProjects.length; i++) {
		IJavaProject javaProject= javaProjects[i];
		if (javaProject.getProject().isAccessible())
			result.add(javaProject);
	}
	return result.toArray(new Object[result.size()]);
}
 
Example #22
Source File: JavaNavigatorContentProvider.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public Object[] getElements(Object inputElement) {
	if (inputElement instanceof IWorkspaceRoot) {
		IWorkspaceRoot root = (IWorkspaceRoot) inputElement;
		return filterResourceProjects(root.getProjects());
	} else if (inputElement instanceof IJavaModel) {
		return filterResourceProjects(((IJavaModel) inputElement).getWorkspace().getRoot().getProjects());
	}
	if (inputElement instanceof IProject) {
		return super.getElements(JavaCore.create((IProject)inputElement));
	}
	return super.getElements(inputElement);
}
 
Example #23
Source File: BuildPathSupport.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Finds a javadoc location for a new archive in the existing classpaths.
 * @param elem The new classpath entry
 * @return A javadoc location found in a similar classpath entry or <code>null</code>.
 */
public static String guessJavadocLocation(CPListElement elem) {
	if (elem.getEntryKind() == IClasspathEntry.CPE_CONTAINER) {
		return null;
	}
	IJavaProject currProject= elem.getJavaProject(); // can be null
	try {
		// try if the jar itself contains the source
		IJavaModel jmodel= JavaCore.create(ResourcesPlugin.getWorkspace().getRoot());
		IJavaProject[] jprojects= jmodel.getJavaProjects();
		for (int i= 0; i < jprojects.length; i++) {
			IJavaProject curr= jprojects[i];
			if (!curr.equals(currProject)) {
				IClasspathEntry[] entries= curr.getRawClasspath();
				for (int k= 0; k < entries.length; k++) {
					IClasspathEntry entry= entries[k];
					if (entry.getEntryKind() == elem.getEntryKind() && entry.getPath().equals(elem.getPath())) {
						IClasspathAttribute[] attributes= entry.getExtraAttributes();
						for (int n= 0; n < attributes.length; n++) {
							IClasspathAttribute attrib= attributes[n];
							if (IClasspathAttribute.JAVADOC_LOCATION_ATTRIBUTE_NAME.equals(attrib.getName())) {
								return attrib.getValue();
							}
						}
					}
				}
			}
		}
	} catch (JavaModelException e) {
		JavaPlugin.log(e.getStatus());
	}
	return null;
}
 
Example #24
Source File: DestinationContentProvider.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private static Object[] getOpenNonJavaProjects(IJavaModel model) throws JavaModelException {
	Object[] nonJavaProjects= model.getNonJavaResources();
	ArrayList<IProject> result= new ArrayList<IProject>(nonJavaProjects.length);
	for (int i= 0; i < nonJavaProjects.length; i++) {
		IProject project = (IProject) nonJavaProjects[i];
		if (project.isOpen())
			result.add(project);
	}
	return result.toArray();
}
 
Example #25
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 #26
Source File: CustomFiltersActionGroup.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private boolean isSelected(Object parent, Object element, IContentProvider contentProvider, ViewerFilter filter) {
	if (filter instanceof EmptyLibraryContainerFilter) // workaround for https://bugs.eclipse.org/341109
		return true;
    if (contentProvider instanceof ITreeContentProvider) {
        // the element and all its parents have to be selected
        ITreeContentProvider provider = (ITreeContentProvider) contentProvider;
        while (element != null && !(element instanceof IJavaModel)) {
            if (!filter.select(fViewer, parent, element))
                return false;
            element= provider.getParent( element);
        }
        return true;
    }
    return filter.select(fViewer, parent, element);
}
 
Example #27
Source File: JarPackageWizardPage.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private Set<Object> removeContainedChildren(Set<Object> elements) {
	Set<Object> newList= new HashSet<Object>(elements.size());
	Set<Object> javaElementResources= getCorrespondingContainers(elements);
	Iterator<Object> iter= elements.iterator();
	boolean removedOne= false;
	while (iter.hasNext()) {
		Object element= iter.next();
		Object parent;
		if (element instanceof IResource)
			parent= ((IResource)element).getParent();
		else if (element instanceof IJavaElement) {
			parent= ((IJavaElement)element).getParent();
			if (parent instanceof IPackageFragmentRoot) {
				IPackageFragmentRoot pkgRoot= (IPackageFragmentRoot)parent;
				try {
					if (pkgRoot.getCorrespondingResource() instanceof IProject)
						parent= pkgRoot.getJavaProject();
				} catch (JavaModelException ex) {
					// leave parent as is
				}
			}
		}
		else {
			// unknown type
			newList.add(element);
			continue;
		}
		if (element instanceof IJavaModel || ((!(parent instanceof IJavaModel)) && (elements.contains(parent) || javaElementResources.contains(parent))))
			removedOne= true;
		else
			newList.add(element);
	}
	if (removedOne)
		return removeContainedChildren(newList);
	else
		return newList;
}
 
Example #28
Source File: PackageExplorerPart.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Updates the title text and title tool tip.
 * Called whenever the input of the viewer changes.
 */
void updateTitle() {
	Object input= fViewer.getInput();
	if (input == null
		|| (input instanceof IJavaModel)) {
		setContentDescription(""); //$NON-NLS-1$
		setTitleToolTip(""); //$NON-NLS-1$
	} else {
		String inputText= JavaElementLabels.getTextLabel(input, AppearanceAwareLabelProvider.DEFAULT_TEXTFLAGS);
		setContentDescription(inputText);
		setTitleToolTip(getToolTipText(input));
	}
}
 
Example #29
Source File: WorkingSetAwareContentProvider.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private List<Object> getModelPath(Object element) {
	List<Object> result= new ArrayList<Object>();
	result.add(element);
	Object parent= super.getParent(element);
	Object input= getViewerInput();
	// stop at input or on JavaModel. We never visualize it anyway.
	while (parent != null && !parent.equals(input) && !(parent instanceof IJavaModel)) {
		result.add(parent);
		parent= super.getParent(parent);
	}
	Collections.reverse(result);
	return result;
}
 
Example #30
Source File: PackageExplorerContentProvider.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private void postRefresh(Object root, int relation, Object affectedElement, Collection<Runnable> runnables) {
	// JFace doesn't refresh when object isn't part of the viewer
	// Therefore move the refresh start down to the viewer's input
	if (isParent(root, fInput) || root instanceof IJavaModel)
		root= fInput;
	List<Object> toRefresh= new ArrayList<Object>(1);
	toRefresh.add(root);
	augmentElementToRefresh(toRefresh, relation, affectedElement);
	postRefresh(toRefresh, true, runnables);
}