use of org.eclipse.xtext.CrossReference in project xtext-eclipse by eclipse.
the class XtextProposalProvider method completeTerminalRuleCall_Rule.
/**
* Do not propose enum and parser rules inside of terminal rules.
*/
@Override
public void completeTerminalRuleCall_Rule(EObject model, Assignment assignment, ContentAssistContext context, ICompletionProposalAcceptor acceptor) {
CrossReference crossReference = (CrossReference) assignment.getTerminal();
lookupCrossReference(crossReference, context, acceptor, new Predicate<IEObjectDescription>() {
@Override
public boolean apply(IEObjectDescription input) {
return input.getEClass() == XtextPackage.Literals.TERMINAL_RULE;
}
});
}
use of org.eclipse.xtext.CrossReference in project xtext-eclipse by eclipse.
the class DefaultReferenceUpdater method createReferenceUpdate.
protected void createReferenceUpdate(EObject referringElement, URI referringResourceURI, EReference reference, int indexInList, EObject newTargetElement, IRefactoringUpdateAcceptor updateAcceptor) {
if (!transientValueService.isValueInListTransient(referringElement, indexInList, reference)) {
ITextRegion referenceTextRegion = locationInFileProvider.getFullTextRegion(referringElement, reference, indexInList);
if (referenceTextRegion != null) {
CrossReference crossReference = getCrossReference(referringElement, referenceTextRegion.getOffset());
if (crossReference != null) {
RefTextEvaluator refTextComparator = getRefTextEvaluator(referringElement, referringResourceURI, reference, indexInList, newTargetElement);
String newReferenceText = crossReferenceSerializer.getCrossRefText(referringElement, crossReference, newTargetElement, refTextComparator, referenceTextRegion, updateAcceptor.getRefactoringStatus());
if (newReferenceText == null) {
newReferenceText = resolveNameConflict(referringElement, reference, newTargetElement, updateAcceptor);
}
if (newReferenceText == null) {
updateAcceptor.getRefactoringStatus().add(RefactoringStatus.ERROR, "Refactoring introduces a name conflict.", referringElement, referenceTextRegion);
}
createTextChange(referenceTextRegion, newReferenceText, referringElement, newTargetElement, reference, referringResourceURI, updateAcceptor);
}
}
}
}
use of org.eclipse.xtext.CrossReference in project n4js by eclipse.
the class ContentAssistTokenTypeMapper method getInternalTokenType.
/**
* Converts a grammar element to an Antlr token type (int).
*/
public int getInternalTokenType(EObject grammarElement) {
Integer type = grammarElements.get(grammarElement);
if (type == null) {
if (grammarElement instanceof Keyword) {
String keyword = ((Keyword) grammarElement).getValue();
type = tokenTypes.get("'" + keyword + "'");
} else if (grammarElement instanceof RuleCall) {
AbstractRule rule = ((RuleCall) grammarElement).getRule();
type = tokenTypes.get("RULE_" + rule.getName().toUpperCase());
} else if (grammarElement instanceof AbstractRule) {
AbstractRule rule = (AbstractRule) grammarElement;
type = tokenTypes.get("RULE_" + rule.getName().toUpperCase());
} else if (grammarElement instanceof EnumLiteralDeclaration) {
String keyword = ((EnumLiteralDeclaration) grammarElement).getLiteral().getValue();
type = tokenTypes.get("'" + keyword + "'");
} else if (grammarElement instanceof CrossReference) {
type = getInternalTokenType(((CrossReference) grammarElement).getTerminal());
} else {
throw new IllegalArgumentException(String.valueOf(grammarElement));
}
grammarElements.put(grammarElement, type);
}
return type;
}
use of org.eclipse.xtext.CrossReference in project n4js by eclipse.
the class TokenTypeRewriter method rewriteIdentifiers.
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);
}
}
}
}
}
}
use of org.eclipse.xtext.CrossReference in project n4js by eclipse.
the class N4JSLinker method installProxies.
/**
* Installs proxies for all non containment references and only if the node representing the EObject that contains
* the cross reference has got leaf nodes (as a leaf node represents the cross reference).
*
* @param resource
* the N4JSResource
* @param obj
* the EObject containing the cross reference
* @param producer
* the error/warning producer
* @param parentNode
* the node representing obj inside the node model
*/
private void installProxies(N4JSResource resource, EObject obj, IDiagnosticProducer producer, ICompositeNode parentNode, boolean dontCheckParent) {
final EClass eClass = obj.eClass();
if (eClass.getEAllReferences().size() - eClass.getEAllContainments().size() == 0)
return;
for (INode node = parentNode.getFirstChild(); node != null; node = node.getNextSibling()) {
EObject grammarElement = node.getGrammarElement();
if (grammarElement instanceof CrossReference && hasLeafNodes(node)) {
producer.setNode(node);
CrossReference crossReference = (CrossReference) grammarElement;
final EReference eRef = GrammarUtil.getReference(crossReference, eClass);
if (eRef == null) {
ParserRule parserRule = GrammarUtil.containingParserRule(crossReference);
final String feature = GrammarUtil.containingAssignment(crossReference).getFeature();
throw new IllegalStateException("Couldn't find EReference for crossreference '" + eClass.getName() + "::" + feature + "' in parser rule '" + parserRule.getName() + "'.");
}
createAndSetProxy(resource, obj, node, eRef, crossReference, producer);
afterCreateAndSetProxy(obj, node, eRef, crossReference, producer);
} else if (grammarElement instanceof RuleCall && node instanceof ICompositeNode) {
RuleCall ruleCall = (RuleCall) grammarElement;
AbstractRule calledRule = ruleCall.getRule();
if (calledRule instanceof ParserRule && ((ParserRule) calledRule).isFragment()) {
installProxies(resource, obj, producer, (ICompositeNode) node, true);
}
}
}
if (!dontCheckParent && shouldCheckParentNode(parentNode)) {
installProxies(resource, obj, producer, parentNode.getParent(), dontCheckParent);
}
}
Aggregations