use of org.eclipse.xtext.EnumRule in project xtext-core by eclipse.
the class OverriddenValueInspector method caseRuleCall.
@Override
public Boolean caseRuleCall(RuleCall object) {
AbstractRule calledRule = object.getRule();
if (calledRule == null || calledRule.eIsProxy() || calledRule instanceof TerminalRule || calledRule instanceof EnumRule)
return Boolean.FALSE;
ParserRule parserRule = (ParserRule) calledRule;
if (GrammarUtil.isDatatypeRule(parserRule))
return Boolean.FALSE;
if (parserRule.isFragment()) {
visitFragment(object);
if (GrammarUtil.isMultipleCardinality(object))
visitFragment(object);
}
if (!addVisited(parserRule))
return Boolean.FALSE;
Multimap<String, AbstractElement> prevAssignedFeatures = assignedFeatures;
assignedFeatures = newMultimap();
doSwitch(parserRule.getAlternatives());
for (String feature : assignedFeatures.keySet()) prevAssignedFeatures.put(feature, object);
assignedFeatures = prevAssignedFeatures;
removeVisited(parserRule);
return Boolean.FALSE;
}
use of org.eclipse.xtext.EnumRule 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.EnumRule 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.EnumRule in project xtext-core by eclipse.
the class XtextValidator method checkEnumLiteralIsUnique.
@Check
public void checkEnumLiteralIsUnique(EnumLiteralDeclaration decl) {
EnumRule rule = GrammarUtil.containingEnumRule(decl);
List<EnumLiteralDeclaration> declarations = EcoreUtil2.getAllContentsOfType(rule, EnumLiteralDeclaration.class);
String literal = decl.getLiteral().getValue();
if (literal != null) {
for (EnumLiteralDeclaration otherDecl : declarations) {
if (otherDecl != decl && literal.equals(otherDecl.getLiteral().getValue())) {
error("Enum literal '" + literal + "' is used multiple times in enum rule '" + rule.getName() + "'.", XtextPackage.Literals.ENUM_LITERAL_DECLARATION__LITERAL);
}
}
}
}
use of org.eclipse.xtext.EnumRule 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;
}
}
}
Aggregations