use of org.eclipse.xtext.xtext.generator.model.TypeReference in project xtext-core by eclipse.
the class CodeMiningFragment method generateXtendCodeMiningProvider.
protected void generateXtendCodeMiningProvider() {
TypeReference _typeRef = TypeReference.typeRef(this.getCodeMiningProviderClass().toString());
StringConcatenationClient _client = new StringConcatenationClient() {
@Override
protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
_builder.append("class ");
String _simpleName = CodeMiningFragment.this.getCodeMiningProviderClass().getSimpleName();
_builder.append(_simpleName);
_builder.append(" extends ");
TypeReference _codeMiningProviderSuperClass = CodeMiningFragment.this.getCodeMiningProviderSuperClass();
_builder.append(_codeMiningProviderSuperClass);
_builder.append(" {");
_builder.newLineIfNotEmpty();
_builder.append("\t");
_builder.append("override void createCodeMinings(");
TypeReference _iDocument = CodeMiningFragment.this.getIDocument();
_builder.append(_iDocument, "\t");
_builder.append(" document, ");
TypeReference _xtextResource = CodeMiningFragment.this.getXtextResource();
_builder.append(_xtextResource, "\t");
_builder.append(" resource, ");
TypeReference _cancelIndicator = CodeMiningFragment.this.getCancelIndicator();
_builder.append(_cancelIndicator, "\t");
_builder.append(" indicator,");
_builder.newLineIfNotEmpty();
_builder.append("\t\t");
TypeReference _iAcceptor = CodeMiningFragment.this.getIAcceptor();
_builder.append(_iAcceptor, "\t\t");
_builder.append("<? super ");
TypeReference _iCodeMining = CodeMiningFragment.this.getICodeMining();
_builder.append(_iCodeMining, "\t\t");
_builder.append("> acceptor) throws ");
TypeReference _badLocationException = CodeMiningFragment.this.getBadLocationException();
_builder.append(_badLocationException, "\t\t");
_builder.append(" {");
_builder.newLineIfNotEmpty();
_builder.append("\t\t");
_builder.newLine();
_builder.append("\t\t");
_builder.append("// TODO: implement me");
_builder.newLine();
_builder.append("\t\t");
_builder.append("// use acceptor.accept(super.createNewLineHeaderCodeMining(...)) to add a new code mining to the final list");
_builder.newLine();
_builder.append("\t\t");
_builder.newLine();
_builder.append("\t\t");
_builder.append("// example:");
_builder.newLine();
_builder.append("\t\t");
_builder.append("// acceptor.accept(createNewLineHeaderCodeMining(1, document, \"Header annotation\"))");
_builder.newLine();
_builder.append("\t");
_builder.append("}");
_builder.newLine();
_builder.append("}");
_builder.newLine();
}
};
this.fileAccessFactory.createXtendFile(_typeRef, _client).writeTo(this.getProjectConfig().getEclipsePlugin().getSrc());
}
use of org.eclipse.xtext.xtext.generator.model.TypeReference in project xtext-core by eclipse.
the class IdeaPluginGenerator method compileElementTypeProvider.
public JavaFileAccess compileElementTypeProvider(final Grammar grammar) {
final JavaFileAccess file = this.fileAccessFactory.createJavaFile(this._ideaPluginClassNames.getElementTypeProvider(grammar));
file.importType(TypeReference.typeRef("org.eclipse.xtext.idea.lang.IElementTypeProvider"));
file.importType(TypeReference.typeRef("org.eclipse.xtext.psi.stubs.XtextFileElementType"));
file.importType(TypeReference.typeRef("org.eclipse.xtext.psi.stubs.XtextFileStub"));
file.importType(TypeReference.typeRef("org.eclipse.xtext.psi.tree.IGrammarAwareElementType"));
file.importType(TypeReference.typeRef("com.intellij.psi.tree.IFileElementType"));
StringConcatenationClient _client = new StringConcatenationClient() {
@Override
protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
_builder.append("public class ");
String _simpleName = IdeaPluginGenerator.this._ideaPluginClassNames.getElementTypeProvider(grammar).getSimpleName();
_builder.append(_simpleName);
_builder.append(" implements IElementTypeProvider {");
_builder.newLineIfNotEmpty();
_builder.newLine();
_builder.append("\t");
_builder.append("public static final IFileElementType FILE_TYPE = new XtextFileElementType<XtextFileStub<");
TypeReference _fileImpl = IdeaPluginGenerator.this._ideaPluginClassNames.getFileImpl(grammar);
_builder.append(_fileImpl, "\t");
_builder.append(">>(");
TypeReference _ideaLanguage = IdeaPluginGenerator.this._ideaPluginClassNames.getIdeaLanguage(grammar);
_builder.append(_ideaLanguage, "\t");
_builder.append(".INSTANCE);");
_builder.newLineIfNotEmpty();
_builder.newLine();
_builder.append("\t");
_builder.append("private static final ");
_builder.append(Map.class, "\t");
_builder.append("<");
_builder.append(EObject.class, "\t");
_builder.append(", IGrammarAwareElementType> GRAMMAR_ELEMENT_TYPE = new ");
_builder.append(HashMap.class, "\t");
_builder.append("<");
_builder.append(EObject.class, "\t");
_builder.append(", IGrammarAwareElementType>();");
_builder.newLineIfNotEmpty();
_builder.newLine();
_builder.append("\t");
_builder.append("private static IGrammarAwareElementType associate(IGrammarAwareElementType grammarAwareElementType) {");
_builder.newLine();
_builder.append("\t\t");
_builder.append("GRAMMAR_ELEMENT_TYPE.put(grammarAwareElementType.getGrammarElement(), grammarAwareElementType);");
_builder.newLine();
_builder.append("\t\t");
_builder.append("return grammarAwareElementType;");
_builder.newLine();
_builder.append("\t");
_builder.append("}");
_builder.newLine();
_builder.newLine();
_builder.append("\t");
_builder.append("private static final ");
TypeReference _grammarAccess = IdeaPluginGenerator.this._grammarAccessExtensions.getGrammarAccess(grammar);
_builder.append(_grammarAccess, "\t");
_builder.append(" GRAMMAR_ACCESS = ");
TypeReference _ideaLanguage_1 = IdeaPluginGenerator.this._ideaPluginClassNames.getIdeaLanguage(grammar);
_builder.append(_ideaLanguage_1, "\t");
_builder.append(".INSTANCE.getInstance(");
TypeReference _grammarAccess_1 = IdeaPluginGenerator.this._grammarAccessExtensions.getGrammarAccess(grammar);
_builder.append(_grammarAccess_1, "\t");
_builder.append(".class);");
_builder.newLineIfNotEmpty();
{
Iterable<AbstractRule> _allNonTerminalRules = IdeaPluginGenerator.this._ideaPluginExtension.getAllNonTerminalRules(grammar);
for (final AbstractRule rule : _allNonTerminalRules) {
_builder.newLine();
_builder.append("\t");
_builder.append("private static class ");
String _grammarElementIdentifier = IdeaPluginGenerator.this._grammarAccessExtensions.grammarElementIdentifier(rule);
_builder.append(_grammarElementIdentifier, "\t");
_builder.append("Factory {");
_builder.newLineIfNotEmpty();
_builder.append("\t");
_builder.append("\t");
_builder.append("public static IGrammarAwareElementType create");
String _grammarElementIdentifier_1 = IdeaPluginGenerator.this._grammarAccessExtensions.grammarElementIdentifier(rule);
_builder.append(_grammarElementIdentifier_1, "\t\t");
_builder.append("ElementType() {");
_builder.newLineIfNotEmpty();
_builder.append("\t");
_builder.append("\t\t");
_builder.append("return new IGrammarAwareElementType(\"");
String _grammarElementIdentifier_2 = IdeaPluginGenerator.this._grammarAccessExtensions.grammarElementIdentifier(rule);
_builder.append(_grammarElementIdentifier_2, "\t\t\t");
_builder.append("_ELEMENT_TYPE\", ");
TypeReference _ideaLanguage_2 = IdeaPluginGenerator.this._ideaPluginClassNames.getIdeaLanguage(grammar);
_builder.append(_ideaLanguage_2, "\t\t\t");
_builder.append(".INSTANCE, GRAMMAR_ACCESS.");
String _gaRuleAccessor = IdeaPluginGenerator.this._grammarAccessExtensions.gaRuleAccessor(rule);
_builder.append(_gaRuleAccessor, "\t\t\t");
_builder.append(");");
_builder.newLineIfNotEmpty();
_builder.append("\t");
_builder.append("\t");
_builder.append("}");
_builder.newLine();
{
Iterable<AbstractElement> _iterable = IteratorExtensions.<AbstractElement>toIterable(Iterators.<AbstractElement>filter(rule.eAllContents(), AbstractElement.class));
for (final AbstractElement element : _iterable) {
_builder.append("\t");
_builder.append("\t");
_builder.append("public static IGrammarAwareElementType create");
String _grammarElementIdentifier_3 = IdeaPluginGenerator.this._grammarAccessExtensions.grammarElementIdentifier(element);
_builder.append(_grammarElementIdentifier_3, "\t\t");
_builder.append("ElementType() {");
_builder.newLineIfNotEmpty();
_builder.append("\t");
_builder.append("\t");
_builder.append("\t");
_builder.append("return new IGrammarAwareElementType(\"");
String _grammarElementIdentifier_4 = IdeaPluginGenerator.this._grammarAccessExtensions.grammarElementIdentifier(element);
_builder.append(_grammarElementIdentifier_4, "\t\t\t");
_builder.append("_ELEMENT_TYPE\", ");
TypeReference _ideaLanguage_3 = IdeaPluginGenerator.this._ideaPluginClassNames.getIdeaLanguage(grammar);
_builder.append(_ideaLanguage_3, "\t\t\t");
_builder.append(".INSTANCE, GRAMMAR_ACCESS.");
String _gaElementsAccessor = IdeaPluginGenerator.this._grammarAccessExtensions.gaElementsAccessor(rule);
_builder.append(_gaElementsAccessor, "\t\t\t");
_builder.append(".");
String _gaElementAccessor = IdeaPluginGenerator.this._grammarAccessExtensions.gaElementAccessor(element);
_builder.append(_gaElementAccessor, "\t\t\t");
_builder.append(");");
_builder.newLineIfNotEmpty();
_builder.append("\t");
_builder.append("\t");
_builder.append("}");
_builder.newLine();
}
}
_builder.append("\t");
_builder.append("}");
_builder.newLine();
_builder.newLine();
_builder.append("\t");
_builder.append("public static final IGrammarAwareElementType ");
String _grammarElementIdentifier_5 = IdeaPluginGenerator.this._grammarAccessExtensions.grammarElementIdentifier(rule);
_builder.append(_grammarElementIdentifier_5, "\t");
_builder.append("_ELEMENT_TYPE = associate(");
String _grammarElementIdentifier_6 = IdeaPluginGenerator.this._grammarAccessExtensions.grammarElementIdentifier(rule);
_builder.append(_grammarElementIdentifier_6, "\t");
_builder.append("Factory.create");
String _grammarElementIdentifier_7 = IdeaPluginGenerator.this._grammarAccessExtensions.grammarElementIdentifier(rule);
_builder.append(_grammarElementIdentifier_7, "\t");
_builder.append("ElementType());");
_builder.newLineIfNotEmpty();
{
Iterable<AbstractElement> _iterable_1 = IteratorExtensions.<AbstractElement>toIterable(Iterators.<AbstractElement>filter(rule.eAllContents(), AbstractElement.class));
for (final AbstractElement element_1 : _iterable_1) {
_builder.newLine();
_builder.append("\t");
_builder.append("public static final IGrammarAwareElementType ");
String _grammarElementIdentifier_8 = IdeaPluginGenerator.this._grammarAccessExtensions.grammarElementIdentifier(element_1);
_builder.append(_grammarElementIdentifier_8, "\t");
_builder.append("_ELEMENT_TYPE = associate(");
String _grammarElementIdentifier_9 = IdeaPluginGenerator.this._grammarAccessExtensions.grammarElementIdentifier(rule);
_builder.append(_grammarElementIdentifier_9, "\t");
_builder.append("Factory.create");
String _grammarElementIdentifier_10 = IdeaPluginGenerator.this._grammarAccessExtensions.grammarElementIdentifier(element_1);
_builder.append(_grammarElementIdentifier_10, "\t");
_builder.append("ElementType());");
_builder.newLineIfNotEmpty();
}
}
}
}
_builder.newLine();
_builder.append("\t");
_builder.append("@Override");
_builder.newLine();
_builder.append("\t");
_builder.append("public IFileElementType getFileType() {");
_builder.newLine();
_builder.append("\t\t");
_builder.append("return FILE_TYPE;");
_builder.newLine();
_builder.append("\t");
_builder.append("}");
_builder.newLine();
_builder.newLine();
_builder.append("\t");
_builder.append("@Override");
_builder.newLine();
_builder.append("\t");
_builder.append("public IGrammarAwareElementType findElementType(");
_builder.append(EObject.class, "\t");
_builder.append(" grammarElement) {");
_builder.newLineIfNotEmpty();
_builder.append("\t\t");
_builder.append("return GRAMMAR_ELEMENT_TYPE.get(grammarElement);");
_builder.newLine();
_builder.append("\t");
_builder.append("}");
_builder.newLine();
{
Iterable<AbstractRule> _allNonTerminalRules_1 = IdeaPluginGenerator.this._ideaPluginExtension.getAllNonTerminalRules(grammar);
for (final AbstractRule rule_1 : _allNonTerminalRules_1) {
_builder.append("\t");
_builder.newLine();
_builder.append("\t");
_builder.append("public IGrammarAwareElementType get");
String _grammarElementIdentifier_11 = IdeaPluginGenerator.this._grammarAccessExtensions.grammarElementIdentifier(rule_1);
_builder.append(_grammarElementIdentifier_11, "\t");
_builder.append("ElementType() {");
_builder.newLineIfNotEmpty();
_builder.append("\t");
_builder.append("\t");
_builder.append("return ");
String _grammarElementIdentifier_12 = IdeaPluginGenerator.this._grammarAccessExtensions.grammarElementIdentifier(rule_1);
_builder.append(_grammarElementIdentifier_12, "\t\t");
_builder.append("_ELEMENT_TYPE;");
_builder.newLineIfNotEmpty();
_builder.append("\t");
_builder.append("}");
_builder.newLine();
{
Iterable<AbstractElement> _iterable_2 = IteratorExtensions.<AbstractElement>toIterable(Iterators.<AbstractElement>filter(rule_1.eAllContents(), AbstractElement.class));
for (final AbstractElement element_2 : _iterable_2) {
_builder.append("\t");
_builder.newLine();
_builder.append("\t");
_builder.append("public IGrammarAwareElementType get");
String _grammarElementIdentifier_13 = IdeaPluginGenerator.this._grammarAccessExtensions.grammarElementIdentifier(element_2);
_builder.append(_grammarElementIdentifier_13, "\t");
_builder.append("ElementType() {");
_builder.newLineIfNotEmpty();
_builder.append("\t");
_builder.append("\t");
_builder.append("return ");
String _grammarElementIdentifier_14 = IdeaPluginGenerator.this._grammarAccessExtensions.grammarElementIdentifier(element_2);
_builder.append(_grammarElementIdentifier_14, "\t\t");
_builder.append("_ELEMENT_TYPE;");
_builder.newLineIfNotEmpty();
_builder.append("\t");
_builder.append("}");
_builder.newLine();
}
}
}
}
_builder.newLine();
_builder.append("}");
_builder.newLine();
}
};
file.setContent(_client);
return file;
}
use of org.eclipse.xtext.xtext.generator.model.TypeReference in project xtext-core by eclipse.
the class IdeaPluginGenerator method compileSemanticHighlightVisitor.
public JavaFileAccess compileSemanticHighlightVisitor(final Grammar grammar) {
TypeReference _semanticHighlightVisitor = this._ideaPluginClassNames.getSemanticHighlightVisitor(grammar);
StringConcatenationClient _client = new StringConcatenationClient() {
@Override
protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
_builder.append("public class ");
String _simpleName = IdeaPluginGenerator.this._ideaPluginClassNames.getSemanticHighlightVisitor(grammar).getSimpleName();
_builder.append(_simpleName);
_builder.append(" extends ");
TypeReference _typeRef = TypeReference.typeRef("org.eclipse.xtext.idea.highlighting.SemanticHighlightVisitor");
_builder.append(_typeRef);
_builder.append(" {");
_builder.newLineIfNotEmpty();
_builder.append("\t");
_builder.append("public ");
String _simpleName_1 = IdeaPluginGenerator.this._ideaPluginClassNames.getSemanticHighlightVisitor(grammar).getSimpleName();
_builder.append(_simpleName_1, "\t");
_builder.append("() {");
_builder.newLineIfNotEmpty();
_builder.append("\t\t");
TypeReference _ideaLanguage = IdeaPluginGenerator.this._ideaPluginClassNames.getIdeaLanguage(grammar);
_builder.append(_ideaLanguage, "\t\t");
_builder.append(".INSTANCE.injectMembers(this);");
_builder.newLineIfNotEmpty();
_builder.append("\t");
_builder.append("}");
_builder.newLine();
_builder.append("}");
_builder.newLine();
}
};
return this.fileAccessFactory.createJavaFile(_semanticHighlightVisitor, _client);
}
use of org.eclipse.xtext.xtext.generator.model.TypeReference in project xtext-core by eclipse.
the class IdeaPluginGenerator method compileExtensionFactory.
public JavaFileAccess compileExtensionFactory(final Grammar grammar) {
TypeReference _extensionFactory = this._ideaPluginClassNames.getExtensionFactory(grammar);
StringConcatenationClient _client = new StringConcatenationClient() {
@Override
protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
_builder.append("public class ");
String _simpleName = IdeaPluginGenerator.this._ideaPluginClassNames.getExtensionFactory(grammar).getSimpleName();
_builder.append(_simpleName);
_builder.append(" implements ");
TypeReference _typeRef = TypeReference.typeRef("com.intellij.openapi.extensions.ExtensionFactory");
_builder.append(_typeRef);
_builder.append(" {");
_builder.newLineIfNotEmpty();
_builder.append("\t");
_builder.append("@Override");
_builder.newLine();
_builder.append("\t");
_builder.append("public Object createInstance(");
_builder.append(String.class, "\t");
_builder.append(" factoryArgument, ");
_builder.append(String.class, "\t");
_builder.append(" implementationClass) {");
_builder.newLineIfNotEmpty();
_builder.append("\t\t");
_builder.append(Class.class, "\t\t");
_builder.append("<?> clazz;");
_builder.newLineIfNotEmpty();
_builder.append("\t\t");
_builder.append("try {");
_builder.newLine();
_builder.append("\t\t\t");
_builder.append("clazz = ");
_builder.append(Class.class, "\t\t\t");
_builder.append(".forName(implementationClass);");
_builder.newLineIfNotEmpty();
_builder.append("\t\t");
_builder.append("} catch (");
_builder.append(ClassNotFoundException.class, "\t\t");
_builder.append(" e) {");
_builder.newLineIfNotEmpty();
_builder.append("\t\t\t");
_builder.append("throw new ");
_builder.append(IllegalArgumentException.class, "\t\t\t");
_builder.append("(\"Couldn\'t load \"+implementationClass, e);");
_builder.newLineIfNotEmpty();
_builder.append("\t\t");
_builder.append("}");
_builder.newLine();
_builder.append("\t\t");
_builder.append("return ");
TypeReference _ideaLanguage = IdeaPluginGenerator.this._ideaPluginClassNames.getIdeaLanguage(grammar);
_builder.append(_ideaLanguage, "\t\t");
_builder.append(".INSTANCE.<Object> getInstance(clazz);");
_builder.newLineIfNotEmpty();
_builder.append("\t");
_builder.append("}");
_builder.newLine();
_builder.append("}");
_builder.newLine();
}
};
return this.fileAccessFactory.createJavaFile(_extensionFactory, _client);
}
use of org.eclipse.xtext.xtext.generator.model.TypeReference in project xtext-core by eclipse.
the class IdeaPluginGenerator method compileBaseColorSettingsPage.
public JavaFileAccess compileBaseColorSettingsPage(final Grammar grammar) {
TypeReference _baseColorSettingsPage = this._ideaPluginClassNames.baseColorSettingsPage(grammar);
StringConcatenationClient _client = new StringConcatenationClient() {
@Override
protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
_builder.append("public class ");
String _simpleName = IdeaPluginGenerator.this._ideaPluginClassNames.baseColorSettingsPage(grammar).getSimpleName();
_builder.append(_simpleName);
_builder.append(" extends ");
TypeReference _typeRef = TypeReference.typeRef("org.eclipse.xtext.idea.highlighting.AbstractColorSettingsPage");
_builder.append(_typeRef);
_builder.append(" {");
_builder.newLineIfNotEmpty();
_builder.append("\t");
_builder.newLine();
_builder.append("\t");
_builder.append("public ");
String _simpleName_1 = IdeaPluginGenerator.this._ideaPluginClassNames.baseColorSettingsPage(grammar).getSimpleName();
_builder.append(_simpleName_1, "\t");
_builder.append("() {");
_builder.newLineIfNotEmpty();
_builder.append("\t\t");
TypeReference _ideaLanguage = IdeaPluginGenerator.this._ideaPluginClassNames.getIdeaLanguage(grammar);
_builder.append(_ideaLanguage, "\t\t");
_builder.append(".INSTANCE.injectMembers(this);");
_builder.newLineIfNotEmpty();
_builder.append("\t");
_builder.append("}");
_builder.newLine();
_builder.newLine();
_builder.append("\t");
_builder.append("@Override");
_builder.newLine();
_builder.append("\t");
_builder.append("public String getDisplayName() {");
_builder.newLine();
_builder.append("\t\t");
_builder.append("return ");
TypeReference _ideaLanguage_1 = IdeaPluginGenerator.this._ideaPluginClassNames.getIdeaLanguage(grammar);
_builder.append(_ideaLanguage_1, "\t\t");
_builder.append(".INSTANCE.getDisplayName();");
_builder.newLineIfNotEmpty();
_builder.append("\t");
_builder.append("}");
_builder.newLine();
_builder.append("}");
_builder.newLine();
}
};
return this.fileAccessFactory.createJavaFile(_baseColorSettingsPage, _client);
}
Aggregations