static void checkFieldType( DmdlSemantics environment, PropertyDeclaration declaration, AstAttribute attribute, BasicTypeKind... types) { assert environment != null; assert declaration != null; assert attribute != null; assert types != null; assert types.length > 0; Type type = declaration.getType(); if (type instanceof BasicType) { BasicTypeKind kind = ((BasicType) type).getKind(); for (BasicTypeKind accept : types) { if (kind == accept) { return; } } } environment.report( new Diagnostic( Level.ERROR, attribute, Messages.getString("TsvFieldTrait.errorInconsistentType"), // $NON-NLS-1$ declaration.getOwner().getName().identifier, declaration.getName().identifier, attribute.name.toString(), Arrays.asList(types))); }
private boolean checkNotEmpty(DmdlSemantics environment, String name, AstLiteral stringLiteral) { assert environment != null; assert name != null; assert stringLiteral != null; assert stringLiteral.kind == LiteralKind.STRING; if (stringLiteral.toStringValue().isEmpty()) { environment.report( new Diagnostic( Level.ERROR, stringLiteral, "@{0}({1}) must not be empty", TARGET_NAME, name)); return false; } return true; }
private AstLiteral take( DmdlSemantics environment, Map<String, AstAttributeElement> elements, String elementName, LiteralKind kind) { assert environment != null; assert elements != null; assert elementName != null; assert kind != null; AstAttributeElement element = elements.remove(elementName); if (element == null) { return null; } else if ((element.value instanceof AstLiteral) == false) { environment.report( new Diagnostic( Level.ERROR, element, "@{0}({1}) must be a string literal", TARGET_NAME, elementName)); return null; } else { AstLiteral literal = (AstLiteral) element.value; if (literal.kind != kind) { environment.report( new Diagnostic( Level.ERROR, element, "@{0}({1}) must be a string literal", TARGET_NAME, elementName)); return null; } return literal; } }
static boolean checkConflict( DmdlSemantics environment, PropertyDeclaration declaration, AstAttribute attribute) { assert environment != null; assert declaration != null; assert attribute != null; if (declaration.getTrait(TsvFieldTrait.class) == null) { return true; } environment.report( new Diagnostic( Level.ERROR, attribute, Messages.getString("TsvFieldTrait.errorConflictAttribute"), // $NON-NLS-1$ declaration.getOwner().getName().identifier, declaration.getName().identifier)); return false; }