org.eclipse.xtext.AbstractElement Java Examples

The following examples show how to use org.eclipse.xtext.AbstractElement. 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 Project: n4js   Author: eclipse   File: TokenTypeRewriter.java    License: Eclipse Public License 1.0 6 votes vote down vote up
private static void rewriteKeywords(AbstractRule rule, N4JSKeywords keywords,
		ImmutableMap.Builder<AbstractElement, Integer> builder) {
	for (EObject obj : EcoreUtil2.eAllContents(rule.getAlternatives())) {
		if (obj instanceof Keyword) {
			Keyword keyword = (Keyword) obj;
			Integer type = keywords.getTokenType(keyword);
			if (type != null) {
				if (keyword.eContainer() instanceof EnumLiteralDeclaration) {
					builder.put((AbstractElement) keyword.eContainer(), type);
				} else {
					builder.put(keyword, type);
				}
			}
		}
	}
}
 
Example #2
Source Project: xtext-core   Author: eclipse   File: SyntacticSequencerPDAProvider.java    License: Eclipse Public License 2.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 #3
Source Project: n4js   Author: eclipse   File: TokenTypeRewriter.java    License: Eclipse Public License 1.0 6 votes vote down vote up
private static void rewriteIdentifiers(N4JSGrammarAccess ga,
		ImmutableMap.Builder<AbstractElement, Integer> builder) {
	ImmutableSet<AbstractRule> identifierRules = ImmutableSet.of(
			ga.getBindingIdentifierRule(),
			ga.getIdentifierNameRule(),
			ga.getIDENTIFIERRule());
	for (ParserRule rule : GrammarUtil.allParserRules(ga.getGrammar())) {
		for (EObject obj : EcoreUtil2.eAllContents(rule.getAlternatives())) {
			if (obj instanceof Assignment) {
				Assignment assignment = (Assignment) obj;
				AbstractElement terminal = assignment.getTerminal();
				int type = InternalN4JSParser.RULE_IDENTIFIER;
				if (terminal instanceof CrossReference) {
					terminal = ((CrossReference) terminal).getTerminal();
					type = IDENTIFIER_REF_TOKEN;
				}
				if (terminal instanceof RuleCall) {
					AbstractRule calledRule = ((RuleCall) terminal).getRule();
					if (identifierRules.contains(calledRule)) {
						builder.put(assignment, type);
					}
				}
			}
		}
	}
}
 
Example #4
Source Project: gama   Author: gama-platform   File: ContentAssistContextFactory.java    License: GNU General Public License v3.0 6 votes vote down vote up
/**
 * AD 08/13 : Workaround for a bug manifesting itself as an infinite recursion over an AlternativesImpl element. The
 * choice here is to allow for 10 occurrences of the element to be computed and then fall back to the caller.
 */
@Override
protected void computeFollowElements(final FollowElementCalculator calculator, final FollowElement element,
		final Multimap<Integer, List<AbstractElement>> visited) {
	if (stop) { return; }
	final AbstractElement e = element.getGrammarElement();
	if (!recurse.containsKey(e)) {
		recurse.put(e, 1);
	} else {
		recurse.put(e, recurse.get(e) + 1);
	}
	if (recurse.get(e) > 3) {
		// GAMA.getGui().debug("Infinite recursion detected in completion proposal for " + e);
		stop = true;
		recurse.clear();
		return;
	}

	// scope.getGui().debug(" Computing FollowElement -- + visited : " +
	// element +
	// " ; number of times : " + recurse.get(e));
	super.computeFollowElements(calculator, element, visited);
}
 
Example #5
Source Project: n4js   Author: eclipse   File: CustomN4JSParser.java    License: Eclipse Public License 1.0 6 votes vote down vote up
/**
 * First pass. Use the tokens that have been computed from the production parser's result and collect the follow
 * elements from those.
 */
private CustomInternalN4JSParser collectFollowElements(
		TokenSource tokens,
		AbstractElement grammarElement,
		String ruleName,
		boolean strict,
		Set<FollowElement> result) {
	CustomInternalN4JSParser parser = createParser();
	parser.setStrict(strict);
	try {
		if (grammarElement != null)
			parser.getGrammarElements().add(grammarElement);
		ObservableXtextTokenStream tokenStream = new ObservableXtextTokenStream(tokens, parser);
		result.addAll(doGetFollowElements(parser, tokenStream, ruleName));
	} catch (InfiniteRecursion infinite) {
		// this guards against erroneous infinite recovery loops in Antlr.
		// Grammar dependent and not expected something that is expected for N4JS
		// is used in the base class thus also used here.
		result.addAll(parser.getFollowElements());
	}
	return parser;
}
 
Example #6
Source Project: xtext-core   Author: eclipse   File: KeywordAlternativeConverter.java    License: Eclipse Public License 2.0 6 votes vote down vote up
/**
 * @throws IllegalArgumentException if the rule is not a datatype rule or does not match
 *   the pattern <pre>RuleName: 'keyword' | 'other';</pre>
 */
@Override
public void setRule(AbstractRule rule) {
	if (!GrammarUtil.isDatatypeRule(rule))
		throw new IllegalArgumentException(rule.getName() + " is not a data type rule");
	if (!(rule.getAlternatives() instanceof Alternatives)) {
		if (rule.getAlternatives() instanceof RuleCall) {
			delegateRule = ((RuleCall) rule.getAlternatives()).getRule();
			keywords = Collections.emptySet();
			return;
		}
		throw mismatchedRuleBody(rule);
	}
	Alternatives alternatives = (Alternatives) rule.getAlternatives();
	ImmutableSet.Builder<String> builder = ImmutableSet.builder();
	for (AbstractElement element : alternatives.getElements()) {
		processElement(element, rule, builder);
	}
	keywords = builder.build();
}
 
Example #7
Source Project: xtext-core   Author: eclipse   File: AntlrContentAssistGrammarGenerator.java    License: Eclipse Public License 2.0 6 votes vote down vote up
@Override
protected String assignmentEbnf(final AbstractElement it, final Assignment assignment, final AntlrOptions options, final boolean supportsActions) {
  if (it instanceof Alternatives) {
    return _assignmentEbnf((Alternatives)it, assignment, options, supportsActions);
  } else if (it instanceof Group) {
    return _assignmentEbnf((Group)it, assignment, options, supportsActions);
  } else if (it instanceof Action) {
    return _assignmentEbnf((Action)it, assignment, options, supportsActions);
  } else if (it instanceof Assignment) {
    return _assignmentEbnf((Assignment)it, assignment, options, supportsActions);
  } else if (it instanceof CrossReference) {
    return _assignmentEbnf((CrossReference)it, assignment, options, supportsActions);
  } else if (it instanceof RuleCall) {
    return _assignmentEbnf((RuleCall)it, assignment, options, supportsActions);
  } else if (it != null) {
    return _assignmentEbnf(it, assignment, options, supportsActions);
  } else {
    throw new IllegalArgumentException("Unhandled parameter types: " +
      Arrays.<Object>asList(it, assignment, options, supportsActions).toString());
  }
}
 
Example #8
Source Project: xtext-core   Author: eclipse   File: BaseContentAssistParser.java    License: Eclipse Public License 2.0 6 votes vote down vote up
protected AbstractElement getEntryGrammarElement(ICompositeNode entryPoint) {
	EObject grammarElement = entryPoint.getGrammarElement();
	if (grammarElement instanceof RuleCall) {
		AbstractRule rule = ((RuleCall) grammarElement).getRule();
		if (rule instanceof ParserRule) {
			if (!GrammarUtil.isMultipleCardinality(rule.getAlternatives())) {
				grammarElement = rule.getAlternatives();
			}
		}
	} else if (grammarElement instanceof ParserRule) {
		grammarElement = ((ParserRule) grammarElement).getAlternatives();
	} else if (grammarElement instanceof CrossReference) {
		grammarElement = GrammarUtil.containingAssignment(grammarElement);
	}
	AbstractElement result = (AbstractElement) grammarElement;
	if (result instanceof Action) {
		return getEntryGrammarElement((ICompositeNode) entryPoint.getFirstChild());
	}
	return result;
}
 
Example #9
Source Project: xtext-eclipse   Author: eclipse   File: DelegatingContentAssistContextFactory.java    License: Eclipse Public License 2.0 6 votes vote down vote up
protected ContentAssistContext.Builder convert(org.eclipse.xtext.ide.editor.contentassist.ContentAssistContext delegateContext) {
	ContentAssistContext.Builder context = contentAssistContextProvider.get();

	context.setRootNode(delegateContext.getRootNode());
	context.setLastCompleteNode(delegateContext.getLastCompleteNode());
	context.setCurrentNode(delegateContext.getCurrentNode());

	context.setRootModel(delegateContext.getRootModel());
	context.setCurrentModel(delegateContext.getCurrentModel());
	context.setPreviousModel(delegateContext.getPreviousModel());
	context.setOffset(delegateContext.getOffset());
	context.setViewer(viewer);
	context.setPrefix(delegateContext.getPrefix());
	Region region = new Region(delegateContext.getReplaceRegion().getOffset(), delegateContext.getReplaceRegion().getLength());
	context.setReplaceRegion(region);
	context.setSelectedText(delegateContext.getSelectedText());
	context.setMatcher(matcher);
	context.setResource(resource);
	for (AbstractElement grammarElement : delegateContext.getFirstSetGrammarElements()) {
		context.accept(grammarElement);
	}
	return context;
}
 
Example #10
Source Project: xtext-core   Author: eclipse   File: GrammarAccessExtensions.java    License: Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Returns the invocation of an element or rule accessor, including the .getType() call.
 * Example1: getFooRule().getType()
 * Example2: getBarRule().getFooAction().getType()
 */
public String gaTypeAccessor(final TypeRef ele) {
  String _switchResult = null;
  EObject _eContainer = ele.eContainer();
  final EObject cnt = _eContainer;
  boolean _matched = false;
  if (cnt instanceof AbstractElement) {
    _matched=true;
    String _gaRuleElementAccessor = this.gaRuleElementAccessor(((AbstractElement)cnt));
    _switchResult = (_gaRuleElementAccessor + ".getType()");
  }
  if (!_matched) {
    if (cnt instanceof AbstractRule) {
      _matched=true;
      String _gaRuleAccessor = this.gaRuleAccessor(((AbstractRule)cnt));
      _switchResult = (_gaRuleAccessor + ".getType()");
    }
  }
  if (!_matched) {
    String _name = ele.eContainer().eClass().getName();
    String _plus = ("<error: unknown type " + _name);
    _switchResult = (_plus + ">");
  }
  return _switchResult;
}
 
Example #11
Source Project: xtext-core   Author: eclipse   File: AntlrContentAssistGrammarGenerator.java    License: Eclipse Public License 2.0 6 votes vote down vote up
@Override
protected String ebnf2(final AbstractElement it, final AntlrOptions options, final boolean supportActions) {
  if (it instanceof Alternatives) {
    return _ebnf2((Alternatives)it, options, supportActions);
  } else if (it instanceof Group) {
    return _ebnf2((Group)it, options, supportActions);
  } else if (it instanceof UnorderedGroup) {
    return _ebnf2((UnorderedGroup)it, options, supportActions);
  } else if (it instanceof Action) {
    return _ebnf2((Action)it, options, supportActions);
  } else if (it instanceof Assignment) {
    return _ebnf2((Assignment)it, options, supportActions);
  } else if (it instanceof EnumLiteralDeclaration) {
    return _ebnf2((EnumLiteralDeclaration)it, options, supportActions);
  } else if (it instanceof Keyword) {
    return _ebnf2((Keyword)it, options, supportActions);
  } else if (it instanceof RuleCall) {
    return _ebnf2((RuleCall)it, options, supportActions);
  } else if (it != null) {
    return _ebnf2(it, options, supportActions);
  } else {
    throw new IllegalArgumentException("Unhandled parameter types: " +
      Arrays.<Object>asList(it, options, supportActions).toString());
  }
}
 
Example #12
Source Project: xtext-core   Author: eclipse   File: FollowElementComputer.java    License: Eclipse Public License 2.0 5 votes vote down vote up
private boolean isAlternativeWithEmptyPath(AbstractElement abstractElement) {
	if (abstractElement instanceof Alternatives) {
		Alternatives alternatives = (Alternatives) abstractElement;
		for(AbstractElement path: alternatives.getElements()) {
			if (GrammarUtil.isOptionalCardinality(path))
				return true;
		}
	}
	return false;
}
 
Example #13
Source Project: xtext-core   Author: eclipse   File: GrammarAccessExtensions.java    License: Eclipse Public License 2.0 5 votes vote down vote up
public String grammarElementIdentifier(final EObject it) {
  if (it instanceof AbstractElement) {
    return _grammarElementIdentifier((AbstractElement)it);
  } else if (it instanceof AbstractRule) {
    return _grammarElementIdentifier((AbstractRule)it);
  } else if (it != null) {
    return _grammarElementIdentifier(it);
  } else {
    throw new IllegalArgumentException("Unhandled parameter types: " +
      Arrays.<Object>asList(it).toString());
  }
}
 
Example #14
Source Project: xtext-core   Author: eclipse   File: BaseContentAssistParser.java    License: Eclipse Public License 2.0 5 votes vote down vote up
protected String[][] getRequiredRuleNames(String ruleName, List<Integer> paramStack,
		AbstractElement elementToParse) {
	return requiredRuleNameComputer
			.getRequiredRuleNames(new RequiredRuleNameComputer.Param(ruleName, paramStack, elementToParse) {
				@Override
				public String getBaseRuleName(AbstractElement element) {
					return getRuleName(element);
				}
			});
}
 
Example #15
Source Project: xtext-eclipse   Author: eclipse   File: AbstractContentProposalProvider.java    License: Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void createProposals(ContentAssistContext context, ICompletionProposalAcceptor acceptor) {
	ICompletionProposalAcceptor nullSafe = new NullSafeCompletionProposalAcceptor(acceptor);
	IFollowElementAcceptor selector = createSelector(context, nullSafe);
	for (AbstractElement element : context.getFirstSetGrammarElements()) {
		selector.accept(element);
	}
}
 
Example #16
Source Project: xtext-eclipse   Author: eclipse   File: ContentAssistContext.java    License: Eclipse Public License 2.0 5 votes vote down vote up
/**
 * The grammar elements that may occur at the given offset.
 */
public ImmutableList<AbstractElement> getFirstSetGrammarElements() {
	if (firstSetGrammarElements == null) {
		firstSetGrammarElements = ImmutableList.copyOf(mutableFirstSetGrammarElements);
	}
	return firstSetGrammarElements;
}
 
Example #17
Source Project: xtext-core   Author: eclipse   File: SemanticNodeProvider.java    License: Eclipse Public License 2.0 5 votes vote down vote up
public SemanticNode(INode node) {
	this.node = node;
	EObject ge = node.getGrammarElement();
	if (ge instanceof CrossReference)
		this.grammarElement = ((CrossReference) ge).getTerminal();
	else if (ge instanceof AbstractElement)
		this.grammarElement = (AbstractElement) ge;
	else
		this.grammarElement = null;
}
 
Example #18
Source Project: xtext-core   Author: eclipse   File: ContentAssistContext.java    License: Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void accept(AbstractElement element) {
	if (element == null)
		throw new NullPointerException("element may not be null");
	assertCanModify();
	context.firstSetGrammarElements = null;
	context.mutableFirstSetGrammarElements.add(element);
}
 
Example #19
Source Project: xtext-core   Author: eclipse   File: CfgAdapter.java    License: Eclipse Public License 2.0 5 votes vote down vote up
@Override
public Iterable<AbstractElement> getAlternativeChildren(AbstractElement ele) {
	switch (ele.eClass().getClassifierID()) {
		case XtextPackage.ALTERNATIVES:
			return ((Alternatives) ele).getElements();
		default:
			return null;
	}
}
 
Example #20
Source Project: xtext-core   Author: eclipse   File: GrammarPDAProvider.java    License: Eclipse Public License 2.0 5 votes vote down vote up
@Override
public ISerState createState(SerializerPDA nfa, AbstractElement token) {
	AbstractElement original = original(token);
	ISerState state = states.get(original);
	if (state == null) {
		state = delegate.createState(nfa, original);
		states.put(original, state);
	}
	return state;
}
 
Example #21
Source Project: xtext-eclipse   Author: eclipse   File: ReferenceGrammarUiTestLanguageParser.java    License: Eclipse Public License 2.0 5 votes vote down vote up
private static void init(ImmutableMap.Builder<AbstractElement, String> builder, ReferenceGrammarUiTestLanguageGrammarAccess grammarAccess) {
	builder.put(grammarAccess.getSpielplatzAccess().getAlternatives_4(), "rule__Spielplatz__Alternatives_4");
	builder.put(grammarAccess.getPersonAccess().getAlternatives(), "rule__Person__Alternatives");
	builder.put(grammarAccess.getFarbeAccess().getWertAlternatives_0(), "rule__Farbe__WertAlternatives_0");
	builder.put(grammarAccess.getFamilieAccess().getNameAlternatives_2_0(), "rule__Familie__NameAlternatives_2_0");
	builder.put(grammarAccess.getSpielplatzAccess().getGroup(), "rule__Spielplatz__Group__0");
	builder.put(grammarAccess.getKindAccess().getGroup(), "rule__Kind__Group__0");
	builder.put(grammarAccess.getErwachsenerAccess().getGroup(), "rule__Erwachsener__Group__0");
	builder.put(grammarAccess.getSpielzeugAccess().getGroup(), "rule__Spielzeug__Group__0");
	builder.put(grammarAccess.getFamilieAccess().getGroup(), "rule__Familie__Group__0");
	builder.put(grammarAccess.getFamilieAccess().getGroup_6(), "rule__Familie__Group_6__0");
	builder.put(grammarAccess.getSpielplatzAccess().getGroesseAssignment_1(), "rule__Spielplatz__GroesseAssignment_1");
	builder.put(grammarAccess.getSpielplatzAccess().getBeschreibungAssignment_2(), "rule__Spielplatz__BeschreibungAssignment_2");
	builder.put(grammarAccess.getSpielplatzAccess().getKinderAssignment_4_0(), "rule__Spielplatz__KinderAssignment_4_0");
	builder.put(grammarAccess.getSpielplatzAccess().getErzieherAssignment_4_1(), "rule__Spielplatz__ErzieherAssignment_4_1");
	builder.put(grammarAccess.getSpielplatzAccess().getSpielzeugeAssignment_4_2(), "rule__Spielplatz__SpielzeugeAssignment_4_2");
	builder.put(grammarAccess.getSpielplatzAccess().getFamilieAssignment_4_3(), "rule__Spielplatz__FamilieAssignment_4_3");
	builder.put(grammarAccess.getKindAccess().getNameAssignment_2(), "rule__Kind__NameAssignment_2");
	builder.put(grammarAccess.getKindAccess().getAgeAssignment_3(), "rule__Kind__AgeAssignment_3");
	builder.put(grammarAccess.getErwachsenerAccess().getNameAssignment_2(), "rule__Erwachsener__NameAssignment_2");
	builder.put(grammarAccess.getErwachsenerAccess().getAgeAssignment_3(), "rule__Erwachsener__AgeAssignment_3");
	builder.put(grammarAccess.getSpielzeugAccess().getNameAssignment_2(), "rule__Spielzeug__NameAssignment_2");
	builder.put(grammarAccess.getSpielzeugAccess().getFarbeAssignment_3(), "rule__Spielzeug__FarbeAssignment_3");
	builder.put(grammarAccess.getFarbeAccess().getWertAssignment(), "rule__Farbe__WertAssignment");
	builder.put(grammarAccess.getFamilieAccess().getNameAssignment_2(), "rule__Familie__NameAssignment_2");
	builder.put(grammarAccess.getFamilieAccess().getMutterAssignment_3(), "rule__Familie__MutterAssignment_3");
	builder.put(grammarAccess.getFamilieAccess().getVaterAssignment_4(), "rule__Familie__VaterAssignment_4");
	builder.put(grammarAccess.getFamilieAccess().getKinderAssignment_5(), "rule__Familie__KinderAssignment_5");
	builder.put(grammarAccess.getFamilieAccess().getKinderAssignment_6_1(), "rule__Familie__KinderAssignment_6_1");
}
 
Example #22
Source Project: xtext-eclipse   Author: eclipse   File: Bug347012TestLanguageParser.java    License: Eclipse Public License 2.0 5 votes vote down vote up
private static void init(ImmutableMap.Builder<AbstractElement, String> builder, Bug347012TestLanguageGrammarAccess grammarAccess) {
	builder.put(grammarAccess.getVirtualSemiAccess().getAlternatives(), "rule__VirtualSemi__Alternatives");
	builder.put(grammarAccess.getLiteralAccess().getAlternatives(), "rule__Literal__Alternatives");
	builder.put(grammarAccess.getMyPrimaryAccess().getAlternatives(), "rule__MyPrimary__Alternatives");
	builder.put(grammarAccess.getMyAttributeAccess().getAlternatives(), "rule__MyAttribute__Alternatives");
	builder.put(grammarAccess.getMyProgramAccess().getGroup(), "rule__MyProgram__Group__0");
	builder.put(grammarAccess.getFQNAccess().getGroup(), "rule__FQN__Group__0");
	builder.put(grammarAccess.getFQNAccess().getGroup_1(), "rule__FQN__Group_1__0");
	builder.put(grammarAccess.getMyPackageAccess().getGroup(), "rule__MyPackage__Group__0");
	builder.put(grammarAccess.getMyPackageAccess().getGroup_6(), "rule__MyPackage__Group_6__0");
	builder.put(grammarAccess.getMyClassAccess().getGroup(), "rule__MyClass__Group__0");
	builder.put(grammarAccess.getMyClassAccess().getGroup_7(), "rule__MyClass__Group_7__0");
	builder.put(grammarAccess.getMyAttributesAccess().getGroup(), "rule__MyAttributes__Group__0");
	builder.put(grammarAccess.getMyFieldAccess().getGroup(), "rule__MyField__Group__0");
	builder.put(grammarAccess.getMyFieldAccess().getGroup_4(), "rule__MyField__Group_4__0");
	builder.put(grammarAccess.getMyBindingAccess().getGroup(), "rule__MyBinding__Group__0");
	builder.put(grammarAccess.getMyBindingAccess().getGroup_1(), "rule__MyBinding__Group_1__0");
	builder.put(grammarAccess.getMyBindingAccess().getGroup_2(), "rule__MyBinding__Group_2__0");
	builder.put(grammarAccess.getMyProgramAccess().getPackageAssignment_2(), "rule__MyProgram__PackageAssignment_2");
	builder.put(grammarAccess.getIdentifierAccess().getNameAssignment(), "rule__Identifier__NameAssignment");
	builder.put(grammarAccess.getLiteralAccess().getNumAssignment_0(), "rule__Literal__NumAssignment_0");
	builder.put(grammarAccess.getLiteralAccess().getStrAssignment_1(), "rule__Literal__StrAssignment_1");
	builder.put(grammarAccess.getLiteralAccess().getBoolAssignment_2(), "rule__Literal__BoolAssignment_2");
	builder.put(grammarAccess.getLiteralAccess().getBoolAssignment_3(), "rule__Literal__BoolAssignment_3");
	builder.put(grammarAccess.getMyPackageAccess().getNameAssignment_2(), "rule__MyPackage__NameAssignment_2");
	builder.put(grammarAccess.getMyPackageAccess().getDirectivesAssignment_6_0(), "rule__MyPackage__DirectivesAssignment_6_0");
	builder.put(grammarAccess.getMyClassAccess().getNameAssignment_3(), "rule__MyClass__NameAssignment_3");
	builder.put(grammarAccess.getMyClassAccess().getDirectivesAssignment_7_0(), "rule__MyClass__DirectivesAssignment_7_0");
	builder.put(grammarAccess.getMyAttributeAccess().getPUBLICAssignment_0(), "rule__MyAttribute__PUBLICAssignment_0");
	builder.put(grammarAccess.getMyAttributeAccess().getPRIVATEAssignment_1(), "rule__MyAttribute__PRIVATEAssignment_1");
	builder.put(grammarAccess.getMyAttributesAccess().getAttributesAssignment_1(), "rule__MyAttributes__AttributesAssignment_1");
	builder.put(grammarAccess.getMyFieldAccess().getAttrAssignment_0(), "rule__MyField__AttrAssignment_0");
	builder.put(grammarAccess.getMyFieldAccess().getBindingsAssignment_3(), "rule__MyField__BindingsAssignment_3");
	builder.put(grammarAccess.getMyFieldAccess().getBindingsAssignment_4_3(), "rule__MyField__BindingsAssignment_4_3");
	builder.put(grammarAccess.getMyBindingAccess().getNameAssignment_0(), "rule__MyBinding__NameAssignment_0");
	builder.put(grammarAccess.getMyBindingAccess().getTypeAssignment_1_3(), "rule__MyBinding__TypeAssignment_1_3");
	builder.put(grammarAccess.getMyBindingAccess().getExpressionAssignment_2_3(), "rule__MyBinding__ExpressionAssignment_2_3");
}
 
Example #23
Source Project: xtext-core   Author: eclipse   File: TreeConstState.java    License: Eclipse Public License 2.0 5 votes vote down vote up
public Status getStatus() {
	if (distances == null) {
		AbstractElement rootEle = containingRule(element).getAlternatives();
		builder.getState(rootEle).initStatus();
	}
	return getStatusInternal();
}
 
Example #24
Source Project: xtext-core   Author: eclipse   File: RuleWithoutInstantiationInspector.java    License: Eclipse Public License 2.0 5 votes vote down vote up
@Override
public Boolean caseCompoundElement(CompoundElement object) {
	if (GrammarUtil.isOptionalCardinality(object))
		return Boolean.FALSE;
	for(AbstractElement element: object.getElements()) {
		if (doSwitch(element))
			return Boolean.TRUE;
	}
	return Boolean.FALSE;
}
 
Example #25
Source Project: xtext-core   Author: eclipse   File: FollowElementCalculator.java    License: Eclipse Public License 2.0 5 votes vote down vote up
public void doSwitch(UnorderedGroup group, List<AbstractElement> handledAlternatives) {
	this.group = group;
	this.handledAlternatives = handledAlternatives;
	try {
		doSwitch(group);
	} finally {
		this.handledAlternatives = null;
		this.group = null;
	}
}
 
Example #26
Source Project: xtext-core   Author: eclipse   File: AssignmentFinderTest.java    License: Eclipse Public License 2.0 5 votes vote down vote up
private String findAssignments(EObject obj, Object value, AbstractElement... assignments) {
	AbstractElement element = (AbstractElement) NodeModelUtils.getNode(obj).getGrammarElement();
	ISerializationContext ctx = SerializationContext.forChild(null, element, obj);
	Multimap<AbstractElement, ISerializationContext> ass = ArrayListMultimap.create();
	for (AbstractElement e : assignments)
		ass.put(e, ctx);
	List<AbstractElement> found = Lists.newArrayList(finder.findAssignmentsByValue(obj, ass, value, null));
	Collections.sort(found, GrammarElementDeclarationOrder.get(GrammarUtil.getGrammar(assignments[0])));
	return Joiner.on(", ").join(Iterables.transform(found, new GrammarElementTitleSwitch().showAssignments()));
}
 
Example #27
Source Project: xtext-core   Author: eclipse   File: ContextPDAProvider.java    License: Eclipse Public License 2.0 5 votes vote down vote up
protected SerializerPDA extract(ISerState last) {
	SerializerPDA result = factory.create(null, null);
	HashMap<Pair<AbstractElement, SerStateType>, SerializerPDAState> oldToNew = Maps.newHashMap();
	CallStack callStack = new CallStack(null, null);
	collectExtracted(last, last.getPrecedents(), result.getStop(), oldToNew, callStack, result.getStart());
	return result;
}
 
Example #28
Source Project: xtext-core   Author: eclipse   File: GrammarAccessExtensions.java    License: Eclipse Public License 2.0 5 votes vote down vote up
public CharSequence toStringLiteral(final AbstractElement it) {
  CharSequence _switchResult = null;
  boolean _matched = false;
  if (it instanceof RuleCall) {
    AbstractRule _rule = ((RuleCall)it).getRule();
    boolean _tripleNotEquals = (_rule != null);
    if (_tripleNotEquals) {
      _matched=true;
      _switchResult = AntlrGrammarGenUtil.getQualifiedNameAsString(((RuleCall)it));
    }
  }
  if (!_matched) {
    if (it instanceof Keyword) {
      _matched=true;
      StringConcatenation _builder = new StringConcatenation();
      _builder.append("\"");
      String _stringInAntlrAction = AntlrGrammarGenUtil.toStringInAntlrAction(((Keyword)it).getValue());
      _builder.append(_stringInAntlrAction);
      _builder.append("\"");
      _switchResult = _builder;
    }
  }
  if (!_matched) {
    _switchResult = "null";
  }
  return _switchResult;
}
 
Example #29
Source Project: xtext-core   Author: eclipse   File: FollowElementComputer.java    License: Eclipse Public License 2.0 5 votes vote down vote up
/**
 * @since 2.14
 */
protected int setParamConfigAndUpdateOffset(FollowElementCalculator calculator, List<Integer> paramStack, int paramIndex, AbstractElement abstractElement) {
	if (paramIndex >= 0) {
		calculator.setParameterConfig(paramStack.get(paramIndex));
	} else {
		calculator.setParameterConfig(0);
	}
	if (abstractElement instanceof RuleCall) {
		RuleCall call = (RuleCall) abstractElement;
		if (!call.getArguments().isEmpty()) {
			paramIndex++;
		}
	}
	return paramIndex;
}
 
Example #30
Source Project: xtext-extras   Author: eclipse   File: XbaseIdeContentProposalProvider.java    License: Eclipse Public License 2.0 5 votes vote down vote up
protected void completeBinaryOperation(final EObject model, final Assignment assignment, final ContentAssistContext context, final IIdeContentProposalAcceptor acceptor) {
  if ((model instanceof XBinaryOperation)) {
    int _length = context.getPrefix().length();
    boolean _tripleEquals = (_length == 0);
    if (_tripleEquals) {
      final INode currentNode = context.getCurrentNode();
      final int offset = currentNode.getOffset();
      final int endOffset = currentNode.getEndOffset();
      if ((((offset < context.getOffset()) && (endOffset >= context.getOffset())) && (currentNode.getGrammarElement() instanceof CrossReference))) {
        return;
      }
    }
    int _endOffset = NodeModelUtils.findActualNodeFor(model).getEndOffset();
    int _offset = context.getOffset();
    boolean _lessEqualsThan = (_endOffset <= _offset);
    if (_lessEqualsThan) {
      AbstractElement _terminal = assignment.getTerminal();
      this.createReceiverProposals(((XExpression) model), ((CrossReference) _terminal), context, acceptor);
    } else {
      AbstractElement _terminal_1 = assignment.getTerminal();
      this.createReceiverProposals(((XBinaryOperation)model).getLeftOperand(), 
        ((CrossReference) _terminal_1), context, acceptor);
    }
  } else {
    final EObject previousModel = context.getPreviousModel();
    if ((previousModel instanceof XExpression)) {
      if (((context.getPrefix().length() == 0) && (NodeModelUtils.getNode(previousModel).getEndOffset() > context.getOffset()))) {
        return;
      }
      AbstractElement _terminal_2 = assignment.getTerminal();
      this.createReceiverProposals(((XExpression)previousModel), 
        ((CrossReference) _terminal_2), context, acceptor);
    }
  }
}