Java 类org.eclipse.xtext.conversion.impl.AbstractNullSafeConverter 实例源码

项目:xtext-core    文件:Ecore2XtextTerminalConverters.java   
@ValueConverter(rule = "EString")
public IValueConverter<String> EString() {
    return new AbstractNullSafeConverter<String>() {
        @Override
        protected String internalToValue(String string, INode node) {
            if((string.startsWith("'") && string.endsWith("'"))||(string.startsWith("\"") && string.endsWith("\""))) {
                return STRING().toValue(string, node);
            }
            return ID().toValue(string, node);
        }

        @Override
        protected String internalToString(String value) {
            if(ID_PATTERN.matcher(value).matches()) {
                return ID().toString(value);
            } else {
                return STRING().toString(value);
            }
        }
    };
}
项目:xtext-core    文件:TerminalRuleTestLanguageConverters.java   
@ValueConverter(rule = "ID")
public IValueConverter<String> ID() {
    return new AbstractNullSafeConverter<String>() {
        @Override
        protected String internalToValue(String string, INode node) {
            return string.startsWith("^") ? string.substring(1) : string;
        }

        @Override
        protected String internalToString(String value) {
            if (GrammarUtil.getAllKeywords(getGrammar()).contains(value)) {
                return "^"+value;
            }
            return value;
        }
    };
}
项目:xtext-core    文件:DatatypeRulesTestLanguageValueConverters.java   
@ValueConverter(rule = "Fraction")
public IValueConverter<BigDecimal> Fraction() {
    return new AbstractNullSafeConverter<BigDecimal>(){
        @Override
        protected BigDecimal internalToValue(String string, INode node) {
            String[] splitted = string.split("/");
            if (splitted.length > 1) {
                return new BigDecimal(splitted[0].trim()).divide(new BigDecimal(splitted[1].trim()));
            }
            return new BigDecimal(string);
        }

        @Override
        protected String internalToString(BigDecimal value) {
            BigDecimal bd = value;
            int scale = bd.scale();
            if (scale <= 0) {
                return bd.toPlainString();
            }
            bd = bd.multiply(BigDecimal.valueOf(1, -1 * scale));
            return bd.toPlainString() + '/' + BigDecimal.valueOf(1, -1 * scale).toPlainString();
        }};
}
项目:xtext-core    文件:FormatterTestValueConverters.java   
@ValueConverter(rule = "FQN")
public IValueConverter<String> FQN() {
    return new AbstractNullSafeConverter<String>() {
        @Override
        protected String internalToString(String value) {
            return value;
        }

        @Override
        protected String internalToValue(String string, INode node) {
            if (!string.equals(string.trim()))
                throw new RuntimeException();
            StringBuffer b = new StringBuffer();
            for (ILeafNode leaf : node.getLeafNodes()) {
                if (!leaf.isHidden()) {
                    b.append(leaf.getText());
                }
            }
            return b.toString();
        }
    };
}
项目:xtext-core    文件:FormatterTestValueConverters.java   
@ValueConverter(rule = "WrappingDataType")
public IValueConverter<String> WrappingDataType() {
    return new AbstractNullSafeConverter<String>() {

        @Override
        protected String internalToString(String value) {
            return value;
        }

        @Override
        protected String internalToValue(String string, INode node) throws ValueConverterException {
            return node.getText().trim();
        }
    };

}
项目:dsl-devkit    文件:FormatterTestValueConverters.java   
@ValueConverter(rule = "FQN")
// CHECKSTYLE:OFF
public IValueConverter<String> FQN() { // NOPMD
  // CHECKSTYLE:ON
  return new AbstractNullSafeConverter<String>() {
    @Override
    protected String internalToValue(final String string, final INode node) {
      if (!string.equals(string.trim())) {
        throw new RuntimeException(); // NOPMD
      }
      StringBuffer b = new StringBuffer();
      for (ILeafNode l : node.getLeafNodes()) {
        if (!l.isHidden()) {
          b.append(l.getText());
        }
      }
      return b.toString();
    }

    @Override
    protected String internalToString(final String value) {
      return value;
    }
  };
}
项目:CooperateModelingEnvironment    文件:CooperateValueConverterBase.java   
@ValueConverter(rule = "NameString")
public IValueConverter<String> NameString() {
    return new AbstractNullSafeConverter<String>() {

        @Override
        protected String internalToString(String value) {
            return String.format("\"%s\"", value);
        }

        @Override
        protected String internalToValue(String string, INode node) throws ValueConverterException {
            if (string.matches("\\\".*\\\"")) {
                return string.subSequence(1, string.length() - 1).toString();
            }
            return string;
        }

    };
}
项目:CooperateModelingEnvironment    文件:CooperateValueConverterBase.java   
@ValueConverter(rule = "FQN")
public IValueConverter<String> FQN() {
    return new AbstractNullSafeConverter<String>() {

        @Override
        protected String internalToString(String value) {
            // this prohibits FQNs with spaces to be serialized
            if (value.contains(" ")) {
                throw new ValueConverterException("Spaces are not allowed inside FQNs.", null, null);
            }
            return value;
        }

        @Override
        protected String internalToValue(String string, INode node) throws ValueConverterException {
            return string;
        }

    };
}
项目:CooperateModelingEnvironment    文件:CooperateValueConverterBase.java   
@ValueConverter(rule = "CardinalityBound")
public IValueConverter<Integer> convertCardinalityBound() {
    return new AbstractNullSafeConverter<Integer>() {

        @Override
        protected String internalToString(Integer value) {
            if (value < 0) {
                return "*";
            }
            return value.toString();
        }

        @Override
        protected Integer internalToValue(String string, INode node) throws ValueConverterException {
            if ("*".equals(string)) {
                return -1;
            }
            return Integer.parseInt(string);
        }

    };
}
项目:eclectic    文件:EclecticValueConverter.java   
@ValueConverter(rule = "QualifiedName")
public IValueConverter<String> EString() {
    return new AbstractNullSafeConverter<String>() {
        @Override
        protected String internalToValue(String string, INode node) {
            if((string.startsWith("'") && string.endsWith("'"))||(string.startsWith("\"") && string.endsWith("\""))) {
                return STRING().toValue(string, node);
            }
            return ID().toValue(string, node);
        }

        @Override
        protected String internalToString(String value) {
            if(ID_PATTERN.matcher(value).matches()) {
                return ID().toString(value);
            } else {
                return STRING().toString(value);
            }
        }
    };
}
项目:xtext-core    文件:XtextValueConverters.java   
@ValueConverter(rule = "LiteralValue")
public IValueConverter<Boolean> LiteralValue() {
    return new AbstractNullSafeConverter<Boolean>() {
        @Override
        protected Boolean internalToValue(String string, INode node) throws ValueConverterException {
            return "+".equals(string);
        }

        @Override
        protected String internalToString(Boolean value) {
            return value.booleanValue() ? "+" : "!";
        }
    };
}
项目:xtext-core    文件:ValueConverterForTerminalFragmentsTest.java   
@ValueConverter(rule = "ESCAPED_CHAR")
public IValueConverter<String> forFragment() {
    return new AbstractNullSafeConverter<String>() {
        @Override
        protected String internalToValue(String string, INode node) {
            return string;
        }

        @Override
        protected String internalToString(String value) {
            return value;
        }
    };
}
项目:xtext-core    文件:TerminalRuleTestLanguageConverters.java   
@ValueConverter(rule = "STRING")
public IValueConverter<String> STRING() {
    return new AbstractNullSafeConverter<String>() {
        @Override
        protected String internalToValue(String string, INode node) {
            return Strings.convertFromJavaString(string.substring(1, string.length() - 1), false);
        }

        @Override
        protected String internalToString(String value) {
            return '"' + Strings.convertToJavaString(value, false) + '"';
        }
    };
}
项目:xtext-core    文件:Bug250313RuntimeModule.java   
@ValueConverter(rule = "Datatype")
public IValueConverter<String> Datatype() {
    return new AbstractNullSafeConverter<String>() {
        @Override
        protected String internalToValue(String string, INode node) {
            return "str";
        }

        @Override
        protected String internalToString(String value) {
            throw new UnsupportedOperationException();
        }
    };
}
项目:xtext-core    文件:Bug250313RuntimeModule.java   
@ValueConverter(rule = "NestedDatatype")
public IValueConverter<String> NestedDatatype() {
    return new AbstractNullSafeConverter<String>() {
        @Override
        protected String internalToValue(String string, INode node) {
            return "str";
        }

        @Override
        protected String internalToString(String value) {
            throw new UnsupportedOperationException();
        }
    };
}