org.eclipse.core.resources.IFile Java Examples
The following examples show how to use
org.eclipse.core.resources.IFile.
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: JavaRefactoringIntegrationTest.java From xtext-xtend with Eclipse Public License 2.0 | 6 votes |
@Test public void testRenameXtendDispatchMethod_2() throws Exception { String superModel = "class Super { def dispatch foo(Integer x) {} def dispatch foo(Object x) {} }"; IFile superClass = createFile("Super.xtend", superModel); String subModel = "class Sub extends Super { def dispatch foo(String x) {} }"; IFile subClass = createFile("Sub.xtend", subModel); String javaCallerModel = "public class JavaCaller { void bar(Sub x) { x.foo(new Object()); x._foo(\"\"); } }"; IFile javaCaller = createFile("JavaCaller.java", javaCallerModel); String xtendCallerModel = "class XtendCaller { def bar(Super x) { x.foo(1) } }"; IFile xtendCaller = createFile("XtendCaller.xtend", xtendCallerModel); final XtextEditor editor = openEditorSafely(subClass); // on Galileo, _foo is a discouraged method name renameXtendElement(editor, subModel.indexOf("foo"), "baz", RefactoringStatus.WARNING); assertDocumentContains(editor, subModel.replace("foo", "baz")); fileAsserts.assertFileContains(xtendCaller, xtendCallerModel.replace("foo", "baz")); fileAsserts.assertFileContains(javaCaller, javaCallerModel.replace("foo", "baz")); fileAsserts.assertFileContains(superClass, superModel.replace("foo", "baz")); }
Example #2
Source File: ItemManagerTester.java From ice with Eclipse Public License 1.0 | 6 votes |
/** * This operation checks the ability of the ItemManager to load a single * Item. */ @Test public void checkSingleItemLoad() { // Reset the fake provider fakePersistenceProvider.reset(); // Create a fake file and direct the manager to load it IFile fakeFile = new FakeIFile(); Form form = itemManager.loadItem(fakeFile); // The form should not be null since the FakePersistenceProvider creates // an Item. assertNotNull(form); // Make sure the name matches the one in the FakePersistenceProvider and // that the load operation was called. assertEquals("The Doctor", form.getName()); assertTrue(fakePersistenceProvider.allLoaded()); // Reset the fake provider one more time, just to be polite. fakePersistenceProvider.reset(); return; }
Example #3
Source File: LegacyGWTLaunchShortcutStrategy.java From gwt-eclipse-plugin with Eclipse Public License 1.0 | 6 votes |
private void inferModuleAndHostPage(IResource selection) { if (selection.getType() == IResource.FILE) { if ("html".equalsIgnoreCase(selection.getFileExtension())) { for (IFile module : allHostPagesByModule.keySet()) { if (allHostPagesByModule.get(module).contains(selection)) { // Try to infer the module from the host page inferFromHostPage(selection); } } } else if (ModuleUtils.isModuleXml(selection)) { if (allHostPagesByModule.containsKey(selection)) { // Try to infer the host page from the selected module inferFromModule(selection); } } } else if (selection.getType() == IResource.PROJECT) { // Try to infer the module and host page from the project inferFromProject(selection.getProject()); } }
Example #4
Source File: StandardFacetInstallationTest.java From google-cloud-eclipse with Apache License 2.0 | 6 votes |
@Test public void testStandardFacetInstallation() throws IOException, CoreException { projects = ProjectUtils.importProjects(getClass(), "projects/test-dynamic-web-project.zip", true /* checkBuildErrors */, null); assertEquals(1, projects.size()); IProject project = projects.values().iterator().next(); IFacetedProject facetedProject = ProjectFacetsManager.create(project); // verify that the appengine-web.xml is installed in the dynamic web root folder AppEngineStandardFacet.installAppEngineFacet(facetedProject, true, null); IFile correctAppEngineWebXml = project.getFile("war/WEB-INF/appengine-web.xml"); IFile wrongAppEngineWebXml = project.getFile("src/main/webapp/WEB-INF/appengine-web.xml"); assertTrue(correctAppEngineWebXml.exists()); assertFalse(wrongAppEngineWebXml.exists()); ProjectUtils.waitForProjects(project); // App Engine runtime is added via a Job, so wait. IRuntime primaryRuntime = facetedProject.getPrimaryRuntime(); assertTrue(AppEngineStandardFacet.isAppEngineStandardRuntime(primaryRuntime)); }
Example #5
Source File: TmfTraceManager.java From tracecompass with Eclipse Public License 2.0 | 6 votes |
/** * Signal handler for the traceOpened signal. * * @param signal * The incoming signal */ @TmfSignalHandler public synchronized void traceOpened(final TmfTraceOpenedSignal signal) { final ITmfTrace trace = signal.getTrace(); final IFile editorFile = signal.getEditorFile(); final TmfTimeRange windowRange = trace.getInitialTimeRange(); final ITmfTimestamp startTs = windowRange.getStartTime(); final TmfTimeRange selectionRange = new TmfTimeRange(startTs, startTs); final TmfTraceContext startCtx = trace.createTraceContext(selectionRange, windowRange, editorFile, null); fTraces.put(trace, startCtx); IResource resource = trace.getResource(); if (resource != null) { fInstanceCounts.add(resource); updateTraceContext(trace, builder -> builder.setInstanceNumber(fInstanceCounts.count(resource))); } /* We also want to set the newly-opened trace as the active trace */ fCurrentTrace = trace; }
Example #6
Source File: GetterSetterCorrectionSubProcessor.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
public TextFileChange getChange(IFile file) throws CoreException { final SelfEncapsulateFieldRefactoring refactoring= new SelfEncapsulateFieldRefactoring(fField); refactoring.setVisibility(Flags.AccPublic); refactoring.setConsiderVisibility(false);//private field references are just searched in local file refactoring.checkInitialConditions(new NullProgressMonitor()); refactoring.checkFinalConditions(new NullProgressMonitor()); Change createdChange= refactoring.createChange(new NullProgressMonitor()); if (createdChange instanceof CompositeChange) { Change[] children= ((CompositeChange) createdChange).getChildren(); for (int i= 0; i < children.length; i++) { Change curr= children[i]; if (curr instanceof TextFileChange && ((TextFileChange) curr).getFile().equals(file)) { return (TextFileChange) curr; } } } return null; }
Example #7
Source File: JavaClasspathTest.java From xtext-xtend with Eclipse Public License 2.0 | 6 votes |
@Test public void testJavaSourceLevelMismatch() throws Exception { IProject project = testHelper.getProject(); // create a fake java.util.List without type param IFolder folder = project.getFolder(new Path("src/java/util")); IResourcesSetupUtil.createFolder(folder.getFullPath()); IFile list = folder.getFile("List.xtend"); list.create(new StringInputStream("package java.util; class List {}"), true, null); IFile file = project.getFile("src/Foo.xtend"); if (!file.exists()) file.create(new StringInputStream(TEST_CLAZZ), true, null); IResourcesSetupUtil.cleanBuild(); IResourcesSetupUtil.waitForBuild(); markerAssert.assertErrorMarker(file, IssueCodes.JDK_NOT_ON_CLASSPATH); list.delete(true, null); IResourcesSetupUtil.cleanBuild(); IResourcesSetupUtil.waitForBuild(); markerAssert.assertNoErrorMarker(file); }
Example #8
Source File: MemoryEditor.java From neoscada with Eclipse Public License 1.0 | 6 votes |
/** * This also changes the editor's input. * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ @Override public void doSaveAs () { SaveAsDialog saveAsDialog = new SaveAsDialog ( getSite ().getShell () ); saveAsDialog.open (); IPath path = saveAsDialog.getResult (); if ( path != null ) { IFile file = ResourcesPlugin.getWorkspace ().getRoot ().getFile ( path ); if ( file != null ) { doSaveAs ( URI.createPlatformResourceURI ( file.getFullPath ().toString (), true ), new FileEditorInput ( file ) ); } } }
Example #9
Source File: ProblemHoverTest.java From xtext-eclipse with Eclipse Public License 2.0 | 6 votes |
@Override public void setUp() throws Exception { super.setUp(); modelAsText = "stuff mystuff\nstuff yourstuff refs _mystuff stuff hisstuff refs _yourstuff// Comment"; IFile file = IResourcesSetupUtil.createFile("test/test.testlanguage", modelAsText); editor = openEditor(file); document = editor.getDocument(); hover = TestsActivator.getInstance().getInjector(getEditorId()).getInstance(ProblemAnnotationHover.class); hover.setSourceViewer(editor.getInternalSourceViewer()); List<Issue> issues = document.readOnly(new IUnitOfWork<List<Issue>, XtextResource>() { @Override public List<Issue> exec(XtextResource state) throws Exception { return state.getResourceServiceProvider().getResourceValidator().validate(state, CheckMode.ALL, null); } }); MarkerCreator markerCreator = TestsActivator.getInstance().getInjector(getEditorId()).getInstance(MarkerCreator.class); for (Issue issue : issues) { markerCreator.createMarker(issue, file, MarkerTypes.forCheckType(issue.getType())); } }
Example #10
Source File: ExternalPackagesPluginTest.java From n4js with Eclipse Public License 1.0 | 6 votes |
/** * Check if index is populated only with workspace project content when the external location with single project is * registered and workspace contains project with the same name. External library is registered before project is * created in the workspace. */ @Test public void testWorkspaceProjectHidingExternalProject_after() throws Exception { IProject createJSProject = ProjectTestsUtils.createJSProject(PROBAND_LIBFOO); IFolder src = configureProjectWithXtext(createJSProject); IFile packageJson = createJSProject.getProject().getFile(IN4JSProject.PACKAGE_JSON); assertMarkers("package.json of first project should have no errors", packageJson, 0); createTestFile(src, "Foo", "console.log('hi')"); createTestFile(src, "AAAA", "console.log('hi')"); createTestFile(src, "BBB", "console.log('hi')"); waitForAutoBuild(); copyProjectsToLocation(projectsRoot, externalLibrariesRoot, PROBAND_LIBFOO); ProjectTestsUtils.importDependencies(new EclipseProjectName(createJSProject.getName()).toN4JSProjectName(), externalLibrariesRoot.toUri(), libraryManager); Collection<String> expectedWorkspace = collectIndexableFiles(ResourcesPlugin.getWorkspace()); // remove those that are shadowed expectedWorkspace.remove("/LibFoo/node_modules/LibFoo/src/Foo.n4js"); expectedWorkspace.remove("/LibFoo/node_modules/LibFoo/package.json"); assertResourceDescriptions(expectedWorkspace, BuilderUtil.getAllResourceDescriptions()); }
Example #11
Source File: CopyResourceChange.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
/** * returns false if source and destination are the same (in workspace or on disk) * in such case, no action should be performed * @param pm the progress monitor * @param newName the new name * @return returns <code>true</code> if the resource already exists * @throws CoreException thrown when teh resource cannpt be accessed */ private boolean deleteIfAlreadyExists(IProgressMonitor pm, String newName) throws CoreException { pm.beginTask("", 1); //$NON-NLS-1$ IResource current= getDestination().findMember(newName); if (current == null) return true; if (! current.exists()) return true; IResource resource= getResource(); Assert.isNotNull(resource); if (ReorgUtils.areEqualInWorkspaceOrOnDisk(resource, current)) return false; if (current instanceof IFile) ((IFile)current).delete(false, true, new SubProgressMonitor(pm, 1)); else if (current instanceof IFolder) ((IFolder)current).delete(false, true, new SubProgressMonitor(pm, 1)); else Assert.isTrue(false); return true; }
Example #12
Source File: RenamePackageProcessor.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 6 votes |
@Override protected IFile[] getChangedFiles() throws CoreException { Set<IFile> combined= new HashSet<>(); combined.addAll(Arrays.asList(ResourceUtil.getFiles(fChangeManager.getAllCompilationUnits()))); if (fRenameSubpackages) { IPackageFragment[] allPackages= JavaElementUtil.getPackageAndSubpackages(fPackage); for (int i= 0; i < allPackages.length; i++) { combined.addAll(Arrays.asList(ResourceUtil.getFiles(allPackages[i].getCompilationUnits()))); } } else { combined.addAll(Arrays.asList(ResourceUtil.getFiles(fPackage.getCompilationUnits()))); } if (fQualifiedNameSearchResult != null) { combined.addAll(Arrays.asList(fQualifiedNameSearchResult.getAllFiles())); } return combined.toArray(new IFile[combined.size()]); }
Example #13
Source File: TestLanguageServers.java From wildwebdeveloper with Eclipse Public License 2.0 | 6 votes |
@Test public void testTSXFile() throws Exception { final IFile file = project.getFile("blah.tsx"); file.create(new ByteArrayInputStream("ERROR".getBytes()), true, null); ITextEditor editor = (ITextEditor) IDE.openEditor(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(), file); editor.getDocumentProvider().getDocument(editor.getEditorInput()).set("FAIL"); assertTrue("Diagnostic not published", new DisplayHelper() { @Override protected boolean condition() { try { return file.findMarkers("org.eclipse.lsp4e.diagnostic", true, IResource.DEPTH_ZERO).length != 0; } catch (CoreException e) { return false; } } }.waitForCondition(PlatformUI.getWorkbench().getDisplay(), 5000)); }
Example #14
Source File: SyncGraphvizExportHandler.java From gef with Eclipse Public License 2.0 | 6 votes |
private void openFile(IFile file) { IEditorRegistry registry = PlatformUI.getWorkbench() .getEditorRegistry(); if (registry.isSystemExternalEditorAvailable(file.getName())) { /** * in case of opening the exported file from an other thread e.g. in * case of listening to an IResourceChangeEvent */ Display.getDefault().asyncExec(new Runnable() { @Override public void run() { IWorkbenchPage page = PlatformUI.getWorkbench() .getActiveWorkbenchWindow().getActivePage(); try { page.openEditor(new FileEditorInput(file), IEditorRegistry.SYSTEM_EXTERNAL_EDITOR_ID); } catch (PartInitException e) { DotActivatorEx.logError(e); } } }); } }
Example #15
Source File: Bug462047Test.java From xtext-eclipse with Eclipse Public License 2.0 | 6 votes |
@Test public void testNoErrors() throws Exception { IResourcesSetupUtil.createFile("bug462047/src/a.bug462047lang", "element CORE ref CORE.b"); IFile file = IResourcesSetupUtil.createFile("bug462047/src/b.bug462047lang", "element b ref CORE.c"); IResourcesSetupUtil.createFile("bug462047/src/c.bug462047lang", "element c"); IResourcesSetupUtil.waitForBuild(); IResourcesSetupUtil.assertNoErrorsInWorkspace(); LoggingTester.captureLogging(Level.ERROR, BatchLinkableResource.class, ()-> { try { XtextEditor editor = openEditor(file); IXtextDocument document = editor.getDocument(); document.readOnly((XtextResource res)->{ EcoreUtil.resolveAll(res); ResourceSet resourceSet = res.getResourceSet(); assertNull(resourceSet.getResource(URI.createURI("java:/Objects/CORE.CORE"), false)); return null; }); } catch (Exception e) { throw new RuntimeException(e); } }).assertNoLogEntries(); }
Example #16
Source File: BuildDataServiceHandler.java From tesb-studio-se with Apache License 2.0 | 5 votes |
private void setFileContent(InputStream inputStream, IFile ifile, IProgressMonitor monitor) throws CoreException { if (ifile.exists()) { ifile.setContents(inputStream, 0, monitor); } else { ifile.create(inputStream, 0, monitor); } }
Example #17
Source File: FileConversionItemAdapterFactory.java From translationstudio8 with GNU General Public License v2.0 | 5 votes |
@SuppressWarnings("rawtypes") public Object getAdapter(Object adaptableObject, Class adapterType) { if (adapterType == IConversionItem.class) { return new FileConversionItem((IFile) adaptableObject); } return null; }
Example #18
Source File: DefaultChangeFactoryTest.java From gwt-eclipse-plugin with Eclipse Public License 1.0 | 5 votes |
public void testCreateChange() { DefaultChangeFactory factory = new DefaultChangeFactory(); // This file doesn't need to actually exist in the workspace IFile file = Util.getWorkspaceRoot().getFile( new Path("/Project/src/com/google/gwt/GWT.java")); // Create a text file change and verify its properties TextFileChange change = factory.createChange(file); assertEquals(file, change.getFile()); assertEquals(file.getName(), change.getName()); }
Example #19
Source File: FileMetaDataProvider.java From gama with GNU General Public License v3.0 | 5 votes |
private GamaOsmFile.OSMInfo createOSMMetaData(final IFile file) { OSMInfo info = null; try { info = new OSMInfo(file.getLocationURI().toURL(), file.getModificationStamp()); } catch (final MalformedURLException e) { e.printStackTrace(); } return info; }
Example #20
Source File: TmfActionProvider.java From tracecompass with Eclipse Public License 2.0 | 5 votes |
@Override public void fillContextMenu(IMenuManager menu) { ISelection selection = getContext().getSelection(); if (selection instanceof IStructuredSelection) { IStructuredSelection structuredSelection = (IStructuredSelection) selection; if (structuredSelection.size() == 1 && structuredSelection.getFirstElement() instanceof TmfTraceElement) { TmfTraceElement traceElement = (TmfTraceElement) structuredSelection.getFirstElement(); if (traceElement.getResource() instanceof IFile) { MenuManager openWithMenu = new MenuManager(Messages.TmfActionProvider_OpenWith); openWithMenu.add(new OpenWithMenu(page, traceElement.getResource())); menu.insertAfter(ICommonMenuConstants.GROUP_OPEN_WITH, openWithMenu); } } } }
Example #21
Source File: RemoveIndexOfFilesOfProjectJob.java From APICloud-Studio with GNU General Public License v3.0 | 5 votes |
public RemoveIndexOfFilesOfProjectJob(IProject project, Set<IFile> files) { super(MessageFormat.format(Messages.RemoveIndexOfFilesOfProjectJob_Name, project.getName()), project .getLocationURI()); this.project = project; this.files = files; }
Example #22
Source File: OpenEditorUtil.java From translationstudio8 with GNU General Public License v2.0 | 5 votes |
/** * 使用系统默认编辑器打开文件 * @param file * IFile 对象(工作空间内的文件); */ public static void OpenFileWithSystemEditor(IFile file) { try { IDE.openEditor(getCurrentPage(), file, IEditorRegistry.SYSTEM_EXTERNAL_EDITOR_ID); } catch (PartInitException e) { e.printStackTrace(); } }
Example #23
Source File: RebuildDependentResourcesTest.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
@Test public void testFixedJavaReference_04() throws Exception { IFile file = createFile("src/foo"+extension, "default pack.SomeFile$Nested"); waitForBuild(); assertEquals(printMarkers(file), 2, countMarkers(file)); IFile javaFile = createFile("src/pack/SomeFile.java", "package pack; class SomeFile {}"); assertEquals(printMarkers(file), 2, countMarkers(file)); javaFile.setContents(new StringInputStream("package pack; class SomeFile { class Nested {} }"), true, true, monitor()); waitForBuild(); assertEquals(printMarkers(file), 0, countMarkers(file)); }
Example #24
Source File: InternalImpl.java From saros with GNU General Public License v2.0 | 5 votes |
@Override public void createFile(String projectName, String path, int size, boolean compressAble) throws RemoteException { log.trace( "creating file in project '" + projectName + "', path '" + path + "' size: " + size + ", compressAble=" + compressAble); path = path.replace('\\', '/'); int idx = path.lastIndexOf('/'); if (idx != -1) createFolder(projectName, path.substring(0, idx)); IFile file = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName).getFile(path); try { file.create(new GeneratingInputStream(size, compressAble), true, null); } catch (CoreException e) { log.error(e.getMessage(), e); throw new RemoteException(e.getMessage(), e.getCause()); } }
Example #25
Source File: FindBrokenNLSKeysAction.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
private void run(SearchPatternData[] data, String scope) { List<IType> wrappers= new ArrayList<IType>(); List<IFile> properties= new ArrayList<IFile>(); for (int i= 0; i < data.length; i++) { SearchPatternData current= data[i]; if (current.getWrapperClass() != null || current.getPropertyFile() != null) { wrappers.add(current.getWrapperClass()); properties.add(current.getPropertyFile()); } } IType[] accessorClasses= wrappers.toArray(new IType[wrappers.size()]); IFile[] propertieFiles= properties.toArray(new IFile[properties.size()]); SearchBrokenNLSKeysUtil.search(scope, accessorClasses, propertieFiles); }
Example #26
Source File: FakeCore.java From ice with Eclipse Public License 1.0 | 5 votes |
@Override public String importFileAsItem(IFile file, String itemType) { // Local Declarations String returnString = String.valueOf(0); // if (file != null && itemType != null) { returnString = String.valueOf(1); imported = true; // } return returnString; }
Example #27
Source File: DefaultCasDocumentProvider.java From uima-uimaj with Apache License 2.0 | 5 votes |
@Override protected void doSaveDocument(IProgressMonitor monitor, Object element, ICasDocument document, boolean overwrite) throws CoreException { if (element instanceof FileEditorInput) { FileEditorInput fileInput = (FileEditorInput) element; IFile file = fileInput.getFile(); if (document instanceof DocumentUimaImpl) { DocumentUimaImpl documentImpl = (DocumentUimaImpl) document; ByteArrayOutputStream outStream = new ByteArrayOutputStream(40000); documentImpl.serialize(outStream); InputStream stream = new ByteArrayInputStream(outStream.toByteArray()); isFileChangeTrackingEnabled = false; try { file.setContents(stream, true, false, null); } finally { isFileChangeTrackingEnabled = true; } } } // tell everyone that the element changed and is not dirty any longer fireElementDirtyStateChanged(element, false); }
Example #28
Source File: ContentFacadeFactory.java From XPagesExtensionLibrary with Apache License 2.0 | 5 votes |
/** * * @param o * @return */ public PreservingProperties.ContentFacade getFacadeForObject(Object o) { if (o instanceof IFile) { return new EFSFileProvider((IFile)o); } // @TODO might want to implement other instances of ContentFacade // else if (o instanceof String) { // how do we get IFile from a path here, vs. java.io.File? // } // else if (o instanceof java.io.File { // } return null; }
Example #29
Source File: JavaRefactoringIntegrationTest.java From xtext-xtend with Eclipse Public License 2.0 | 5 votes |
@Test public void testRenameStaticImportStable() throws Exception { String xtendModel = "import static java.util.Collections.* class XtendClass { def foo() { val bar = new Object() singleton(bar)}}"; IFile xtendClass = createFile("XtendClass.xtend", xtendModel); final XtextEditor editor = openEditorSafely(xtendClass); renameXtendElement(editor, xtendModel.indexOf("bar"), "baz"); assertDocumentContains(editor, "import static java.util.Collections.*"); }
Example #30
Source File: OutputFileManager.java From texlipse with Eclipse Public License 1.0 | 5 votes |
/** * Retrieves the IFile object of the actually used source file, no matter * if it actually exists. * This method is used to respect partial builds. * * @return actually selected source file, or null if no source file has * been set */ private IFile getActualSourceFile() { if (currentSourceFile == null) { return sourceFile; } else { return currentSourceFile; } }