Java Code Examples for org.eclipse.core.resources.IFile#equals()
The following examples show how to use
org.eclipse.core.resources.IFile#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: SwaggerFileFinder.java From KaiZen-OpenAPI-Editor with Eclipse Public License 1.0 | 6 votes |
@Override public boolean visit(IResourceProxy proxy) throws CoreException { if (proxy.getType() == IResource.FILE && (proxy.getName().endsWith("yaml") || proxy.getName().endsWith("yml"))) { if (!proxy.isDerived()) { IFile file = (IFile) proxy.requestResource(); if (!file.equals(currentFile)) { String currFileType = file.getContentDescription().getContentType().getId(); if (fileContentType == null || fileContentType.equals(currFileType)) { files.add(file); } } } } else if (proxy.getType() == IResource.FOLDER && (proxy.isDerived() || proxy.getName().equalsIgnoreCase("gentargets"))) { return false; } return true; }
Example 2
Source File: PyRefactoringRequest.java From Pydev with Eclipse Public License 1.0 | 6 votes |
@Override public IFile getIFileResource() { IFile f = null; for (RefactoringRequest r : requests) { if (f == null) { f = r.getIFileResource(); } else { IFile f2 = r.getIFileResource(); if (!f.equals(f2)) { // This is inconsistent return null; } } } return f; }
Example 3
Source File: JsonReferenceProposalProvider.java From KaiZen-OpenAPI-Editor with Eclipse Public License 1.0 | 6 votes |
/** * Returns collection of JSON reference proposals. * * If the scope is local, it will only return JSON references from within the current document. * * If the scope is project, it will return all JSON references from within the current document and from all * documents inside the same project. * * If the scope is workspace, it will return all JSON references from within the current document and from all * documents inside the same workspace. * * @param pointer * @param document * @param scope * @return proposals */ public Collection<ProposalDescriptor> getProposals(JsonPointer pointer, JsonDocument document, Scope scope) { final ContextType type = contextTypes.get(document.getModel(), pointer); final IFile currentFile = getActiveFile(); final IPath basePath = currentFile.getParent().getFullPath(); final List<ProposalDescriptor> proposals = new ArrayList<>(); if (scope == Scope.LOCAL) { proposals.addAll(type.collectProposals(document, null)); } else if (!type.isLocalOnly()) { final SwaggerFileFinder fileFinder = new SwaggerFileFinder(fileContentType); for (IFile file : fileFinder.collectFiles(scope, currentFile)) { IPath relative = file.equals(currentFile) ? null : file.getFullPath().makeRelativeTo(basePath); if (file.equals(currentFile)) { proposals.addAll(type.collectProposals(document, relative)); } else { proposals.addAll(type.collectProposals(manager.getDocument(file.getLocationURI()), relative)); } } } return proposals; }
Example 4
Source File: TLCModelFactory.java From tlaplus with MIT License | 6 votes |
public static Model getBy(final IFile aFile) { Assert.isNotNull(aFile); final ILaunchManager launchManager = DebugPlugin.getDefault().getLaunchManager(); final ILaunchConfigurationType launchConfigurationType = launchManager .getLaunchConfigurationType(TLCModelLaunchDelegate.LAUNCH_CONFIGURATION_TYPE); try { final ILaunchConfiguration[] launchConfigurations = launchManager.getLaunchConfigurations(launchConfigurationType); for (int i = 0; i < launchConfigurations.length; i++) { final ILaunchConfiguration launchConfiguration = launchConfigurations[i]; if (aFile.equals(launchConfiguration.getFile())) { return launchConfiguration.getAdapter(Model.class); } } } catch (CoreException shouldNeverHappen) { shouldNeverHappen.printStackTrace(); } return null; }
Example 5
Source File: ModulaSearchUtils.java From xds-ide with Eclipse Public License 1.0 | 6 votes |
private static void evaluateTextEditor(Map<IFile, IDocument> result, IEditorPart ep, IFile filter) { IEditorInput input = ep.getEditorInput(); if (input instanceof IFileEditorInput) { IFile file = ((IFileEditorInput) input).getFile(); if (filter == null || filter.equals(file)) { if (!result.containsKey(file)) { // take the first editor found ITextFileBufferManager bufferManager = FileBuffers.getTextFileBufferManager(); ITextFileBuffer textFileBuffer = bufferManager .getTextFileBuffer(file.getFullPath(), LocationKind.IFILE); if (textFileBuffer != null) { // file buffer has precedence result.put(file, textFileBuffer.getDocument()); } else { // use document provider IDocument document = ((ITextEditor) ep).getDocumentProvider().getDocument(input); if (document != null) { result.put(file, document); } } } } } }
Example 6
Source File: EclipseBuildSupport.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 6 votes |
@Override public boolean fileChanged(IResource resource, CHANGE_TYPE changeType, IProgressMonitor monitor) throws CoreException { if (resource == null || !applies(resource.getProject())) { return false; } refresh(resource, changeType, monitor); IProject project = resource.getProject(); if (ProjectUtils.isJavaProject(project)) { IJavaProject javaProject = JavaCore.create(project); IClasspathEntry[] classpath = javaProject.getRawClasspath(); for (IClasspathEntry entry : classpath) { if (entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) { IPath path = entry.getPath(); IFile r = ResourcesPlugin.getWorkspace().getRoot().getFile(path); if (r != null && r.equals(resource)) { IClasspathEntry[] rawClasspath = javaProject.getRawClasspath(); javaProject.setRawClasspath(new IClasspathEntry[0], monitor); javaProject.setRawClasspath(rawClasspath, monitor); break; } } } } return false; }
Example 7
Source File: AppEngineProjectElement.java From google-cloud-eclipse with Apache License 2.0 | 6 votes |
/** * Update a possibly-existing configuration file element. Return the replacement element or {@code * null} if the configuration file no longer exists. */ private AppEngineResourceElement updateElement( String baseName, AppEngineResourceElement element) { Preconditions.checkArgument(elementFactories.containsKey(baseName)); // Check that each model element, if present, corresponds to the current configuration file. // Rebuild the element representation using the provided element creator, or remove // it, as required. IFile configurationFile = AppEngineConfigurationUtil.findConfigurationFile(project, new Path(baseName)); if (configurationFile == null || !configurationFile.exists()) { // remove the element e.g., file has disappeared return null; } else if (element == null || !configurationFile.equals(element.getFile())) { // create or recreate the element return elementFactories.get(baseName).apply(configurationFile); } else { return element.reload(); } }
Example 8
Source File: ModulaSearchResult.java From xds-ide with Eclipse Public License 1.0 | 5 votes |
protected boolean isMatchContained(IEditorPart editor, IFile f) { IFile resource = (IFile) editor.getEditorInput().getAdapter(IFile.class); if (resource != null) { return resource.equals(f); } return false; }
Example 9
Source File: BuilderUtilities.java From gwt-eclipse-plugin with Eclipse Public License 1.0 | 5 votes |
private static IEditorPart getOpenEditor(ICompilationUnit cu) { // Need to get the workbench window from the UI thread final IWorkbenchWindow[][] windows = new IWorkbenchWindow[1][]; Display.getDefault().syncExec(new Runnable() { public void run() { windows[0] = PlatformUI.getWorkbench().getWorkbenchWindows(); } }); for (IWorkbenchWindow window : windows[0]) { for (IWorkbenchPage page : window.getPages()) { for (IEditorReference editorRef : page.getEditorReferences()) { try { IEditorInput editorInput = editorRef.getEditorInput(); // See if this editor has the compilation unit resource open if (editorInput instanceof FileEditorInput) { IFile file = ((FileEditorInput) editorInput).getFile(); if (file.equals(cu.getResource())) { return editorRef.getEditor(false); } } } catch (PartInitException e) { CorePluginLog.logError(e); } } } } return null; }
Example 10
Source File: DerivedResourceMarkerCopier.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
private void copyProblemMarker(IFile javaFile, IEclipseTrace traceToSource, Set<IMarker> problemsInJava, IFile srcFile) throws CoreException { String sourceMarkerType = null; for (IMarker marker : problemsInJava) { String message = (String) marker.getAttribute(IMarker.MESSAGE); if (message == null) { continue; } Integer charStart = marker.getAttribute(IMarker.CHAR_START, 0); Integer charEnd = marker.getAttribute(IMarker.CHAR_END, 0); int severity = MarkerUtilities.getSeverity(marker); ILocationInEclipseResource associatedLocation = traceToSource.getBestAssociatedLocation(new TextRegion(charStart, charEnd - charStart)); if (associatedLocation != null) { if (sourceMarkerType == null) { sourceMarkerType = determinateMarkerTypeByURI(associatedLocation.getSrcRelativeResourceURI()); } if (!srcFile.equals(findIFile(associatedLocation, srcFile.getWorkspace()))) { LOG.error("File in associated location is not the same as main source file."); } IMarker xtendMarker = srcFile.createMarker(sourceMarkerType); xtendMarker.setAttribute(IMarker.MESSAGE, "Java problem: " + message); xtendMarker.setAttribute(IMarker.SEVERITY, severity); ITextRegionWithLineInformation region = associatedLocation.getTextRegion(); xtendMarker.setAttribute(IMarker.LINE_NUMBER, region.getLineNumber()); xtendMarker.setAttribute(IMarker.CHAR_START, region.getOffset()); xtendMarker.setAttribute(IMarker.CHAR_END, region.getOffset() + region.getLength()); xtendMarker.setAttribute(COPIED_FROM_FILE, javaFile.getFullPath().toString()); } } }
Example 11
Source File: PropertiesFileEditor.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
private boolean evaluateCU(ICompilationUnit compilationUnit, IFile file) throws JavaModelException { IStorage bundle= FindBrokenNLSKeysAction.getResourceBundle(compilationUnit); if (!(bundle instanceof IFile)) return false; return file.equals(bundle); }
Example 12
Source File: OccurrencesSearchResult.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
public Match[] computeContainedMatches(AbstractTextSearchResult result, IFile file) { Object[] elements= getElements(); if (elements.length == 0) return NO_MATCHES; //all matches from same file: JavaElementLine jel= (JavaElementLine) elements[0]; if (file.equals(jel.getJavaElement().getResource())) return collectMatches(elements); return NO_MATCHES; }
Example 13
Source File: ExtLibToolingUtil.java From XPagesExtensionLibrary with Apache License 2.0 | 5 votes |
public static boolean isPropertiesOpenInEditor(DesignerProject dproject) { boolean openInEditor = false; IFile ifile = dproject.getProject().getFile("/WebContent/WEB-INF/xsp.properties"); //$NON-NLS-1$ // check if its already open IEditorReference[] er = ExtLibPanelUtil.getActiveWorkbenchPage().getEditorReferences(); for (IEditorReference ref : er) { try { IEditorInput ei = ref.getEditorInput(); IFile f = (IFile)ei.getAdapter(IFile.class); if (null != f) { if (f.equals(ifile)) { openInEditor = true; break; } else { IPath proppath = ifile.getFullPath(); IPath edpath = f.getFullPath(); if (edpath.segmentCount() >= 3 && proppath.segmentCount() > 1) { String[] segs = edpath.segments(); String nsfname = proppath.segment(0); if (StringUtil.equalsIgnoreCase(nsfname, segs[0]) && StringUtil.equalsIgnoreCase("AppProperties", segs[1])) { //$NON-NLS-1$ if (StringUtil.equalsIgnoreCase("database.properties", segs[2])) { //$NON-NLS-1$ openInEditor = true; break; } } } } } } catch(PartInitException pe) { ExtLibToolingLogger.EXT_LIB_TOOLING_LOGGER.warn(pe, "exception trying to find open property editors"); // $NLW-ExtLibToolingUtil.exceptiontryingtofind-1$ } } return openInEditor; }
Example 14
Source File: ResourceCloseManagement.java From birt with Eclipse Public License 1.0 | 5 votes |
private static IEditorReference getEditorRefInOpenFileList( IFile resourceToCheck ) { IEditorReference[] editors = getOpenedFileRefs( ); for ( int i = 0; i < editors.length; i++ ) { IFile file = getEditorFile( editors[i] ); if ( ( file != null ) && file.equals( resourceToCheck ) ) { return editors[i]; } } return null; }
Example 15
Source File: PythonLinkHelper.java From Pydev with Eclipse Public License 1.0 | 5 votes |
@Override public void activateEditor(IWorkbenchPage aPage, IStructuredSelection aSelection) { if (aSelection == null || aSelection.isEmpty()) { return; } Object firstElement = aSelection.getFirstElement(); //if it is a python element, let's first get the actual object for finding the editor if (firstElement instanceof IWrappedResource) { IWrappedResource resource = (IWrappedResource) firstElement; firstElement = resource.getActualObject(); } //and now, if it is really a file... if (firstElement instanceof IFile) { //ok, let's check if the active editor is already the selection, because although the findEditor(editorInput) method //may return an editor for the correct file, we may have multiple editors for the same file, and if the current //editor is already correct, we don't want to change it //@see bug: https://sourceforge.net/tracker/?func=detail&atid=577329&aid=2037682&group_id=85796 IEditorPart activeEditor = aPage.getActiveEditor(); if (activeEditor != null) { IEditorInput editorInput = activeEditor.getEditorInput(); IFile currFile = (IFile) editorInput.getAdapter(IFile.class); if (currFile != null && currFile.equals(firstElement)) { return; //the current editor is already the active editor. } } //if we got here, the active editor is not a match, so, let's find one and show it. IEditorPart editor = null; IEditorInput fileInput = new FileEditorInput((IFile) firstElement); if ((editor = aPage.findEditor(fileInput)) != null) { aPage.bringToTop(editor); } } }
Example 16
Source File: TexDocumentModel.java From texlipse with Eclipse Public License 1.0 | 4 votes |
/** * Updates the references and project data based on the data in the * parsed document. * * @param monitor Progress monitor */ private void updateReferences(IProgressMonitor monitor) { this.updateLabels(parser.getLabels()); this.updateCommands(parser.getCommands()); IProject project = getCurrentProject(); if (project == null) return; IFile cFile = ((FileEditorInput) editor.getEditorInput()).getFile(); boolean isMainFile = cFile.equals(TexlipseProperties.getProjectSourceFile(project)); pollCancel(monitor); // After here we just store those fun properties... if (parser.isLocalBib()) { TexlipseProperties.setSessionProperty(project, TexlipseProperties.SESSION_BIBLATEXLOCALBIB_PROPERTY, new Boolean(true)); } else { TexlipseProperties.setSessionProperty(project, TexlipseProperties.SESSION_BIBLATEXLOCALBIB_PROPERTY, null); } //Only update Preamble, Bibstyle if main Document if (isMainFile) { boolean biblatexMode = parser.isBiblatexMode(); updateBiblatex(project, biblatexMode, parser.getBiblatexBackend(), false); String[] bibs = parser.getBibs(); this.updateBibs(bibs, biblatexMode, cFile); pollCancel(monitor); String preamble = parser.getPreamble(); if (preamble != null) { TexlipseProperties.setSessionProperty(project, TexlipseProperties.PREAMBLE_PROPERTY, preamble); } if (!biblatexMode) { String bibstyle = parser.getBibstyle(); if (bibstyle != null) { String oldStyle = (String) TexlipseProperties.getSessionProperty(project, TexlipseProperties.BIBSTYLE_PROPERTY); if (oldStyle == null || !bibstyle.equals(oldStyle)) { TexlipseProperties.setSessionProperty(project, TexlipseProperties.BIBSTYLE_PROPERTY, bibstyle); // schedule running bibtex on the next build TexlipseProperties.setSessionProperty(project, TexlipseProperties.BIBFILES_CHANGED, new Boolean(true)); } } } } }
Example 17
Source File: AppEngineProjectElement.java From google-cloud-eclipse with Apache License 2.0 | 4 votes |
/** * Update to the set of resource modifications in this project (added, removed, or changed). * Return {@code true} if there were changes. * * @throws AppEngineException when some error occurred parsing or interpreting some relevant file */ public boolean resourcesChanged(Collection<IFile> changedFiles) throws AppEngineException { Preconditions.checkNotNull(changedFiles); Preconditions.checkNotNull(descriptorFile); boolean layoutChanged = hasLayoutChanged(changedFiles); // files may be newly exposed or removed boolean hasNewDescriptor = (layoutChanged || hasAppEngineDescriptor(changedFiles)) && !descriptorFile.equals(findAppEngineDescriptor(project)); if (changedFiles.contains(descriptorFile) || hasNewDescriptor) { // reload everything: e.g., may no longer be "default" reload(); return true; } else if (!descriptorFile.exists()) { // if our descriptor was removed then we're not really an App Engine project throw new AppEngineException(descriptorFile.getName() + " no longer exists"); } // So descriptor is unchanged. if (!isDefaultService()) { // Only the default service carries ancilliary configuration files Preconditions.checkState(configurations.isEmpty()); return false; } else if (layoutChanged) { // Reload as new configuration files may have become available or previous // configuration files may have disappeared return reloadConfigurationFiles(); } // Since this is called on any file change to the project (e.g., to a java or text file), // we walk the files and see if they may correspond to an App Engine configuration file to // avoid unnecessary work. Since the layout hasn't changed then (1) reload any changed // configuration file models, (2) remove any deleted models, and (3) add models for new files. boolean changed = false; for (IFile file : changedFiles) { String baseName = file.getName(); AppEngineResourceElement previous = configurations.get(baseName); if (previous != null) { // Since first file resolved wins check if this file was (and thus remains) the winner if (file.equals(previous.getFile())) { // Case 1 and 2: reload() returns null if underlying file no longer exists configurations.compute(baseName, (ignored, element) -> element.reload()); changed = true; } } else if (elementFactories.containsKey(baseName)) { // Case 3: file has a recognized configuration file name AppEngineResourceElement current = configurations.compute(baseName, this::updateElement); // updateElement() returns null if file not resolved changed |= current != null; } } return changed; }
Example 18
Source File: FileMetaDataProvider.java From gama with GNU General Public License v3.0 | 4 votes |
public static boolean isSupport(final IFile shapefile, final IFile other) { final IResource r = shapeFileSupportedBy(other); return shapefile.equals(r); }