Java Code Examples for org.eclipse.xtext.xtext.generator.model.TypeReference#typeRef()

The following examples show how to use org.eclipse.xtext.xtext.generator.model.TypeReference#typeRef() . 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: GrammarAccessFragment2.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
protected StringConcatenationClient loadElementStatement(final AbstractElement ele) {
  StringConcatenationClient _client = new StringConcatenationClient() {
    @Override
    protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
      _builder.append("(");
      TypeReference _typeRef = TypeReference.typeRef(ele.eClass(), GrammarAccessFragment2.this.getLanguage());
      _builder.append(_typeRef);
      _builder.append(")");
      String _loadElementParentStatement = GrammarAccessFragment2.this.loadElementParentStatement(ele);
      _builder.append(_loadElementParentStatement);
      _builder.append(".eContents().get(");
      int _indexOf = ele.eContainer().eContents().indexOf(ele);
      _builder.append(_indexOf);
      _builder.append(")");
    }
  };
  return _client;
}
 
Example 2
Source File: SimpleProjectWizardFragment2.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
public void generateProjectInfo() {
  final TypeReference projectInfoClass = TypeReference.typeRef(this.getProjectInfoClassName());
  final JavaFileAccess file = this.fileAccessFactory.createJavaFile(projectInfoClass);
  StringConcatenationClient _client = new StringConcatenationClient() {
    @Override
    protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
      _builder.append("public class ");
      String _simpleName = projectInfoClass.getSimpleName();
      _builder.append(_simpleName);
      _builder.append(" extends ");
      TypeReference _typeRef = TypeReference.typeRef("org.eclipse.xtext.ui.wizard.DefaultProjectInfo");
      _builder.append(_typeRef);
      _builder.append(" {");
      _builder.newLineIfNotEmpty();
      _builder.newLine();
      _builder.append("}");
      _builder.newLine();
    }
  };
  file.setContent(_client);
  file.writeTo(this.getProjectConfig().getEclipsePlugin().getSrc());
}
 
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: ImportNamespacesScopingFragment2.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
protected TypeReference getDefaultScopeProviderSuperClass() {
  TypeReference _xifexpression = null;
  boolean _inheritsXbase = this._xbaseUsageDetector.inheritsXbase(this.getLanguage().getGrammar());
  if (_inheritsXbase) {
    _xifexpression = TypeReference.typeRef("org.eclipse.xtext.xbase.scoping.batch.XbaseBatchScopeProvider");
  } else {
    _xifexpression = TypeReference.typeRef(DelegatingScopeProvider.class);
  }
  return _xifexpression;
}
 
Example 5
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 6
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 7
Source File: ImportNamespacesScopingFragment2.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
protected TypeReference getDelegateScopeProvider() {
  TypeReference _xifexpression = null;
  boolean _inheritsXbase = this._xbaseUsageDetector.inheritsXbase(this.getLanguage().getGrammar());
  if (_inheritsXbase) {
    _xifexpression = TypeReference.typeRef("org.eclipse.xtext.xbase.scoping.XImportSectionNamespaceScopeProvider");
  } else {
    _xifexpression = TypeReference.typeRef(ImportedNamespaceAwareLocalScopeProvider.class);
  }
  return _xifexpression;
}
 
Example 8
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 9
Source File: Formatter2Fragment2.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
protected TypeReference getStubSuperClass() {
  final Grammar superGrammar = GrammarUtil2.getNonTerminalsSuperGrammar(this.getLanguage().getGrammar());
  if ((superGrammar != null)) {
    return this.getFormatter2Stub(superGrammar);
  } else {
    return TypeReference.typeRef(AbstractFormatter2.class);
  }
}
 
Example 10
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 11
Source File: TypeReferenceTest.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
@Test(expected = IllegalArgumentException.class)
public void testWrongNestedTypeUsage() {
	TypeReference.typeRef("java.util.Map.Entry");
}
 
Example 12
Source File: TypeReferenceTest.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
@Test
public void testJavaPath() {
	TypeReference ref = TypeReference.typeRef("org.example.MyType");
	Assert.assertEquals("org/example/MyType.java", ref.getJavaPath());
}
 
Example 13
Source File: WebIntegrationFragment.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
@Override
protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
  _builder.append("/**");
  _builder.newLine();
  _builder.append(" ");
  _builder.append("* Deploy this class into a servlet container to enable DSL-specific services.");
  _builder.newLine();
  _builder.append(" ");
  _builder.append("*/");
  _builder.newLine();
  {
    if (WebIntegrationFragment.this.useServlet3Api) {
      _builder.append("@");
      TypeReference _typeReference = new TypeReference("javax.servlet.annotation.WebServlet");
      _builder.append(_typeReference);
      _builder.append("(name = \"XtextServices\", urlPatterns = \"/xtext-service/*\")");
      _builder.newLineIfNotEmpty();
    }
  }
  _builder.append("public class ");
  String _simpleName = WebIntegrationFragment.this.getServletClass(WebIntegrationFragment.this.getGrammar()).getSimpleName();
  _builder.append(_simpleName);
  _builder.append(" extends ");
  TypeReference _typeRef = TypeReference.typeRef("org.eclipse.xtext.web.servlet.XtextServlet");
  _builder.append(_typeRef);
  _builder.append(" {");
  _builder.newLineIfNotEmpty();
  _builder.append("\t");
  _builder.newLine();
  _builder.append("\t");
  _builder.append(DisposableRegistry.class, "\t");
  _builder.append(" disposableRegistry;");
  _builder.newLineIfNotEmpty();
  _builder.append("\t");
  _builder.newLine();
  _builder.append("\t");
  _builder.append("public void init() throws ");
  TypeReference _typeRef_1 = TypeReference.typeRef("javax.servlet.ServletException");
  _builder.append(_typeRef_1, "\t");
  _builder.append(" {");
  _builder.newLineIfNotEmpty();
  _builder.append("\t\t");
  _builder.append("super.init();");
  _builder.newLine();
  _builder.append("\t\t");
  TypeReference _typeRef_2 = TypeReference.typeRef("com.google.inject.Injector");
  _builder.append(_typeRef_2, "\t\t");
  _builder.append(" injector = new ");
  TypeReference _webSetup = WebIntegrationFragment.this._xtextGeneratorNaming.getWebSetup(WebIntegrationFragment.this.getGrammar());
  _builder.append(_webSetup, "\t\t");
  _builder.append("().createInjectorAndDoEMFRegistration();");
  _builder.newLineIfNotEmpty();
  _builder.append("\t\t");
  _builder.append("this.disposableRegistry = injector.getInstance(");
  _builder.append(DisposableRegistry.class, "\t\t");
  _builder.append(".class);");
  _builder.newLineIfNotEmpty();
  _builder.append("\t");
  _builder.append("}");
  _builder.newLine();
  _builder.append("\t");
  _builder.newLine();
  _builder.append("\t");
  _builder.append("public void destroy() {");
  _builder.newLine();
  _builder.append("\t\t");
  _builder.append("if (disposableRegistry != null) {");
  _builder.newLine();
  _builder.append("\t\t\t");
  _builder.append("disposableRegistry.dispose();");
  _builder.newLine();
  _builder.append("\t\t\t");
  _builder.append("disposableRegistry = null;");
  _builder.newLine();
  _builder.append("\t\t");
  _builder.append("}");
  _builder.newLine();
  _builder.append("\t\t");
  _builder.append("super.destroy();");
  _builder.newLine();
  _builder.append("\t");
  _builder.append("}");
  _builder.newLine();
  _builder.append("\t");
  _builder.newLine();
  _builder.append("}");
  _builder.newLine();
}
 
Example 14
Source File: CodeMiningFragment.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
protected TypeReference getCodeMiningProviderSuperClass() {
  return TypeReference.typeRef("org.eclipse.xtext.ui.codemining.AbstractXtextCodeMiningProvider");
}
 
Example 15
Source File: CodeMiningFragment.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
protected TypeReference getBadLocationException() {
  return TypeReference.typeRef("org.eclipse.jface.text.BadLocationException");
}
 
Example 16
Source File: CodeMiningFragment.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
protected TypeReference getCancelIndicator() {
  return TypeReference.typeRef("org.eclipse.xtext.util.CancelIndicator");
}
 
Example 17
Source File: TypeReferenceTest.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
@Test
public void testUnderscopresAnd$02() {
	TypeReference ref = TypeReference.typeRef("$.$._$.E_$tring");
	Assert.assertEquals("$.$._$", ref.getPackageName());
	Assert.assertEquals("E_$tring", ref.getSimpleName());
}
 
Example 18
Source File: CodeMiningFragment.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
protected TypeReference getICodeMining() {
  return TypeReference.typeRef("org.eclipse.jface.text.codemining.ICodeMining");
}
 
Example 19
Source File: SimpleProjectWizardFragment2.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
public void generateNewProjectWizardInitialContents() {
  final TypeReference initialContentsClass = TypeReference.typeRef(this.getProjectWizardInitialContentsClassName());
  final XtendFileAccess file = this.fileAccessFactory.createXtendFile(initialContentsClass);
  StringConcatenationClient _client = new StringConcatenationClient() {
    @Override
    protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
      _builder.append("import com.google.inject.Inject");
      _builder.newLine();
      _builder.append("import org.eclipse.xtext.generator.IFileSystemAccess2");
      _builder.newLine();
      _builder.append("import org.eclipse.xtext.resource.FileExtensionProvider");
      _builder.newLine();
      _builder.newLine();
      _builder.append("class ");
      String _simpleName = initialContentsClass.getSimpleName();
      _builder.append(_simpleName);
      _builder.append(" {");
      _builder.newLineIfNotEmpty();
      _builder.append("\t");
      _builder.append("@Inject");
      _builder.newLine();
      _builder.append("\t");
      _builder.append("FileExtensionProvider fileExtensionProvider");
      _builder.newLine();
      _builder.newLine();
      _builder.append("\t");
      _builder.append("def generateInitialContents(IFileSystemAccess2 fsa) {");
      _builder.newLine();
      _builder.append("\t\t");
      _builder.append("fsa.generateFile(");
      _builder.newLine();
      _builder.append("\t\t\t");
      _builder.append("\"src/model/Model.\" + fileExtensionProvider.primaryFileExtension,");
      _builder.newLine();
      _builder.append("\t\t\t");
      _builder.append("\'\'");
      _builder.append("\'");
      _builder.newLine();
      _builder.append("\t\t\t");
      _builder.append("/*");
      _builder.newLine();
      _builder.append("\t\t\t ");
      _builder.append("* This is an example model");
      _builder.newLine();
      _builder.append("\t\t\t ");
      _builder.append("*/");
      _builder.newLine();
      _builder.append("\t\t\t");
      _builder.append("Hello Xtext!");
      _builder.newLine();
      _builder.append("\t\t\t");
      _builder.append("\'\'");
      _builder.append("\'");
      _builder.newLine();
      _builder.append("\t\t\t");
      _builder.append(")");
      _builder.newLine();
      _builder.append("\t");
      _builder.append("}");
      _builder.newLine();
      _builder.append("}");
      _builder.newLine();
    }
  };
  file.setContent(_client);
  file.writeTo(this.getProjectConfig().getEclipsePlugin().getSrc());
}
 
Example 20
Source File: XtextAntlrGeneratorFragment2.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
protected void addIdeBindingsAndImports() {
  @Extension
  final ContentAssistGrammarNaming naming = this.contentAssistNaming;
  ManifestAccess _manifest = this.getProjectConfig().getGenericIde().getManifest();
  boolean _tripleNotEquals = (_manifest != null);
  if (_tripleNotEquals) {
    ManifestAccess _manifest_1 = this.getProjectConfig().getGenericIde().getManifest();
    final Procedure1<ManifestAccess> _function = (ManifestAccess it) -> {
      Set<String> _exportedPackages = it.getExportedPackages();
      String _packageName = naming.getLexerClass(this.getGrammar()).getPackageName();
      String _packageName_1 = naming.getParserClass(this.getGrammar()).getPackageName();
      String _packageName_2 = naming.getInternalParserClass(this.getGrammar()).getPackageName();
      Iterables.<String>addAll(_exportedPackages, Collections.<String>unmodifiableList(CollectionLiterals.<String>newArrayList(_packageName, _packageName_1, _packageName_2)));
      Set<String> _requiredBundles = it.getRequiredBundles();
      _requiredBundles.add("org.antlr.runtime;bundle-version=\"[3.2.0,3.2.1)\"");
    };
    ObjectExtensions.<ManifestAccess>operator_doubleArrow(_manifest_1, _function);
  }
  GuiceModuleAccess.BindingFactory _bindingFactory = new GuiceModuleAccess.BindingFactory();
  StringConcatenationClient _client = new StringConcatenationClient() {
    @Override
    protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
      _builder.append("binder.bind(");
      TypeReference _lexerSuperClass = naming.getLexerSuperClass(XtextAntlrGeneratorFragment2.this.getGrammar());
      _builder.append(_lexerSuperClass);
      _builder.append(".class)");
      _builder.newLineIfNotEmpty();
      _builder.append("\t");
      _builder.append(".annotatedWith(");
      _builder.append(Names.class, "\t");
      _builder.append(".named(");
      TypeReference _typeRef = TypeReference.typeRef("org.eclipse.xtext.ide.LexerIdeBindings");
      _builder.append(_typeRef, "\t");
      _builder.append(".CONTENT_ASSIST))");
      _builder.newLineIfNotEmpty();
      _builder.append("\t");
      _builder.append(".to(");
      TypeReference _lexerClass = naming.getLexerClass(XtextAntlrGeneratorFragment2.this.getGrammar());
      _builder.append(_lexerClass, "\t");
      _builder.append(".class);");
      _builder.newLineIfNotEmpty();
    }
  };
  final GuiceModuleAccess.BindingFactory ideBindings = _bindingFactory.addConfiguredBinding("ContentAssistLexer", _client).addTypeToType(TypeReference.typeRef("org.eclipse.xtext.ide.editor.contentassist.antlr.IContentAssistParser"), naming.getParserClass(this.getGrammar())).addTypeToType(
    TypeReference.typeRef("org.eclipse.xtext.ide.editor.contentassist.IProposalConflictHelper"), 
    TypeReference.typeRef("org.eclipse.xtext.ide.editor.contentassist.antlr.AntlrProposalConflictHelper"));
  if (this.partialParsing) {
    ideBindings.addTypeToType(
      TypeReference.typeRef("org.eclipse.xtext.ide.editor.contentassist.antlr.ContentAssistContextFactory"), 
      TypeReference.typeRef("org.eclipse.xtext.ide.editor.contentassist.antlr.PartialContentAssistContextFactory"));
  }
  boolean _hasSyntheticTerminalRule = this.hasSyntheticTerminalRule();
  if (_hasSyntheticTerminalRule) {
    ideBindings.addTypeToType(
      TypeReference.typeRef("org.eclipse.xtext.ide.editor.contentassist.CompletionPrefixProvider"), 
      TypeReference.typeRef("org.eclipse.xtext.ide.editor.contentassist.IndentationAwareCompletionPrefixProvider"));
  }
  ideBindings.contributeTo(this.getLanguage().getIdeGenModule());
}