use of org.eclipse.xtext.GeneratedMetamodel in project xtext-eclipse by eclipse.
the class XtextHyperlinkHelper method acceptHyperLink.
protected boolean acceptHyperLink(XtextResource resource, EObject objectAtOffset) {
if (objectAtOffset instanceof EClass) {
EClass eClass = (EClass) objectAtOffset;
Grammar grammar = GrammarUtil.getGrammar(resource.getEObject("/"));
List<AbstractMetamodelDeclaration> allMetamodelDeclarations = GrammarUtil.allMetamodelDeclarations(grammar);
for (GeneratedMetamodel generatedMetamodel : Iterables.filter(allMetamodelDeclarations, GeneratedMetamodel.class)) {
if (eClass.getEPackage().equals(generatedMetamodel.getEPackage())) {
return false;
}
}
}
return true;
}
use of org.eclipse.xtext.GeneratedMetamodel in project xtext-eclipse by eclipse.
the class XtextProposalProvider method completeGeneratedMetamodel_Alias.
@Override
public void completeGeneratedMetamodel_Alias(EObject model, Assignment assignment, ContentAssistContext context, ICompletionProposalAcceptor acceptor) {
if (model instanceof GeneratedMetamodel) {
EPackage ePackage = ((GeneratedMetamodel) model).getEPackage();
String name = ((GeneratedMetamodel) model).getName();
createAliasProposal(context, acceptor, ePackage, name);
}
super.completeGeneratedMetamodel_Alias(model, assignment, context, acceptor);
}
use of org.eclipse.xtext.GeneratedMetamodel in project xtext-core by eclipse.
the class XtextLinker method createDiagnosticProducer.
@Override
protected IDiagnosticProducer createDiagnosticProducer(final IDiagnosticConsumer consumer) {
return new AbstractDiagnosticProducerDecorator(super.createDiagnosticProducer(consumer)) {
private boolean filter = false;
@Override
public void addDiagnostic(DiagnosticMessage message) {
if (!filter)
super.addDiagnostic(message);
}
@Override
public void setTarget(EObject object, EStructuralFeature feature) {
super.setTarget(object, feature);
// we don't want to mark generated types as errors unless generation fails
filter = isTypeRef(object, feature) || isGeneratedPackage(object, feature) || isEnumLiteral(object, feature);
}
private boolean isEnumLiteral(EObject object, EStructuralFeature feature) {
if (feature == XtextPackage.eINSTANCE.getEnumLiteralDeclaration_EnumLiteral()) {
EnumRule rule = GrammarUtil.containingEnumRule(object);
return rule.getType() == null || rule.getType().getClassifier() == null;
}
return false;
}
private boolean isGeneratedPackage(EObject object, EStructuralFeature feature) {
return (feature == XtextPackage.eINSTANCE.getAbstractMetamodelDeclaration_EPackage() && (object instanceof GeneratedMetamodel));
}
private boolean isTypeRef(EObject object, EStructuralFeature feature) {
return (feature == XtextPackage.eINSTANCE.getTypeRef_Classifier() && ((TypeRef) object).getMetamodel() instanceof GeneratedMetamodel);
}
};
}
use of org.eclipse.xtext.GeneratedMetamodel 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.xtext.GeneratedMetamodel in project xtext-core by eclipse.
the class Xtext2EcoreTransformerTest method testBug296496_02.
@Test
public void testBug296496_02() throws Exception {
StringConcatenation _builder = new StringConcatenation();
_builder.append("grammar test with org.eclipse.xtext.common.Terminals");
_builder.newLine();
_builder.append("import \"classpath:/org/eclipse/xtext/enumrules/enums.ecore\"");
_builder.newLine();
_builder.append("generate myDsl \"http://example.xtext.org/MyDsl\"");
_builder.newLine();
_builder.append("CreatedType:");
_builder.newLine();
_builder.append(" ");
_builder.append("enumFeature=ExistingEnum otherEnumFeature=ExistingEnum;");
_builder.newLine();
_builder.append("enum ExistingEnum:");
_builder.newLine();
_builder.append(" ");
_builder.append("SameName | OverriddenLiteral = \"overridden\" | DifferentName;");
_builder.newLine();
final String grammarAsString = _builder.toString();
final XtextResource resource = this.getResourceFromStringAndExpect(grammarAsString, 0);
Assert.assertTrue(resource.getErrors().toString(), resource.getErrors().isEmpty());
EObject _head = IterableExtensions.<EObject>head(resource.getContents());
final Grammar grammar = ((Grammar) _head);
AbstractMetamodelDeclaration _get = grammar.getMetamodelDeclarations().get(1);
GeneratedMetamodel generatedMetamodel = ((GeneratedMetamodel) _get);
Assert.assertEquals("myDsl", generatedMetamodel.getName());
EClassifier _type = this.<EClassifier>type(generatedMetamodel.getEPackage(), "CreatedType");
EClass createdType = ((EClass) _type);
Assert.assertEquals(this.<EStructuralFeature>feature(createdType, "enumFeature").getEType(), this.<EStructuralFeature>feature(createdType, "otherEnumFeature").getEType());
}
Aggregations