Java Code Examples for org.eclipse.xtext.GrammarUtil#getGrammar()

The following examples show how to use org.eclipse.xtext.GrammarUtil#getGrammar() . 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: GrammarPDAProviderTest.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
private void assertNoLeakedGrammarElements(final Grammar grammar, final Pda<ISerState, RuleCall> pda) {
  final Function1<ISerState, AbstractElement> _function = (ISerState it) -> {
    return it.getGrammarElement();
  };
  Iterable<AbstractElement> _filterNull = IterableExtensions.<AbstractElement>filterNull(IterableExtensions.<ISerState, AbstractElement>map(new NfaUtil().<ISerState>collect(pda), _function));
  for (final AbstractElement ele : _filterNull) {
    {
      final Grammar actual = GrammarUtil.getGrammar(ele);
      if ((actual != grammar)) {
        String _objPath = EmfFormatter.objPath(ele);
        String _plus = ("Element " + _objPath);
        String _plus_1 = (_plus + " leaked!");
        Assert.fail(_plus_1);
      }
    }
  }
}
 
Example 2
Source File: GrammarElementDeclarationOrder.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
public int getElementID(EObject ele) {
	Integer result = elementIDCache.get(ele);
	if (result == null) {
		Grammar grammar = GrammarUtil.getGrammar(ele);
		if (!elementIDCache.containsKey(grammar)) {
			String grammarName = grammar.getName() + "#" + System.identityHashCode(grammar);
			List<String> indexed = Lists.newArrayList();
			for (EObject o : elementIDCache.keySet())
				if (o instanceof Grammar)
					indexed.add(((Grammar) o).getName() + "#" + System.identityHashCode(o));
			throw new IllegalStateException("No ID found. Wrong grammar. \nRequested: " + grammarName
					+ "\nAvailable: " + Joiner.on(", ").join(indexed));
		} else
			throw new IllegalStateException("No ID found. Not indexed. \nElement: " + EmfFormatter.objPath(ele));
	}
	return result;
}
 
Example 3
Source File: KeywordInspector.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
public void inspectKeywordHidesTerminalRule(Keyword keyword) {
	AbstractRule container = GrammarUtil.containingRule(keyword);
	if (container instanceof TerminalRule)
		return;
	Grammar grammar = GrammarUtil.getGrammar(container);
	List<TerminalRule> rules = cache.get(KeywordInspector.class, grammar.eResource(), ()->GrammarUtil.allTerminalRules(grammar));
	for(TerminalRule rule: rules) {
		if (!rule.isFragment()) {
			AbstractElement element = rule.getAlternatives();
			if (element instanceof Keyword && Strings.isEmpty(element.getCardinality())) {
				String value = ((Keyword) element).getValue();
				if (value.equals(keyword.getValue()))
					acceptor.acceptError(
						"The keyword '" + value + "' hides the terminal rule " + rule.getName()+ ".", 
						keyword,
						XtextPackage.Literals.KEYWORD__VALUE,
						ValidationMessageAcceptor.INSIGNIFICANT_INDEX, null);
			}
		}
	}
}
 
Example 4
Source File: SuperCallScope.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public Iterable<IEObjectDescription> getElements(EObject object) {
	if (object instanceof AbstractRule) {
		Grammar grammar = GrammarUtil.getGrammar(context);
		AbstractRule rule = (AbstractRule) object;
		if (GrammarUtil.getGrammar(rule) == grammar) {
			return Lists.newArrayList(
					EObjectDescription.create(GrammarUtil.getSimpleName(grammar) + "." + rule.getName(), rule),
					EObjectDescription.create(grammar.getName() + "." + rule.getName(), rule));
		}
		List<IEObjectDescription> result = Lists.newArrayList(
				EObjectDescription.create(SUPER + "." + rule.getName(), rule),
				EObjectDescription.create(GrammarUtil.getSimpleName(grammar) + "." + rule.getName(), rule),
				EObjectDescription.create(grammar.getName() + "." + rule.getName(), rule));
		AbstractRule contextRule = GrammarUtil.containingRule(context);
		if (contextRule != null && contextRule.getName().equals(rule.getName())) {
			result.add(0, EObjectDescription.create(SUPER, rule));
		}
		return result;
	}
	return Collections.emptyList();
}
 
Example 5
Source File: EClassifierInfos.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
public EClassifierInfo getInfo(TypeRef typeRef) {
	if (typeRef.getClassifier() == null)
		return null;
	EClassifierInfo result = getInfo(typeRef.getMetamodel(), typeRef.getClassifier().getName());
	if (result == null) {
		Grammar declaringGrammar = GrammarUtil.getGrammar(typeRef);
		if (grammar.equals(declaringGrammar))
			return result;
		for(EClassifierInfos parent: parents) {
			result = parent.getInfo(typeRef);
			if (result != null)
				return result;
		}
	}
	return result;
}
 
Example 6
Source File: RuleOverrideUtil.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
public List<IEObjectDescription> getOverriddenRules(final AbstractRule originalRule) {
	Grammar grammar = GrammarUtil.getGrammar(originalRule);
	final List<IEObjectDescription> overriddenRules = newArrayList();
	IAcceptor<AbstractRule> acceptor = new IAcceptor<AbstractRule>() {
		@Override
		public void accept(AbstractRule overriddenRule) {
			if (overriddenRule != null) {
				IEObjectDescription description = EObjectDescription.create(
						qualifiedNameProvider.getFullyQualifiedName(overriddenRule), overriddenRule);
				overriddenRules.add(description);
			}
		}
	};
	findOverriddenRule(originalRule, grammar.getUsedGrammars(), acceptor);
	return overriddenRules;
}
 
Example 7
Source File: StableOrderSyntacticSequencerPDAProvider.java    From n4js with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Extracts the grammar from this transition or the NFA if this transition does not point to an
 * {@link AbstractElement}.
 */
private Grammar getGrammar(Nfa<ISynState> nfa) {
	AbstractElement grammarElement = getGrammarElement();
	if (grammarElement == null) {
		grammarElement = nfa.getStart().getGrammarElement();
		if (grammarElement == null) {
			grammarElement = nfa.getStop().getGrammarElement();
			if (grammarElement == null) {
				Iterator<ISynState> iter = nfa.getStart().getFollowers().iterator();
				while (grammarElement == null && iter.hasNext()) {
					grammarElement = iter.next().getGrammarElement();
				}
			}
		}
	}
	Grammar grammar = GrammarUtil.getGrammar(grammarElement);
	return grammar;
}
 
Example 8
Source File: XtextHyperlinkHelper.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
protected void createLinksToBase(ITextRegion nameLocation,	AbstractRule rule, IHyperlinkAcceptor acceptor) {
	Set<AbstractRule> visited = Sets.newHashSet();
	Grammar grammar = GrammarUtil.getGrammar(rule);
	for(Grammar used: grammar.getUsedGrammars()) {
		String ruleName = rule.getName();
		AbstractRule overwritten = GrammarUtil.findRuleForName(used, ruleName);
		if (overwritten != null && visited.add(overwritten)) {
			URIConverter uriConverter = rule.eResource().getResourceSet().getURIConverter();
			String hyperlinkText = getLabelProvider().getText(rule) + " - " + GrammarUtil.getGrammar(overwritten).getName();
			URI uri = uriConverter.normalize(EcoreUtil.getURI(overwritten));

			XtextHyperlink result = getHyperlinkProvider().get();
			deprecatedSetRegion(result, toRegion(nameLocation));
			result.setURI(uri);
			result.setHyperlinkText(hyperlinkText);
			result.setTypeLabel("Go To Base");
			acceptor.accept(result);
		}
	}
}
 
Example 9
Source File: XtextProposalProvider.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
private void completeParserRule(EObject model, final ContentAssistContext context,
		ICompletionProposalAcceptor acceptor) {
	final Grammar grammar = GrammarUtil.getGrammar(model);
	for (AbstractMetamodelDeclaration metamodelDeclaration : grammar.getMetamodelDeclarations()) {
		if (metamodelDeclaration instanceof ReferencedMetamodel) {
			ReferencedMetamodel referencedMetamodel = (ReferencedMetamodel) metamodelDeclaration;
			EPackage ePackage = referencedMetamodel.getEPackage();
			if (ePackage != null) {
				for (EClassifier eClassifier : ePackage.getEClassifiers()) {
					if (isProposeParserRule(eClassifier, grammar)) {
						String proposal = eClassifier.getName();
						String metamodelAlias = referencedMetamodel.getAlias();
						if (metamodelAlias != null) {
							proposal = proposal + " returns " + metamodelAlias + "::" + eClassifier.getName();
						}
						proposal = proposal + ": \n;\n";
						ConfigurableCompletionProposal completionProposal = (ConfigurableCompletionProposal) createCompletionProposal(
								proposal, eClassifier.getName() + " - parser rule",
								getImage(XtextFactory.eINSTANCE.createParserRule()), context);
						if (completionProposal != null) {
							completionProposal.setCursorPosition(proposal.length() - 3);
							acceptor.accept(completionProposal);
						}
					}
				}
			}
		}
	}
}
 
Example 10
Source File: XtextHyperlinkHelper.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
protected boolean acceptHyperLink(XtextResource resource, EObject objectAtOffset) {
	if (objectAtOffset instanceof EClass) {
		EClass eClass = (EClass) objectAtOffset;
		Grammar grammar = GrammarUtil.getGrammar(resource.getEObject("/"));
		List<AbstractMetamodelDeclaration> allMetamodelDeclarations = GrammarUtil.allMetamodelDeclarations(grammar);
		for (GeneratedMetamodel generatedMetamodel : Iterables.filter(allMetamodelDeclarations,
				GeneratedMetamodel.class)) {
			if (eClass.getEPackage().equals(generatedMetamodel.getEPackage())) {
				return false;
			}
		}
	}
	return true;
}
 
Example 11
Source File: XtextProposalProvider.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
private void completeInheritedRules(EObject model, ContentAssistContext context,
		ICompletionProposalAcceptor acceptor) {
	final Grammar grammar = GrammarUtil.getGrammar(model);
	Set<AbstractRule> allRules = collectOverrideCandidates(grammar);
	Map<String, AbstractRule> existingRules = collectExistingRules(grammar);
	for (final AbstractRule newRule : allRules) {
		if (existingRules.put(newRule.getName(), newRule) == null) {
			createOverrideProposal(newRule, grammar, context, acceptor);
		}
	}
}
 
Example 12
Source File: XtextProposalProvider.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void completeTypeRef_Classifier(EObject model, Assignment assignment, ContentAssistContext context,
		ICompletionProposalAcceptor acceptor) {
	Grammar grammar = GrammarUtil.getGrammar(model);
	ContentAssistContext.Builder myContextBuilder = context.copy();
	myContextBuilder.setMatcher(new ClassifierPrefixMatcher(context.getMatcher(), classifierQualifiedNameConverter));
	if (model instanceof TypeRef) {
		ICompositeNode node = NodeModelUtils.getNode(model);
		if (node != null) {
			int offset = node.getOffset();
			Region replaceRegion = new Region(offset, context.getReplaceRegion().getLength()
					+ context.getReplaceRegion().getOffset() - offset);
			myContextBuilder.setReplaceRegion(replaceRegion);
			myContextBuilder.setLastCompleteNode(node);
			StringBuilder availablePrefix = new StringBuilder(4);
			for (ILeafNode leaf : node.getLeafNodes()) {
				if (leaf.getGrammarElement() != null && !leaf.isHidden()) {
					if ((leaf.getTotalLength() + leaf.getTotalOffset()) < context.getOffset())
						availablePrefix.append(leaf.getText());
					else
						availablePrefix.append(leaf.getText().substring(0,
								context.getOffset() - leaf.getTotalOffset()));
				}
				if (leaf.getTotalOffset() >= context.getOffset())
					break;
			}
			myContextBuilder.setPrefix(availablePrefix.toString());
		}
	}
	ContentAssistContext myContext = myContextBuilder.toContext();
	for (AbstractMetamodelDeclaration declaration : grammar.getMetamodelDeclarations()) {
		if (declaration.getEPackage() != null) {
			createClassifierProposals(declaration, model, myContext, acceptor);
		}
	}
}
 
Example 13
Source File: XtextProposalProvider.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Override
protected StyledString getStyledDisplayString(IEObjectDescription description) {
	if (EcorePackage.Literals.EPACKAGE == description.getEClass()) {
		if ("true".equals(description.getUserData("nsURI"))) {
			String name = description.getUserData("name");
			if (name == null) {
				return new StyledString(description.getName().toString());
			}
			String string = name + " - " + description.getName();
			return new StyledString(string);
		}
	} else if(XtextPackage.Literals.GRAMMAR == description.getEClass()){
		QualifiedName qualifiedName = description.getQualifiedName();
		if(qualifiedName.getSegmentCount() >1) {
			return new StyledString(qualifiedName.getLastSegment() + " - " + qualifiedName.toString());
		}
		return new StyledString(qualifiedName.toString());
	} else if (XtextPackage.Literals.ABSTRACT_RULE.isSuperTypeOf(description.getEClass())) {
		EObject object = description.getEObjectOrProxy();
		if (!object.eIsProxy()) {
			AbstractRule rule = (AbstractRule) object;
			Grammar grammar = GrammarUtil.getGrammar(rule);
			if (description instanceof EnclosingGrammarAwareDescription) {
				if (grammar == ((EnclosingGrammarAwareDescription) description).getGrammar()) {
					return getStyledDisplayString(rule, null, rule.getName());
				}
			}
			return getStyledDisplayString(rule,
					grammar.getName() + "." + rule.getName(),
					description.getName().toString().replace(".", "::"));	
		}
		
	}
	return super.getStyledDisplayString(description);
}
 
Example 14
Source File: SyntaxFilteredScopesTest.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
public List<String> getEnumeratedValues(ParserRule rule) {
	CfgAdapter adapter = new CfgAdapter(GrammarUtil.getGrammar(rule));
	FollowerFunction<AbstractElement> followers = new FollowerFunctionImpl<AbstractElement, AbstractElement>(adapter);
	List<String> result = Lists.newArrayList();
	Iterable<AbstractElement> starts = followers.getStarts(rule.getAlternatives());
	collect(starts, null, "", result, followers);
	return result;
}
 
Example 15
Source File: XtextValidator.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
protected List<GeneratedMetamodel> getInheritedGeneratedMetamodels(ReferencedMetamodel metamodel) {
	List<GeneratedMetamodel> allGeneratedMetamodels = new ArrayList<GeneratedMetamodel>();
	Grammar grammar = GrammarUtil.getGrammar(metamodel);
	Set<Grammar> visited = Sets.newHashSet();
	for (Grammar usedGrammar : grammar.getUsedGrammars())
		Iterables.addAll(allGeneratedMetamodels, getAllGeneratedMetamodels(usedGrammar, visited));
	if (allGeneratedMetamodels.isEmpty())
		return Collections.emptyList();
	return allGeneratedMetamodels;
}
 
Example 16
Source File: XtextLinkingService.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
private boolean isReferencedByUsedGrammar(GeneratedMetamodel generatedMetamodel, String nsURI) {
	final Grammar grammar = GrammarUtil.getGrammar(generatedMetamodel);
	if (grammar != null) {
		final Set<Grammar> visitedGrammars = Sets.newHashSet(grammar);
		for (Grammar usedGrammar: grammar.getUsedGrammars()) {
			if (isReferencedByUsedGrammar(usedGrammar, nsURI, visitedGrammars))
				return true;
		}
	}
	return false;
}
 
Example 17
Source File: GrammarAccessFragment2.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
protected StringConcatenationClient _getter(final TerminalRule it, final Grammar original) {
  StringConcatenationClient _client = new StringConcatenationClient() {
    @Override
    protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
      String _grammarFragmentToString = GrammarAccessFragment2.this._grammarAccessExtensions.grammarFragmentToString(it, "//");
      _builder.append(_grammarFragmentToString);
      _builder.newLineIfNotEmpty();
      _builder.append("public ");
      _builder.append(TerminalRule.class);
      _builder.append(" ");
      String _gaRuleAccessor = GrammarAccessFragment2.this._grammarAccessExtensions.gaRuleAccessor(it);
      _builder.append(_gaRuleAccessor);
      _builder.append(" {");
      _builder.newLineIfNotEmpty();
      {
        Grammar _grammar = GrammarUtil.getGrammar(it);
        boolean _tripleEquals = (_grammar == original);
        if (_tripleEquals) {
          _builder.append("\t");
          _builder.append("return ");
          String _gaRuleAccessorLocalVarName = GrammarAccessFragment2.this.gaRuleAccessorLocalVarName(it);
          _builder.append(_gaRuleAccessorLocalVarName, "\t");
          _builder.append(";");
          _builder.newLineIfNotEmpty();
        } else {
          _builder.append("\t");
          _builder.append("return ");
          String _gaGrammarAccessLocalVarName = GrammarAccessFragment2.this.gaGrammarAccessLocalVarName(GrammarUtil.getGrammar(it));
          _builder.append(_gaGrammarAccessLocalVarName, "\t");
          _builder.append(".");
          String _gaBaseRuleAccessor = GrammarAccessFragment2.this._grammarAccessExtensions.gaBaseRuleAccessor(it);
          _builder.append(_gaBaseRuleAccessor, "\t");
          _builder.append(";");
          _builder.newLineIfNotEmpty();
        }
      }
      _builder.append("}");
      _builder.newLine();
    }
  };
  return _client;
}
 
Example 18
Source File: GrammarAccessFragment2.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
protected StringConcatenationClient _getter(final EnumRule it, final Grammar original) {
  StringConcatenationClient _client = new StringConcatenationClient() {
    @Override
    protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
      String _grammarFragmentToString = GrammarAccessFragment2.this._grammarAccessExtensions.grammarFragmentToString(it, "//");
      _builder.append(_grammarFragmentToString);
      _builder.newLineIfNotEmpty();
      {
        Grammar _grammar = GrammarUtil.getGrammar(it);
        boolean _tripleEquals = (_grammar == original);
        if (_tripleEquals) {
          _builder.append("public ");
          String _gaRuleAccessorClassName = GrammarAccessFragment2.this._grammarAccessExtensions.gaRuleAccessorClassName(it);
          _builder.append(_gaRuleAccessorClassName);
          _builder.append(" ");
          String _gaElementsAccessor = GrammarAccessFragment2.this._grammarAccessExtensions.gaElementsAccessor(it);
          _builder.append(_gaElementsAccessor);
          _builder.append(" {");
          _builder.newLineIfNotEmpty();
          _builder.append("\t");
          _builder.append("return ");
          String _gaRuleAccessorLocalVarName = GrammarAccessFragment2.this.gaRuleAccessorLocalVarName(it);
          _builder.append(_gaRuleAccessorLocalVarName, "\t");
          _builder.append(";");
          _builder.newLineIfNotEmpty();
          _builder.append("}");
          _builder.newLine();
        } else {
          _builder.append("public ");
          TypeReference _grammarAccess = GrammarAccessFragment2.this._grammarAccessExtensions.getGrammarAccess(GrammarUtil.getGrammar(it));
          _builder.append(_grammarAccess);
          _builder.append(".");
          String _gaRuleAccessorClassName_1 = GrammarAccessFragment2.this._grammarAccessExtensions.gaRuleAccessorClassName(it);
          _builder.append(_gaRuleAccessorClassName_1);
          _builder.append(" ");
          String _gaElementsAccessor_1 = GrammarAccessFragment2.this._grammarAccessExtensions.gaElementsAccessor(it);
          _builder.append(_gaElementsAccessor_1);
          _builder.append(" {");
          _builder.newLineIfNotEmpty();
          _builder.append("\t");
          _builder.append("return ");
          String _gaGrammarAccessLocalVarName = GrammarAccessFragment2.this.gaGrammarAccessLocalVarName(GrammarUtil.getGrammar(it));
          _builder.append(_gaGrammarAccessLocalVarName, "\t");
          _builder.append(".");
          String _gaElementsAccessor_2 = GrammarAccessFragment2.this._grammarAccessExtensions.gaElementsAccessor(it);
          _builder.append(_gaElementsAccessor_2, "\t");
          _builder.append(";");
          _builder.newLineIfNotEmpty();
          _builder.append("}");
          _builder.newLine();
        }
      }
      _builder.newLine();
      _builder.append("public ");
      _builder.append(EnumRule.class);
      _builder.append(" ");
      String _gaRuleAccessor = GrammarAccessFragment2.this._grammarAccessExtensions.gaRuleAccessor(it);
      _builder.append(_gaRuleAccessor);
      _builder.append(" {");
      _builder.newLineIfNotEmpty();
      _builder.append("\t");
      _builder.append("return ");
      String _gaElementsAccessor_3 = GrammarAccessFragment2.this._grammarAccessExtensions.gaElementsAccessor(it);
      _builder.append(_gaElementsAccessor_3, "\t");
      _builder.append(".getRule();");
      _builder.newLineIfNotEmpty();
      _builder.append("}");
      _builder.newLine();
    }
  };
  return _client;
}
 
Example 19
Source File: GrammarAccessFragment2.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
protected StringConcatenationClient _getter(final ParserRule it, final Grammar original) {
  StringConcatenationClient _client = new StringConcatenationClient() {
    @Override
    protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
      String _grammarFragmentToString = GrammarAccessFragment2.this._grammarAccessExtensions.grammarFragmentToString(it, "//");
      _builder.append(_grammarFragmentToString);
      _builder.newLineIfNotEmpty();
      {
        Grammar _grammar = GrammarUtil.getGrammar(it);
        boolean _tripleEquals = (_grammar == original);
        if (_tripleEquals) {
          _builder.append("public ");
          String _gaRuleAccessorClassName = GrammarAccessFragment2.this._grammarAccessExtensions.gaRuleAccessorClassName(it);
          _builder.append(_gaRuleAccessorClassName);
          _builder.append(" ");
          String _gaElementsAccessor = GrammarAccessFragment2.this._grammarAccessExtensions.gaElementsAccessor(it);
          _builder.append(_gaElementsAccessor);
          _builder.append(" {");
          _builder.newLineIfNotEmpty();
          _builder.append("\t");
          _builder.append("return ");
          String _gaRuleAccessorLocalVarName = GrammarAccessFragment2.this.gaRuleAccessorLocalVarName(it);
          _builder.append(_gaRuleAccessorLocalVarName, "\t");
          _builder.append(";");
          _builder.newLineIfNotEmpty();
          _builder.append("}");
          _builder.newLine();
        } else {
          _builder.append("public ");
          TypeReference _grammarAccess = GrammarAccessFragment2.this._grammarAccessExtensions.getGrammarAccess(GrammarUtil.getGrammar(it));
          _builder.append(_grammarAccess);
          _builder.append(".");
          String _gaBaseRuleAccessorClassName = GrammarAccessFragment2.this._grammarAccessExtensions.gaBaseRuleAccessorClassName(it);
          _builder.append(_gaBaseRuleAccessorClassName);
          _builder.append(" ");
          String _gaElementsAccessor_1 = GrammarAccessFragment2.this._grammarAccessExtensions.gaElementsAccessor(it);
          _builder.append(_gaElementsAccessor_1);
          _builder.append(" {");
          _builder.newLineIfNotEmpty();
          _builder.append("\t");
          _builder.append("return ");
          String _gaGrammarAccessLocalVarName = GrammarAccessFragment2.this.gaGrammarAccessLocalVarName(GrammarUtil.getGrammar(it));
          _builder.append(_gaGrammarAccessLocalVarName, "\t");
          _builder.append(".");
          String _gaBaseElementsAccessor = GrammarAccessFragment2.this._grammarAccessExtensions.gaBaseElementsAccessor(it);
          _builder.append(_gaBaseElementsAccessor, "\t");
          _builder.append(";");
          _builder.newLineIfNotEmpty();
          _builder.append("}");
          _builder.newLine();
        }
      }
      _builder.newLine();
      _builder.append("public ParserRule ");
      String _gaRuleAccessor = GrammarAccessFragment2.this._grammarAccessExtensions.gaRuleAccessor(it);
      _builder.append(_gaRuleAccessor);
      _builder.append(" {");
      _builder.newLineIfNotEmpty();
      _builder.append("\t");
      _builder.append("return ");
      String _gaElementsAccessor_2 = GrammarAccessFragment2.this._grammarAccessExtensions.gaElementsAccessor(it);
      _builder.append(_gaElementsAccessor_2, "\t");
      _builder.append(".getRule();");
      _builder.newLineIfNotEmpty();
      _builder.append("}");
      _builder.newLine();
    }
  };
  return _client;
}
 
Example 20
Source File: PackratParserGenUtil.java    From xtext-extras with Eclipse Public License 2.0 4 votes vote down vote up
/**
 * @param rule
 *            - the rule
 * @return <code>firstLetterToUpper(rule.name) + "Consumer"</code>
 */
public static String getConsumerClassName(AbstractRule rule) {
	Grammar grammar = GrammarUtil.getGrammar(rule);
	return (grammar != null ? GrammarUtil.getSimpleName(grammar) : "")
			+ (rule.getName() == null ? "Consumer" : Strings.toFirstUpper(rule.getName()) + "Consumer");
}