use of org.eclipse.xtext.conversion.ValueConverterException in project xtext-core by eclipse.
the class EFactoryValueConverterTest method testEmptyString.
@Test
public void testEmptyString() {
EFactoryValueConverter eIntConverter = new EFactoryValueConverter(EcorePackage.Literals.EINT);
try {
eIntConverter.toValue("", null);
fail("EInt converter should not convert empty string");
} catch (ValueConverterException e) {
// expected result
}
try {
EFactoryValueConverter eIntegerConverter = new EFactoryValueConverter(EcorePackage.Literals.EINTEGER_OBJECT);
eIntegerConverter.toValue("", null);
fail("EInteger converter should not convert empty string");
} catch (ValueConverterException e) {
// expected result
assertTrue(e.getCause() instanceof NumberFormatException);
}
}
use of org.eclipse.xtext.conversion.ValueConverterException in project xtext-core by eclipse.
the class LinkingHelper method getCrossRefNodeAsString.
public String getCrossRefNodeAsString(INode node, boolean convert) {
String convertMe = NodeModelUtils.getTokenText(node);
if (!convert)
return convertMe;
try {
String ruleName = getRuleNameFrom(node.getGrammarElement());
if (ruleName == null)
return convertMe;
Object result = valueConverter.toValue(convertMe, ruleName, node);
return result != null ? result.toString() : null;
} catch (ValueConverterWithValueException ex) {
Object result = ex.getValue();
return result != null ? result.toString() : null;
} catch (ValueConverterException ex) {
throw new IllegalNodeException(node, ex);
}
}
use of org.eclipse.xtext.conversion.ValueConverterException in project xtext-core by eclipse.
the class CrossReferenceSerializer method getCrossReferenceNameFromScope.
protected String getCrossReferenceNameFromScope(EObject semanticObject, CrossReference crossref, EObject target, final IScope scope, Acceptor errors) {
String ruleName = linkingHelper.getRuleNameFrom(crossref);
boolean foundOne = false;
List<ISerializationDiagnostic> recordedErrors = null;
for (IEObjectDescription desc : scope.getElements(target)) {
foundOne = true;
String unconverted = qualifiedNameConverter.toString(desc.getName());
try {
return valueConverter.toString(unconverted, ruleName);
} catch (ValueConverterException e) {
if (errors != null) {
if (recordedErrors == null)
recordedErrors = Lists.newArrayList();
recordedErrors.add(diagnostics.getValueConversionExceptionDiagnostic(semanticObject, crossref, unconverted, e));
}
}
}
if (errors != null) {
if (recordedErrors != null)
for (ISerializationDiagnostic diag : recordedErrors) errors.accept(diag);
if (!foundOne)
errors.accept(diagnostics.getNoEObjectDescriptionFoundDiagnostic(semanticObject, crossref, target, scope));
}
return null;
}
use of org.eclipse.xtext.conversion.ValueConverterException in project xtext-eclipse by eclipse.
the class JdtTypesProposalProvider method createTypeProposal.
protected void createTypeProposal(final String typeName, int modifiers, boolean isInnerType, ICompletionProposalFactory proposalFactory, ContentAssistContext context, ICompletionProposalAcceptor acceptor, final IJvmTypeProvider jvmTypeProvider, IValueConverter<String> valueConverter) {
if (acceptor.canAcceptMoreProposals()) {
int lastDot = typeName.lastIndexOf('.');
final StyledString displayString;
if (lastDot != -1) {
if (isInnerType) {
displayString = new StyledString(typeName.substring(lastDot + 1).replace('$', '.')).append(" - " + typeName.substring(0, lastDot), StyledString.QUALIFIER_STYLER);
} else {
displayString = new StyledString(typeName.substring(lastDot + 1)).append(" - " + typeName.substring(0, lastDot), StyledString.QUALIFIER_STYLER);
}
} else {
displayString = new StyledString(isInnerType ? typeName.replace('$', '.') : typeName);
}
Image img = computeImage(typeName, isInnerType, modifiers);
String proposalAsString = typeName;
if (valueConverter != null) {
try {
proposalAsString = valueConverter.toString(isInnerType ? proposalAsString.replace('$', '.') : proposalAsString);
} catch (ValueConverterException vce) {
return;
}
}
ICompletionProposal proposal = proposalFactory.createCompletionProposal(proposalAsString, displayString, img, context);
if (proposal instanceof ConfigurableCompletionProposal) {
ConfigurableCompletionProposal theProposal = (ConfigurableCompletionProposal) proposal;
// calculate the type lazy, as this require a lot of time for large completion lists
theProposal.setAdditionalProposalInfo(new Provider<EObject>() {
@Override
public EObject get() {
return jvmTypeProvider.findTypeByName(typeName);
}
});
theProposal.setHover(hover);
priorities.adjustCrossReferencePriority(theProposal, context.getPrefix());
theProposal.setPriority(theProposal.getPriority() + jdtTypeRelevance.getRelevance(typeName, context.getPrefix()));
}
acceptor.accept(proposal);
}
}
use of org.eclipse.xtext.conversion.ValueConverterException in project n4js by eclipse.
the class PropertyNameAwareElementFactory method set.
/**
* {@inheritDoc}
*
* <p>
* If we parsed a {@link PropertyAssignment}, the set operation also initializes the {@link PropertyNameKind}.
* </p>
*/
@Override
public void set(EObject object, String feature, Object value, String ruleName, INode node) throws N4JSValueConverterException {
final EStructuralFeature structuralFeature = object.eClass().getEStructuralFeature(feature);
if (structuralFeature == null)
throw new IllegalArgumentException(object.eClass().getName() + "." + feature + " does not exist");
try {
final Object tokenValue = getTokenValue(value, ruleName, node);
checkNullForPrimitiveFeatures(structuralFeature, tokenValue, node);
object.eSet(structuralFeature, tokenValue);
// this call is an extra to the super class method
setPropertyNameKind(object, feature, ruleName);
setRawStringValue(object, feature, value);
} catch (ValueConverterWithValueException e) {
final Object tokenValue = e.getValue();
checkNullForPrimitiveFeatures(structuralFeature, tokenValue, node);
object.eSet(structuralFeature, tokenValue);
// this call is an extra to the super class method
setPropertyNameKind(object, feature, ruleName);
setRawStringValue(object, feature, value);
throw e;
} catch (ValueConverterException e) {
throw e;
} catch (NullPointerException e) {
throw new N4JSValueConverterException(IssueCodes.getMessageForVCO_NPE(), IssueCodes.VCO_NPE, node, e);
} catch (Exception e) {
throw new ValueConverterException(null, node, e);
}
}
Aggregations