use of org.eclipse.xtext.AbstractElement in project xtext-core by eclipse.
the class AbstractParseTreeConstructor method initStream.
/**
* @since 2.0
*/
protected void initStream(AbstractToken token, WsMergerStream out) {
AbstractElement rootMostElement = null;
if (!token.getTokensForSemanticChildren().isEmpty()) {
for (AbstractToken t : Lists.reverse(token.getTokensForSemanticChildren())) if (t.getGrammarElement() != null) {
rootMostElement = t.getGrammarElement();
break;
}
} else if (token.getGrammarElement() != null) {
rootMostElement = token.getGrammarElement();
}
if (rootMostElement != null) {
ParserRule rootRule = GrammarUtil.containingParserRule(rootMostElement);
out.init(rootRule);
}
}
use of org.eclipse.xtext.AbstractElement 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.AbstractElement in project xtext-core by eclipse.
the class IdeaPluginGenerator method compileParserDefinition.
public JavaFileAccess compileParserDefinition(final Grammar grammar) {
final Function1<AbstractRule, Boolean> _function = (AbstractRule it) -> {
return Boolean.valueOf(GrammarUtil.isEObjectRule(it));
};
final Iterable<AbstractRule> EObjectRules = IterableExtensions.<AbstractRule>filter(GrammarUtil.allRules(grammar), _function);
TypeReference _parserDefinition = this._ideaPluginClassNames.getParserDefinition(grammar);
StringConcatenationClient _client = new StringConcatenationClient() {
@Override
protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
_builder.append("public class ");
String _simpleName = IdeaPluginGenerator.this._ideaPluginClassNames.getParserDefinition(grammar).getSimpleName();
_builder.append(_simpleName);
_builder.append(" extends ");
TypeReference _superParserDefinition = IdeaPluginGenerator.this._ideaPluginClassNames.getSuperParserDefinition(grammar);
_builder.append(_superParserDefinition);
_builder.append(" {");
_builder.newLineIfNotEmpty();
{
boolean _isEmpty = IterableExtensions.isEmpty(EObjectRules);
boolean _not = (!_isEmpty);
if (_not) {
_builder.newLine();
_builder.append("\t");
_builder.append("@");
_builder.append(Inject.class, "\t");
_builder.append(" ");
_builder.newLineIfNotEmpty();
_builder.append("\t");
_builder.append("private ");
TypeReference _elementTypeProvider = IdeaPluginGenerator.this._ideaPluginClassNames.getElementTypeProvider(grammar);
_builder.append(_elementTypeProvider, "\t");
_builder.append(" elementTypeProvider;");
_builder.newLineIfNotEmpty();
}
}
_builder.newLine();
_builder.append("\t");
_builder.append("@Override");
_builder.newLine();
_builder.append("\t");
_builder.append("public ");
TypeReference _typeRef = TypeReference.typeRef("com.intellij.psi.PsiFile");
_builder.append(_typeRef, "\t");
_builder.append(" createFile(");
TypeReference _typeRef_1 = TypeReference.typeRef("com.intellij.psi.FileViewProvider");
_builder.append(_typeRef_1, "\t");
_builder.append(" viewProvider) {");
_builder.newLineIfNotEmpty();
_builder.append("\t\t");
_builder.append("return new ");
TypeReference _fileImpl = IdeaPluginGenerator.this._ideaPluginClassNames.getFileImpl(grammar);
_builder.append(_fileImpl, "\t\t");
_builder.append("(viewProvider);");
_builder.newLineIfNotEmpty();
_builder.append("\t");
_builder.append("}");
_builder.newLine();
{
boolean _isEmpty_1 = IterableExtensions.isEmpty(EObjectRules);
boolean _not_1 = (!_isEmpty_1);
if (_not_1) {
_builder.append("\t");
_builder.newLine();
_builder.append("\t");
_builder.append("@Override");
_builder.newLine();
_builder.append("\t");
_builder.append("@SuppressWarnings(\"rawtypes\")");
_builder.newLine();
_builder.append("\t");
_builder.append("public ");
TypeReference _typeRef_2 = TypeReference.typeRef("com.intellij.psi.PsiElement");
_builder.append(_typeRef_2, "\t");
_builder.append(" createElement(");
TypeReference _typeRef_3 = TypeReference.typeRef("com.intellij.lang.ASTNode");
_builder.append(_typeRef_3, "\t");
_builder.append(" node) {");
_builder.newLineIfNotEmpty();
_builder.append("\t");
_builder.append("\t");
_builder.append("Boolean hasSemanticElement = node.getUserData(");
TypeReference _typeRef_4 = TypeReference.typeRef("org.eclipse.xtext.idea.nodemodel.IASTNodeAwareNodeModelBuilder");
_builder.append(_typeRef_4, "\t\t");
_builder.append(".HAS_SEMANTIC_ELEMENT_KEY);");
_builder.newLineIfNotEmpty();
_builder.append("\t");
_builder.append("\t");
_builder.append("if (hasSemanticElement != null && hasSemanticElement) {");
_builder.newLine();
_builder.append("\t");
_builder.append("\t\t");
TypeReference _typeRef_5 = TypeReference.typeRef("com.intellij.psi.tree.IElementType");
_builder.append(_typeRef_5, "\t\t\t");
_builder.append(" elementType = node.getElementType();");
_builder.newLineIfNotEmpty();
{
for (final AbstractRule rule : EObjectRules) {
_builder.append("\t");
_builder.append("\t\t");
_builder.append("if (elementType == elementTypeProvider.get");
String _grammarElementIdentifier = IdeaPluginGenerator.this._grammarAccessExtensions.grammarElementIdentifier(rule);
_builder.append(_grammarElementIdentifier, "\t\t\t");
_builder.append("ElementType()) {");
_builder.newLineIfNotEmpty();
{
boolean _isNamed = IdeaPluginGenerator.this.isNamed(rule);
if (_isNamed) {
_builder.append("\t");
_builder.append("\t\t");
_builder.append("\t");
_builder.append("return new ");
TypeReference _typeRef_6 = TypeReference.typeRef("org.eclipse.xtext.psi.impl.PsiNamedEObjectImpl");
_builder.append(_typeRef_6, "\t\t\t\t");
_builder.append("(node) {};");
_builder.newLineIfNotEmpty();
} else {
_builder.append("\t");
_builder.append("\t\t");
_builder.append("\t");
_builder.append("return new ");
TypeReference _typeRef_7 = TypeReference.typeRef("org.eclipse.xtext.psi.impl.PsiEObjectImpl");
_builder.append(_typeRef_7, "\t\t\t\t");
_builder.append("(node) {};");
_builder.newLineIfNotEmpty();
}
}
_builder.append("\t");
_builder.append("\t\t");
_builder.append("}");
_builder.newLine();
{
Iterable<AbstractElement> _eObjectElements = IdeaPluginGenerator.this.getEObjectElements(rule);
for (final AbstractElement element : _eObjectElements) {
_builder.append("\t");
_builder.append("\t\t");
_builder.append("if (elementType == elementTypeProvider.get");
String _grammarElementIdentifier_1 = IdeaPluginGenerator.this._grammarAccessExtensions.grammarElementIdentifier(element);
_builder.append(_grammarElementIdentifier_1, "\t\t\t");
_builder.append("ElementType()) {");
_builder.newLineIfNotEmpty();
{
boolean _isNamed_1 = IdeaPluginGenerator.this.isNamed(element);
if (_isNamed_1) {
_builder.append("\t");
_builder.append("\t\t");
_builder.append("\t");
_builder.append("return new ");
TypeReference _typeRef_8 = TypeReference.typeRef("org.eclipse.xtext.psi.impl.PsiNamedEObjectImpl");
_builder.append(_typeRef_8, "\t\t\t\t");
_builder.append("(node) {};");
_builder.newLineIfNotEmpty();
} else {
_builder.append("\t");
_builder.append("\t\t");
_builder.append("\t");
_builder.append("return new ");
TypeReference _typeRef_9 = TypeReference.typeRef("org.eclipse.xtext.psi.impl.PsiEObjectImpl");
_builder.append(_typeRef_9, "\t\t\t\t");
_builder.append("(node) {};");
_builder.newLineIfNotEmpty();
}
}
_builder.append("\t");
_builder.append("\t\t");
_builder.append("}");
_builder.newLine();
}
}
}
}
_builder.append("\t");
_builder.append("\t\t");
_builder.append("throw new ");
TypeReference _typeRef_10 = TypeReference.typeRef("java.lang.IllegalStateException");
_builder.append(_typeRef_10, "\t\t\t");
_builder.append("(\"Unexpected element type: \" + elementType);");
_builder.newLineIfNotEmpty();
_builder.append("\t");
_builder.append("\t");
_builder.append("}");
_builder.newLine();
_builder.append("\t");
_builder.append("\t");
_builder.append("return super.createElement(node);");
_builder.newLine();
_builder.append("\t");
_builder.append("}");
_builder.newLine();
}
}
_builder.newLine();
_builder.append("}");
_builder.newLine();
}
};
return this.fileAccessFactory.createJavaFile(_parserDefinition, _client);
}
use of org.eclipse.xtext.AbstractElement in project xtext-core by eclipse.
the class AbstractAntlrGrammarGenerator method _crossrefEbnf.
protected String _crossrefEbnf(final Alternatives it, final CrossReference ref, final boolean supportActions) {
StringConcatenation _builder = new StringConcatenation();
{
EList<AbstractElement> _elements = it.getElements();
boolean _hasElements = false;
for (final AbstractElement element : _elements) {
if (!_hasElements) {
_hasElements = true;
} else {
_builder.appendImmediate("\n |", "");
}
String _crossrefEbnf = this.crossrefEbnf(element, ref, supportActions);
_builder.append(_crossrefEbnf);
}
}
_builder.newLineIfNotEmpty();
return _builder.toString();
}
use of org.eclipse.xtext.AbstractElement in project xtext-core by eclipse.
the class AbstractAntlrGrammarGenerator method ebnfPredicate.
protected String ebnfPredicate(final AbstractElement it, final AntlrOptions options) {
StringConcatenation _builder = new StringConcatenation();
{
if ((this._grammarAccessExtensions.predicated(it) || it.isFirstSetPredicated())) {
_builder.append("(");
{
boolean _predicated = this._grammarAccessExtensions.predicated(it);
if (_predicated) {
String _ebnf2 = this.ebnf2(this._grammarAccessExtensions.predicatedElement(it), options, false);
_builder.append(_ebnf2);
} else {
{
List<AbstractElement> _firstSet = AntlrGrammarGenUtil.getFirstSet(it);
boolean _hasElements = false;
for (final AbstractElement e : _firstSet) {
if (!_hasElements) {
_hasElements = true;
} else {
_builder.appendImmediate(" | ", "");
}
String _ebnf2_1 = this.ebnf2(e, options, false);
_builder.append(_ebnf2_1);
}
}
}
}
_builder.append(")=>");
}
}
_builder.newLineIfNotEmpty();
return _builder.toString();
}
Aggregations