use of org.eclipse.xtext.EnumLiteralDeclaration in project xtext-eclipse by eclipse.
the class XtextGrammarQuickfixProvider method fixEmptyEnumLiteral.
@Fix(EMPTY_ENUM_LITERAL)
public void fixEmptyEnumLiteral(final Issue issue, IssueResolutionAcceptor acceptor) {
acceptor.acceptMulti(issue, "Fix empty enum literal", "Fix empty enum literal", NULL_QUICKFIX_IMAGE, (EObject element) -> {
EnumLiteralDeclaration enumLiteralDeclaration = (EnumLiteralDeclaration) element;
Keyword keyword = XtextFactory.eINSTANCE.createKeyword();
keyword.setValue(enumLiteralDeclaration.getEnumLiteral().getName().toLowerCase());
enumLiteralDeclaration.setLiteral(keyword);
});
}
use of org.eclipse.xtext.EnumLiteralDeclaration 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.EnumLiteralDeclaration 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.EnumLiteralDeclaration 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.EnumLiteralDeclaration in project xtext-core by eclipse.
the class GrammarAccessExtensions method getSingleElementDescription.
private List<String> getSingleElementDescription(final AbstractElement ele) {
final ArrayList<String> r = new ArrayList<String>(2);
boolean _matched = false;
if (ele instanceof Keyword) {
_matched = true;
String _value = ((Keyword) ele).getValue();
r.add(_value);
}
if (!_matched) {
if (ele instanceof Assignment) {
_matched = true;
String _feature = ((Assignment) ele).getFeature();
r.add(_feature);
}
}
if (!_matched) {
if (ele instanceof RuleCall) {
_matched = true;
String _name = ((RuleCall) ele).getRule().getName();
r.add(_name);
}
}
if (!_matched) {
if (ele instanceof Action) {
_matched = true;
TypeRef _type = ((Action) ele).getType();
EClassifier _classifier = null;
if (_type != null) {
_classifier = _type.getClassifier();
}
boolean _tripleNotEquals = (_classifier != null);
if (_tripleNotEquals) {
String _name = ((Action) ele).getType().getClassifier().getName();
r.add(_name);
}
boolean _isNullOrEmpty = StringExtensions.isNullOrEmpty(((Action) ele).getFeature());
boolean _not = (!_isNullOrEmpty);
if (_not) {
String _feature = ((Action) ele).getFeature();
r.add(_feature);
}
}
}
if (!_matched) {
if (ele instanceof CrossReference) {
_matched = true;
TypeRef _type = ((CrossReference) ele).getType();
EClassifier _classifier = null;
if (_type != null) {
_classifier = _type.getClassifier();
}
boolean _tripleNotEquals = (_classifier != null);
if (_tripleNotEquals) {
String _name = ((CrossReference) ele).getType().getClassifier().getName();
r.add(_name);
}
}
}
if (!_matched) {
if (ele instanceof EnumLiteralDeclaration) {
_matched = true;
String _name = ((EnumLiteralDeclaration) ele).getEnumLiteral().getName();
r.add(_name);
}
}
return r;
}
Aggregations