Search in sources :

Example 16 with IEObjectDescription

use of org.eclipse.xtext.resource.IEObjectDescription in project xtext-eclipse by eclipse.

the class XtextProposalProvider method completeAction_Feature.

@Override
public void completeAction_Feature(EObject model, Assignment assignment, ContentAssistContext context, ICompletionProposalAcceptor acceptor) {
    Action action = EcoreUtil2.getContainerOfType(model, Action.class);
    if (action != null && action.getType() != null) {
        EClassifier classifier = action.getType().getClassifier();
        if (classifier instanceof EClass) {
            List<EReference> containments = ((EClass) classifier).getEAllContainments();
            Function<IEObjectDescription, ICompletionProposal> factory = getProposalFactory(grammarAccess.getValidIDRule().getName(), context);
            completeStructuralFeatures(context, factory, acceptor, containments);
        }
    }
    super.completeAction_Feature(model, assignment, context, acceptor);
}
Also used : Action(org.eclipse.xtext.Action) EClass(org.eclipse.emf.ecore.EClass) ICompletionProposal(org.eclipse.jface.text.contentassist.ICompletionProposal) EClassifier(org.eclipse.emf.ecore.EClassifier) EReference(org.eclipse.emf.ecore.EReference) IEObjectDescription(org.eclipse.xtext.resource.IEObjectDescription)

Example 17 with IEObjectDescription

use of org.eclipse.xtext.resource.IEObjectDescription in project xtext-eclipse by eclipse.

the class XtextProposalProvider method createFeatureProposal.

protected ICompletionProposal createFeatureProposal(EStructuralFeature feature, int priorityFactor, Function<IEObjectDescription, ICompletionProposal> factory, ContentAssistContext context) {
    IEObjectDescription description = EObjectDescription.create(QualifiedName.create(feature.getName()), feature);
    ConfigurableCompletionProposal proposal = (ConfigurableCompletionProposal) factory.apply(description);
    if (proposal != null) {
        proposal.setPriority(proposal.getPriority() * priorityFactor);
        if (SemanticHighlightingCalculator.SPECIAL_ATTRIBUTES.contains(feature.getName())) {
            StyledString displayString = stylerFactory.createFromXtextStyle(feature.getName(), semanticHighlightingConfiguration.specialAttribute()).append(" - Assignment of special attribute ").append(stylerFactory.createFromXtextStyle(feature.getName(), semanticHighlightingConfiguration.specialAttribute()));
            proposal.setDisplayString(displayString);
        } else {
            proposal.setDisplayString(new StyledString(feature.getName() + " - Assignment of feature " + feature.getName()));
        }
        if (feature.isMany()) {
            proposal.setReplacementString(feature.getName() + "+=");
            proposal.setCursorPosition(proposal.getCursorPosition() + 2);
        } else if (feature.getEType() == EcorePackage.Literals.EBOOLEAN) {
            proposal.setReplacementString(feature.getName() + "?=");
            proposal.setCursorPosition(proposal.getCursorPosition() + 2);
        } else {
            proposal.setReplacementString(feature.getName() + "=");
            proposal.setCursorPosition(proposal.getCursorPosition() + 1);
        }
    }
    return proposal;
}
Also used : ConfigurableCompletionProposal(org.eclipse.xtext.ui.editor.contentassist.ConfigurableCompletionProposal) StyledString(org.eclipse.jface.viewers.StyledString) IEObjectDescription(org.eclipse.xtext.resource.IEObjectDescription)

Example 18 with IEObjectDescription

use of org.eclipse.xtext.resource.IEObjectDescription in project xtext-eclipse by eclipse.

the class XtextProposalProvider method completeRuleCall.

private void completeRuleCall(EObject model, Assignment assignment, final ContentAssistContext context, ICompletionProposalAcceptor acceptor) {
    final Assignment containingAssignment = GrammarUtil.containingAssignment(model);
    CrossReference crossReference = (CrossReference) assignment.getTerminal();
    lookupCrossReference(crossReference, context, acceptor, new Predicate<IEObjectDescription>() {

        @Override
        public boolean apply(IEObjectDescription input) {
            if (input.getEClass() == XtextPackage.Literals.TERMINAL_RULE) {
                EObject object = resolve(input, context);
                if (object instanceof TerminalRule) {
                    return !((TerminalRule) object).isFragment();
                }
            }
            if (containingAssignment != null && input.getEClass() == XtextPackage.Literals.PARSER_RULE) {
                EObject object = resolve(input, context);
                if (object instanceof ParserRule) {
                    return !((ParserRule) object).isFragment();
                }
            }
            return true;
        }
    });
}
Also used : Assignment(org.eclipse.xtext.Assignment) ParserRule(org.eclipse.xtext.ParserRule) EObject(org.eclipse.emf.ecore.EObject) CrossReference(org.eclipse.xtext.CrossReference) TerminalRule(org.eclipse.xtext.TerminalRule) IEObjectDescription(org.eclipse.xtext.resource.IEObjectDescription)

Example 19 with IEObjectDescription

use of org.eclipse.xtext.resource.IEObjectDescription in project xtext-eclipse by eclipse.

the class XtextProposalProvider method createClassifierProposals.

private void createClassifierProposals(AbstractMetamodelDeclaration declaration, EObject model, ContentAssistContext context, ICompletionProposalAcceptor acceptor) {
    String alias = declaration.getAlias();
    QualifiedName prefix = (!Strings.isEmpty(alias)) ? QualifiedName.create(getValueConverter().toString(alias, grammarAccess.getValidIDRule().getName())) : null;
    boolean createDatatypeProposals = !(model instanceof AbstractElement) && modelOrContainerIs(model, AbstractRule.class);
    boolean createEnumProposals = !(model instanceof AbstractElement) && modelOrContainerIs(model, EnumRule.class);
    boolean createClassProposals = modelOrContainerIs(model, ParserRule.class, CrossReference.class, Action.class);
    Function<IEObjectDescription, ICompletionProposal> factory = new DefaultProposalCreator(context, null, classifierQualifiedNameConverter);
    for (EClassifier classifier : declaration.getEPackage().getEClassifiers()) {
        if (classifier instanceof EDataType && createDatatypeProposals || classifier instanceof EEnum && createEnumProposals || classifier instanceof EClass && createClassProposals) {
            String classifierName = getValueConverter().toString(classifier.getName(), grammarAccess.getValidIDRule().getName());
            QualifiedName proposalQualifiedName = (prefix != null) ? prefix.append(classifierName) : QualifiedName.create(classifierName);
            IEObjectDescription description = EObjectDescription.create(proposalQualifiedName, classifier);
            ConfigurableCompletionProposal proposal = (ConfigurableCompletionProposal) factory.apply(description);
            if (proposal != null) {
                if (prefix != null)
                    proposal.setDisplayString(classifier.getName() + " - " + alias);
                proposal.setPriority(proposal.getPriority() * 2);
            }
            acceptor.accept(proposal);
        }
    }
}
Also used : AbstractElement(org.eclipse.xtext.AbstractElement) EDataType(org.eclipse.emf.ecore.EDataType) QualifiedName(org.eclipse.xtext.naming.QualifiedName) EClassifier(org.eclipse.emf.ecore.EClassifier) StyledString(org.eclipse.jface.viewers.StyledString) EEnum(org.eclipse.emf.ecore.EEnum) IEObjectDescription(org.eclipse.xtext.resource.IEObjectDescription) EnumRule(org.eclipse.xtext.EnumRule) EClass(org.eclipse.emf.ecore.EClass) ConfigurableCompletionProposal(org.eclipse.xtext.ui.editor.contentassist.ConfigurableCompletionProposal) ICompletionProposal(org.eclipse.jface.text.contentassist.ICompletionProposal) AbstractRule(org.eclipse.xtext.AbstractRule)

Example 20 with IEObjectDescription

use of org.eclipse.xtext.resource.IEObjectDescription in project xtext-eclipse by eclipse.

the class XtextProposalProvider method completeHiddenTokens.

/**
 * Do not propose terminal fragments in hidden token sections.
 */
protected void completeHiddenTokens(Assignment assignment, final ContentAssistContext context, ICompletionProposalAcceptor acceptor) {
    CrossReference crossReference = (CrossReference) assignment.getTerminal();
    lookupCrossReference(crossReference, context, acceptor, new Predicate<IEObjectDescription>() {

        @Override
        public boolean apply(IEObjectDescription input) {
            if (input.getEClass() == XtextPackage.Literals.TERMINAL_RULE) {
                EObject object = resolve(input, context);
                if (object instanceof TerminalRule)
                    return !((TerminalRule) object).isFragment();
            }
            return false;
        }
    });
}
Also used : EObject(org.eclipse.emf.ecore.EObject) CrossReference(org.eclipse.xtext.CrossReference) TerminalRule(org.eclipse.xtext.TerminalRule) IEObjectDescription(org.eclipse.xtext.resource.IEObjectDescription)

Aggregations

IEObjectDescription (org.eclipse.xtext.resource.IEObjectDescription)324 Test (org.junit.Test)95 EObject (org.eclipse.emf.ecore.EObject)82 QualifiedName (org.eclipse.xtext.naming.QualifiedName)79 IScope (org.eclipse.xtext.scoping.IScope)56 URI (org.eclipse.emf.common.util.URI)41 IResourceDescription (org.eclipse.xtext.resource.IResourceDescription)33 EClass (org.eclipse.emf.ecore.EClass)30 Resource (org.eclipse.emf.ecore.resource.Resource)28 EObjectDescription (org.eclipse.xtext.resource.EObjectDescription)22 AliasedEObjectDescription (org.eclipse.xtext.resource.impl.AliasedEObjectDescription)22 ArrayList (java.util.ArrayList)19 IResourceDescriptions (org.eclipse.xtext.resource.IResourceDescriptions)14 ResourceSet (org.eclipse.emf.ecore.resource.ResourceSet)12 ICompletionProposal (org.eclipse.jface.text.contentassist.ICompletionProposal)12 StyledString (org.eclipse.jface.viewers.StyledString)12 XtextResource (org.eclipse.xtext.resource.XtextResource)11 StringInputStream (org.eclipse.xtext.util.StringInputStream)11 EReference (org.eclipse.emf.ecore.EReference)10 List (java.util.List)9