Java Code Examples for org.eclipse.xtext.CrossReference#getTerminal()

The following examples show how to use org.eclipse.xtext.CrossReference#getTerminal() . 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: XbaseIdeCrossrefProposalProvider.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
protected boolean hasIdRule(CrossReference crossRef) {
	if (crossRef.getTerminal() instanceof RuleCall) {
		String ruleName = ((RuleCall) crossRef.getTerminal()).getRule().getName();
		return "IdOrSuper".equals(ruleName) || "ValidID".equals(ruleName) || "FeatureCallID".equals(ruleName);
	}
	return false;
}
 
Example 2
Source File: XbaseIdeContentProposalProvider.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
protected String _getConcreteSyntaxRuleName(final CrossReference crossReference) {
  String _xifexpression = null;
  AbstractElement _terminal = crossReference.getTerminal();
  if ((_terminal instanceof RuleCall)) {
    _xifexpression = this.getConcreteSyntaxRuleName(crossReference.getTerminal());
  }
  return _xifexpression;
}
 
Example 3
Source File: XtextLabelProvider.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
private String getLabel(CrossReference ref) {
	TypeRef type = ref.getType();
	String typeName = getClassifierName(type);
	if (ref.getTerminal() instanceof RuleCall)
		return "[" + typeName + "|" + getLabel((RuleCall) ref.getTerminal()) + "]";
	return "[" + typeName + "|..]";
}
 
Example 4
Source File: AbstractJavaBasedContentProposalProvider.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
protected void lookupCrossReference(CrossReference crossReference, EReference reference,
		ContentAssistContext contentAssistContext, ICompletionProposalAcceptor acceptor,
		Predicate<IEObjectDescription> filter) {
	String ruleName = null;
	if (crossReference.getTerminal() instanceof RuleCall) {
		ruleName = ((RuleCall) crossReference.getTerminal()).getRule().getName();
	}
	lookupCrossReference(contentAssistContext.getCurrentModel(), reference, acceptor, filter,
			getProposalFactory(ruleName, contentAssistContext));
}
 
Example 5
Source File: XbaseProposalProvider.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
protected String getConcreteSyntaxRuleName(CrossReference crossReference) {
	String ruleName = null;
	if (crossReference.getTerminal() instanceof RuleCall) {
		ruleName = getConcreteSyntaxRuleName((RuleCall) crossReference.getTerminal());
	}
	return ruleName;
}
 
Example 6
Source File: Linker.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@Override
protected void afterCreateAndSetProxy(EObject obj, INode node, EReference eRef, CrossReference xref, IDiagnosticProducer diagnosticProducer) {
	AbstractElement terminal = xref.getTerminal();
	if (!(terminal instanceof RuleCall)) { 
		throw new IllegalArgumentException(String.valueOf(xref));
	}
	AbstractRule rule = ((RuleCall) terminal).getRule();
	try {
		String tokenText = NodeModelUtils.getTokenText(node);
		valueConverterService.toValue(tokenText, rule.getName(), node);
	} catch(ValueConverterException e) {
		diagnosticProducer.addDiagnostic(new DiagnosticMessage(e.getMessage(), Severity.ERROR, Diagnostic.SYNTAX_DIAGNOSTIC, Strings.EMPTY_ARRAY));
	}
}
 
Example 7
Source File: XtextValidator.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@Check
public void checkCrossReferenceTerminal(CrossReference reference) {
	if (reference.getTerminal() != null) {
		if (reference.getTerminal() instanceof RuleCall) {
			RuleCall call = (RuleCall) reference.getTerminal();
			checkCrossReferenceTerminal(call);
		} 
	}
	
}
 
Example 8
Source File: PredicateUsesUnorderedGroupInspector.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public Boolean caseCrossReference(CrossReference object) {
	// Do not create duplicate errors
	if (shouldTraverse(object)) {
		pushChecked(object);
		if (object.getTerminal() != null)
			doSwitch(object.getTerminal());
		popChecked(object);
	}
	return Boolean.FALSE;
}
 
Example 9
Source File: N4JSLinker.java    From n4js with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Creates the proxy with a custom encoded URI format (starting with "|"). The object used to produce the encoded
 * URI are collected as tuple inside {@link N4JSResource}. Then the node text is checked if it is convertible to a
 * valid value. If there is a {@link BadEscapementException} is thrown then there is either a warning or an error
 * produced via the diagnosticProducer.
 *
 *
 * @param resource
 *            the N4JSResource
 * @param obj
 *            the EObject containing the cross reference
 * @param node
 *            the node representing the EObject
 * @param eRef
 *            the cross reference in the domain model
 * @param xref
 *            the cross reference in the node model
 * @param diagnosticProducer
 *            to produce errors or warnings
 * @return the created proxy
 */
private EObject createProxy(N4JSResource resource, EObject obj, INode node, EReference eRef, CrossReference xref,
		IDiagnosticProducer diagnosticProducer) {
	final URI uri = resource.getURI();
	/*
	 * as otherwise with 0 the EObjectDescription created for Script would be fetched
	 */
	final int fragmentNumber = resource.addLazyProxyInformation(obj, eRef, node);
	final URI encodedLink = uri.appendFragment("|" + fragmentNumber);
	EClass referenceType = findInstantiableCompatible(eRef.getEReferenceType());
	final EObject proxy = EcoreUtil.create(referenceType);
	((InternalEObject) proxy).eSetProxyURI(encodedLink);
	AbstractElement terminal = xref.getTerminal();
	if (!(terminal instanceof RuleCall)) {
		throw new IllegalArgumentException(String.valueOf(xref));
	}
	AbstractRule rule = ((RuleCall) terminal).getRule();
	try {
		String tokenText = NodeModelUtils.getTokenText(node);
		Object value = valueConverterService.toValue(tokenText, rule.getName(), node);
		if (obj instanceof IdentifierRef && value instanceof String) {
			((IdentifierRef) obj).setIdAsText((String) value);
		} else if (obj instanceof ParameterizedTypeRef && value instanceof String) {
			((ParameterizedTypeRef) obj).setDeclaredTypeAsText((String) value);
		} else if (obj instanceof LabelRef && value instanceof String) {
			((LabelRef) obj).setLabelAsText((String) value);
		} else if (obj instanceof ParameterizedPropertyAccessExpression && value instanceof String) {
			((ParameterizedPropertyAccessExpression) obj).setPropertyAsText((String) value);
		} else if (obj instanceof ImportDeclaration && value instanceof String) {
			((ImportDeclaration) obj).setModuleSpecifierAsText((String) value);
		} else if (obj instanceof NamedImportSpecifier && value instanceof String) {
			((NamedImportSpecifier) obj).setImportedElementAsText((String) value);
		} else if ((obj instanceof JSXPropertyAttribute) && (value instanceof String)) {
			((JSXPropertyAttribute) obj).setPropertyAsText((String) value);
		} else {
			setOtherElementAsText(tokenText, obj, value);
		}
	} catch (BadEscapementException e) {
		diagnosticProducer.addDiagnostic(new DiagnosticMessage(e.getMessage(), e.getSeverity(), e.getIssueCode(),
				Strings.EMPTY_ARRAY));
	} catch (N4JSValueConverterException vce) {
		diagnosticProducer.addDiagnostic(new DiagnosticMessage(vce.getMessage(), vce.getSeverity(),
				vce.getIssueCode(), Strings.EMPTY_ARRAY));
	} catch (N4JSValueConverterWithValueException vcwve) {
		diagnosticProducer.addDiagnostic(new DiagnosticMessage(vcwve.getMessage(), vcwve.getSeverity(),
				vcwve.getIssueCode(), Strings.EMPTY_ARRAY));
	}
	return proxy;
}
 
Example 10
Source File: UsedRulesFinder.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public Void caseCrossReference(CrossReference object) {
	if (object.getTerminal() != null)
		return doSwitch(object.getTerminal());
	return null;
}