use of org.eclipse.xtext.AbstractMetamodelDeclaration in project xtext-core by eclipse.
the class XtextResourceDescriptionStrategy method createEObjectDescriptions.
@Override
public boolean createEObjectDescriptions(EObject eObject, IAcceptor<IEObjectDescription> acceptor) {
if (eObject instanceof Grammar) {
String grammarName = ((Grammar) eObject).getName();
if (!Strings.isEmpty(grammarName)) {
QualifiedName qualifiedName = defaultQualifiedNameConverter.toQualifiedName(grammarName);
acceptor.accept(EObjectDescription.create(qualifiedName, eObject));
}
} else if (eObject instanceof AbstractMetamodelDeclaration || eObject instanceof AbstractRule)
return super.createEObjectDescriptions(eObject, acceptor);
return eObject instanceof Grammar;
}
use of org.eclipse.xtext.AbstractMetamodelDeclaration in project xtext-core by eclipse.
the class XtextTransientValueService2 method isValueTransient.
@Override
public ValueTransient isValueTransient(EObject owner, EStructuralFeature feature) {
if (feature == XtextPackage.eINSTANCE.getTypeRef_Metamodel()) {
final TypeRef typeRef = (TypeRef) owner;
final AbstractMetamodelDeclaration m = typeRef.getMetamodel();
if (m == null || Strings.isEmpty(m.getAlias()))
return YES;
} else if (feature == XtextPackage.eINSTANCE.getAbstractRule_Type()) {
final AbstractRule rule = (AbstractRule) owner;
if (!GrammarUtil.isDatatypeRule(rule) && (rule instanceof ParserRule || rule instanceof EnumRule)) {
final TypeRef returnType = rule.getType();
if (returnType == null || returnType.getClassifier() == null)
return YES;
else if (rule.getName().equals(returnType.getClassifier().getName())) {
if (isValueTransient(returnType, XtextPackage.eINSTANCE.getTypeRef_Metamodel()) == YES)
return PREFERABLY;
else
return NO;
} else if (GrammarUtil.isDatatypeRule(rule)) {
return NodeModelUtils.getNode(returnType) == null ? YES : NO;
}
} else if (rule instanceof TerminalRule || GrammarUtil.isDatatypeRule(rule)) {
final TypeRef returnType = rule.getType();
if (returnType == null)
return YES;
if (rule instanceof TerminalRule) {
if (((TerminalRule) rule).isFragment()) {
return YES;
}
}
if (GrammarUtil.findEString(GrammarUtil.getGrammar(owner)).equals(rule.getType().getClassifier()))
return PREFERABLY;
return NO;
}
} else if (feature == XtextPackage.eINSTANCE.getCrossReference_Terminal()) {
final CrossReference ref = (CrossReference) owner;
if (ref.getTerminal() instanceof RuleCall && ((RuleCall) ref.getTerminal()).getRule() != null) {
if ("ID".equals(((RuleCall) ref.getTerminal()).getRule().getName()))
return PREFERABLY;
else
return NO;
}
return YES;
} else if (feature == XtextPackage.eINSTANCE.getEnumLiteralDeclaration_Literal()) {
final EnumLiteralDeclaration decl = (EnumLiteralDeclaration) owner;
if (decl.getEnumLiteral() != null && decl.getLiteral() != null) {
if (Strings.equal(decl.getLiteral().getValue(), decl.getEnumLiteral().getName()))
return PREFERABLY;
return NO;
}
return YES;
} else if (feature == XtextPackage.eINSTANCE.getRuleCall_ExplicitlyCalled()) {
return YES;
} else if (feature == XtextPackage.eINSTANCE.getNamedArgument_Parameter()) {
if (((NamedArgument) owner).isCalledByName()) {
return NO;
}
return YES;
}
return super.isValueTransient(owner, feature);
}
use of org.eclipse.xtext.AbstractMetamodelDeclaration in project xtext-core by eclipse.
the class XtextValidator method checkMetamodelUris.
@Check
public void checkMetamodelUris(final AbstractMetamodelDeclaration declaration) {
if (!(declaration.getEPackage() != null && declaration.getEPackage().getNsURI() != null))
return;
Grammar grammar = GrammarUtil.getGrammar(declaration);
Iterable<String> nsUris = Iterables.transform(grammar.getMetamodelDeclarations(), new Function<AbstractMetamodelDeclaration, String>() {
@Override
public String apply(AbstractMetamodelDeclaration param) {
if (param.getEPackage() != null)
return param.getEPackage().getNsURI();
return null;
}
});
int count = Iterables.size(Iterables.filter(nsUris, new Predicate<String>() {
@Override
public boolean apply(String param) {
return declaration.getEPackage().getNsURI().equals(param);
}
}));
if (count != 1) {
error("EPackage with ns-uri '" + declaration.getEPackage().getNsURI() + "' is used twice.", XtextPackage.Literals.ABSTRACT_METAMODEL_DECLARATION__EPACKAGE);
}
}
use of org.eclipse.xtext.AbstractMetamodelDeclaration in project xtext-core by eclipse.
the class ToEcoreTrafoTest method testConcreteLanguageToMetamodel1.
@Test
public void testConcreteLanguageToMetamodel1() throws Exception {
XtextResource r = getResource("classpath:/" + ConcreteTestLanguage.class.getName().replace('.', '/') + ".xtext");
EObject element = r.getContents().get(0);
Grammar g = (Grammar) element;
List<AbstractMetamodelDeclaration> mms = Lists.<AbstractMetamodelDeclaration>newArrayList(Iterables.filter(g.getMetamodelDeclarations(), GeneratedMetamodel.class));
assertNotNull(mms);
assertEquals(1, mms.size());
}
use of org.eclipse.xtext.AbstractMetamodelDeclaration in project xtext-core by eclipse.
the class NodeModelUtilsTest method testFindNodesForFeature.
@Test
public void testFindNodesForFeature() throws Exception {
Grammar grammar = (Grammar) getModel("grammar foo.Bar with org.eclipse.xtext.common.Terminals generate foo 'bar' Model : name=ID;");
List<INode> nodes = NodeModelUtils.findNodesForFeature(grammar, XtextPackage.eINSTANCE.getGrammar_Name());
assertEquals(1, nodes.size());
assertEquals("foo.Bar", nodes.get(0).getText().trim());
nodes = NodeModelUtils.findNodesForFeature(grammar, XtextPackage.eINSTANCE.getGrammar_Rules());
assertEquals(1, nodes.size());
assertEquals("Model : name=ID;", nodes.get(0).getText().trim());
AbstractMetamodelDeclaration declaration = grammar.getMetamodelDeclarations().get(0);
nodes = NodeModelUtils.findNodesForFeature(declaration, XtextPackage.eINSTANCE.getGeneratedMetamodel_Name());
assertEquals(1, nodes.size());
assertEquals("foo", nodes.get(0).getText().trim());
nodes = NodeModelUtils.findNodesForFeature(declaration, null);
assertEquals(0, nodes.size());
}
Aggregations