Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[NONE] Ensure empty style value is accepted by STYLE grammar.
  • Loading branch information
nyssen committed Dec 22, 2016
1 parent e4a9b3b commit c060eaf
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 13 deletions.
Expand Up @@ -447,21 +447,21 @@ public void acceptWarning(String message, EObject object,
}
});

Map<Object, Object> context = new HashMap<>();
context.put(AbstractInjectableValidator.CURRENT_LANGUAGE_NAME,
Map<Object, Object> validationContext = new HashMap<>();
validationContext.put(
AbstractInjectableValidator.CURRENT_LANGUAGE_NAME,
ReflectionUtils.getPrivateFieldValue(validator,
"languageName"));

// validate the root element...
validator.validate(attributeValue, null /* diagnostic chain */,
context);
validationContext);

// ...and all its children
for (Iterator<EObject> iterator = EcoreUtil
.getAllProperContents(attributeValue, true); iterator
.hasNext();) {
validator.validate(iterator.next(),
null /* diagnostic chain */, context);
null /* diagnostic chain */, validationContext);
}
}
return diagnostics;
Expand Down
Expand Up @@ -15,8 +15,9 @@ grammar org.eclipse.gef.dot.internal.language.DotStyle hidden(WS)
generate style "http://www.eclipse.org/gef/dot/internal/language/DotStyle"
import "http://www.eclipse.org/emf/2002/Ecore" as ecore

// XXX: While not documented explicitly, an empty style seems to be valid as well
Style:
styleItems += StyleItem (',' styleItems+=StyleItem)*;
{Style} (styleItems += StyleItem (',' styleItems+=StyleItem)*)?;

StyleItem:
name=NAME ('(' args+=NAME (',' args+=NAME)* ')')?;
Expand Down
Expand Up @@ -173,7 +173,7 @@ public List<Diagnostic> validateAttributeValue(final Context context,
return validateDoubleAttributeValue(name, value, 0.01);
} else if (DotAttributes.HEIGHT__N.equals(name)) {
return validateDoubleAttributeValue(name, value, 0.02);
} else if (DotAttributes.STYLE__GNE.equals(name) && !value.isEmpty()) {
} else if (DotAttributes.STYLE__GNE.equals(name)) {
// validate style using delegate parser and validator
List<Diagnostic> grammarFindings = validateAttributeValue(
DotLanguageSupport.STYLE_PARSER,
Expand All @@ -185,7 +185,6 @@ public List<Diagnostic> validateAttributeValue(final Context context,
IAttributeValueParser.IParseResult<Style> parseResult = DotLanguageSupport.STYLE_PARSER
.parse(value);
Style style = parseResult.getParsedValue();

List<Diagnostic> findings = new ArrayList<>();
// TODO: this logic should rather be within
// DotStyleValidator
Expand Down Expand Up @@ -217,6 +216,7 @@ public List<Diagnostic> validateAttributeValue(final Context context,
return validateAttributeValue(DotLanguageSupport.COLOR_PARSER,
DotLanguageSupport.COLOR_VALIDATOR, name, value, "color");
} else if (DotAttributes.COLORSCHEME__GNE.equals(name)) {
// TODO: Move into ColorScheme validator
return validateStringAttributeValue(name, value,
DotAttributes.COLORSCHEME__GNE,
DotColors.getColorSchemes().toArray());
Expand Down
Expand Up @@ -19,12 +19,52 @@
public class DotStyleJavaValidator extends
org.eclipse.gef.dot.internal.language.validation.AbstractDotStyleJavaValidator {

// /**
// * Validates that the used {@link StyleItem}s are applicable in the
// * respective {@link Context}.
// *
// * @param styleItem
// * The {@link StyleItem} to check.
// */
// @Check
// public void checkGreetingStartsWithCapital(Greeting greeting) {
// if (!Character.isUpperCase(greeting.getName().charAt(0))) {
// warning("Name should start with a capital",
// MyDslPackage.Literals.GREETING__NAME);
// public void checkNodeAndEdgeStylesUsedInRightContext(StyleItem styleItem)
// {
// Context attributeContext = (Context) getContext()
// .get(DotLanguageSupport.Context.class.getName());
// if (attributeContext == null) {
// throw new IllegalStateException("Attribute context not specified.");
// }
// if (Context.NODE.equals(attributeContext)) {
// for (Object validValue : NodeStyle.values()) {
// if (validValue.toString().equals(styleItem.getName())) {
// return;
// }
// }
// // check each style item with the corresponding parser
// error("Value should be one of "
// + getFormattedValues(NodeStyle.values()) + ".",
// StylePackage.Literals.STYLE__STYLE_ITEMS);
// } else if (Context.EDGE.equals(attributeContext)) {
// for (Object validValue : EdgeStyle.values()) {
// if (validValue.toString().equals(styleItem.getName())) {
// return;
// }
// }
// // check each style item with the corresponding parser
// error("Value should be one of "
// + getFormattedValues(EdgeStyle.values()) + ".",
// StylePackage.Literals.STYLE__STYLE_ITEMS);
// }
// }
//
// private String getFormattedValues(Object[] values) {
// StringBuilder sb = new StringBuilder();
// for (Object value : new TreeSet<>(Arrays.asList(values))) {
// if (sb.length() > 0) {
// sb.append(", ");
// }
// sb.append("'" + value + "'");
// }
// return sb.toString();
// }
// TODO: validate edge style and node style
}

0 comments on commit c060eaf

Please sign in to comment.