org.eclipse.xtext.xtext.generator.model.TypeReference Java Examples

The following examples show how to use org.eclipse.xtext.xtext.generator.model.TypeReference. 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: BindingFactory.java    From sarl with Apache License 2.0 6 votes vote down vote up
/** Bind an annotated element.
 *
 * @param bind the type to bind.
 * @param annotatedWith the annotation to consider.
 * @param to the instance.
 * @param functionName the optional function name.
 * @return the binding element.
 */
protected Binding bindAnnotatedWithToInstance(TypeReference bind, TypeReference annotatedWith, String to,
		String functionName) {
	final StringConcatenationClient client = new StringConcatenationClient() {
		@Override
		protected void appendTo(TargetStringConcatenation builder) {
			builder.append("binder.bind("); //$NON-NLS-1$
			builder.append(bind);
			builder.append(".class).annotatedWith("); //$NON-NLS-1$
			builder.append(annotatedWith);
			builder.append(".class).toInstance("); //$NON-NLS-1$
			builder.append(to);
			builder.append(".class);"); //$NON-NLS-1$
		}
	};
	String fctname = functionName;
	if (Strings.isEmpty(fctname)) {
		fctname = bind.getSimpleName();
	}
	final BindKey key = new GuiceModuleAccess.BindKey(formatFunctionName(fctname), null, false, false);
	final  BindValue statements = new BindValue(null, null, false, Collections.singletonList(client));
    return new Binding(key, statements, true, this.name);
}
 
Example #2
Source File: QuickfixProviderFragment2.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
public void generateGenQuickfixProvider() {
  final TypeReference genClass = this.getQuickfixProviderClass(this.getGrammar());
  final GeneratedJavaFileAccess file = this.fileAccessFactory.createGeneratedJavaFile(genClass);
  StringConcatenationClient _client = new StringConcatenationClient() {
    @Override
    protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
      _builder.append("public class ");
      String _simpleName = genClass.getSimpleName();
      _builder.append(_simpleName);
      _builder.append(" extends ");
      TypeReference _quickfixProviderSuperClass = QuickfixProviderFragment2.this.getQuickfixProviderSuperClass(QuickfixProviderFragment2.this.getGrammar());
      _builder.append(_quickfixProviderSuperClass);
      _builder.append(" {");
      _builder.newLineIfNotEmpty();
      _builder.append("}");
      _builder.newLine();
    }
  };
  file.setContent(_client);
  file.writeTo(this.getProjectConfig().getEclipsePlugin().getSrcGen());
}
 
Example #3
Source File: CodeMiningFragment.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
protected TypeReference getCodeMiningProviderClass() {
  String _eclipsePluginBasePackage = this._xtextGeneratorNaming.getEclipsePluginBasePackage(this.getGrammar());
  String _plus = (_eclipsePluginBasePackage + ".codemining.");
  String _simpleName = GrammarUtil.getSimpleName(this.getGrammar());
  String _plus_1 = (_plus + _simpleName);
  return TypeReference.typeRef(this._iQualifiedNameConverter.toQualifiedName((_plus_1 + "CodeMiningProvider")).toString());
}
 
Example #4
Source File: XtextGeneratorTemplates.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
private String getSimpleMethodName(final TypeReference type) {
  String _join = IterableExtensions.join(type.getSimpleNames(), "$");
  final Function1<TypeReference, CharSequence> _function = (TypeReference it) -> {
    return this.getSimpleMethodName(it);
  };
  String _join_1 = IterableExtensions.<TypeReference>join(type.getTypeArguments(), "$", "$", "", _function);
  return (_join + _join_1);
}
 
Example #5
Source File: ImportNamespacesScopingFragment2.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
protected TypeReference getScopeProviderSuperClass(final Grammar grammar) {
  final Grammar superGrammar = GrammarUtil2.getNonTerminalsSuperGrammar(grammar);
  if ((this.isInheritImplementation() && (superGrammar != null))) {
    return this.getScopeProviderClass(superGrammar);
  } else {
    return this.getDefaultScopeProviderSuperClass();
  }
}
 
Example #6
Source File: ValidatorFragment2.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
protected TypeReference getGenValidatorSuperClass(final Grammar grammar) {
  TypeReference _xblockexpression = null;
  {
    final Grammar superGrammar = GrammarUtil2.getNonTerminalsSuperGrammar(grammar);
    TypeReference _xifexpression = null;
    if ((this.isInheritImplementation() && (superGrammar != null))) {
      _xifexpression = this._validatorNaming.getValidatorClass(superGrammar);
    } else {
      _xifexpression = this.getDefaultValidatorSuperClass();
    }
    _xblockexpression = _xifexpression;
  }
  return _xblockexpression;
}
 
Example #7
Source File: OutlineTreeProviderFragment2.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void generate() {
  ManifestAccess _manifest = this.getProjectConfig().getEclipsePlugin().getManifest();
  boolean _tripleNotEquals = (_manifest != null);
  if (_tripleNotEquals) {
    Set<String> _requiredBundles = this.getProjectConfig().getEclipsePlugin().getManifest().getRequiredBundles();
    _requiredBundles.add("org.eclipse.xtext.ui");
  }
  boolean _isGenerateStub = this.isGenerateStub();
  boolean _not = (!_isGenerateStub);
  if (_not) {
    return;
  }
  IXtextGeneratorFileSystemAccess _src = this.getProjectConfig().getEclipsePlugin().getSrc();
  boolean _tripleNotEquals_1 = (_src != null);
  if (_tripleNotEquals_1) {
    boolean _isGenerateXtendStub = this.isGenerateXtendStub();
    if (_isGenerateXtendStub) {
      this.generateXtendOutlineTreeProvider();
    } else {
      this.generateJavaOutlineTreeProvider();
    }
  }
  GuiceModuleAccess.BindingFactory _bindingFactory = new GuiceModuleAccess.BindingFactory();
  TypeReference _typeReference = new TypeReference("org.eclipse.xtext.ui.editor.outline.IOutlineTreeProvider");
  GuiceModuleAccess.BindingFactory _addTypeToType = _bindingFactory.addTypeToType(_typeReference, 
    this.getOutlineTreeProviderClass(this.getGrammar()));
  TypeReference _typeReference_1 = new TypeReference("org.eclipse.xtext.ui.editor.outline.impl.IOutlineTreeStructureProvider");
  _addTypeToType.addTypeToType(_typeReference_1, 
    this.getOutlineTreeProviderClass(this.getGrammar())).contributeTo(this.getLanguage().getEclipsePluginGenModule());
}
 
Example #8
Source File: ImportURIScopingFragment2.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public TypeReference getDelegateScopeProvider() {
	if (xbaseUsageDetector.inheritsXbase(getLanguage().getGrammar())) {
		return TypeReference.typeRef("org.eclipse.xtext.xbase.scoping.XImportSectionNamespaceScopeProvider");
	} else {
		return TypeReference.typeRef(SimpleLocalScopeProvider.class);
	}
}
 
Example #9
Source File: BindingFactory.java    From sarl with Apache License 2.0 5 votes vote down vote up
private static TypeReference typeRef(String qualifiedName) {
	int index = qualifiedName.indexOf('$');
	if (index > 0) {
		String classname = qualifiedName.substring(0, index);
		final String innerClasses = qualifiedName.substring(index + 1);
		index = classname.lastIndexOf('.');
		if (index >= 0) {
			final String packageName = classname.substring(0, index);
			classname = classname.substring(index + 1) + '.' + innerClasses;
			return new TypeReference(packageName, classname);
		}
	}
	return TypeReference.typeRef(qualifiedName);
}
 
Example #10
Source File: AbstractMemberBuilderFragment.java    From sarl with Apache License 2.0 5 votes vote down vote up
/** Generate the member builder interface.
 *
 * @param description the description of the member.
 */
protected void generateIMemberBuilder(MemberDescription description) {
	if (description.isTopElement()) {
		return;
	}
	final TypeReference builder = description.getElementDescription().getBuilderInterfaceType();
	final StringConcatenationClient content = new StringConcatenationClient() {
		@Override
		protected void appendTo(TargetStringConcatenation it) {
			it.append("/** Builder of a " + getLanguageName() //$NON-NLS-1$
					+ " " + description.getElementDescription().getName() + "."); //$NON-NLS-1$ //$NON-NLS-2$
			it.newLine();
			it.append(" */"); //$NON-NLS-1$
			it.newLine();
			it.append("@SuppressWarnings(\"all\")"); //$NON-NLS-1$
			it.newLine();
			it.append("public interface "); //$NON-NLS-1$
			it.append(builder.getSimpleName());
			it.append(" {"); //$NON-NLS-1$
			it.newLineIfNotEmpty();
			it.newLine();
			it.append(generateMembers(description, true, false));
			it.append("}"); //$NON-NLS-1$
			it.newLineIfNotEmpty();
			it.newLine();
		}
	};
	final JavaFileAccess javaFile = getFileAccessFactory().createJavaFile(builder, content);
	javaFile.writeTo(getSrcGen());
}
 
Example #11
Source File: ScriptBuilderFragment.java    From sarl with Apache License 2.0 5 votes vote down vote up
/** Generate the script appender.
 */
protected void generateScriptSourceAppender() {
	final List<StringConcatenationClient> topElements = generateTopElements(false, true);
	final TypeReference appender = getCodeElementExtractor().getElementAppenderImpl("Script"); //$NON-NLS-1$
	final StringConcatenationClient content = new StringConcatenationClient() {
		@Override
		protected void appendTo(TargetStringConcatenation it) {
			it.append("/** Appender of " + getLanguageName() + " scripts."); //$NON-NLS-1$ //$NON-NLS-2$
			it.newLine();
			it.append(" *"); //$NON-NLS-1$
			it.newLine();
			it.append(" */"); //$NON-NLS-1$
			it.newLine();
			it.append("@SuppressWarnings(\"all\")"); //$NON-NLS-1$
			it.newLine();
			it.append("public class "); //$NON-NLS-1$
			it.append(getScriptAppender().getSimpleName());
			it.append(" extends "); //$NON-NLS-1$
			it.append(getCodeElementExtractor().getAbstractAppenderImpl());
			it.append(" implements "); //$NON-NLS-1$
			it.append(getScriptBuilderInterface());
			it.append(" {"); //$NON-NLS-1$
			it.newLineIfNotEmpty();
			it.newLine();
			it.append(generateFieldsAndMethods(false, true));
			for (final StringConcatenationClient element : topElements) {
				it.append(element);
			}
			it.append("}"); //$NON-NLS-1$
			it.newLineIfNotEmpty();
			it.newLine();
		}

	};
	final JavaFileAccess javaFile = getFileAccessFactory().createJavaFile(appender, content);
	javaFile.writeTo(getSrcGen());
}
 
Example #12
Source File: ContentAssistFragment2.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
protected TypeReference getProposalProviderClass(final Grammar g) {
  String _eclipsePluginBasePackage = this._xtextGeneratorNaming.getEclipsePluginBasePackage(g);
  String _plus = (_eclipsePluginBasePackage + ".contentassist.");
  String _simpleName = GrammarUtil.getSimpleName(g);
  String _plus_1 = (_plus + _simpleName);
  String _plus_2 = (_plus_1 + "ProposalProvider");
  return new TypeReference(_plus_2);
}
 
Example #13
Source File: OutlineTreeProviderFragment2.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
protected void generateJavaOutlineTreeProvider() {
  TypeReference _outlineTreeProviderClass = this.getOutlineTreeProviderClass(this.getGrammar());
  StringConcatenationClient _client = new StringConcatenationClient() {
    @Override
    protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
      _builder.append("/**");
      _builder.newLine();
      _builder.append(" ");
      _builder.append("* Customization of the default outline structure.");
      _builder.newLine();
      _builder.append(" ");
      _builder.append("*");
      _builder.newLine();
      _builder.append(" ");
      _builder.append("* See https://www.eclipse.org/Xtext/documentation/310_eclipse_support.html#outline");
      _builder.newLine();
      _builder.append(" ");
      _builder.append("*/");
      _builder.newLine();
      _builder.append("public class ");
      String _simpleName = OutlineTreeProviderFragment2.this.getOutlineTreeProviderClass(OutlineTreeProviderFragment2.this.getGrammar()).getSimpleName();
      _builder.append(_simpleName);
      _builder.append(" extends ");
      TypeReference _typeRef = TypeReference.typeRef("org.eclipse.xtext.ui.editor.outline.impl.DefaultOutlineTreeProvider");
      _builder.append(_typeRef);
      _builder.append(" {");
      _builder.newLineIfNotEmpty();
      _builder.newLine();
      _builder.append("}");
      _builder.newLine();
    }
  };
  this.fileAccessFactory.createJavaFile(_outlineTreeProviderClass, _client).writeTo(this.getProjectConfig().getEclipsePlugin().getSrc());
}
 
Example #14
Source File: SimpleProjectWizardFragment2.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
public void generateWizardNewProjectCreationPage() {
  final TypeReference mainPageClass = TypeReference.typeRef(this.getProjectWizardCreationPageClassName());
  final JavaFileAccess file = this.fileAccessFactory.createJavaFile(mainPageClass);
  StringConcatenationClient _client = new StringConcatenationClient() {
    @Override
    protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
      _builder.append("public class ");
      String _simpleName = mainPageClass.getSimpleName();
      _builder.append(_simpleName);
      _builder.append(" extends ");
      TypeReference _typeRef = TypeReference.typeRef("org.eclipse.ui.dialogs.WizardNewProjectCreationPage");
      _builder.append(_typeRef);
      _builder.append(" {");
      _builder.newLineIfNotEmpty();
      _builder.newLine();
      _builder.append("\t");
      _builder.append("public ");
      String _simpleName_1 = mainPageClass.getSimpleName();
      _builder.append(_simpleName_1, "\t");
      _builder.append("(String pageName) {");
      _builder.newLineIfNotEmpty();
      _builder.append("\t\t");
      _builder.append("super(pageName);");
      _builder.newLine();
      _builder.append("\t");
      _builder.append("}");
      _builder.newLine();
      _builder.newLine();
      _builder.append("}");
      _builder.newLine();
    }
  };
  file.setContent(_client);
  file.writeTo(this.getProjectConfig().getEclipsePlugin().getSrc());
}
 
Example #15
Source File: GrammarNaming.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
public TypeReference getInternalParserClass(final Grammar it) {
  String _packageName = this.getParserGrammar(it).getPackageName();
  StringConcatenation _builder = new StringConcatenation();
  String _simpleName = this.getParserGrammar(it).getSimpleName();
  _builder.append(_simpleName);
  {
    boolean _isCombinedGrammar = this.isCombinedGrammar(it);
    if (_isCombinedGrammar) {
      _builder.append("Parser");
    }
  }
  return new TypeReference(_packageName, _builder.toString());
}
 
Example #16
Source File: AbstractCodeElementExtractor.java    From sarl with Apache License 2.0 5 votes vote down vote up
@Override
public ElementDescription newElementDescription(String name, EObject grammarComponent, EClassifier elementType,
		TypeReference commonType) {
	final TypeReference interfaceType = getElementBuilderInterface(name);
	final TypeReference implementationType = getElementBuilderImpl(name);
	final TypeReference customImplementationType = getElementBuilderImplCustom(name);
	final TypeReference appenderType = getElementAppenderImpl(name);
	final boolean isAnnotationInfo = findAction(grammarComponent, getAnnotationInfoFieldName()) != null;
	return new ElementDescription(name, grammarComponent,
			newTypeReference(elementType), commonType,
			interfaceType, implementationType, customImplementationType, appenderType,
			isAnnotationInfo);
}
 
Example #17
Source File: ImportNamespacesScopingFragment2.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
protected void generateXtendScopeProvider() {
  TypeReference _scopeProviderClass = this.getScopeProviderClass(this.getGrammar());
  StringConcatenationClient _client = new StringConcatenationClient() {
    @Override
    protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
      _builder.append("/**");
      _builder.newLine();
      _builder.append(" ");
      _builder.append("* This class contains custom scoping description.");
      _builder.newLine();
      _builder.append(" ");
      _builder.append("* ");
      _builder.newLine();
      _builder.append(" ");
      _builder.append("* See https://www.eclipse.org/Xtext/documentation/303_runtime_concepts.html#scoping");
      _builder.newLine();
      _builder.append(" ");
      _builder.append("* on how and when to use it.");
      _builder.newLine();
      _builder.append(" ");
      _builder.append("*/");
      _builder.newLine();
      _builder.append("class ");
      String _simpleName = ImportNamespacesScopingFragment2.this.getScopeProviderClass(ImportNamespacesScopingFragment2.this.getGrammar()).getSimpleName();
      _builder.append(_simpleName);
      _builder.append(" extends ");
      TypeReference _abstractScopeProviderClass = ImportNamespacesScopingFragment2.this.getAbstractScopeProviderClass(ImportNamespacesScopingFragment2.this.getGrammar());
      _builder.append(_abstractScopeProviderClass);
      _builder.append(" {");
      _builder.newLineIfNotEmpty();
      _builder.newLine();
      _builder.append("}");
      _builder.newLine();
    }
  };
  this.fileAccessFactory.createXtendFile(_scopeProviderClass, _client).writeTo(this.getProjectConfig().getRuntime().getSrc());
}
 
Example #18
Source File: ResourceDescriptionStrategyFragment.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
protected TypeReference getDefaultResourceDescriptionStrategyClass() {
  String _runtimeBasePackage = this._xtextGeneratorNaming.getRuntimeBasePackage(this.getGrammar());
  String _plus = (_runtimeBasePackage + ".resource.");
  String _simpleName = GrammarUtil.getSimpleName(this.getGrammar());
  String _plus_1 = (_plus + _simpleName);
  String _plus_2 = (_plus_1 + "DefaultResourceDescriptionStrategy");
  return new TypeReference(_plus_2);
}
 
Example #19
Source File: OutlineTreeProviderFragment2.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
protected void generateXtendOutlineTreeProvider() {
  TypeReference _outlineTreeProviderClass = this.getOutlineTreeProviderClass(this.getGrammar());
  StringConcatenationClient _client = new StringConcatenationClient() {
    @Override
    protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
      _builder.append("/**");
      _builder.newLine();
      _builder.append(" ");
      _builder.append("* Customization of the default outline structure.");
      _builder.newLine();
      _builder.append(" ");
      _builder.append("*");
      _builder.newLine();
      _builder.append(" ");
      _builder.append("* See https://www.eclipse.org/Xtext/documentation/310_eclipse_support.html#outline");
      _builder.newLine();
      _builder.append(" ");
      _builder.append("*/");
      _builder.newLine();
      _builder.append("class ");
      String _simpleName = OutlineTreeProviderFragment2.this.getOutlineTreeProviderClass(OutlineTreeProviderFragment2.this.getGrammar()).getSimpleName();
      _builder.append(_simpleName);
      _builder.append(" extends ");
      TypeReference _typeRef = TypeReference.typeRef("org.eclipse.xtext.ui.editor.outline.impl.DefaultOutlineTreeProvider");
      _builder.append(_typeRef);
      _builder.append(" {");
      _builder.newLineIfNotEmpty();
      _builder.newLine();
      _builder.append("}");
      _builder.newLine();
    }
  };
  this.fileAccessFactory.createXtendFile(_outlineTreeProviderClass, _client).writeTo(this.getProjectConfig().getEclipsePlugin().getSrc());
}
 
Example #20
Source File: GrammarNaming.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
public TypeReference getAntlrTokenFileProviderClass(final Grammar it) {
  String _parserPackage = this.getParserPackage(it);
  StringConcatenation _builder = new StringConcatenation();
  String _simpleName = GrammarUtil.getSimpleName(it);
  _builder.append(_simpleName);
  _builder.append("AntlrTokenFileProvider");
  return new TypeReference(_parserPackage, _builder.toString());
}
 
Example #21
Source File: XtextGeneratorTemplates.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@Deprecated
private static void addBackwardsCompabibleImportsTo(final IXtextGeneratorLanguage langConfig, final GeneratedJavaFileAccess file) {
  Set<TypeReference> _imports = langConfig.getRuntimeGenSetup().getImports();
  for (final TypeReference type : _imports) {
    file.importType(type);
  }
}
 
Example #22
Source File: AbstractCodeElementExtractor.java    From sarl with Apache License 2.0 5 votes vote down vote up
@Pure
@Override
public TypeReference getLanguageScriptInterface() {
	final AbstractRule rule = GrammarUtil.findRuleForName(getGrammar(), this.configuration.getScriptRuleName());
	final EClassifier type = getGeneratedTypeFor(rule);
	return newTypeReference(type);
}
 
Example #23
Source File: TypeReferenceTest.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testParametrizedType() {
	TypeReference ref = TypeReference.typeRef("java.util.List", TypeReference.typeRef("String"));
	Assert.assertEquals("List", ref.getSimpleName());
	Assert.assertEquals("java.util", ref.getPackageName());
	Assert.assertEquals("String", ref.getTypeArguments().get(0).getSimpleName());
}
 
Example #24
Source File: ResourceDescriptionStrategyFragment.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
protected TypeReference getSuperTypeRef() {
  TypeReference _xifexpression = null;
  if ((this.isGenerateStub() || this.isGenerateXtendStub())) {
    _xifexpression = this.getAbstractResourceDescriptionStrategyClass();
  } else {
    _xifexpression = this.getDefaultResourceDescriptionStrategyClass();
  }
  return _xifexpression;
}
 
Example #25
Source File: SerializerFragment2.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
protected TypeReference getAbstractSemanticSequencerClass(final Grammar grammar) {
  String _serializerBasePackage = this.getSerializerBasePackage(grammar);
  String _simpleName = GrammarUtil.getSimpleName(grammar);
  String _plus = ("Abstract" + _simpleName);
  String _plus_1 = (_plus + "SemanticSequencer");
  return new TypeReference(_serializerBasePackage, _plus_1);
}
 
Example #26
Source File: JUnitFragment.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
protected JavaFileAccess generateUiInjectorProvider() {
  JavaFileAccess _xblockexpression = null;
  {
    final JavaFileAccess file = this.fileAccessFactory.createJavaFile(this.uiInjectorProvider());
    StringConcatenationClient _client = new StringConcatenationClient() {
      @Override
      protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
        _builder.append("public class ");
        String _simpleName = JUnitFragment.this.uiInjectorProvider().getSimpleName();
        _builder.append(_simpleName);
        _builder.append(" implements ");
        TypeReference _iInjectorProvider = JUnitFragment.this.iInjectorProvider();
        _builder.append(_iInjectorProvider);
        _builder.append(" {");
        _builder.newLineIfNotEmpty();
        _builder.newLine();
        _builder.append("\t");
        _builder.append("@Override");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("public ");
        _builder.append(Injector.class, "\t");
        _builder.append(" getInjector() {");
        _builder.newLineIfNotEmpty();
        _builder.append("\t\t");
        _builder.append("return ");
        TypeReference _eclipsePluginActivator = JUnitFragment.this._xtextGeneratorNaming.getEclipsePluginActivator();
        _builder.append(_eclipsePluginActivator, "\t\t");
        _builder.append(".getInstance().getInjector(\"");
        String _name = JUnitFragment.this.getGrammar().getName();
        _builder.append(_name, "\t\t");
        _builder.append("\");");
        _builder.newLineIfNotEmpty();
        _builder.append("\t");
        _builder.append("}");
        _builder.newLine();
        _builder.newLine();
        _builder.append("}");
        _builder.newLine();
      }
    };
    file.setContent(_client);
    _xblockexpression = file;
  }
  return _xblockexpression;
}
 
Example #27
Source File: GeneratorFragment2.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
protected void doGenerateJavaStubFile() {
  TypeReference _generatorStub = this.getGeneratorStub(this.getGrammar());
  StringConcatenationClient _client = new StringConcatenationClient() {
    @Override
    protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
      _builder.append("/**");
      _builder.newLine();
      _builder.append(" ");
      _builder.append("* Generates code from your model files on save.");
      _builder.newLine();
      _builder.append(" ");
      _builder.append("* ");
      _builder.newLine();
      _builder.append(" ");
      _builder.append("* See https://www.eclipse.org/Xtext/documentation/303_runtime_concepts.html#code-generation");
      _builder.newLine();
      _builder.append(" ");
      _builder.append("*/");
      _builder.newLine();
      _builder.append("public class ");
      String _simpleName = GeneratorFragment2.this.getGeneratorStub(GeneratorFragment2.this.getLanguage().getGrammar()).getSimpleName();
      _builder.append(_simpleName);
      _builder.append(" extends ");
      _builder.append(AbstractGenerator.class);
      _builder.append(" {");
      _builder.newLineIfNotEmpty();
      _builder.newLine();
      _builder.append("\t");
      _builder.append("@");
      _builder.append(Override.class, "\t");
      _builder.newLineIfNotEmpty();
      _builder.append("\t");
      _builder.append("public void doGenerate(");
      _builder.append(Resource.class, "\t");
      _builder.append(" resource, ");
      _builder.append(IFileSystemAccess2.class, "\t");
      _builder.append(" fsa, ");
      _builder.append(IGeneratorContext.class, "\t");
      _builder.append(" context) {");
      _builder.newLineIfNotEmpty();
      _builder.append("//\t\tIterator<Greeting> filtered = Iterators.filter(resource.getAllContents(), Greeting.class);");
      _builder.newLine();
      _builder.append("//\t\tIterator<String> names = Iterators.transform(filtered, new Function<Greeting, String>() {");
      _builder.newLine();
      _builder.append("//");
      _builder.newLine();
      _builder.append("//\t\t\t@");
      _builder.append(Override.class);
      _builder.newLineIfNotEmpty();
      _builder.append("//\t\t\tpublic String apply(Greeting greeting) {");
      _builder.newLine();
      _builder.append("//\t\t\t\treturn greeting.getName();");
      _builder.newLine();
      _builder.append("//\t\t\t}");
      _builder.newLine();
      _builder.append("//\t\t});");
      _builder.newLine();
      _builder.append("//\t\tfsa.generateFile(\"greetings.txt\", \"People to greet: \" + IteratorExtensions.join(names, \", \"));");
      _builder.newLine();
      _builder.append("\t");
      _builder.append("}");
      _builder.newLine();
      _builder.append("}");
      _builder.newLine();
    }
  };
  this.fileAccessFactory.createJavaFile(_generatorStub, _client).writeTo(this.getProjectConfig().getRuntime().getSrc());
}
 
Example #28
Source File: XtextGeneratorNaming.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
public TypeReference getEclipsePluginGenModule(Grammar grammar) {
	return new TypeReference(getEclipsePluginBasePackage(grammar),
			"Abstract" + GrammarUtil.getSimpleName(grammar) + "UiModule");
}
 
Example #29
Source File: ResourceDescriptionStrategyFragmentTests.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
@Override
protected TypeReference getSuperTypeRef() {
  return super.getSuperTypeRef();
}
 
Example #30
Source File: LabelProviderFragment2.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
protected void generateJavaEObjectLabelProvider() {
  TypeReference _eObjectLabelProviderClass = this.getEObjectLabelProviderClass(this.getGrammar());
  StringConcatenationClient _client = new StringConcatenationClient() {
    @Override
    protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
      _builder.append("/**");
      _builder.newLine();
      _builder.append(" ");
      _builder.append("* Provides labels for EObjects.");
      _builder.newLine();
      _builder.append(" ");
      _builder.append("* ");
      _builder.newLine();
      _builder.append(" ");
      _builder.append("* See https://www.eclipse.org/Xtext/documentation/310_eclipse_support.html#label-provider");
      _builder.newLine();
      _builder.append(" ");
      _builder.append("*/");
      _builder.newLine();
      _builder.append("public class ");
      String _simpleName = LabelProviderFragment2.this.getEObjectLabelProviderClass(LabelProviderFragment2.this.getGrammar()).getSimpleName();
      _builder.append(_simpleName);
      _builder.append(" extends ");
      TypeReference _eObjectLabelProviderSuperClass = LabelProviderFragment2.this.getEObjectLabelProviderSuperClass(LabelProviderFragment2.this.getGrammar());
      _builder.append(_eObjectLabelProviderSuperClass);
      _builder.append(" {");
      _builder.newLineIfNotEmpty();
      _builder.newLine();
      _builder.append("\t");
      _builder.append("@");
      _builder.append(Inject.class, "\t");
      _builder.newLineIfNotEmpty();
      _builder.append("\t");
      _builder.append("public ");
      String _simpleName_1 = LabelProviderFragment2.this.getEObjectLabelProviderClass(LabelProviderFragment2.this.getGrammar()).getSimpleName();
      _builder.append(_simpleName_1, "\t");
      _builder.append("(");
      TypeReference _typeReference = new TypeReference("org.eclipse.emf.edit.ui.provider.AdapterFactoryLabelProvider");
      _builder.append(_typeReference, "\t");
      _builder.append(" delegate) {");
      _builder.newLineIfNotEmpty();
      _builder.append("\t\t");
      _builder.append("super(delegate);");
      _builder.newLine();
      _builder.append("\t");
      _builder.append("}");
      _builder.newLine();
      _builder.newLine();
      _builder.append("\t");
      _builder.append("// Labels and icons can be computed like this:");
      _builder.newLine();
      _builder.append("\t");
      _builder.newLine();
      _builder.append("//\tString text(Greeting ele) {");
      _builder.newLine();
      _builder.append("//\t\treturn \"A greeting to \" + ele.getName();");
      _builder.newLine();
      _builder.append("//\t}");
      _builder.newLine();
      _builder.append("//");
      _builder.newLine();
      _builder.append("//\tString image(Greeting ele) {");
      _builder.newLine();
      _builder.append("//\t\treturn \"Greeting.gif\";");
      _builder.newLine();
      _builder.append("//\t}");
      _builder.newLine();
      _builder.append("}");
      _builder.newLine();
    }
  };
  this.fileAccessFactory.createJavaFile(_eObjectLabelProviderClass, _client).writeTo(this.getProjectConfig().getEclipsePlugin().getSrc());
}