Java Code Examples for org.eclipse.jdt.core.IJavaProject#equals()

The following examples show how to use org.eclipse.jdt.core.IJavaProject#equals() . 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: Standalone.java    From JDeodorant with MIT License 7 votes vote down vote up
public static Set<ASTSliceGroup> getExtractMethodRefactoringOpportunities(IJavaProject project) {
	CompilationUnitCache.getInstance().clearCache();
	try {
		if(ASTReader.getSystemObject() != null && project.equals(ASTReader.getExaminedProject())) {
			new ASTReader(project, ASTReader.getSystemObject(), null);
		}
		else {
			new ASTReader(project, null);
		}
	}
	catch(CompilationErrorDetectedException e) {
		e.printStackTrace();
	}
	SystemObject systemObject = ASTReader.getSystemObject();
	Set<ASTSliceGroup> extractedSliceGroups = new TreeSet<ASTSliceGroup>();
	if(systemObject != null) {
		Set<ClassObject> classObjectsToBeExamined = new LinkedHashSet<ClassObject>();
		classObjectsToBeExamined.addAll(systemObject.getClassObjects());
		
		for(ClassObject classObject : classObjectsToBeExamined) {
			if(!classObject.isEnum() && !classObject.isInterface() && !classObject.isGeneratedByParserGenenator()) {
				ListIterator<MethodObject> methodIterator = classObject.getMethodIterator();
				while(methodIterator.hasNext()) {
					MethodObject methodObject = methodIterator.next();
					processMethod(extractedSliceGroups,classObject, methodObject);
				}
			}
		}
	}
	return extractedSliceGroups;
}
 
Example 2
Source File: JavaProjectsStateHelper.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
protected List<String> getPackageFragmentRootHandles(IJavaProject project) {
	List<String> result = Lists.newArrayList();
	List<String> binaryAndNonLocalFragments = Lists.newArrayList();
	try {
		IPackageFragmentRoot[] roots = project.getAllPackageFragmentRoots();
		result = Lists.newArrayListWithCapacity(roots.length);
		for (IPackageFragmentRoot root : roots) {
			if (root != null && !JavaRuntime.newDefaultJREContainerPath().isPrefixOf(root.getRawClasspathEntry().getPath())) {
				if (root.getKind() == IPackageFragmentRoot.K_SOURCE && project.equals(root.getJavaProject())) {
					// treat local sources with higher priority
					// see Java behavior in SameClassNamesTest
					result.add(root.getHandleIdentifier());	
				} else {
					binaryAndNonLocalFragments.add(root.getHandleIdentifier());
				}
			}
		}
	} catch (JavaModelException e) {
		if (!e.isDoesNotExist()) {
			log.error("Cannot find rootHandles in project " + project.getProject().getName(), e);
		}
	}
	result.addAll(binaryAndNonLocalFragments);
	return result;
}
 
Example 3
Source File: JFaceCompletionProposalComputer.java    From saneclipse with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public void elementChanged(ElementChangedEvent event) {
	final IJavaProject javaProject = getCachedJavaProject();
	if (javaProject == null) {
		return;
	}

	final IJavaElementDelta[] children = event.getDelta().getChangedChildren();
	for (int i = 0; i < children.length; i++) {
		final IJavaElementDelta child = children[i];
		if (javaProject.equals(child.getElement())) {
			if (isClasspathChange(child)) {
				setCachedJavaProject(null);
			}
		}
	}
}
 
Example 4
Source File: GWTCompileDialog.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 6 votes vote down vote up
private void updateEntryPointModulesIfProjectChanged() {
  if (project != null) {
    IJavaProject javaProject = JavaCore.create(project);
    if (javaProject != null && !javaProject.equals(entryPointModulesBlock.getJavaProject())) {
      // Set the project for the block (needed for adding a module)
      entryPointModulesBlock.setJavaProject(javaProject);

      GWTCompileSettings settings = GWTProjectProperties.getGwtCompileSettings(project);

      // Set the default and initially-selected modules for the block from
      // the saved settings
      entryPointModulesBlock.setDefaultModules(settings.getEntryPointModules());
      entryPointModulesBlock.setModules(settings.getEntryPointModules());
    }
  } else {
    entryPointModulesBlock.setJavaProject(null);
    entryPointModulesBlock.setDefaultModules(Collections.<String> emptyList());
    entryPointModulesBlock.setModules(Collections.<String> emptyList());
  }
}
 
Example 5
Source File: Standalone.java    From JDeodorant with MIT License 6 votes vote down vote up
public static Set<TypeCheckEliminationGroup> getTypeCheckEliminationRefactoringOpportunities(IJavaProject project) {
	CompilationUnitCache.getInstance().clearCache();
	try {
		if(ASTReader.getSystemObject() != null && project.equals(ASTReader.getExaminedProject())) {
			new ASTReader(project, ASTReader.getSystemObject(), null);
		}
		else {
			new ASTReader(project, null);
		}
	}
	catch(CompilationErrorDetectedException e) {
		e.printStackTrace();
	}
	SystemObject systemObject = ASTReader.getSystemObject();
	Set<TypeCheckEliminationGroup> typeCheckEliminationGroups = new TreeSet<TypeCheckEliminationGroup>();
	if(systemObject != null) {
		Set<ClassObject> classObjectsToBeExamined = new LinkedHashSet<ClassObject>();
		for(ClassObject classObject : systemObject.getClassObjects()) {
			if(!classObject.isEnum() && !classObject.isInterface() && !classObject.isGeneratedByParserGenenator()) {
				classObjectsToBeExamined.add(classObject);
			}
		}
		typeCheckEliminationGroups.addAll(systemObject.generateTypeCheckEliminations(classObjectsToBeExamined, null));
	}
	return typeCheckEliminationGroups;
}
 
Example 6
Source File: Standalone.java    From JDeodorant with MIT License 5 votes vote down vote up
public static List<MoveMethodCandidateRefactoring> getMoveMethodRefactoringOpportunities(IJavaProject project) {
	CompilationUnitCache.getInstance().clearCache();
	try {
		if(ASTReader.getSystemObject() != null && project.equals(ASTReader.getExaminedProject())) {
			new ASTReader(project, ASTReader.getSystemObject(), null);
		}
		else {
			new ASTReader(project, null);
		}
	}
	catch(CompilationErrorDetectedException e) {
		e.printStackTrace();
	}
	List<MoveMethodCandidateRefactoring> moveMethodCandidateList = new ArrayList<MoveMethodCandidateRefactoring>();
	SystemObject systemObject = ASTReader.getSystemObject();
	if(systemObject != null) {
		Set<ClassObject> classObjectsToBeExamined = new LinkedHashSet<ClassObject>();
		classObjectsToBeExamined.addAll(systemObject.getClassObjects());
		
		Set<String> classNamesToBeExamined = new LinkedHashSet<String>();
		for(ClassObject classObject : classObjectsToBeExamined) {
			if(!classObject.isEnum() && !classObject.isInterface() && !classObject.isGeneratedByParserGenenator())
				classNamesToBeExamined.add(classObject.getName());
		}
		MySystem system = new MySystem(systemObject, false);
		DistanceMatrix distanceMatrix = new DistanceMatrix(system);
		
		moveMethodCandidateList.addAll(distanceMatrix.getMoveMethodCandidateRefactoringsByAccess(classNamesToBeExamined, null));
		Collections.sort(moveMethodCandidateList);
	}
	return moveMethodCandidateList;
}
 
Example 7
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 8
Source File: BuildPathSupport.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Finds a source attachment for a new archive in the existing classpaths.
 * @param elem The new classpath entry
 * @return A path to be taken for the source attachment or <code>null</code>
 */
public static IPath guessSourceAttachment(CPListElement elem) {
	if (elem.getEntryKind() == IClasspathEntry.CPE_CONTAINER) {
		return null;
	}
	IJavaProject currProject= elem.getJavaProject(); // can be null
	try {
		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())) {
						IPath attachPath= entry.getSourceAttachmentPath();
						if (attachPath != null && !attachPath.isEmpty()) {
							return attachPath;
						}
					}
				}
			}
		}
	} catch (JavaModelException e) {
		JavaPlugin.log(e.getStatus());
	}
	return null;
}
 
Example 9
Source File: SWTTemplateCompletionProposalComputer.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public void elementChanged(ElementChangedEvent event) {
	IJavaProject javaProject= getCachedJavaProject();
	if (javaProject == null)
		return;

	IJavaElementDelta[] children= event.getDelta().getChangedChildren();
	for (int i= 0; i < children.length; i++) {
		IJavaElementDelta child= children[i];
		if (javaProject.equals(child.getElement())) {
			if (isClasspathChange(child)) {
				setCachedJavaProject(null);
			}
		}
	}
}
 
Example 10
Source File: JavadocOptionsManager.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private IJavaProject getSingleProjectFromInitialSelection() {
	IJavaProject res= null;
	for (int i= 0; i < fInitialElements.length; i++) {
		IJavaProject curr= fInitialElements[i].getJavaProject();
		if (res == null) {
			res= curr;
		} else if (!res.equals(curr)) {
			return null;
		}
	}
	if (res != null && res.isOpen()) {
		return res;
	}
	return null;
}
 
Example 11
Source File: JavaElementComparator.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private boolean needsClasspathComparision(Object e1, int cat1, Object e2, int cat2) {
	if ((cat1 == PACKAGEFRAGMENTROOTS && cat2 == PACKAGEFRAGMENTROOTS) ||
		(cat1 == PACKAGEFRAGMENT &&
			((IPackageFragment)e1).getParent().getResource() instanceof IProject &&
			cat2 == PACKAGEFRAGMENTROOTS) ||
		(cat1 == PACKAGEFRAGMENTROOTS &&
			cat2 == PACKAGEFRAGMENT &&
			((IPackageFragment)e2).getParent().getResource() instanceof IProject)) {
		IJavaProject p1= getJavaProject(e1);
		return p1 != null && p1.equals(getJavaProject(e2));
	}
	return false;
}
 
Example 12
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 IFolder}. Clients can override this method.
 * @param folder The folder to evaluate the children for.
 * @return The children of the given folder.
 * @exception CoreException if the folder does not exist.
 *
 * @since 3.3
 */
protected Object[] getFolderContent(IFolder folder) throws CoreException {
	IResource[] members= folder.members();
	IJavaProject javaProject= JavaCore.create(folder.getProject());
	if (javaProject == null || !javaProject.exists())
		return members;
	boolean isFolderOnClasspath = javaProject.isOnClasspath(folder);
	List<IResource> nonJavaResources= new ArrayList<IResource>();
	// Can be on classpath but as a member of non-java resource folder
	for (int i= 0; i < members.length; i++) {
		IResource member= members[i];
		// A resource can also be a java element
		// in the case of exclusion and inclusion filters.
		// We therefore exclude Java elements from the list
		// of non-Java resources.
		if (isFolderOnClasspath) {
			if (javaProject.findPackageFragmentRoot(member.getFullPath()) == null) {
				nonJavaResources.add(member);
			}
		} else if (!javaProject.isOnClasspath(member)) {
			nonJavaResources.add(member);
		} else {
			IJavaElement element= JavaCore.create(member, javaProject);
			if (element instanceof IPackageFragmentRoot
					&& javaProject.equals(element.getJavaProject())
					&& ((IPackageFragmentRoot)element).getKind() != IPackageFragmentRoot.K_SOURCE) {
				// don't skip libs and class folders on the classpath of their project
				nonJavaResources.add(member);
			}
		}
	}
	return nonJavaResources.toArray();
}
 
Example 13
Source File: ASTBatchParser.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private static boolean hasOnlyOneProject(ICompilationUnit[] units) {
	IJavaProject javaProject= units[0].getJavaProject();
	for (int i= 1; i < units.length; i++) {
		if (!javaProject.equals(units[i].getJavaProject()))
			return false;
	}

	return true;
}
 
Example 14
Source File: OverwriteHelper.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private boolean canOverwrite(IPackageFragmentRoot root) {
	if (fDestination instanceof IJavaProject) {
		IJavaProject destination= (IJavaProject)fDestination;
		IFolder conflict= destination.getProject().getFolder(root.getElementName());
		try {
			return !destination.equals(root.getParent()) && conflict.exists() &&  conflict.members().length > 0;
		} catch (CoreException e) {
			return true;
		}
	} else {
		return willOverwrite(root.getResource());
	}
}
 
Example 15
Source File: CuCollectingSearchRequestor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
protected IScanner getScanner(ICompilationUnit unit) {
	IJavaProject project= unit.getJavaProject();
	if (project.equals(fProjectCache))
		return fScannerCache;

	fProjectCache= project;
	String sourceLevel= project.getOption(JavaCore.COMPILER_SOURCE, true);
	String complianceLevel= project.getOption(JavaCore.COMPILER_COMPLIANCE, true);
	fScannerCache= ToolFactory.createScanner(false, false, false, sourceLevel, complianceLevel);
	return fScannerCache;
}
 
Example 16
Source File: InferTypeArgumentsRefactoring.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private IJavaProject getSingleProject() {
	IJavaProject first= null;
	for (int index= 0; index < fElements.length; index++) {
		final IJavaProject project= fElements[index].getJavaProject();
		if (project != null) {
			if (first == null)
				first= project;
			else if (!project.equals(first))
				return null;
		}
	}
	return first;
}
 
Example 17
Source File: ModuleCompletionProcessor.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 5 votes vote down vote up
public void setProject(IJavaProject javaProject) {
  if (javaProject == null) {
    // Clear the list if we don't have a project
    this.javaProject = null;
    this.allProposals = new ArrayList<ModuleCompletionProposal>();
  } else if (!javaProject.equals(this.javaProject)) {
    // Regenerate the list of proposals when we switch projects (note that
    // the javaProject field must be set before calling createProposals).
    this.javaProject = javaProject;
    this.allProposals = createProposals();
  }
}
 
Example 18
Source File: JFaceCompletionProposalComputer.java    From saneclipse with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Tells whether E4 is on the given project's class path.
 *
 * @param javaProject the Java project
 * @return <code>true</code> if the given project's class path
 */
private synchronized boolean isJFaceOnClasspath(IJavaProject javaProject) {
	if (!javaProject.equals(cachedJavaProject)) {
		cachedJavaProject = javaProject;
		try {
			final IType type = javaProject.findType(JFace_TYPE_NAME);
			isJFaceInClasspath = type != null;
		} catch (final JavaModelException e) {
			isJFaceInClasspath = false;
		}
	}
	return isJFaceInClasspath;
}
 
Example 19
Source File: CuCollectingSearchRequestor.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
protected IScanner getScanner(ICompilationUnit unit) {
	IJavaProject project= unit.getJavaProject();
	if (project.equals(fProjectCache)) {
		return fScannerCache;
	}

	fProjectCache= project;
	String sourceLevel= project.getOption(JavaCore.COMPILER_SOURCE, true);
	String complianceLevel= project.getOption(JavaCore.COMPILER_COMPLIANCE, true);
	fScannerCache= ToolFactory.createScanner(false, false, false, sourceLevel, complianceLevel);
	return fScannerCache;
}
 
Example 20
Source File: Standalone.java    From JDeodorant with MIT License 4 votes vote down vote up
public static Set<ExtractClassCandidateGroup> getExtractClassRefactoringOpportunities(IJavaProject project) {
	CompilationUnitCache.getInstance().clearCache();
	try {
		if(ASTReader.getSystemObject() != null && project.equals(ASTReader.getExaminedProject())) {
			new ASTReader(project, ASTReader.getSystemObject(), null);
		}
		else {
			new ASTReader(project, null);
		}
	}
	catch(CompilationErrorDetectedException e) {
		e.printStackTrace();
	}
	SystemObject systemObject = ASTReader.getSystemObject();
	if(systemObject != null) {
		Set<ClassObject> classObjectsToBeExamined = new LinkedHashSet<ClassObject>();
		classObjectsToBeExamined.addAll(systemObject.getClassObjects());
		
		Set<String> classNamesToBeExamined = new LinkedHashSet<String>();
		for(ClassObject classObject : classObjectsToBeExamined) {
			if(!classObject.isEnum() && !classObject.isInterface() && !classObject.isGeneratedByParserGenenator())
				classNamesToBeExamined.add(classObject.getName());
		}
		MySystem system = new MySystem(systemObject, true);
		DistanceMatrix distanceMatrix = new DistanceMatrix(system);
		
		List<ExtractClassCandidateRefactoring> extractClassCandidateList = new ArrayList<ExtractClassCandidateRefactoring>();
		extractClassCandidateList.addAll(distanceMatrix.getExtractClassCandidateRefactorings(classNamesToBeExamined, null));
		
		HashMap<String, ExtractClassCandidateGroup> groupedBySourceClassMap = new HashMap<String, ExtractClassCandidateGroup>();
		for(ExtractClassCandidateRefactoring candidate : extractClassCandidateList) {
			if(groupedBySourceClassMap.keySet().contains(candidate.getSourceEntity())) {
				groupedBySourceClassMap.get(candidate.getSourceEntity()).addCandidate(candidate);
			}
			else {
				ExtractClassCandidateGroup group = new ExtractClassCandidateGroup(candidate.getSourceEntity());
				group.addCandidate(candidate);
				groupedBySourceClassMap.put(candidate.getSourceEntity(), group);
			}
		}
		for(String sourceClass : groupedBySourceClassMap.keySet()) {
			groupedBySourceClassMap.get(sourceClass).groupConcepts();
		}
		return new TreeSet<ExtractClassCandidateGroup>(groupedBySourceClassMap.values());
	}
	else {
		return new TreeSet<ExtractClassCandidateGroup>();
	}
}