Java Code Examples for org.eclipse.core.resources.IFile#setContents()

The following examples show how to use org.eclipse.core.resources.IFile#setContents() . These examples are extracted from open source projects. 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
public static IFile createFile(final String name, final IContainer container, final String content) {
	final IFile file = container.getFile(new Path(name));
	try {
		final InputStream stream = new ByteArrayInputStream(content.getBytes(file.getCharset()));
		if (file.exists()) {
			file.setContents(stream, true, true, null);
		}
		else {
			file.create(stream, true, null);
		}
		stream.close();
	}
	catch (final Exception e) {
		throw new RuntimeException(e);
	}
	return file;
}
 
Example 2
public static IFile createFile(final String name, final IContainer container, final String content) {
	final IFile file = container.getFile(new Path(name));
	try {
		final InputStream stream = new ByteArrayInputStream(content.getBytes(file.getCharset()));
		if (file.exists()) {
			file.setContents(stream, true, true, null);
		}
		else {
			file.create(stream, true, null);
		}
		stream.close();
	}
	catch (final Exception e) {
		throw new RuntimeException(e);
	}
	return file;
}
 
Example 3
/**
 * Create a file in the appropriate location for the project's {@code WEB-INF}. This
 * implementation respects the order and tags on the WTP virtual component model, creating the
 * file in the {@code <wb-resource>} with the {@code defaultRootSource} tag when present. This
 * method is typically used after ensuring the file does not exist with {@link
 * #findInWebInf(IProject, IPath)}.
 *
 * <p>See <a href="https://bugs.eclipse.org/bugs/show_bug.cgi?id=448544">Eclipse bug 448544</a>
 * for details of the {@code defaultRootSource} tag.
 *
 * @param project the hosting project
 * @param filePath the path of the file within the project's {@code WEB-INF}
 * @param contents the content for the file
 * @param overwrite if {@code true} then overwrite the file if it exists
 * @see #findInWebInf(IProject, IPath)
 */
public static IFile createFileInWebInf(
    IProject project,
    IPath filePath,
    InputStream contents,
    boolean overwrite,
    IProgressMonitor monitor)
    throws CoreException {
  IFolder webInfDir = findWebInfForNewResource(project);
  IFile file = webInfDir.getFile(filePath);
  SubMonitor progress = SubMonitor.convert(monitor, 2);
  if (!file.exists()) {
    ResourceUtils.createFolders(file.getParent(), progress.newChild(1));
    file.create(contents, true, progress.newChild(1));
  } else if (overwrite) {
    file.setContents(contents, IResource.FORCE | IResource.KEEP_HISTORY, progress.newChild(2));
  }
  return file;
}
 
Example 4
@Test
public void testDefaultConfiguration() throws Exception {
	IJavaProject project = createJavaProject("foo");
	addNature(project.getProject(), XtextProjectHelper.NATURE_ID);
	IFolder folder = project.getProject().getFolder("src");
	IFile file = folder.getFile("Foo" + F_EXT);
	file.create(new StringInputStream("object Foo"), true, monitor());
	build();
	IFile generatedFile = project.getProject().getFile("./src-gen/Foo.txt");
	assertTrue(generatedFile.exists());
	assertTrue(generatedFile.isDerived());
	assertTrue(generatedFile.findMarkers(DerivedResourceMarkers.MARKER_ID, false, IResource.DEPTH_ZERO).length == 1);
	assertEquals("object Foo", readFile(generatedFile).trim());
	file.setContents(new StringInputStream("object Bar"), true, true, monitor());
	build();
	assertFalse(generatedFile.exists());
	generatedFile = project.getProject().getFile("./src-gen/Bar.txt");
	assertTrue(generatedFile.exists());
	assertTrue(generatedFile.isDerived());
	assertTrue(generatedFile.findMarkers(DerivedResourceMarkers.MARKER_ID, false, IResource.DEPTH_ZERO).length == 1);
	assertEquals("object Bar", readFile(generatedFile).trim());
	file.delete(true, monitor());
	build();
	assertFalse(generatedFile.exists());
}
 
Example 5
@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 6
@Test public void testUpdateOfReferencedFile() throws Exception {
	IJavaProject project = createJavaProject("foo");
	addNature(project.getProject(), XtextProjectHelper.NATURE_ID);
	IFolder folder = project.getProject().getFolder("src");
	IFile file = folder.getFile("Foo" + F_EXT);
	file.create(new StringInputStream("object Foo"), true, monitor());
	IFile fileB = folder.getFile("Boo" + F_EXT);
	fileB.create(new StringInputStream("object Bar references Foo"), true, monitor());
	build();
	assertTrue(indexContainsElement(file.getFullPath().toString(), "Foo"));
	assertTrue(indexContainsElement(fileB.getFullPath().toString(), "Bar"));
	assertEquals(2, countResourcesInIndex());

	getBuilderState().addListener(this);
	file.setContents(new StringInputStream("object Foo"), true, true, monitor());
	build();
	assertEquals(1, getEvents().get(0).getDeltas().size());
	assertNumberOfMarkers(fileB, 0);
	assertEquals(1, getIncomingReferences(URI.createPlatformResourceURI("foo/src/Foo" + F_EXT, true)).size());

	file.setContents(new StringInputStream("object Fop"), true, true, monitor());
	build();
	assertEquals(2, getEvents().get(1).getDeltas().size());
	assertNumberOfMarkers(fileB, 1);
	assertEquals(0, getIncomingReferences(URI.createPlatformResourceURI("foo/src/Foo" + F_EXT, true)).size());

	file.setContents(new StringInputStream("object Foo"), true, true, monitor());
	build();
	assertEquals(2, getEvents().get(2).getDeltas().size());
	assertNumberOfMarkers(fileB, 0);

	file.setContents(new StringInputStream("object Foo"), true, true, monitor());
	build();
	assertEquals(1, getEvents().get(3).getDeltas().size());
	assertNumberOfMarkers(fileB, 0);
}
 
Example 7
@Ignore("Since the name acme.A is considered to be derived, it is filtered from the Java delta")
@Test
public void testXtendAndJavaSameProjectXtendFirst() {
  try {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("package acme");
    _builder.newLine();
    _builder.append("class A {");
    _builder.newLine();
    _builder.append("}");
    _builder.newLine();
    final IFile firstFile = IResourcesSetupUtil.createFile("first.p384008/src/acme/B.xtend", _builder.toString());
    this.first.build(IncrementalProjectBuilder.INCREMENTAL_BUILD, XtextBuilder.BUILDER_ID, UniqueClassNameValidatorUITest.emptyStringMap(), null);
    StringConcatenation _builder_1 = new StringConcatenation();
    _builder_1.append("package acme;");
    _builder_1.newLine();
    _builder_1.append("class A2 {");
    _builder_1.newLine();
    _builder_1.append("}");
    _builder_1.newLine();
    final IFile javaFile = IResourcesSetupUtil.createFile("first.p384008/src/acme/A.java", _builder_1.toString());
    this.first.build(IncrementalProjectBuilder.INCREMENTAL_BUILD, JavaCore.BUILDER_ID, UniqueClassNameValidatorUITest.emptyStringMap(), null);
    this.first.build(IncrementalProjectBuilder.INCREMENTAL_BUILD, XtextBuilder.BUILDER_ID, UniqueClassNameValidatorUITest.emptyStringMap(), null);
    StringInputStream _stringInputStream = new StringInputStream("package acme; class A{}");
    javaFile.setContents(_stringInputStream, false, false, null);
    this.first.build(IncrementalProjectBuilder.INCREMENTAL_BUILD, JavaCore.BUILDER_ID, UniqueClassNameValidatorUITest.emptyStringMap(), null);
    this.first.build(IncrementalProjectBuilder.INCREMENTAL_BUILD, XtextBuilder.BUILDER_ID, UniqueClassNameValidatorUITest.emptyStringMap(), null);
    final IMarker[] markers = firstFile.findMarkers(IMarker.PROBLEM, true, IResource.DEPTH_INFINITE);
    Assert.assertEquals(IResourcesSetupUtil.printMarker(markers), 1, markers.length);
    Assert.assertEquals("The type A is already defined in A.java.", IterableExtensions.<IMarker>head(((Iterable<IMarker>)Conversions.doWrapArray(markers))).getAttribute(IMarker.MESSAGE));
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
Example 8
public IFile createFile( IContainer parent, String fileName, String content )
  throws CoreException
{
  initializeProject();
  IFile result = parent.getFile( new Path( fileName ) );
  InputStream stream = new ByteArrayInputStream( content.getBytes( UTF_8 ) );
  if( !result.exists() ) {
    result.create( stream, true, newProgressMonitor() );
  } else {
    result.setContents( stream, false, false, newProgressMonitor() );
  }
  return result;
}
 
Example 9
/**
 * Imports resources from <code>bundleSourcePath</code> to
 * <code>importTarget</code>.
 *
 * @param importTarget
 *            the parent container
 * @param bundleSourcePath
 *            the path to a folder containing resources
 *
 * @throws CoreException
 *             import failed
 * @throws IOException
 *             import failed
 */
public static void importResources(IContainer importTarget, Bundle bundle, String bundleSourcePath) throws CoreException,
        IOException {
    Enumeration<?> entryPaths = bundle.getEntryPaths(bundleSourcePath);
    while (entryPaths.hasMoreElements()) {
        String path = (String) entryPaths.nextElement();
        IPath name = new Path(path.substring(bundleSourcePath.length()));
        if (path.endsWith("/.svn/")) {
            continue; // Ignore SVN folders
        } else if (path.endsWith("/")) {
            IFolder folder = importTarget.getFolder(name);
            if (folder.exists()) {
                folder.delete(true, null);
            }
            folder.create(true, true, null);
            importResources(folder, bundle, path);
        } else {
            URL url = bundle.getEntry(path);
            IFile file = importTarget.getFile(name);
            if (!file.exists()) {
                file.create(url.openStream(), true, null);
            } else {
                file.setContents(url.openStream(), true, false, null);
            }
        }
    }
}
 
Example 10
private void createFile(IProject project, String content, String encoding) throws Exception {
	IFile file = workbenchTestHelper.createFile("Example.xtend", "");
	if (encoding == null)
		encoding = project.getDefaultCharset();
	else
		file.setCharset(encoding, null);
	file.setContents(new StringInputStream(content, encoding), true, true, null);
	project.build(IncrementalProjectBuilder.INCREMENTAL_BUILD, null);
}
 
Example 11
/**
 * This operation insures that IReader interface is implemented as described
 * by the XML persistence provider and that the operations function.
 * 
 * @throws JAXBException
 *             JAXB could not load
 * @throws CoreException
 *             Eclispe Resources could not read the file
 */
@Test
public void checkIReaderOperations() throws JAXBException, CoreException {

	// Create a Form
	Form form = new Form();
	form.setName("The artist formerly known as Prince");
	IFile file = project.getFile("ireader_test_form.xml");

	// Create a context and write the Form to a stream
	JAXBContext jaxbContext = JAXBContext.newInstance(Form.class);
	Marshaller marshaller = jaxbContext.createMarshaller();
	marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
	ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
	marshaller.marshal(form, outputStream);
	// Convert it to an input stream so it can be pushed to file
	ByteArrayInputStream inputStream = new ByteArrayInputStream(
			outputStream.toByteArray());
	// Update the output file if it already exists
	if (file.exists()) {
		file.setContents(inputStream, IResource.FORCE, null);
	} else {
		// Or create it from scratch
		file.create(inputStream, IResource.FORCE, null);
	}

	// Read the Form back in with the provider
	Form loadedForm = xmlpp.read(file);
	assertNotNull(loadedForm);
	assertEquals(loadedForm, form);

	return;
}
 
Example 12
public void createFile(IFile file, InputStream source) {
	ensureContainerExists(file.getParent());
	try {
		if (file.exists()) {
			file.setContents(source, true, false, new NullProgressMonitor());
		} else {
			file.create(source, true, new NullProgressMonitor());
		}
	} catch (CoreException e) {
		throw new RuntimeException(e);
	}
}
 
Example 13
@Test
public void testPropertyOfTypeInSameProject() {
  try {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("package mypack");
    _builder.newLine();
    _builder.newLine();
    _builder.append("class TypeA {");
    _builder.newLine();
    _builder.append("}");
    _builder.newLine();
    this.workbenchTestHelper.createFile("mypack/TypeA.xtend", _builder.toString());
    StringConcatenation _builder_1 = new StringConcatenation();
    _builder_1.append("package otherpack;");
    _builder_1.newLine();
    _builder_1.newLine();
    _builder_1.append("import mypack.TypeA;");
    _builder_1.newLine();
    _builder_1.newLine();
    _builder_1.append("class Client {");
    _builder_1.newLine();
    _builder_1.append("\t");
    _builder_1.append("@Property TypeA myTypeA");
    _builder_1.newLine();
    _builder_1.append("\t");
    _builder_1.newLine();
    _builder_1.append("\t");
    _builder_1.append("def void setMyTypeA(TypeA myType) {");
    _builder_1.newLine();
    _builder_1.append("\t\t");
    _builder_1.append("_myTypeA = myType");
    _builder_1.newLine();
    _builder_1.append("\t");
    _builder_1.append("}");
    _builder_1.newLine();
    _builder_1.append("}");
    _builder_1.newLine();
    final IFile type2 = this.workbenchTestHelper.createFile("otherpack/Client.xtend", _builder_1.toString());
    IResourcesSetupUtil.waitForBuild();
    this.assertNoErrorsInWorkspace();
    StringConcatenation _builder_2 = new StringConcatenation();
    _builder_2.append("package otherpack;");
    _builder_2.newLine();
    _builder_2.newLine();
    _builder_2.append("import mypack.TypeA;");
    _builder_2.newLine();
    _builder_2.newLine();
    _builder_2.append("class Client {");
    _builder_2.newLine();
    _builder_2.append("\t");
    _builder_2.append("@Property TypeA myTypeA");
    _builder_2.newLine();
    _builder_2.append("\t");
    _builder_2.newLine();
    _builder_2.append("\t");
    _builder_2.append("def void setMyTypeA(TypeA myType) {");
    _builder_2.newLine();
    _builder_2.append("\t\t");
    _builder_2.append("_myTypeA = myType");
    _builder_2.newLine();
    _builder_2.append("\t");
    _builder_2.append("}");
    _builder_2.newLine();
    _builder_2.append("}");
    _builder_2.newLine();
    StringInputStream _stringInputStream = new StringInputStream(_builder_2.toString());
    type2.setContents(_stringInputStream, true, true, null);
    IResourcesSetupUtil.waitForBuild();
    this.assertNoErrorsInWorkspace();
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
Example 14
private void changeFile(IFolder folder, String fileName, String content) throws CoreException {
	IFile file = folder.getFile(fileName + F_EXT);
	file.setContents(new StringInputStream(content), IResource.FORCE, monitor());
	build();
}
 
Example 15
@Test
public void testIncrementalChangeOnBidirectionalDep() {
  try {
    WorkbenchTestHelper.createPluginProject("my.project", "org.eclipse.xtext.xbase.lib", "org.eclipse.xtend.lib");
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("package mypack");
    _builder.newLine();
    _builder.newLine();
    _builder.append("class ClassA {");
    _builder.newLine();
    _builder.append("\t");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("def void myMethod(ClassB b) {");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("b.myMethod");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("}");
    _builder.newLine();
    _builder.append("}");
    _builder.newLine();
    final IFile fileA = IResourcesSetupUtil.createFile("my.project/src/mypack/ClassA.xtend", _builder.toString());
    StringConcatenation _builder_1 = new StringConcatenation();
    _builder_1.append("package mypack");
    _builder_1.newLine();
    _builder_1.newLine();
    _builder_1.append("class ClassB {");
    _builder_1.newLine();
    _builder_1.append("\t");
    _builder_1.newLine();
    _builder_1.append("\t");
    _builder_1.append("def void anotherMethod(ClassA a) {");
    _builder_1.newLine();
    _builder_1.append("\t\t");
    _builder_1.append("a.anotherMethod");
    _builder_1.newLine();
    _builder_1.append("\t");
    _builder_1.append("}");
    _builder_1.newLine();
    _builder_1.append("}");
    _builder_1.newLine();
    IResourcesSetupUtil.createFile("my.project/src/mypack/ClassB.xtend", _builder_1.toString());
    IResourcesSetupUtil.waitForBuild();
    IResourcesSetupUtil.assertNoErrorsInWorkspace();
    final IFile javaB = fileA.getProject().getFile("xtend-gen/mypack/ClassB.java");
    Assert.assertTrue(WorkbenchTestHelper.getContentsAsString(javaB).contains("anotherMethod(a);"));
    StringConcatenation _builder_2 = new StringConcatenation();
    _builder_2.append("package mypack");
    _builder_2.newLine();
    _builder_2.newLine();
    _builder_2.append("class ClassA {");
    _builder_2.newLine();
    _builder_2.append("\t");
    _builder_2.newLine();
    _builder_2.append("\t");
    _builder_2.append("def void myMethod(ClassB b) {");
    _builder_2.newLine();
    _builder_2.append("\t\t");
    _builder_2.append("b.myMethod");
    _builder_2.newLine();
    _builder_2.append("\t");
    _builder_2.append("}");
    _builder_2.newLine();
    _builder_2.append("\t");
    _builder_2.newLine();
    _builder_2.append("\t");
    _builder_2.append("def void anotherMethod() {}");
    _builder_2.newLine();
    _builder_2.append("}");
    _builder_2.newLine();
    StringInputStream _stringInputStream = new StringInputStream(_builder_2.toString());
    fileA.setContents(_stringInputStream, true, true, null);
    IResourcesSetupUtil.waitForBuild();
    IResourcesSetupUtil.assertNoErrorsInWorkspace();
    Assert.assertTrue(WorkbenchTestHelper.getContentsAsString(javaB).contains("a.anotherMethod();"));
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
Example 16
@SuppressWarnings({ "resource", "javadoc" })
/**
 *
 * 01. CRole consumes BRole, BRole consumes ARole
 * 02. BRole calls method of ARole, BRole calls method of BRole and a method of ARole
 * 03. method of BRole is renamed
 * 04. CRole should get error marker at call of B's method, call to A's method should be ok
 * 05. method of BRole is renamed back
 * 06. C should have no error markers
 *
 * @throws Exception
 */
//@formatter:on
@Test
public void testMethodInConsumedRoleInBetweenRenamed() throws Exception {
	final IProject project = createJSProject("testMethodInConsumedRoleInBetweenRenamed");
	IFolder folder = configureProjectWithXtext(project);
	IFolder moduleFolder = createFolder(folder, RoleTestFiles.moduleFolder());

	IFile fileARole = createTestFile(moduleFolder, "ARole", RoleTestFiles.roleA());
	IFile fileBRole = createTestFile(moduleFolder, "BRole", RoleTestFiles.roleB());
	IFile fileCRole = createTestFile(moduleFolder, "CRole", RoleTestFiles.roleC());
	waitForAutoBuild();

	assertMarkers("File A should have no errors", fileARole, 0);
	assertMarkers("File B should have no errors", fileBRole, 0);
	assertMarkers("File C should have no errors", fileCRole, 0);

	fileBRole.setContents(new StringInputStream(RoleTestFiles.roleBChanged().toString()), true, true,
			monitor());
	waitForAutoBuild();

	assertMarkers("File A should have no errors", fileARole, 0);

	assertMarkers("File B with other method name should have no errors", fileBRole, 0);

	assertMarkers("File C should have errors as using old method name", fileCRole, 1);

	fileBRole.setContents(new StringInputStream(RoleTestFiles.roleB().toString()), true, true, monitor());
	waitForAutoBuild();

	assertMarkers("File A should have no errors", fileARole, 0);

	assertMarkers("File B should have no errors", fileBRole, 0);

	assertMarkers("File C should have no errors after changing back to old B", fileCRole, 0);
}
 
Example 17
/**
 * @throws CoreException
 *             if something unexpected happens during resource access
 * @throws IOException
 *             if serialization of the trace data fails
 * @since 2.3
 */
protected void updateTraceInformation(IFile traceFile, CharSequence contents, boolean derived)
		throws CoreException, IOException {
	if (contents instanceof ITraceRegionProvider) {
		try {
			AbstractTraceRegion traceRegion = ((ITraceRegionProvider) contents).getTraceRegion();
			if (sourceTraces == null) {
				sourceTraces = HashMultimap.create();
			}
			IPath tracePath = traceFile.getFullPath();
			Iterator<AbstractTraceRegion> iterator = traceRegion.treeIterator();
			while (iterator.hasNext()) {
				AbstractTraceRegion region = iterator.next();
				for (ILocationData location : region.getAssociatedLocations()) {
					SourceRelativeURI path = location.getSrcRelativePath();
					if (path != null) {
						sourceTraces.put(path, tracePath);
					}
				}
			}
			class AccessibleOutputStream extends ByteArrayOutputStream {
				byte[] internalBuffer() {
					return buf;
				}

				int internalLength() {
					return count;
				}
			}
			AccessibleOutputStream data = new AccessibleOutputStream();
			traceSerializer.writeTraceRegionTo(traceRegion, data);
			// avoid copying the byte array
			InputStream input = new ByteArrayInputStream(data.internalBuffer(), 0, data.internalLength());
			if (traceFile.exists()) {
				traceFile.setContents(input, true, false, monitor);
			} else {
				traceFile.create(input, true, monitor);
			}
			setDerived(traceFile, derived);
			return;
		} catch (TraceNotFoundException e) {
			// ok
		}
	}
	if (traceFile.exists()) {
		traceFile.delete(IResource.FORCE, monitor);
	}
}
 
Example 18
/**
 * The worker method. It will find the container, create the file if missing or just replace its
 * contents, and open the editor on the newly created file.
 */
private void doFinish(String containerName, String fileName, IProgressMonitor monitor)
    throws CoreException {
  // create a sample file
  monitor.beginTask("Creating " + fileName, 2);
  
  IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
  IResource resource = root.findMember(new Path(containerName));
  
  if (!resource.exists() || !(resource instanceof IContainer)) {
    throwCoreException("Container \"" + containerName + "\" does not exist.");
  }
  
  IContainer container = (IContainer) resource;
  
  final IFile file = container.getFile(new Path(fileName));
  InputStream stream = openContentStream(file);
  
  if (file.exists()) {
    file.setContents(stream, true, true, monitor);
  } else {
    file.create(stream, true, monitor);
  }
  
  monitor.worked(1);
  monitor.setTaskName("Opening file for editing...");
  
  getShell().getDisplay().asyncExec(new Runnable() {
    @Override
    public void run() {
      IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
      try {
        IDE.openEditor(page, file, true);
      } catch (PartInitException e) {
        LangCore.logError("Error opening editor", e);
      }
    }
  });
  
  monitor.worked(1);
}
 
Example 19
@SuppressWarnings({ "resource", "javadoc" })
/**
 *
 * 01. static called member is changed to non-static -> errors at callers and errors gone, when changed back
 * 02. static added to getter -> errors at callers and errors gone, when changed back
 * 03a. static method overrides static method in super class, sub class is called in caller
 * 03b. method in sub class renamed -> no errors expected, as now linking to method in super class
 *
 * @throws Exception
 */
//@formatter:on
@Test
public void testStaticMethodCalls() throws Exception {
	final IProject project = createJSProject("testStaticMethodCalls");
	IFolder folder = configureProjectWithXtext(project);
	IFolder moduleFolder = createFolder(folder, StaticTestFiles.moduleFolder());

	IFile fileCallee = createTestFile(moduleFolder, "Callee", StaticTestFiles.callee());
	IFile fileSubCallee = createTestFile(moduleFolder, "SubCallee", StaticTestFiles.subCallee());
	IFile fileCaller = createTestFile(moduleFolder, "Caller", StaticTestFiles.caller());
	waitForAutoBuild();

	assertMarkers("File Callee should have no errors", fileCallee, 0);
	assertMarkers("File SubCallee should have no errors", fileSubCallee, 0);
	assertMarkers("File Caller should have no errors", fileCaller, 0);

	fileCallee.setContents(new StringInputStream(StaticTestFiles.callee_changedStaticMember().toString()),
			true,
			true,
			monitor());
	waitForAutoBuild();

	assertMarkers("File Caller with field not static anymore should have errors", fileCaller,
			2);
	assertMarkers("File Callee should have no errors", fileCallee, 0);
	assertMarkers("File SubCallee should have one error", fileSubCallee, 1);

	fileCallee.setContents(new StringInputStream(StaticTestFiles.callee().toString()),
			true,
			true,
			monitor());
	waitForAutoBuild();

	assertMarkers("File Caller with old field access should have no errors", fileCaller, 0);
	assertMarkers("File SubCallee with old field access should have no errors", fileSubCallee, 0);

	fileCallee.setContents(new StringInputStream(StaticTestFiles.callee_changedNonStaticAccessors().toString()),
			true,
			true,
			monitor());
	waitForAutoBuild();

	assertMarkers("File Caller with getter static now should have errors", fileCaller,
			1); // 1 for static access in non-static context + 1 any is not sub type of string
	assertMarkers("File Callee should have one error, because of wrong this access", fileCallee, 1);
	assertMarkers("File SubCallee should have no errors", fileSubCallee, 0);

	fileCallee.setContents(new StringInputStream(StaticTestFiles.callee().toString()),
			true,
			true,
			monitor());
	waitForAutoBuild();

	assertMarkers("File Caller with old getter access should have no errors", fileCaller, 0);
	assertMarkers("File Callee with old this access should have no errors", fileCallee, 0);

	fileSubCallee.setContents(new StringInputStream(StaticTestFiles.subCallee_changed().toString()),
			true,
			true,
			monitor());
	waitForAutoBuild();

	assertMarkers("File SubCallee should have no errors", fileSubCallee, 0);
	assertMarkers("File Callee should have no errors", fileCallee, 0);
	assertMarkers("File Caller should have no errors as now linking to super class method", fileCaller, 0);

	fileSubCallee.setContents(new StringInputStream(StaticTestFiles.subCallee().toString()),
			true,
			true,
			monitor());
	waitForAutoBuild();

	assertMarkers("File Caller with old method should have no errors", fileCaller, 0);
}
 
Example 20
/**
 * Save installation descriptor.
 *
 * @param currentContainer          An IProject with the UIMA nature
 * @param insd          The installation descriptor object
 * @throws CoreException           if there is problem accessing the corresponding resource
 * @throws IOException           if there is problem writing to the corresponding resource
 */
public static void saveInstallationDescriptor(IContainer currentContainer,
        InstallationDescriptor insd) throws CoreException, IOException {
  IFile installFile = currentContainer.getFile(new Path(INSTALLATION_DESCRIPTOR_PATH));
  installFile.setContents(InstallationDescriptorHandler.getInstallationDescriptorAsStream(insd),
          false, true, null);
}