Search in sources :

Example 81 with EClassifier

use of org.eclipse.emf.ecore.EClassifier in project xtext-eclipse by eclipse.

the class XtextProposalProvider method appendReturnType.

protected boolean appendReturnType(final AbstractRule overrideMe, final Grammar grammar, StringBuilder newRuleFragment) {
    if (overrideMe instanceof ParserRule && ((ParserRule) overrideMe).isWildcard()) {
        newRuleFragment.append(" *");
        // no need to add an import to the grammar
        return true;
    } else {
        EClassifier classifier = overrideMe.getType().getClassifier();
        final EPackage classifierPackage = classifier.getEPackage();
        boolean foundPack = false;
        for (AbstractMetamodelDeclaration metamodel : grammar.getMetamodelDeclarations()) {
            EPackage available = metamodel.getEPackage();
            if (classifierPackage == available) {
                EDataType eString = GrammarUtil.findEString(grammar);
                if (eString == null)
                    eString = EcorePackage.Literals.ESTRING;
                if (classifier != eString && (!Strings.isEmpty(metamodel.getAlias()) || !classifier.getName().equals(overrideMe.getName()))) {
                    newRuleFragment.append(" returns ");
                    if (!Strings.isEmpty(metamodel.getAlias())) {
                        newRuleFragment.append(metamodel.getAlias()).append("::");
                    }
                    newRuleFragment.append(classifier.getName());
                }
                foundPack = true;
                break;
            }
        }
        if (!foundPack) {
            EDataType eString = GrammarUtil.findEString(grammar);
            if (eString == null)
                eString = EcorePackage.Literals.ESTRING;
            if (classifier == eString) {
                for (AbstractMetamodelDeclaration mm : GrammarUtil.allMetamodelDeclarations(grammar)) {
                    if (mm.getEPackage() == classifierPackage) {
                        foundPack = true;
                        break;
                    }
                }
            }
            if (!foundPack) {
                newRuleFragment.append(" returns ");
                newRuleFragment.append(classifierPackage.getName());
                newRuleFragment.append("::");
                newRuleFragment.append(classifier.getName());
            }
        }
        return foundPack;
    }
}
Also used : ParserRule(org.eclipse.xtext.ParserRule) EDataType(org.eclipse.emf.ecore.EDataType) EClassifier(org.eclipse.emf.ecore.EClassifier) AbstractMetamodelDeclaration(org.eclipse.xtext.AbstractMetamodelDeclaration) EPackage(org.eclipse.emf.ecore.EPackage)

Example 82 with EClassifier

use of org.eclipse.emf.ecore.EClassifier 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 83 with EClassifier

use of org.eclipse.emf.ecore.EClassifier 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 84 with EClassifier

use of org.eclipse.emf.ecore.EClassifier in project iobserve-analysis by research-iobserve.

the class cloudprofileModelWizard method getInitialObjectNames.

/**
 * Returns the names of the types that can be created as the root object.
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
protected Collection<String> getInitialObjectNames() {
    if (initialObjectNames == null) {
        initialObjectNames = new ArrayList<String>();
        for (EClassifier eClassifier : _cloudprofilePackage.getEClassifiers()) {
            if (eClassifier instanceof EClass) {
                EClass eClass = (EClass) eClassifier;
                if (!eClass.isAbstract()) {
                    initialObjectNames.add(eClass.getName());
                }
            }
        }
        Collections.sort(initialObjectNames, CommonPlugin.INSTANCE.getComparator());
    }
    return initialObjectNames;
}
Also used : EClass(org.eclipse.emf.ecore.EClass) EClassifier(org.eclipse.emf.ecore.EClassifier)

Example 85 with EClassifier

use of org.eclipse.emf.ecore.EClassifier in project openhab1-addons by openhab.

the class ConfigurationHandler method checkTfType.

/**
     * Checks if the {@code deviceType} is known by the {@link Ecosystem}.
     *
     * @param ohId The name of the device found in openhab.cfg as {@code String}.
     * @param deviceType The device type found in openhab.cfg as {@code String}.
     * @throws ConfigurationException
     */
private void checkTfType(String ohId, String deviceType) throws ConfigurationException {
    ModelPackage modelPackage = ModelPackage.eINSTANCE;
    boolean deviceFound = false;
    for (EClassifier eClassifier : modelPackage.getEClassifiers()) {
        if (eClassifier instanceof EClass) {
            EList<EAttribute> attributes = ((EClass) eClassifier).getEAllAttributes();
            for (EAttribute attribute : attributes) {
                if (attribute.getName().equals("deviceType")) {
                    if (attribute.getDefaultValueLiteral().equals(deviceType)) {
                        deviceFound = true;
                        break;
                    }
                }
            }
        }
    }
    if (!deviceFound) {
        throw new ConfigurationException(ohId, "unknown device type: " + deviceType);
    }
}
Also used : EClass(org.eclipse.emf.ecore.EClass) EAttribute(org.eclipse.emf.ecore.EAttribute) ConfigurationException(org.osgi.service.cm.ConfigurationException) ModelPackage(org.openhab.binding.tinkerforge.internal.model.ModelPackage) EClassifier(org.eclipse.emf.ecore.EClassifier)

Aggregations

EClassifier (org.eclipse.emf.ecore.EClassifier)153 EClass (org.eclipse.emf.ecore.EClass)94 Test (org.junit.Test)36 EPackage (org.eclipse.emf.ecore.EPackage)32 EReference (org.eclipse.emf.ecore.EReference)22 EStructuralFeature (org.eclipse.emf.ecore.EStructuralFeature)16 AbstractRule (org.eclipse.xtext.AbstractRule)14 EDataType (org.eclipse.emf.ecore.EDataType)13 EObject (org.eclipse.emf.ecore.EObject)13 XtextResource (org.eclipse.xtext.resource.XtextResource)10 EAttribute (org.eclipse.emf.ecore.EAttribute)8 EEnum (org.eclipse.emf.ecore.EEnum)8 Grammar (org.eclipse.xtext.Grammar)8 ParserRule (org.eclipse.xtext.ParserRule)8 ArrayList (java.util.ArrayList)7 ResourceSet (org.eclipse.emf.ecore.resource.ResourceSet)7 Assignment (org.eclipse.xtext.Assignment)7 IScope (org.eclipse.xtext.scoping.IScope)6 HashSet (java.util.HashSet)5 BimserverDatabaseException (org.bimserver.BimserverDatabaseException)5