Search in sources :

Example 31 with TypeRef

use of org.eclipse.xtext.TypeRef in project xtext-eclipse by eclipse.

the class XtextLabelProvider method getLabel.

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 + "|..]";
}
Also used : TypeRef(org.eclipse.xtext.TypeRef) StyledString(org.eclipse.jface.viewers.StyledString) RuleCall(org.eclipse.xtext.RuleCall)

Example 32 with TypeRef

use of org.eclipse.xtext.TypeRef in project xtext-eclipse by eclipse.

the class XtextProposalProvider method completeAssignment_Feature.

/**
 * Not a full featured solution for the computation of available structural features, but it is sufficient for some
 * interesting 85%.
 */
@Override
public void completeAssignment_Feature(EObject model, Assignment assignment, ContentAssistContext context, ICompletionProposalAcceptor acceptor) {
    AbstractRule rule = EcoreUtil2.getContainerOfType(model, AbstractRule.class);
    TypeRef typeRef = rule.getType();
    if (typeRef != null && typeRef.getClassifier() instanceof EClass) {
        Iterable<EStructuralFeature> features = ((EClass) typeRef.getClassifier()).getEAllStructuralFeatures();
        Function<IEObjectDescription, ICompletionProposal> factory = getProposalFactory(grammarAccess.getValidIDRule().getName(), context);
        Iterable<String> processedFeatures = completeStructuralFeatures(context, factory, acceptor, features);
        if (rule.getType().getMetamodel() instanceof GeneratedMetamodel) {
            if (notNull(rule.getName()).toLowerCase().startsWith("import")) {
                completeSpecialAttributeAssignment("importedNamespace", 2, processedFeatures, factory, context, acceptor);
                completeSpecialAttributeAssignment("importURI", 1, processedFeatures, factory, context, acceptor);
            } else {
                completeSpecialAttributeAssignment("name", 3, processedFeatures, factory, context, acceptor);
            }
        }
    }
    super.completeAssignment_Feature(model, assignment, context, acceptor);
}
Also used : GeneratedMetamodel(org.eclipse.xtext.GeneratedMetamodel) EClass(org.eclipse.emf.ecore.EClass) TypeRef(org.eclipse.xtext.TypeRef) ICompletionProposal(org.eclipse.jface.text.contentassist.ICompletionProposal) EStructuralFeature(org.eclipse.emf.ecore.EStructuralFeature) StyledString(org.eclipse.jface.viewers.StyledString) AbstractRule(org.eclipse.xtext.AbstractRule) IEObjectDescription(org.eclipse.xtext.resource.IEObjectDescription)

Aggregations

TypeRef (org.eclipse.xtext.TypeRef)32 RuleCall (org.eclipse.xtext.RuleCall)15 ParserRule (org.eclipse.xtext.ParserRule)13 AbstractRule (org.eclipse.xtext.AbstractRule)10 Test (org.junit.Test)9 AbstractMetamodelDeclaration (org.eclipse.xtext.AbstractMetamodelDeclaration)7 CrossReference (org.eclipse.xtext.CrossReference)7 EObject (org.eclipse.emf.ecore.EObject)5 Action (org.eclipse.xtext.Action)5 Assignment (org.eclipse.xtext.Assignment)5 EnumLiteralDeclaration (org.eclipse.xtext.EnumLiteralDeclaration)4 EnumRule (org.eclipse.xtext.EnumRule)4 Grammar (org.eclipse.xtext.Grammar)4 ReferencedMetamodel (org.eclipse.xtext.ReferencedMetamodel)4 TerminalRule (org.eclipse.xtext.TerminalRule)4 UnorderedGroup (org.eclipse.xtext.UnorderedGroup)4 EClass (org.eclipse.emf.ecore.EClass)3 EClassifier (org.eclipse.emf.ecore.EClassifier)3 EPackage (org.eclipse.emf.ecore.EPackage)3 ENotificationImpl (org.eclipse.emf.ecore.impl.ENotificationImpl)3