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;
}
}
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);
}
}
}
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);
}
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;
}
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);
}
}
Aggregations