Ejemplo n.º 1
0
 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)));
 }
Ejemplo n.º 2
0
 private void analyzeElements(
     DmdlSemantics environment,
     AstAttribute attribute,
     Map<String, AstAttributeElement> elements,
     HiveFieldTrait trait) {
   trait.setTimestampTypeInfo();
   environment.reportAll(AttributeUtil.reportInvalidElements(attribute, elements.values()));
 }
Ejemplo n.º 3
0
 @Override
 public void process(
     DmdlSemantics environment, PropertyDeclaration declaration, AstAttribute attribute) {
   environment.reportAll(AttributeUtil.reportInvalidElements(attribute, attribute.elements));
   CsvFieldDriver.checkFieldType(environment, declaration, attribute, BasicTypeKind.TEXT);
   if (CsvFieldDriver.checkConflict(environment, declaration, attribute)) {
     declaration.putTrait(CsvFieldTrait.class, new CsvFieldTrait(attribute, Kind.FILE_NAME, null));
   }
 }
 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;
   }
 }
Ejemplo n.º 6
0
 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;
 }
  private Configuration analyzeConfig(
      DmdlSemantics environment,
      AstAttribute attribute,
      Map<String, AstAttributeElement> elements) {
    AstLiteral charset = take(environment, elements, ELEMENT_CHARSET_NAME, LiteralKind.STRING);
    AstLiteral header = take(environment, elements, ELEMENT_HAS_HEADER_NAME, LiteralKind.BOOLEAN);
    AstLiteral codec = take(environment, elements, ELEMENT_CODEC_NAME, LiteralKind.STRING);
    environment.reportAll(AttributeUtil.reportInvalidElements(attribute, elements.values()));

    Configuration result = new Configuration();
    if (charset != null && checkNotEmpty(environment, ELEMENT_CHARSET_NAME, charset)) {
      result.setCharsetName(charset.toStringValue());
    }
    if (header != null) {
      result.setEnableHeader(header.toBooleanValue());
    }
    if (codec != null && checkNotEmpty(environment, ELEMENT_CODEC_NAME, codec)) {
      result.setCodecName(codec.toStringValue());
    }
    return result;
  }