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

The following examples show how to use org.eclipse.core.resources.IResource#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: OverwriteHelper.java    From eclipse.jdt.ls with Eclipse Public License 2.0 6 votes vote down vote up
private boolean willOverwrite(IResource resource) {
	if (resource == null) {
		return false;
	}

	IResource destinationResource= ResourceUtil.getResource(fDestination);
	if (destinationResource.equals(resource.getParent())) {
		return false;
	}

	if (destinationResource instanceof IContainer) {
		IContainer container= (IContainer)destinationResource;
		IResource member=  container.findMember(resource.getName());
		if (member == null || !member.exists()) {
			return false;
		}

		return true;
	}
	return false;
}
 
Example 2
Source File: ToggleBreakpointAdapter.java    From typescript.java with MIT License 6 votes vote down vote up
IBreakpoint lineBreakpointExists(IResource resource, int linenumber) {
	IBreakpoint[] breakpoints = DebugPlugin.getDefault().getBreakpointManager().getBreakpoints(JavaScriptDebugModel.MODEL_ID);
	IJavaScriptLineBreakpoint breakpoint = null;
	for (int i = 0; i < breakpoints.length; i++) {
		if(breakpoints[i] instanceof IJavaScriptLineBreakpoint) {
			breakpoint = (IJavaScriptLineBreakpoint) breakpoints[i];
			try {
				if(IJavaScriptLineBreakpoint.MARKER_ID.equals(breakpoint.getMarker().getType()) &&
					resource.equals(breakpoint.getMarker().getResource()) &&
					linenumber == breakpoint.getLineNumber()) {
					return breakpoint;
				}
			} catch (CoreException e) {}
		}
	}
	return null;
}
 
Example 3
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(IResource destination) throws JavaModelException {
	RefactoringStatus superStatus= super.verifyDestination(destination);
	if (superStatus.hasFatalError())
		return superStatus;

	Object commonParent= getCommonParent();
	if (destination.equals(commonParent))
		return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ReorgPolicyFactory_parent);
	IContainer destinationAsContainer= getDestinationAsContainer();
	if (destinationAsContainer != null && destinationAsContainer.equals(commonParent))
		return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ReorgPolicyFactory_parent);
	IJavaElement destinationContainerAsPackage= getDestinationContainerAsJavaElement();
	if (destinationContainerAsPackage != null && destinationContainerAsPackage.equals(commonParent))
		return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ReorgPolicyFactory_parent);
	
	if (cannotUpdateReferencesForDestination())
		superStatus.addInfo(RefactoringCoreMessages.ReorgPolicyFactory_noJavaUpdates);

	return superStatus;
}
 
Example 4
Source File: ReorgPolicyFactory.java    From eclipse.jdt.ls with Eclipse Public License 2.0 6 votes vote down vote up
@Override
protected RefactoringStatus verifyDestination(IResource destination) throws JavaModelException {
	RefactoringStatus superStatus= super.verifyDestination(destination);
	if (superStatus.hasFatalError()) {
		return superStatus;
	}

	Object commonParent= getCommonParent();
	if (destination.equals(commonParent)) {
		return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ReorgPolicyFactory_parent);
	}
	IContainer destinationAsContainer= getDestinationAsContainer();
	if (destinationAsContainer != null && destinationAsContainer.equals(commonParent)) {
		return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ReorgPolicyFactory_parent);
	}
	IJavaElement destinationContainerAsPackage= getDestinationContainerAsJavaElement();
	if (destinationContainerAsPackage != null && destinationContainerAsPackage.equals(commonParent)) {
		return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ReorgPolicyFactory_parent);
	}

	if (cannotUpdateReferencesForDestination()) {
		superStatus.addInfo(RefactoringCoreMessages.ReorgPolicyFactory_noJavaUpdates);
	}

	return superStatus;
}
 
Example 5
Source File: Repository.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
@Override
public IRepositoryStore<? extends IRepositoryFileStore> getRepositoryStore(final IResource resource) {
    for (final IRepositoryStore<? extends IRepositoryFileStore> store : getAllStores()) {
        if (resource instanceof IFile) {
            final IResource storeResource = store.getResource();
            IResource parent = resource.getParent();
            while (parent != null && !storeResource.equals(parent)) {
                parent = parent.getParent();
            }
            if (parent != null) {
                return store;
            }
        } else {
            if (store.getResource() != null && store.getResource().equals(resource)) {
                return store;
            }
        }
    }
    return null;
}
 
Example 6
Source File: EditorTitleImageUpdater.java    From goclipse with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public void problemsChanged(IResource[] changedResources, boolean isMarkerChange, boolean calledFromDisplayThread) {
	if(!isMarkerChange)
		return;
	
	IEditorInput input = editor.getEditorInput();
	if(input == null)
		return;
	
	IFile file = EditorUtils.getAssociatedFile(input);
	for (IResource changedResource : changedResources) {
		if(changedResource.equals(file)) {
			updateEditorImage(file);
		}
	}
}
 
Example 7
Source File: OverwriteHelper.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private boolean willOverwrite(IResource resource) {
	if (resource == null)
		return false;

	IResource destinationResource= ResourceUtil.getResource(fDestination);
	if (destinationResource.equals(resource.getParent()))
		return false;

	if (destinationResource instanceof IContainer) {
		IContainer container= (IContainer)destinationResource;
		IResource member=  container.findMember(resource.getName());
		if (member == null || !member.exists())
			return false;

		return true;
	}
	return false;
}
 
Example 8
Source File: RefactoringSearchEngine2.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public final void acceptSearchMatch(final SearchMatch match) throws CoreException {
	final SearchMatch accepted= fRequestor.acceptSearchMatch(match);
	if (accepted != null) {
		fCollectedMatches.add(accepted);
		final IResource resource= accepted.getResource();
		if (!resource.equals(fLastResource)) {
			if (fBinary) {
				final IJavaElement element= JavaCore.create(resource);
				if (!(element instanceof ICompilationUnit)) {
					final IProject project= resource.getProject();
					if (!fGrouping)
						fStatus.addEntry(fSeverity, Messages.format(RefactoringCoreMessages.RefactoringSearchEngine_binary_match_ungrouped, BasicElementLabels.getResourceName(project)), null, null, RefactoringStatusEntry.NO_CODE);
					else if (!fBinaryResources.contains(resource))
						fStatus.addEntry(fSeverity, Messages.format(RefactoringCoreMessages.RefactoringSearchEngine_binary_match_grouped, BasicElementLabels.getResourceName(project)), null, null, RefactoringStatusEntry.NO_CODE);
					fBinaryResources.add(resource);
				}
			}
			if (fInaccurate && accepted.getAccuracy() == SearchMatch.A_INACCURATE && !fInaccurateMatches.contains(accepted)) {
				fStatus.addEntry(fSeverity, Messages.format(RefactoringCoreMessages.RefactoringSearchEngine_inaccurate_match, BasicElementLabels.getResourceName(resource)), null, null, RefactoringStatusEntry.NO_CODE);
				fInaccurateMatches.add(accepted);
			}
		}
	}
}
 
Example 9
Source File: RefactoringSearchEngine2.java    From eclipse.jdt.ls with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public final void acceptSearchMatch(final SearchMatch match) throws CoreException {
	final SearchMatch accepted= fRequestor.acceptSearchMatch(match);
	if (accepted != null) {
		final IResource resource= accepted.getResource();
		if (!resource.equals(fLastResource)) {
			final IJavaElement element= JavaCore.create(resource);
			if (element instanceof ICompilationUnit) {
				fCollectedUnits.add((ICompilationUnit) element);
			}
		}
		if (fInaccurate && accepted.getAccuracy() == SearchMatch.A_INACCURATE && !fInaccurateMatches.contains(accepted)) {
			fStatus.addEntry(fSeverity, Messages.format(RefactoringCoreMessages.RefactoringSearchEngine_inaccurate_match, BasicElementLabels.getResourceName(accepted.getResource())), null, null, RefactoringStatusEntry.NO_CODE);
			fInaccurateMatches.add(accepted);
		}
	}
}
 
Example 10
Source File: Checks.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public static RefactoringStatus checkCompileErrorsInAffectedFiles(SearchResultGroup[] references, IResource declaring) throws JavaModelException {
	RefactoringStatus result= new RefactoringStatus();
	for (int i= 0; i < references.length; i++){
		IResource resource= references[i].getResource();
		if (resource.equals(declaring))
			declaring= null;
		checkCompileErrorsInAffectedFile(result, resource);
	}
	if (declaring != null)
		checkCompileErrorsInAffectedFile(result, declaring);
	return result;
}
 
Example 11
Source File: SVNPristineCopyQuickDiffProvider.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
public void subscriberResourceChanged(ISubscriberChangeEvent[] deltas) {
	if(isReferenceInitialized) {
		for (int i = 0; i < deltas.length; i++) {
			ISubscriberChangeEvent delta = deltas[i];
			IResource resource = delta.getResource();
			if(resource.getType() == IResource.FILE && 
			   fLastSyncState != null && resource.equals(fLastSyncState.getLocal())) {
				if(delta.getFlags() == ISubscriberChangeEvent.SYNC_CHANGED) {
					fetchContentsInJob();
				}
			} 
		}
	}
}
 
Example 12
Source File: WorkspaceAction.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
private boolean needsToSave(IFile file, IResource[] selectedResources) {
	if (file != null) {
		IResource parent = file;
		while (parent != null) {
			for (IResource selectedResource : selectedResources) {
				if (selectedResource.equals(parent)) {
					return true;
				}
			}
			parent = parent.getParent();
		}
	}
	return false;
}
 
Example 13
Source File: ReorgPolicyFactory.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
@Override
protected RefactoringStatus verifyDestination(IResource destination) {
	RefactoringStatus superStatus= super.verifyDestination(destination);
	if (superStatus.hasFatalError()) {
		return superStatus;
	}

	Object commonParent= new ParentChecker(getResources(), getJavaElements()).getCommonParent();
	if (destination.equals(commonParent)) {
		return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ReorgPolicyFactory_cannot_move_source_to_parent);
	}

	return superStatus;
}
 
Example 14
Source File: ReorgPolicyFactory.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
protected RefactoringStatus verifyDestination(IResource destination) {
	RefactoringStatus superStatus= super.verifyDestination(destination);
	if (superStatus.hasFatalError())
		return superStatus;

	Object commonParent= new ParentChecker(getResources(), getJavaElements()).getCommonParent();
	if (destination.equals(commonParent))
		return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ReorgPolicyFactory_cannot_move_source_to_parent);

	return superStatus;
}
 
Example 15
Source File: ResourceUtils.java    From xds-ide with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Tests IResources for equality. If either of them is null - returns null.
 * @return
 */
public static boolean equals(IResource resource1, IResource resource2) { 
	if (resource1 == null || resource2 == null) {
		return false;
	}
	
	return resource1.equals(resource2);
}
 
Example 16
Source File: ParentChecker.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private boolean resourcesHaveCommonParent() {
	if (fResources.length == 0)
		return true;
	IResource firstParent= fResources[0].getParent();
	Assert.isNotNull(firstParent);
	for (int i= 1; i < fResources.length; i++) {
		if (! firstParent.equals(fResources[i].getParent()))
			return false;
	}
	return true;
}
 
Example 17
Source File: ReorgPolicyFactory.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private boolean isChildOfOrEqualToAnyFolder(IResource resource) {
	for (int i= 0; i < fPackageFragmentRoots.length; i++) {
		IResource fragmentRootResource= fPackageFragmentRoots[i].getResource();
		if (fragmentRootResource.equals(resource) || ParentChecker.isDescendantOf(resource, fragmentRootResource))
			return true;
	}
	return false;
}
 
Example 18
Source File: TmfTraceElement.java    From tracecompass with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public ITmfTrace getTrace() {
    ITmfProjectModelElement parent = getParent();
    if (parent instanceof TmfExperimentElement) {
        IResource resource = getElementUnderTraceFolder().getResource();
        ITmfTrace experiment = ((TmfExperimentElement) parent).getTrace();
        for (ITmfTrace trace : TmfTraceManager.getTraceSet(experiment)) {
            if (resource.equals(trace.getResource())) {
                return trace;
            }
        }
        return null;
    }
    return super.getTrace();
}
 
Example 19
Source File: PasteAction.java    From translationstudio8 with GNU General Public License v2.0 4 votes vote down vote up
/**
   * The <code>PasteAction</code> implementation of this
   * <code>SelectionListenerAction</code> method enables this action if 
   * a resource compatible with what is on the clipboard is selected.
   * 
   * -Clipboard must have IResource or java.io.File
   * -Projects can always be pasted if they are open
   * -Workspace folder may not be copied into itself
   * -Files and folders may be pasted to a single selected folder in open 
   * 	project or multiple selected files in the same folder 
   */
  protected boolean updateSelection(IStructuredSelection selection) {
      if (!super.updateSelection(selection)) {
	return false;
}

      final IResource[][] clipboardData = new IResource[1][];
      shell.getDisplay().syncExec(new Runnable() {
          public void run() {
              // clipboard must have resources or files
              ResourceTransfer resTransfer = ResourceTransfer.getInstance();
              clipboardData[0] = (IResource[]) clipboard
                      .getContents(resTransfer);
          }
      });
      IResource[] resourceData = clipboardData[0];
      boolean isProjectRes = resourceData != null && resourceData.length > 0
              && resourceData[0].getType() == IResource.PROJECT;

      if (isProjectRes) {
          for (int i = 0; i < resourceData.length; i++) {
              // make sure all resource data are open projects
              // can paste open projects regardless of selection
              if (resourceData[i].getType() != IResource.PROJECT
                      || ((IProject) resourceData[i]).isOpen() == false) {
			return false;
		}
          }
          return true;
      }

      if (getSelectedNonResources().size() > 0) {
	return false;
}

      IResource targetResource = getTarget();
      // targetResource is null if no valid target is selected (e.g., open project) 
      // or selection is empty	
      if (targetResource == null) {
	return false;
}

      // can paste files and folders to a single selection (file, folder, 
      // open project) or multiple file selection with the same parent
      List selectedResources = getSelectedResources();
      if (selectedResources.size() > 1) {
          for (int i = 0; i < selectedResources.size(); i++) {
              IResource resource = (IResource) selectedResources.get(i);
              if (resource.getType() != IResource.FILE) {
			return false;
		}
              if (!targetResource.equals(resource.getParent())) {
			return false;
		}
          }
      }
      if (resourceData != null) {
          // linked resources can only be pasted into projects
          if (isLinked(resourceData)
              && targetResource.getType() != IResource.PROJECT
              && targetResource.getType() != IResource.FOLDER) {
		return false;
	}

          if (targetResource.getType() == IResource.FOLDER) {
              // don't try to copy folder to self
              for (int i = 0; i < resourceData.length; i++) {
                  if (targetResource.equals(resourceData[i])) {
				return false;
			}
              }
          }
          return true;
      }
      TransferData[] transfers = clipboard.getAvailableTypes();
      FileTransfer fileTransfer = FileTransfer.getInstance();
      for (int i = 0; i < transfers.length; i++) {
          if (fileTransfer.isSupportedType(transfers[i])) {
		return true;
	}
      }
      return false;
  }
 
Example 20
Source File: ScriptLineBreakpointAdapter.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
public void toggleLineBreakpoints( IWorkbenchPart part, ISelection selection )
		throws CoreException
{
	DecoratedScriptEditor textEditor = getEditor( part );
	if ( textEditor != null )
	{
		ITextSelection textSelection = (ITextSelection) selection;
		IReportScriptLocation location = (IReportScriptLocation) textEditor.getAdapter( IReportScriptLocation.class );
		if ( location == null )
		{
			return;
		}

		int lineNumber = textSelection.getStartLine( );
		if ( location.getLineNumber( ) > 0 )
		{
			lineNumber = location.getLineNumber( );
		}

		IResource resource = (IResource) textEditor.getEditorInput( )
				.getAdapter( IResource.class );
		if ( resource == null )
		{
			resource = ScriptDebugUtil.getDefaultResource( );
		}

		IBreakpoint[] breakpoints = DebugPlugin.getDefault( )
				.getBreakpointManager( )
				.getBreakpoints( IScriptConstants.SCRIPT_DEBUG_MODEL );
		for ( int i = 0; i < breakpoints.length; i++ )
		{
			IBreakpoint breakpoint = breakpoints[i];
			if ( resource.equals( breakpoint.getMarker( ).getResource( ) ) )
			{
				if ( ( (ScriptLineBreakpoint) breakpoint ).getLineNumber( ) == ( lineNumber + 1 )
						&& ( (ScriptLineBreakpoint) breakpoint ).getFileName( )
								.equals( location.getReportFileName( ) )
						&& ( (ScriptLineBreakpoint) breakpoint ).getSubName( )
								.equals( location.getID( ) ) )
				{
					breakpoint.delete( );
					return;
				}
			}
		}
		// create line breakpoint (doc line numbers start at 0)
		ScriptLineBreakpoint lineBreakpoint = new ScriptLineBreakpoint( resource,
				location.getReportFileName( ),
				location.getID( ),
				lineNumber + 1 , location.getDisplayName( ));
		//lineBreakpoint.setDisplayName( location.getDisplayName( ) );
		DebugPlugin.getDefault( )
				.getBreakpointManager( )
				.addBreakpoint( lineBreakpoint );
	}

}