org.eclipse.jdt.core.IRegion Java Examples

The following examples show how to use org.eclipse.jdt.core.IRegion. 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: TypeHierarchyLifeCycle.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private ITypeHierarchy createTypeHierarchy(IJavaElement[] elements, IProgressMonitor pm) throws JavaModelException {
	if (elements.length == 1 && elements[0].getElementType() == IJavaElement.TYPE) {
		IType type= (IType)elements[0];
		if (fIsSuperTypesOnly) {
			return type.newSupertypeHierarchy(pm);
		} else {
			return type.newTypeHierarchy(pm);
		}
	} else {
		IRegion region= JavaCore.newRegion();
		for (int i= 0; i < elements.length; i++) {
			if (elements[i].getElementType() == IJavaElement.JAVA_PROJECT) {
				// for projects only add the contained source folders
				IPackageFragmentRoot[] roots= ((IJavaProject)elements[i]).getPackageFragmentRoots();
				for (int j= 0; j < roots.length; j++) {
					if (!roots[j].isExternal()) {
						region.add(roots[j]);
					}
				}
			} else {
				region.add(elements[i]);
			}
		}
		return JavaCore.newTypeHierarchy(region, null, pm);
	}
}
 
Example #2
Source File: JavaProject.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * @see IJavaProject
 */
public ITypeHierarchy newTypeHierarchy(
	IRegion region,
	WorkingCopyOwner owner,
	IProgressMonitor monitor)
	throws JavaModelException {

	if (region == null) {
		throw new IllegalArgumentException(Messages.hierarchy_nullRegion);
	}
	ICompilationUnit[] workingCopies = JavaModelManager.getJavaModelManager().getWorkingCopies(owner, true/*add primary working copies*/);
	CreateTypeHierarchyOperation op =
		new CreateTypeHierarchyOperation(region, workingCopies, null, true);
	op.runOperation(monitor);
	return op.getResult();
}
 
Example #3
Source File: JavaProject.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * @see IJavaProject
 */
public ITypeHierarchy newTypeHierarchy(
	IType type,
	IRegion region,
	WorkingCopyOwner owner,
	IProgressMonitor monitor)
	throws JavaModelException {

	if (type == null) {
		throw new IllegalArgumentException(Messages.hierarchy_nullFocusType);
	}
	if (region == null) {
		throw new IllegalArgumentException(Messages.hierarchy_nullRegion);
	}
	ICompilationUnit[] workingCopies = JavaModelManager.getJavaModelManager().getWorkingCopies(owner, true/*add primary working copies*/);
	CreateTypeHierarchyOperation op =
		new CreateTypeHierarchyOperation(region, workingCopies, type, true/*compute subtypes*/);
	op.runOperation(monitor);
	return op.getResult();
}
 
Example #4
Source File: ClassFinder.java    From birt with Eclipse Public License 1.0 6 votes vote down vote up
private IRegion getRegion( IJavaElement element ) throws JavaModelException
{
	IRegion result = JavaCore.newRegion( );
	if ( element.getElementType( ) == IJavaElement.JAVA_PROJECT )
	{
		// for projects only add the contained source folders
		IPackageFragmentRoot[] roots = ( (IJavaProject) element ).getPackageFragmentRoots( );
		for ( int i = 0; i < roots.length; i++ )
		{
			if ( !roots[i].isArchive( ) )
			{
				result.add( roots[i] );
			}
		}
	}
	else
	{
		result.add( element );
	}
	return result;
}
 
Example #5
Source File: BusinessObjectModelRepositoryStore.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
protected IRegion regionWithBDM(final IJavaProject javaProject) throws JavaModelException {
    final IRegion newRegion = JavaCore.newRegion();
    IClasspathEntry[] rawClasspath = javaProject.getRawClasspath();
    if (rawClasspath != null) {
        final IClasspathEntry repositoryDependenciesClasspathEntry = find(asIterable(rawClasspath),
                repositoryDependenciesEntry(), null);
        final IPackageFragmentRoot[] fragmentRoots = javaProject
                .findPackageFragmentRoots(repositoryDependenciesClasspathEntry);
        if (fragmentRoots != null) {
            final IPackageFragmentRoot packageFragmentRoot = find(asIterable(fragmentRoots),
                    withElementName(BDM_CLIENT_POJO_JAR_NAME), null);
            if (packageFragmentRoot != null) {
                newRegion.add(packageFragmentRoot);
            }
        }
    }
    return newRegion;
}
 
Example #6
Source File: DebugSourceInstallingCompilationParticipant.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
protected List<IFile> findGeneratedJavaClassFiles(IJavaElement element) {
	IRegion region = JavaCore.newRegion();
	region.add(element);
	List<IFile> result = Lists.newLinkedList();
	for (IResource res : JavaCore.getGeneratedResources(region, false))
		if (res instanceof IFile)
			result.add((IFile) res);
	return result;
}
 
Example #7
Source File: RippleMethodFinder.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
private void createHierarchyOfDeclarations(IProgressMonitor pm, WorkingCopyOwner owner) throws JavaModelException {
	IRegion region = JavaCore.newRegion();
	for (Iterator<IMethod> iter = fDeclarations.iterator(); iter.hasNext();) {
		IType declaringType = iter.next().getDeclaringType();
		region.add(declaringType);
	}
	fHierarchy = JavaCore.newTypeHierarchy(region, owner, pm);
}
 
Example #8
Source File: RippleMethodFinder2.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
private void createHierarchyOfDeclarations(IProgressMonitor pm, WorkingCopyOwner owner) throws JavaModelException {
	IRegion region= JavaCore.newRegion();
	for (Iterator<IMethod> iter= fDeclarations.iterator(); iter.hasNext();) {
		IType declaringType= iter.next().getDeclaringType();
		region.add(declaringType);
	}
	fHierarchy= JavaCore.newTypeHierarchy(region, owner, pm);
}
 
Example #9
Source File: RippleMethodFinder2.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private void createHierarchyOfDeclarations(IProgressMonitor pm, WorkingCopyOwner owner) throws JavaModelException {
	IRegion region= JavaCore.newRegion();
	for (Iterator<IMethod> iter= fDeclarations.iterator(); iter.hasNext();) {
		IType declaringType= iter.next().getDeclaringType();
		region.add(declaringType);
	}
	fHierarchy= JavaCore.newTypeHierarchy(region, owner, pm);
}
 
Example #10
Source File: SerialVersionHashOperation.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private static IFile getClassfile(ITypeBinding typeBinding) throws CoreException {
	// bug 191943
	IType type= (IType) typeBinding.getJavaElement();
	if (type == null || type.getCompilationUnit() == null) {
		return null;
	}

	IRegion region= JavaCore.newRegion();
	region.add(type.getCompilationUnit());

	String name= typeBinding.getBinaryName();
	if (name != null) {
		int packStart= name.lastIndexOf('.');
		if (packStart != -1) {
			name= name.substring(packStart + 1);
		}
	} else {
		throw new CoreException(new Status(IStatus.ERROR, JavaUI.ID_PLUGIN, CorrectionMessages.SerialVersionHashOperation_error_classnotfound));
	}

	name += ".class"; //$NON-NLS-1$

	IResource[] classFiles= JavaCore.getGeneratedResources(region, false);
	for (int i= 0; i < classFiles.length; i++) {
		IResource resource= classFiles[i];
		if (resource.getType() == IResource.FILE && resource.getName().equals(name)) {
			return (IFile) resource;
		}
	}
	throw new CoreException(new Status(IStatus.ERROR, JavaUI.ID_PLUGIN, CorrectionMessages.SerialVersionHashOperation_error_classnotfound));
}
 
Example #11
Source File: DeleteElementsOperation.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Deletes this element from its compilation unit.
 * @see MultiOperation
 */
protected void processElement(IJavaElement element) throws JavaModelException {
	ICompilationUnit cu = (ICompilationUnit) element;

	// keep track of the import statements - if all are removed, delete
	// the import container (and report it in the delta)
	int numberOfImports = cu.getImports().length;

	JavaElementDelta delta = new JavaElementDelta(cu);
	IJavaElement[] cuElements = ((IRegion) this.childrenToRemove.get(cu)).getElements();
	for (int i = 0, length = cuElements.length; i < length; i++) {
		IJavaElement e = cuElements[i];
		if (e.exists()) {
			deleteElement(e, cu);
			delta.removed(e);
			if (e.getElementType() == IJavaElement.IMPORT_DECLARATION) {
				numberOfImports--;
				if (numberOfImports == 0) {
					delta.removed(cu.getImportContainer());
				}
			}
		}
	}
	if (delta.getAffectedChildren().length > 0) {
		cu.save(getSubProgressMonitor(1), this.force);
		if (!cu.isWorkingCopy()) { // if unit is working copy, then save will have already fired the delta
			addDelta(delta);
			setAttribute(HAS_MODIFIED_RESOURCE_ATTR, TRUE);
		}
	}
}
 
Example #12
Source File: DeleteElementsOperation.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * @see MultiOperation
 */
protected void verify(IJavaElement element) throws JavaModelException {
	IJavaElement[] children = ((IRegion) this.childrenToRemove.get(element)).getElements();
	for (int i = 0; i < children.length; i++) {
		IJavaElement child = children[i];
		if (child.getCorrespondingResource() != null)
			error(IJavaModelStatusConstants.INVALID_ELEMENT_TYPES, child);

		if (child.isReadOnly())
			error(IJavaModelStatusConstants.READ_ONLY, child);
	}
}
 
Example #13
Source File: JavaProject.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * @see IJavaProject
 */
public ITypeHierarchy newTypeHierarchy(
	IRegion region,
	IProgressMonitor monitor)
	throws JavaModelException {

	return newTypeHierarchy(region, DefaultWorkingCopyOwner.PRIMARY, monitor);
}
 
Example #14
Source File: JavaProject.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * @see IJavaProject
 */
public ITypeHierarchy newTypeHierarchy(
	IType type,
	IRegion region,
	IProgressMonitor monitor)
	throws JavaModelException {

	return newTypeHierarchy(type, region, DefaultWorkingCopyOwner.PRIMARY, monitor);
}
 
Example #15
Source File: CreateTypeHierarchyOperation.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 2 votes vote down vote up
/**
 * Constructs an operation to create a type hierarchy for the
 * given type within the specified region, in the context of
 * the given project.
 */
public CreateTypeHierarchyOperation(IRegion region, ICompilationUnit[] workingCopies, IType element, boolean computeSubtypes) {
	super(element);
	this.typeHierarchy = new RegionBasedTypeHierarchy(region, workingCopies, element, computeSubtypes);
}