Java 类org.eclipse.xtext.conversion.IValueConverter 实例源码

项目:xtext-extras    文件:RewritableImportSection.java   
public RewritableImportSection(XtextResource resource, IImportsConfiguration importsConfiguration, XImportSection originalImportSection,
        String lineSeparator, ImportSectionRegionUtil regionUtil, IValueConverter<String> nameConverter) {
    this.importsConfiguration = importsConfiguration;
    this.resource = resource;
    this.lineSeparator = lineSeparator;
    this.regionUtil = regionUtil;
    this.nameValueConverter = nameConverter;
    this.implicitlyImportedPackages = importsConfiguration.getImplicitlyImportedPackages(resource);
    this.importRegion = regionUtil.computeRegion(resource);
    if (originalImportSection != null) {
        for (XImportDeclaration originalImportDeclaration : originalImportSection.getImportDeclarations()) {
            this.originalImportDeclarations.add(originalImportDeclaration);
            JvmDeclaredType importedType = originalImportDeclaration.getImportedType();
            if (originalImportDeclaration.isStatic()) {
                String memberName = originalImportDeclaration.getMemberName();
                if (originalImportDeclaration.isExtension()) {
                    Maps2.putIntoSetMap(importedType, memberName, staticExtensionImports);
                } else {
                    Maps2.putIntoSetMap(importedType, memberName, staticImports);
                }
            } else if (importedType != null) {
                Maps2.putIntoListMap(importedType.getSimpleName(), importedType, plainImports);
            }
        }
    }
}
项目:xtext-core    文件:QualifiedNameValueConverter.java   
private IValueConverter<Object> initializeDelegateConverter() {
    if (valueConverterService instanceof IValueConverterService.Introspectable) {
        return delegateConverter = ((IValueConverterService.Introspectable) valueConverterService).getConverter(getDelegateRuleName());
    } else {
        final String ruleName = getDelegateRuleName();
        return delegateConverter = new IValueConverter<Object>() {

            @Override
            public Object toValue(String string, INode node) throws ValueConverterException {
                return valueConverterService.toValue(string, ruleName, node);
            }

            @Override
            public String toString(Object value) throws ValueConverterException {
                return valueConverterService.toString(value, ruleName);
            }

        };
    }
}
项目:xtext-core    文件:KeywordAlternativeConverter.java   
private IValueConverter<Object> getDelegateConverter() {
    if (delegateConverter != null) {
        return delegateConverter;
    }
    if (delegateService instanceof IValueConverterService.Introspectable) {
        return delegateConverter = ((IValueConverterService.Introspectable) delegateService).getConverter(delegateRule.getName());
    } else {
        final String ruleName = delegateRule.getName();
        return delegateConverter = new IValueConverter<Object>() {

            @Override
            public Object toValue(String string, INode node) throws ValueConverterException {
                return delegateService.toValue(string, ruleName, node);
            }

            @Override
            public String toString(Object value) throws ValueConverterException {
                return delegateService.toString(value, ruleName);
            }

        };
    }
}
项目: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();
        }
    };

}
项目:xtext-core    文件:AssignmentFinderTestLanguageRuntimeModule.java   
@ValueConverter(rule = "DatEnum")
public IValueConverter<TestEnum> DatEnum() {
    return new IValueConverter<TestEnum>() {

        @Override
        public TestEnum toValue(String string, INode node) throws ValueConverterException {
            if ("lit3".equals(string))
                return TestEnum.LIT3;
            else
                throw new ValueConverterException(null, null, null);
        }

        @Override
        public String toString(TestEnum value) throws ValueConverterException {
            if (value == TestEnum.LIT3)
                return TestEnum.LIT3.getName();
            else
                throw new ValueConverterException(null, null, null);
        }
    };
}
项目:xtext-core    文件:SequencerTestLanguageRuntimeModule.java   
@ValueConverter(rule = "NULL_STRING")
public IValueConverter<String> NULL_STRING() {
    return new IValueConverter<String>() {
        @Override
        public String toString(String value) throws ValueConverterException {
            if (value == null)
                return "''";
            return "'" + value + "'";
        }

        @Override
        public String toValue(String string, INode node) throws ValueConverterException {
            if (string.length() <= 2) {
                return null;
            }
            return string.substring(1, string.length() - 1);
        }
    };
}
项目:xtext-core    文件:Bug362902ValueConverters.java   
@Override
@ValueConverter(rule = "MyId")
public IValueConverter<String> ID() {
    return new IValueConverter<String>() {

        @Override
        public String toValue(String string, INode node) throws ValueConverterException {
            if (string != null && string.length() > 3) {
                throw new ValueConverterException("ID too long", node, null);
            }
            return string;
        }

        @Override
        public String toString(String value) throws ValueConverterException {
            return value;
        }
    };
}
项目: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);
        }

    };
}
项目:SensIDL    文件:SensIDLValueConverterService.java   
@ValueConverter(rule = "DESCRIPTION")
public IValueConverter<String> DESCRIPTION() {
    return new IValueConverter<String>() {

        @Override
        public String toValue(String string, INode node) throws ValueConverterException {
            return toString(string);
        }

        @Override
        public String toString(String value) throws ValueConverterException {
            return value.substring(3, value.length() - 2);
        }

    };
}
项目:questionaire    文件:TextQuestionLengthConverter.java   
@ValueConverter(rule = "SHORT_LONG")
   public IValueConverter<Integer> SHORT_LONG() {
       return new IValueConverter<Integer>() {
           public Integer toValue(String string, INode node) {
               if (Strings.isEmpty(string))
                   throw new ValueConverterException("Couldn't convert empty string to int", node, null);
               else if ("short".equals(string.trim()))
                   return 1;
               else if ("long".equals(string.trim()))
                   return 5;
               try {
                   return Integer.parseInt(string);
               } catch (NumberFormatException e) {
                   throw new ValueConverterException("Couldn't convert '"+string+"' to int", node, e);
               }
           }

           public String toString(Integer value) {
               return Integer.toString(value);
           }
       };
}
项目: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);
            }
        }
    };
}
项目:textram    文件:TextRAMConverter.java   
@ValueConverter(rule = "ElementBound")
   public IValueConverter<Integer> ElementBound() {
       return new IValueConverter<Integer>() {

        @Override
        public Integer toValue(String string, INode node)
                throws ValueConverterException {

            if (Strings.isEmpty(string))
                   throw new ValueConverterException("Couldn't convert empty string to int", node, null);
               else if ("*".equals(string.trim()))
                   return -1;
               try {
                   return Integer.parseInt(string);
               } catch (NumberFormatException e) {
                   throw new ValueConverterException("Couldn't convert '"+string+"' to int", node, e);
               }
        }

        @Override
        public String toString(Integer value)
                throws ValueConverterException {
               return ((value == -1) ? "*" : Integer.toString(value));
        }
       };
}
项目:n4js    文件:FQNImporter.java   
FQNImporter(
        Resource context,
        IScope scope,
        IValueConverter<String> valueConverter,
        Predicate<IEObjectDescription> filter,
        ITextViewer viewer) {
    this.context = context;
    this.scope = scope;
    this.valueConverter = valueConverter;
    this.filter = filter;
    this.viewer = viewer;
}
项目:n4js    文件:ImportsAwareReferenceProposalCreator.java   
@Inject
private void setValueConverter(IValueConverterService service, N4JSGrammarAccess grammarAccess) {
    @SuppressWarnings({ "unchecked", "rawtypes" })
    IValueConverter<String> converter = (IValueConverter) ((IValueConverterService.Introspectable) service)
            .getConverter(grammarAccess
                    .getTypeReferenceNameRule()
                    .getName());
    this.valueConverter = converter;
}
项目: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    文件:AbstractDeclarativeValueConverterService.java   
/**
 * @since 2.7
 */
@Override
@SuppressWarnings("unchecked")
public IValueConverter<Object> getConverter(String lexerRule) {
    Map<String, IValueConverter<Object>> map = getConverters();
    if (map.containsKey(lexerRule)) {
        return map.get(lexerRule);
    }
    return (IValueConverter<Object>) IValueConverter.NO_OP_CONVERTER;
}
项目:xtext-core    文件:AbstractDeclarativeValueConverterService.java   
/**
 * @since 2.9
 */
protected void recursiveRegisterForClass(Class<?> clazz, Map<String, IValueConverter<Object>> converters) {
    Method[] methods = clazz.getDeclaredMethods();
    Set<String> thisConverters = Sets.newHashSet();
    recursiveRegisterForClass(methods, thisConverters, true, converters);
    recursiveRegisterForClass(methods, thisConverters, false, converters);
    if (clazz.getSuperclass() != null) {
        recursiveRegisterForClass(clazz.getSuperclass(), converters);
    }
}
项目:xtext-core    文件:AbstractDeclarativeValueConverterService.java   
private IValueConverter<Object> registerIfMissing(String name, AbstractRule rule, Method method,
        Map<String, IValueConverter<Object>> converters) throws IllegalAccessException, InvocationTargetException {
    if (!converters.containsKey(name)) {
        IValueConverter<Object> valueConverter = reflectiveGetConverter(method, rule);
        converters.put(name, valueConverter);
        return valueConverter;
    }
    return null;
}
项目:xtext-core    文件:AbstractDeclarativeValueConverterService.java   
@SuppressWarnings("unchecked")
private IValueConverter<Object> reflectiveGetConverter(Method method, AbstractRule rule)
        throws IllegalAccessException, InvocationTargetException {
    IValueConverter<Object> valueConverter = (IValueConverter<Object>) method.invoke(this);
    if (valueConverter instanceof IValueConverter.RuleSpecific)
        ((IValueConverter.RuleSpecific) valueConverter).setRule(rule);
    return valueConverter;
}
项目:xtext-core    文件:AbstractDeclarativeValueConverterService.java   
private void registerIfMissing(String name, AbstractRule rule, IValueConverter<Object> valueConverter, Method method,
        Map<String, IValueConverter<Object>> converters) throws IllegalAccessException, InvocationTargetException {
    if (!converters.containsKey(name)) {
        if (valueConverter == null) {
            valueConverter = reflectiveGetConverter(method, rule);
        }
        converters.put(name, valueConverter);
    }
}
项目:xtext-core    文件:AbstractDeclarativeValueConverterService.java   
/**
 * @since 2.4
 * @nooverride This method is not intended to be re-implemented or extended by clients.
 * @noreference This method is not intended to be referenced by clients.
 */
protected void registerEFactoryConverters(Map<String, IValueConverter<Object>> converters) {
    for (ParserRule parserRule : allParserRules(getGrammar())) {
        if (isDatatypeRule(parserRule)) {
            registerIfMissing(parserRule.getName(), parserRule, converters);
            registerIfMissing(ruleNames.getQualifiedName(parserRule), parserRule, converters);
        }
    }
    for (TerminalRule terminalRule : allTerminalRules(getGrammar())) {
        if (!terminalRule.isFragment()) {
            registerIfMissing(terminalRule.getName(), terminalRule, converters);
            registerIfMissing(ruleNames.getQualifiedName(terminalRule), terminalRule, converters);
        }
    }
}
项目:xtext-core    文件:AbstractDeclarativeValueConverterService.java   
private void registerIfMissing(String name, ParserRule parserRule,
        Map<String, IValueConverter<Object>> converters) {
    if (!converters.containsKey(name)) {
        EDataType datatype = (EDataType) parserRule.getType().getClassifier();
        converters.put(name, new EFactoryValueConverter(datatype));
    }
}
项目: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    文件:AssignmentsTestLanguageRuntimeModule.java   
@ValueConverter(rule = "IdDatatype")
public IValueConverter<String> IdDatatype() {
    return new AbstractToStringConverter<String>() {
        @Override
        protected String internalToValue(String string, INode node) {
            return "IdDatatype: " + string;
        }
    };
}
项目:xtext-core    文件:AssignmentsTestLanguageRuntimeModule.java   
@ValueConverter(rule = "StringDatatype")
public IValueConverter<String> StringDatatype() {
    return new AbstractToStringConverter<String>() {
        @Override
        protected String internalToValue(String string, INode node) {
            return "StringDatatype: " + string;
        }
    };
}
项目:xtext-core    文件:AbstractTestLanguageValueConverters.java   
@ValueConverter(rule = "REAL")
public IValueConverter<Double> REAL() {
    return new AbstractToStringConverter<Double>(){

        @Override
        protected Double internalToValue(String string, INode node) {
            return Double.valueOf(string);
        }
    };
}
项目: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();
        }
    };
}
项目:idl4emf    文件:IDLValueConverterService.java   
@ValueConverter(rule = "longdouble_type")
public IValueConverter<PrimitiveKind> longdouble_type() {
    return new AbstractValueConverter<PrimitiveKind>() {

        public PrimitiveKind toValue(String string, INode node) {
            return PrimitiveKind.PK_LONGDOUBLE;
        }

        public String toString(PrimitiveKind value) {
            return "long double";
        }

    };
}
项目:idl4emf    文件:IDLValueConverterService.java   
@ValueConverter(rule = "longlong_type")
public IValueConverter<PrimitiveKind> longlong_type() {
    return new AbstractValueConverter<PrimitiveKind>() {

        public PrimitiveKind toValue(String string, INode node) {
            return PrimitiveKind.PK_LONGLONG;
        }

        public String toString(PrimitiveKind value) {
            return "long long";
        }

    };
}
项目:idl4emf    文件:IDLValueConverterService.java   
@ValueConverter(rule = "ushort_type")
public IValueConverter<PrimitiveKind> ushort_type() {
    return new AbstractValueConverter<PrimitiveKind>() {

        public PrimitiveKind toValue(String string, INode node) {
            return PrimitiveKind.PK_USHORT;
        }

        public String toString(PrimitiveKind value) {
            return "unsigned short";
        }

    };
}
项目:idl4emf    文件:IDLValueConverterService.java   
@ValueConverter(rule = "ulong_type")
public IValueConverter<PrimitiveKind> ulong_type() {
    return new AbstractValueConverter<PrimitiveKind>() {

        public PrimitiveKind toValue(String string, INode node) {
            return PrimitiveKind.PK_ULONG;
        }

        public String toString(PrimitiveKind value) {
            return "unsigned long";
        }

    };
}