Java Code Examples for org.eclipse.core.resources.IProject#equals()

The following examples show how to use org.eclipse.core.resources.IProject#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: ExternalFoldersManager.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
public void refreshReferences(IProject source, IProgressMonitor monitor) {
	IProject externalProject = getExternalFoldersProject();
	if (source.equals(externalProject))
		return;
	if (!JavaProject.hasJavaNature(source))
		return;
	try {
		HashSet externalFolders = getExternalFolders(((JavaProject) JavaCore.create(source)).getResolvedClasspath());
		if (externalFolders == null)
			return;
		
		runRefreshJob(externalFolders);
	} catch (CoreException e) {
		Util.log(e, "Exception while refreshing external project"); //$NON-NLS-1$
	}
	return;
}
 
Example 2
Source File: SCTHotModelReplacementManager.java    From statecharts with Eclipse Public License 1.0 6 votes vote down vote up
private void handleCloseEvent(IResourceChangeEvent event) {
	if (event.getResource() instanceof IProject) {
		IProject project = ((IProject) event.getResource());
		for (IDebugTarget target : activeTargets) {
			EObject object = (EObject) target.getAdapter(EObject.class);
			IFile file = WorkspaceSynchronizer.getFile(object.eResource());
			if (project.equals(file.getProject())) {
				try {
					target.terminate();
				} catch (DebugException e) {
					e.printStackTrace();
				}
			}
		}
	}
}
 
Example 3
Source File: SVNTeamProviderType.java    From APICloud-Studio with GNU General Public License v3.0 6 votes vote down vote up
private boolean isNestedProject(IProject testProject)
{
	IPath testProjectLocation = testProject.getLocation();

	IProject[] projects = ResourcesPlugin.getWorkspace().getRoot().getProjects();
	for (int i = 0; i < projects.length; i++) {
		IProject project = projects[i];

		if (project.equals(testProject))
			continue;

		IPath projectLocation = project.getLocation();
		if ((projectLocation != null) && projectLocation.isPrefixOf(testProjectLocation))
			return true;
	}

	return false;
}
 
Example 4
Source File: ContainedLibraryFilter.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public boolean select(Viewer viewer, Object parentElement, Object element) {
	if (element instanceof IPackageFragmentRoot) {
		IPackageFragmentRoot root= (IPackageFragmentRoot)element;
		if (root.isArchive()) {
			// don't filter out JARs contained in the project itself
			IResource resource= root.getResource();
			if (resource != null) {
				IProject jarProject= resource.getProject();
				IProject container= root.getJavaProject().getProject();
				return !container.equals(jarProject);
			}
		}
	}
	return true;
}
 
Example 5
Source File: ChooseGhidraModuleProjectWizardPage.java    From ghidra with Apache License 2.0 6 votes vote down vote up
@Override
public void createControl(Composite parent) {

	Composite container = new Composite(parent, SWT.NULL);
	container.setLayout(new GridLayout(2, false));

	Label projectNameLabel = new Label(container, SWT.NULL);
	projectNameLabel.setText("Ghida module project:");
	projectCombo = new Combo(container, SWT.DROP_DOWN | SWT.READ_ONLY);
	GridData gd = new GridData(GridData.FILL_HORIZONTAL);
	projectCombo.setLayoutData(gd);
	projectCombo.addModifyListener(evt -> validate());
	for (IJavaProject javaProject : GhidraProjectUtils.getGhidraProjects()) {
		if (GhidraProjectUtils.isGhidraModuleProject(javaProject.getProject())) {
			IProject project = javaProject.getProject();
			projectCombo.add(project.getName());
			if (project.equals(selectedProject)) {
				projectCombo.setText(project.getName());
			}
		}
	}

	validate();
	setControl(container);
}
 
Example 6
Source File: BuilderPropertyPage.java    From statecharts with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public boolean select(Viewer viewer, Object parentElement, Object element) {
	// just show files of the current project
	if (element instanceof IResource) {
		IResource resource = (IResource) element;
		IProject projectOfResource = resource.getProject();
		if (!projectOfResource.equals(actualProject)) {
			return false;
		}
	}
	// just show header files
	if (element instanceof IFile) {
		IFile iFile = (IFile) element;
		if (!getFileExtension().equals(iFile.getFileExtension())) {
			return false;
		}
	}

	return true;
}
 
Example 7
Source File: LibraryFilter.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public boolean select(Viewer viewer, Object parentElement, Object element) {
	if (element instanceof IPackageFragmentRoot) {
		IPackageFragmentRoot root= (IPackageFragmentRoot)element;
		if (root.isArchive()) {
			// don't filter out JARs contained in the project itself
			IResource resource= root.getResource();
			if (resource != null) {
				IProject jarProject= resource.getProject();
				IProject container= root.getJavaProject().getProject();
				return container.equals(jarProject);
			}
			return false;
		}
	} else if (element instanceof ClassPathContainer.RequiredProjectWrapper) {
		return false;
	}
	return true;
}
 
Example 8
Source File: LaunchConfigurationUtilities.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * @param typeIds launch configuration type ids that will be searched for, or
 *          empty to match all
 * @throws CoreException
 */
public static List<ILaunchConfiguration> getLaunchConfigurations(
    IProject project, String... typeIds) throws CoreException {
  Set<String> setOfTypeIds = new HashSet<String>(Arrays.asList(typeIds));
  ILaunchManager manager = DebugPlugin.getDefault().getLaunchManager();
  List<ILaunchConfiguration> launchConfigs = new ArrayList<ILaunchConfiguration>();
  for (ILaunchConfiguration launchConfig : manager.getLaunchConfigurations()) {
    IJavaProject javaProject = getJavaProject(launchConfig);
    boolean typeIdIsOk = setOfTypeIds.isEmpty()
        || setOfTypeIds.contains(launchConfig.getType().getIdentifier());
    if (javaProject != null && project.equals(javaProject.getProject())
        && typeIdIsOk) {
      launchConfigs.add(launchConfig);
    }
  }

  return launchConfigs;
}
 
Example 9
Source File: ErrorMarkerGenerator.java    From CogniCrypt with Eclipse Public License 2.0 6 votes vote down vote up
public boolean clearMarkers(final IProject curProj) {
	final boolean allMarkersDeleted = true;
	try {
		for (final IMarker marker : this.markers) {
			if (curProj == null || (curProj != null && curProj.equals(marker.getResource().getProject()))) {
				marker.delete();
			}
		}
		if (curProj != null) {
			curProj.refreshLocal(IResource.DEPTH_INFINITE, null);
		}
	}
	catch (final CoreException e) {
		Activator.getDefault().logError(e);
	}
	this.markers.clear();
	return allMarkersDeleted;
}
 
Example 10
Source File: ToBeBuiltComputer.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
protected ToBeBuilt doRemoveProject(IProject project, IProgressMonitor monitor) {
	queuedBuildData.reset(project);
	SubMonitor progress = SubMonitor.convert(monitor, Iterables.size(builderState.getAllResourceDescriptions()) / MONITOR_CHUNK_SIZE + 1);
	ToBeBuilt result = new ToBeBuilt();
	Iterable<IResourceDescription> allResourceDescriptions = builderState.getAllResourceDescriptions();
	int i = 0;
	for (IResourceDescription description : allResourceDescriptions) {
		if (monitor.isCanceled()) {
			throw new OperationCanceledException();
		}
		Iterable<Pair<IStorage, IProject>> storages = mapper.getStorages(description.getURI());
		boolean onlyOnThisProject = true;
		Iterator<Pair<IStorage, IProject>> iterator = storages.iterator();
		while (iterator.hasNext() && onlyOnThisProject) {
			Pair<IStorage, IProject> storage2Project = iterator.next();
			final IProject second = storage2Project.getSecond();
			final boolean isSameProject = project.equals(second);
			onlyOnThisProject = isSameProject || second == null || !second.isAccessible();
		}
		if (onlyOnThisProject)
			result.getToBeDeleted().add(description.getURI());
		i++;
		if (i % MONITOR_CHUNK_SIZE == 0)
			progress.worked(1);
	}
	return result;
}
 
Example 11
Source File: ReorgPolicyFactory.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
private IProject getSingleProject() {
	IProject result= null;
	for (int index= 0; index < fPackageFragments.length; index++) {
		if (result == null) {
			result= fPackageFragments[index].getJavaProject().getProject();
		} else if (!result.equals(fPackageFragments[index].getJavaProject().getProject())) {
			return null;
		}
	}
	return result;
}
 
Example 12
Source File: ReorgPolicyFactory.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
private IProject getSingleProject() {
	IProject result= null;
	for (int index= 0; index < fJavaElements.length; index++) {
		if (result == null) {
			result= fJavaElements[index].getJavaProject().getProject();
		} else if (!result.equals(fJavaElements[index].getJavaProject().getProject())) {
			return null;
		}
	}
	return result;
}
 
Example 13
Source File: JavaElementLabelComposer.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Returns <code>true</code> if the given package fragment root is
 * referenced. This means it is a descendant of a different project but is referenced
 * by the root's parent. Returns <code>false</code> if the given root
 * doesn't have an underlying resource.
 *
 * @param root the package fragment root
 * @return returns <code>true</code> if the given package fragment root is referenced
 */
private boolean isReferenced(IPackageFragmentRoot root) {
	IResource resource= root.getResource();
	if (resource != null) {
		IProject jarProject= resource.getProject();
		IProject container= root.getJavaProject().getProject();
		return !container.equals(jarProject);
	}
	return false;
}
 
Example 14
Source File: WorkspaceDiagnosticsHandler.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
private List<IMarker> getProblemMarkers(IProgressMonitor monitor) throws CoreException {
	IProject[] projects = ResourcesPlugin.getWorkspace().getRoot().getProjects();
	List<IMarker> markers = new ArrayList<>();
	for (IProject project : projects) {
		if (monitor != null && monitor.isCanceled()) {
			throw new OperationCanceledException();
		}
		if (JavaLanguageServerPlugin.getProjectsManager().getDefaultProject().equals(project)) {
			continue;
		}
		IMarker[] allMarkers = project.findMarkers(null, true, IResource.DEPTH_INFINITE);
		for (IMarker marker : allMarkers) {
			if (!marker.exists() || CheckMissingNaturesListener.MARKER_TYPE.equals(marker.getType())) {
				continue;
			}
			if (IJavaModelMarker.JAVA_MODEL_PROBLEM_MARKER.equals(marker.getType()) || IJavaModelMarker.TASK_MARKER.equals(marker.getType())) {
				markers.add(marker);
				continue;
			}
			IResource resource = marker.getResource();
			if (project.equals(resource) || projectsManager.isBuildFile(resource)) {
				markers.add(marker);
			}
		}
	}
	return markers;
}
 
Example 15
Source File: N4JSProjectInWorkingSetDropAdapterAssistant.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
private boolean workingSetContains(WorkingSet workingSet, IProject project) {
	for (IAdaptable element : workingSet.getElements()) {
		if (project.equals(element.getAdapter(IProject.class))) {
			return true;
		}
	}
	return false;
}
 
Example 16
Source File: XtendUIResourceDescriptionManager.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
private boolean isProjectDependency(URI deltaURI, URI candidateURI, Map<String, Boolean> checkedProjects) {
	if (deltaURI.isPlatformResource() && candidateURI.isPlatformResource()) {
		// replace escape sequence e.g. %20 by a proper char, e.g. ' ' (blank)
		String deltaProjectName = URI.decode(deltaURI.segment(1));
		// avoid checking the same project again
		Boolean prev = checkedProjects.get(deltaProjectName);
		if (prev == null) {
			IProject deltaProject = workspaceRoot.getProject(deltaProjectName);
			// check if the delta is for a resource from an IJavaProject
			if (deltaProject.isAccessible() && JavaCore.create(deltaProject).exists()) {
				// same here, replace escape sequences by proper chars
				String candidateProjectName = URI.decode(candidateURI.segment(1));
				IProject candidateProject = workspaceRoot.getProject(candidateProjectName);
				if (candidateProject.isAccessible() && JavaCore.create(deltaProject).exists()) {
					if (candidateProject.equals(deltaProject)) {
						return checked(checkedProjects, deltaProjectName, true);
					}
					try {
						if (Arrays.asList(candidateProject.getReferencedProjects()).contains(deltaProject)) {
							return checked(checkedProjects, deltaProjectName, true);
						}
					} catch (CoreException e) {
						return checked(checkedProjects, deltaProjectName, false);
					}
				}
			}
			return checked(checkedProjects, deltaProjectName, false);
		}
		return prev;
	}
	return false;
}
 
Example 17
Source File: AddProjectToSessionWizard.java    From saros with GNU General Public License v2.0 5 votes vote down vote up
private Collection<IEditorPart> getOpenEditorsForSharedProjects(Collection<IProject> projects) {

    List<IEditorPart> openEditors = new ArrayList<IEditorPart>();
    Set<IEditorPart> editors = EditorAPI.getOpenEditors();

    for (IProject project : projects) {
      for (IEditorPart editor : editors) {
        if (editor.getEditorInput() instanceof IFileEditorInput) {
          IFile file = ((IFileEditorInput) editor.getEditorInput()).getFile();
          if (project.equals(file.getProject())) openEditors.add(editor);
        }
      }
    }
    return openEditors;
  }
 
Example 18
Source File: ReorgPolicyFactory.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private IProject getSingleProject() {
	IProject result= null;
	for (int index= 0; index < fPackageFragmentRoots.length; index++) {
		if (result == null)
			result= fPackageFragmentRoots[index].getJavaProject().getProject();
		else if (!result.equals(fPackageFragmentRoots[index].getJavaProject().getProject()))
			return null;
	}
	return result;
}
 
Example 19
Source File: Builder.java    From cppcheclipse with Apache License 2.0 4 votes vote down vote up
/**
 * (re-)initialize checker if necessary (first use or different project)
 * 
 * @param currentProject
 * @throws CoreException
 */
private void initChecker(IProject currentProject) throws CoreException {
	if (!currentProject.equals(project)) {
		runChecker();
		try {
			// separate try for empty path exception (common exception
			// which needs special handling)
			try {
				checker = new Checker(console, CppcheclipsePlugin
						.getProjectPreferenceStore(currentProject),
						CppcheclipsePlugin
								.getWorkspacePreferenceStore(),
						currentProject, new ToolchainSettings(currentProject), problemReporter);
				project = currentProject;
			} catch (EmptyPathException e1) {
				Runnable runnable = new Runnable() {
					public void run() {
						Shell shell = PlatformUI.getWorkbench()
								.getActiveWorkbenchWindow().getShell();
						if (MessageDialog.openQuestion(shell,
								Messages.Builder_PathEmptyTitle,
								Messages.Builder_PathEmptyMessage)) {
							PreferenceDialog dialog = PreferencesUtil
									.createPreferenceDialogOn(
											shell,
											BinaryPathPreferencePage.PAGE_ID,
											null, null);
							dialog.open();
						}
					}
				};
				Display.getDefault().asyncExec(runnable);
				throw e1;
			}
		} catch (Exception e2) {
			// all exceptions in initialization lead to non-recoverable
			// errors, therefore throw them as CoreExceptions
			IStatus status = new Status(IStatus.ERROR,
					CppcheclipsePlugin.getId(),
					"Could not initialize cppcheck for project "+ currentProject.getName(), e2); //$NON-NLS-1$
			throw new CoreException(status);
		}
	}
}
 
Example 20
Source File: ProjectConfigurationWorkingCopy.java    From eclipse-cs with GNU Lesser General Public License v2.1 4 votes vote down vote up
/**
 * Writes a local check configuration.
 *
 * @param checkConfig
 *          the local check configuration
 * @param docRoot
 *          the root element of the project configuration
 */
private void writeLocalConfiguration(ICheckConfiguration checkConfig, Element docRoot) {

  // TODO refactor to avoid code duplication with
  // GlobalCheckConfigurationWorkingSet

  // don't store built-in configurations to persistence or local
  // configurations
  if (checkConfig.getType() instanceof BuiltInConfigurationType || checkConfig.isGlobal()) {
    return;
  }

  // RFE 1420212
  String location = checkConfig.getLocation();
  if (checkConfig.getType() instanceof ProjectConfigurationType) {
    IProject project = mProjectConfig.getProject();
    IWorkspaceRoot root = project.getWorkspace().getRoot();
    IFile configFile = root.getFile(new Path(location));
    IProject configFileProject = configFile.getProject();

    // if the configuration is in *same* project don't store project
    // path part
    if (project.equals(configFileProject)) {
      location = configFile.getProjectRelativePath().toString();
    }
  }

  Element configEl = docRoot.addElement(XMLTags.CHECK_CONFIG_TAG);
  configEl.addAttribute(XMLTags.NAME_TAG, checkConfig.getName());
  configEl.addAttribute(XMLTags.LOCATION_TAG, location);
  configEl.addAttribute(XMLTags.TYPE_TAG, checkConfig.getType().getInternalName());
  if (checkConfig.getDescription() != null) {
    configEl.addAttribute(XMLTags.DESCRIPTION_TAG, checkConfig.getDescription());
  }

  // Write resolvable properties
  for (ResolvableProperty prop : checkConfig.getResolvableProperties()) {

    Element propEl = configEl.addElement(XMLTags.PROPERTY_TAG);
    propEl.addAttribute(XMLTags.NAME_TAG, prop.getPropertyName());
    propEl.addAttribute(XMLTags.VALUE_TAG, prop.getValue());
  }

  // Write additional data
  for (Map.Entry<String, String> entry : checkConfig.getAdditionalData().entrySet()) {

    Element addEl = configEl.addElement(XMLTags.ADDITIONAL_DATA_TAG);
    addEl.addAttribute(XMLTags.NAME_TAG, entry.getKey());
    addEl.addAttribute(XMLTags.VALUE_TAG, entry.getValue());
  }
}