org.eclipse.xtext.xbase.imports.RewritableImportSection Java Examples

The following examples show how to use org.eclipse.xtext.xbase.imports.RewritableImportSection. 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: AbstractRewritableImportSectionTest.java    From xtext-xtend with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testVariousAddAsString() {
  final RewritableImportSection section = this.getSection();
  section.addStaticExtensionImport("java.util.Set", "*");
  section.addStaticImport("java.util.Collections", "*");
  section.addStaticImport("org.eclipse.xtext.xbase.lib.InputOutput", "println");
  section.addImport("java.util.List");
  StringConcatenation _builder = new StringConcatenation();
  _builder.append("import static extension java.util.Set.*");
  _builder.newLine();
  _builder.append("import static java.util.Collections.*");
  _builder.newLine();
  _builder.append("import java.util.List");
  _builder.newLine();
  this.assertEquals(section, _builder);
}
 
Example #2
Source File: AbstractRewritableImportSectionTest.java    From xtext-xtend with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testVariousAddAsString_2() {
  final RewritableImportSection section = this.getSection();
  section.addStaticExtensionImport("java.util.Set", "*");
  section.addStaticImport("java.util.Collections", "*");
  section.addStaticImport("org.eclipse.xtext.xbase.lib.InputOutput", "println");
  section.addImport("java.util.List");
  StringConcatenation _builder = new StringConcatenation();
  _builder.append("import static extension java.util.Set.*");
  _builder.newLine();
  _builder.append("import static java.util.Collections.*");
  _builder.newLine();
  _builder.append("import java.util.List");
  _builder.newLine();
  this.assertEquals(section, _builder);
}
 
Example #3
Source File: AbstractRewritableImportSectionTest.java    From xtext-xtend with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testSort() {
  final RewritableImportSection section = this.getSection();
  this.addExtensionImport(section, Set.class);
  this.addImport(section, Set.class);
  this.addStaticImport(section, Collections.class);
  this.addImport(section, List.class);
  section.setSort(true);
  StringConcatenation _builder = new StringConcatenation();
  _builder.append("import java.util.List");
  _builder.newLine();
  _builder.append("import java.util.Set");
  _builder.newLine();
  _builder.newLine();
  _builder.append("import static java.util.Collections.*");
  _builder.newLine();
  _builder.newLine();
  _builder.append("import static extension java.util.Set.*");
  _builder.newLine();
  this.assertEquals(section, _builder);
}
 
Example #4
Source File: AbstractRewritableImportSectionTest.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testDoubleAddAsString_2() {
  final RewritableImportSection section = this.getSection();
  section.addStaticExtensionImport("java.util.Collections", "*");
  section.addStaticExtensionImport("java.util.Collections", "*");
  StringConcatenation _builder = new StringConcatenation();
  _builder.append("import static extension java.util.Collections.*");
  _builder.newLine();
  this.assertEquals(section, _builder);
}
 
Example #5
Source File: ImportingTypesProposalProvider.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
public FQNImporter(Resource context, ITextViewer viewer, IScope scope,
		IQualifiedNameConverter qualifiedNameConverter, IValueConverter<String> valueConverter, 
		RewritableImportSection.Factory importSectionFactory,
		ReplaceConverter replaceConverter) {
	super(context, scope, qualifiedNameConverter, valueConverter);
	this.viewer = viewer;
	this.importSectionFactory = importSectionFactory;
	this.replaceConverter = replaceConverter;
}
 
Example #6
Source File: AbstractRewritableImportSectionTest.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
protected RewritableImportSection getStaticSection(final Class<?>... types) {
  try {
    RewritableImportSection _xblockexpression = null;
    {
      this.model = this.getModel(true, types).toString();
      this.xtendFile = this.file(this.model);
      Resource _eResource = this.xtendFile.eResource();
      _xblockexpression = this._factory.parse(((XtextResource) _eResource));
    }
    return _xblockexpression;
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
Example #7
Source File: CheckRewritableImportSectionFactory.java    From dsl-devkit with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Override of parse(), to create {@link RewritableImportSection}s which automatically sort import lines.
 */
@Override
public RewritableImportSection parse(final XtextResource resource) {
  RewritableImportSection rewritableImportSection = super.parse(resource);
  rewritableImportSection.setSort(true);
  return rewritableImportSection;
}
 
Example #8
Source File: DocumentSourceAppender.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
public T create(IXtextDocument document, XtextResource resource, int offset, int length, OptionalParameters params) {
	int baseIndentationLevel = (params.baseIndentationLevel != -1) ? params.baseIndentationLevel : getIndentationLevelAtOffset(offset, document, resource);
	RewritableImportSection importSection = (params.importSection != null) ? params.importSection : rewritableImportSectionFactory.parse(resource);
	String indentString = getIndentString(resource);
	String lineSeparator = whitespaceInformationProvider.getLineSeparatorInformation(resource.getURI()).getLineSeparator();
	WhitespaceHelper whitespaceHelper = whitespaceHelperProvider.get();
	whitespaceHelper.initialize(document, offset, length, params.ensureEmptyLinesAround);
	T appendable = newInstance(document, importSection, whitespaceHelper,
			indentString, lineSeparator, baseIndentationLevel, params.isJava);
	return appendable;
}
 
Example #9
Source File: AbstractRewritableImportSectionTest.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
protected RewritableImportSection getSection(final Class<?>... types) {
  try {
    RewritableImportSection _xblockexpression = null;
    {
      this.model = this.getModel(false, types).toString();
      this.xtendFile = this.file(this.model);
      Resource _eResource = this.xtendFile.eResource();
      _xblockexpression = this._factory.parse(((XtextResource) _eResource));
    }
    return _xblockexpression;
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
Example #10
Source File: AbstractRewritableImportSectionTest.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testVariousAdd_3() {
  final RewritableImportSection section = this.getSection();
  this.addStaticImport(section, Set.class);
  this.addExtensionImport(section, Set.class);
  this.addImport(section, Set.class);
  StringConcatenation _builder = new StringConcatenation();
  _builder.append("import static extension java.util.Set.*");
  _builder.newLine();
  _builder.append("import java.util.Set");
  _builder.newLine();
  this.assertEquals(section, _builder);
}
 
Example #11
Source File: AbstractRewritableImportSectionTest.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testVariousAddAsString_3() {
  final RewritableImportSection section = this.getSection();
  section.addStaticExtensionImport("com.google.common.base.Strings", "*");
  section.addStaticImport("com.google.common.base.Strings", "*");
  section.addStaticImport("com.google.common.base.Strings", "emptyToNull");
  section.addImport("com.google.common.base.Strings");
  StringConcatenation _builder = new StringConcatenation();
  _builder.append("import static extension com.google.common.base.Strings.*");
  _builder.newLine();
  _builder.append("import com.google.common.base.Strings");
  _builder.newLine();
  this.assertEquals(section, _builder);
}
 
Example #12
Source File: AbstractRewritableImportSectionTest.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testVariousAddAsString_4() {
  final RewritableImportSection section = this.getStaticSection(Collections.class);
  section.addStaticImport("java.util.Collections", "*");
  section.addStaticImport("java.util.Collections", "sort");
  section.addImport("java.util.Collections");
  StringConcatenation _builder = new StringConcatenation();
  _builder.append("import static java.util.Collections.*");
  _builder.newLine();
  _builder.append("import java.util.Collections");
  _builder.newLine();
  this.assertEquals(section, _builder);
}
 
Example #13
Source File: AbstractRewritableImportSectionTest.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testDoubleAdd() {
  final RewritableImportSection section = this.getSection(List.class);
  this.addImport(section, List.class);
  this.addImport(section, List.class);
  StringConcatenation _builder = new StringConcatenation();
  _builder.append("import java.util.List");
  _builder.newLine();
  this.assertEquals(section, _builder);
}
 
Example #14
Source File: AbstractRewritableImportSectionTest.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testDoubleAdd_2() {
  final RewritableImportSection section = this.getSection();
  this.addExtensionImport(section, Collections.class);
  this.addExtensionImport(section, Collections.class);
  StringConcatenation _builder = new StringConcatenation();
  _builder.append("import static extension java.util.Collections.*");
  _builder.newLine();
  this.assertEquals(section, _builder);
}
 
Example #15
Source File: AbstractRewritableImportSectionTest.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testDoubleAdd_3() {
  final RewritableImportSection section = this.getSection();
  this.addStaticImport(section, Collections.class);
  this.addStaticImport(section, Collections.class);
  StringConcatenation _builder = new StringConcatenation();
  _builder.append("import static java.util.Collections.*");
  _builder.newLine();
  this.assertEquals(section, _builder);
}
 
Example #16
Source File: AbstractRewritableImportSectionTest.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testDoubleAddAsString() {
  final RewritableImportSection section = this.getSection(List.class);
  section.addImport("java.util.List");
  section.addImport("java.util.List");
  StringConcatenation _builder = new StringConcatenation();
  _builder.append("import java.util.List");
  _builder.newLine();
  this.assertEquals(section, _builder);
}
 
Example #17
Source File: AbstractRewritableImportSectionTest.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testVariousAdd_2() {
  final RewritableImportSection section = this.getSection();
  this.addExtensionImport(section, Set.class);
  this.addStaticImport(section, Set.class);
  this.addImport(section, Set.class);
  StringConcatenation _builder = new StringConcatenation();
  _builder.append("import static extension java.util.Set.*");
  _builder.newLine();
  _builder.append("import java.util.Set");
  _builder.newLine();
  this.assertEquals(section, _builder);
}
 
Example #18
Source File: AbstractRewritableImportSectionTest.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testDoubleAddAsString_3() {
  final RewritableImportSection section = this.getSection();
  section.addStaticImport("java.util.Collections", "*");
  section.addStaticImport("java.util.Collections", "*");
  StringConcatenation _builder = new StringConcatenation();
  _builder.append("import static java.util.Collections.*");
  _builder.newLine();
  this.assertEquals(section, _builder);
}
 
Example #19
Source File: AbstractRewritableImportSectionTest.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testDoubleAddAsString_4() {
  final RewritableImportSection section = this.getSection(Collections.class);
  section.addStaticImport("java.util.Collections", "*");
  section.addStaticImport("java.util.Collections", "sort");
  StringConcatenation _builder = new StringConcatenation();
  _builder.append("import java.util.Collections");
  _builder.newLine();
  _builder.append("import static java.util.Collections.*");
  _builder.newLine();
  this.assertEquals(section, _builder);
}
 
Example #20
Source File: AbstractRewritableImportSectionTest.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testDoubleAddAsString_5() {
  final RewritableImportSection section = this.getSection(Collections.class);
  section.addStaticImport("java.util.Collections", "sort");
  section.addStaticImport("java.util.Collections", "*");
  StringConcatenation _builder = new StringConcatenation();
  _builder.append("import java.util.Collections");
  _builder.newLine();
  _builder.append("import static java.util.Collections.sort");
  _builder.newLine();
  _builder.append("import static java.util.Collections.*");
  _builder.newLine();
  this.assertEquals(section, _builder);
}
 
Example #21
Source File: AbstractRewritableImportSectionTest.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testDoubleAddAsString_6() {
  final RewritableImportSection section = this.getSection(Collections.class);
  section.addStaticExtensionImport("java.util.Collections", "*");
  section.addStaticExtensionImport("java.util.Collections", "sort");
  StringConcatenation _builder = new StringConcatenation();
  _builder.append("import java.util.Collections");
  _builder.newLine();
  _builder.append("import static extension java.util.Collections.*");
  _builder.newLine();
  this.assertEquals(section, _builder);
}
 
Example #22
Source File: AbstractRewritableImportSectionTest.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testDoubleAddAsString_7() {
  final RewritableImportSection section = this.getSection(Collections.class);
  section.addStaticExtensionImport("java.util.Collections", "sort");
  section.addStaticExtensionImport("java.util.Collections", "*");
  StringConcatenation _builder = new StringConcatenation();
  _builder.append("import java.util.Collections");
  _builder.newLine();
  _builder.append("import static extension java.util.Collections.sort");
  _builder.newLine();
  _builder.append("import static extension java.util.Collections.*");
  _builder.newLine();
  this.assertEquals(section, _builder);
}
 
Example #23
Source File: AbstractRewritableImportSectionTest.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testSimpleRemove() {
  final RewritableImportSection section = this.getSection(List.class, Set.class);
  this.removeImport(section, Set.class);
  StringConcatenation _builder = new StringConcatenation();
  _builder.append("import java.util.List");
  _builder.newLine();
  this.assertEquals(section, _builder);
}
 
Example #24
Source File: AbstractRewritableImportSectionTest.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testRemoveAll() {
  final RewritableImportSection section = this.getSection(List.class, Set.class);
  this.removeImport(section, Set.class);
  this.removeImport(section, List.class);
  StringConcatenation _builder = new StringConcatenation();
  this.assertEquals(section, _builder);
}
 
Example #25
Source File: AbstractRewritableImportSectionTest.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testRemoveAdd() {
  final RewritableImportSection section = this.getSection(List.class);
  this.removeImport(section, List.class);
  this.addImport(section, List.class);
  StringConcatenation _builder = new StringConcatenation();
  _builder.append("import java.util.List");
  _builder.newLine();
  this.assertEquals(section, _builder);
}
 
Example #26
Source File: AbstractRewritableImportSectionTest.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testRemoveAdd_2() {
  final RewritableImportSection section = this.getSection(List.class, Set.class);
  this.removeImport(section, List.class);
  this.addImport(section, List.class);
  StringConcatenation _builder = new StringConcatenation();
  _builder.append("import java.util.Set");
  _builder.newLine();
  _builder.append("import java.util.List");
  _builder.newLine();
  this.assertEquals(section, _builder);
}
 
Example #27
Source File: AbstractRewritableImportSectionTest.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testRemoveAddRemove() {
  final RewritableImportSection section = this.getSection(List.class);
  this.removeImport(section, List.class);
  this.addImport(section, List.class);
  this.removeImport(section, List.class);
  StringConcatenation _builder = new StringConcatenation();
  this.assertEquals(section, _builder);
}
 
Example #28
Source File: AbstractRewritableImportSectionTest.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testRemoveAddRemoveAdd() {
  final RewritableImportSection section = this.getSection(List.class);
  this.removeImport(section, List.class);
  this.addImport(section, List.class);
  this.removeImport(section, List.class);
  this.addImport(section, List.class);
  StringConcatenation _builder = new StringConcatenation();
  _builder.append("import java.util.List");
  _builder.newLine();
  this.assertEquals(section, _builder);
}
 
Example #29
Source File: AbstractRewritableImportSectionTest.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testRemoveAdd_3() {
  final RewritableImportSection section = this.getSection(List.class);
  this.removeImport(section, List.class);
  this.addStaticImport(section, List.class);
  StringConcatenation _builder = new StringConcatenation();
  _builder.append("import static java.util.List.*");
  _builder.newLine();
  this.assertEquals(section, _builder);
}
 
Example #30
Source File: AbstractRewritableImportSectionTest.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testRemoveAdd_4() {
  final RewritableImportSection section = this.getSection(List.class);
  this.removeImport(section, List.class);
  this.addStaticImport(section, List.class);
  this.addExtensionImport(section, List.class);
  this.removeStaticImport(section, List.class);
  StringConcatenation _builder = new StringConcatenation();
  _builder.append("import static extension java.util.List.*");
  _builder.newLine();
  this.assertEquals(section, _builder);
}