use of org.eclipse.emf.ecore.EEnum in project xtext-core by eclipse.
the class GrammarParserTest method testEnum_08.
@Test
public void testEnum_08() throws Exception {
String modelAsString = "grammar TestLanguage with org.eclipse.xtext.common.Terminals\n" + "generate testLanguage 'http://www.eclipse.org/2009/tmf/xtext/AbstractEnumRulesTest/TestEnum/8'\n" + "Model: enumValue=MyEnum;\n" + "enum MyEnum: Value | Value = 'foo';";
Grammar grammar = (Grammar) getModel(modelAsString);
assertTrue(grammar.eResource().getErrors().toString(), grammar.eResource().getErrors().isEmpty());
checkEnums(grammar);
EPackage pack = grammar.getMetamodelDeclarations().get(0).getEPackage();
assertEquals("http://www.eclipse.org/2009/tmf/xtext/AbstractEnumRulesTest/TestEnum/8", pack.getNsURI());
EEnum eEnum = (EEnum) pack.getEClassifier("MyEnum");
assertNotNull(eEnum);
assertEquals(1, eEnum.getELiterals().size());
EEnumLiteral value = eEnum.getELiterals().get(0);
assertEquals("Value", value.getName());
assertEquals(0, value.getValue());
assertEquals("Value", value.getLiteral());
}
use of org.eclipse.emf.ecore.EEnum in project xtext-core by eclipse.
the class GrammarParserTest method testEnum_04.
@Test
public void testEnum_04() throws Exception {
String modelAsString = "grammar TestLanguage with org.eclipse.xtext.common.Terminals\n" + "import 'classpath:/org/eclipse/xtext/enumrules/enums.ecore'\n" + "generate testLanguage 'http://www.eclipse.org/2009/tmf/xtext/AbstractEnumRulesTest/TestEnum/4'\n" + "Model: enumValue=ExistingEnum;\n" + "enum ExistingEnum: SameName;";
Grammar grammar = (Grammar) getModel(modelAsString);
assertTrue(grammar.eResource().getErrors().toString(), grammar.eResource().getErrors().isEmpty());
checkEnums(grammar);
EPackage pack = grammar.getMetamodelDeclarations().get(0).getEPackage();
assertEquals("http://www.eclipse.org/2009/tmf/xtext/EnumRulesTestLanguage/imported", pack.getNsURI());
EEnum eEnum = (EEnum) pack.getEClassifier("ExistingEnum");
assertNotNull(eEnum);
assertEquals(3, eEnum.getELiterals().size());
EEnumLiteral value = eEnum.getELiterals().get(0);
assertEquals(ExistingEnum.SAME_NAME.getName(), value.getName());
assertEquals(ExistingEnum.SAME_NAME.getValue(), value.getValue());
assertEquals(ExistingEnum.SAME_NAME.getLiteral(), value.getLiteral());
EnumRule rule = (EnumRule) grammar.getRules().get(1);
assertEquals(eEnum, rule.getType().getClassifier());
EnumLiteralDeclaration decl = (EnumLiteralDeclaration) rule.getAlternatives();
assertEquals(value, decl.getEnumLiteral());
assertNotNull(decl.getLiteral());
assertEquals(value.getLiteral(), decl.getLiteral().getValue());
}
use of org.eclipse.emf.ecore.EEnum in project xtext-core by eclipse.
the class XtextValidator method checkGeneratedEnumIsValid.
@Check
public void checkGeneratedEnumIsValid(EnumLiteralDeclaration decl) {
EnumRule rule = GrammarUtil.containingEnumRule(decl);
if (!(rule.getType().getMetamodel() instanceof GeneratedMetamodel))
return;
if (!(rule.getType().getClassifier() instanceof EEnum))
return;
EEnum eEnum = (EEnum) rule.getType().getClassifier();
List<EnumLiteralDeclaration> declarations = EcoreUtil2.getAllContentsOfType(rule, EnumLiteralDeclaration.class);
if (declarations.size() == eEnum.getELiterals().size())
return;
for (EnumLiteralDeclaration otherDecl : declarations) {
if (decl == otherDecl) {
return;
}
if (otherDecl.getEnumLiteral() == decl.getEnumLiteral()) {
if (!decl.getEnumLiteral().getLiteral().equals(decl.getLiteral().getValue()))
addIssue("Enum literal '" + decl.getEnumLiteral().getName() + "' has already been defined with literal '" + decl.getEnumLiteral().getLiteral() + "'.", decl, XtextPackage.Literals.ENUM_LITERAL_DECLARATION__ENUM_LITERAL, DUPLICATE_ENUM_LITERAL);
return;
}
}
}
use of org.eclipse.emf.ecore.EEnum 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.EEnum in project BIMserver by opensourceBIM.
the class ByteBufferVirtualObject method setAttribute.
public void setAttribute(EStructuralFeature feature, Object value) throws BimserverDatabaseException {
if (feature.isMany()) {
throw new UnsupportedOperationException("Feature isMany not supported by setAttribute");
} else {
if (feature.getEType() instanceof EEnum) {
writeEnum(feature, value);
} else if (feature.getEType() instanceof EClass) {
if (value == null) {
ensureCapacity(buffer.position(), 2);
buffer.order(ByteOrder.LITTLE_ENDIAN);
buffer.putShort((short) -1);
buffer.order(ByteOrder.BIG_ENDIAN);
} else if (value instanceof WrappedVirtualObject) {
ByteBuffer otherBuffer = ((WrappedVirtualObject) value).write();
ensureCapacity(buffer.position(), otherBuffer.position());
buffer.put(otherBuffer.array(), 0, otherBuffer.position());
// writeWrappedValue(getPid(), getRid(), (WrappedVirtualObject) value, getPackageMetaData());
} else {
throw new UnsupportedOperationException("??");
}
} else if (feature.getEType() instanceof EDataType) {
writePrimitiveValue(feature, value);
}
}
incrementFeatureCounter(feature);
}
Aggregations