org.eclipse.xtext.conversion.ValueConverterWithValueException Java Examples
The following examples show how to use
org.eclipse.xtext.conversion.ValueConverterWithValueException.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: JavaIDValueConverterTest.java From xtext-xtend with Eclipse Public License 2.0 | 6 votes |
@Test public void testInvalidUnicode() { final String s = "a\\u0060"; try { this.valueConverterService.toValue(s, "ID", null); } catch (final Throwable _t) { if (_t instanceof ValueConverterWithValueException) { final ValueConverterWithValueException e = (ValueConverterWithValueException)_t; Object _value = e.getValue(); final String value = ((String) _value); Assert.assertEquals("a", value); } else { throw Exceptions.sneakyThrow(_t); } } }
Example #2
Source File: JavaIDValueConverterTest.java From xtext-xtend with Eclipse Public License 2.0 | 6 votes |
@Test public void testUnclosedUnicode_01() { final String s = "a\\u006"; try { this.valueConverterService.toValue(s, "ID", null); } catch (final Throwable _t) { if (_t instanceof ValueConverterWithValueException) { final ValueConverterWithValueException e = (ValueConverterWithValueException)_t; Object _value = e.getValue(); final String value = ((String) _value); Assert.assertEquals("au006", value); } else { throw Exceptions.sneakyThrow(_t); } } }
Example #3
Source File: JavaIDValueConverterTest.java From xtext-xtend with Eclipse Public License 2.0 | 6 votes |
@Test public void testUnclosedUnicode_02() { final String s = "a\\u"; try { this.valueConverterService.toValue(s, "ID", null); } catch (final Throwable _t) { if (_t instanceof ValueConverterWithValueException) { final ValueConverterWithValueException e = (ValueConverterWithValueException)_t; Object _value = e.getValue(); final String value = ((String) _value); Assert.assertEquals("au", value); } else { throw Exceptions.sneakyThrow(_t); } } }
Example #4
Source File: JavaIDValueConverterTest.java From xtext-xtend with Eclipse Public License 2.0 | 6 votes |
@Test public void testTrailingBackslash() { final String s = "a\\"; try { this.valueConverterService.toValue(s, "ID", null); } catch (final Throwable _t) { if (_t instanceof ValueConverterWithValueException) { final ValueConverterWithValueException e = (ValueConverterWithValueException)_t; Object _value = e.getValue(); final String value = ((String) _value); Assert.assertEquals("a", value); } else { throw Exceptions.sneakyThrow(_t); } } }
Example #5
Source File: JavaIDValueConverter.java From xtext-xtend with Eclipse Public License 2.0 | 6 votes |
/** * Converts a string with valid or invalid escape sequences to a semantic value. * If the escape sequences are invalid, a {@link ValueConverterException} is thrown * with detailed information about the broken character combination. */ public static String convertFromJavaIdentifier(String identifier, INode node) { int idx = identifier.indexOf('\\'); if (idx < 0) { return identifier; } Implementation converter = new Implementation(); String result = converter.convertFromJavaString(identifier, idx); if (converter.error) { throw new ValueConverterWithValueException("Illegal escape sequence in identifier '" + identifier + "'", node, result, null); } if (converter.badChar) { if (result.length() != 0) throw new ValueConverterWithValueException("Illegal character in identifier '" + result + "' (" + identifier + ")", node, result, null); else throw new ValueConverterWithValueException("Illegal character in identifier '" + identifier + "'", node, null, null); } return result; }
Example #6
Source File: STRINGValueConverter.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
/** * Converts a string literal (including leading and trailing single or double quote) to a semantic * string value. Recovers from invalid escape sequences and announces the first problem with a * {@link ValueConverterWithValueException}. * * @since 2.7 * @throws ValueConverterWithValueException if the given string is syntactically invalid. * @see Strings#convertFromJavaString(String, boolean) */ protected String convertFromString(String literal, INode node) throws ValueConverterWithValueException { Implementation converter = createConverter(); String result = converter.convertFromJavaString(literal); if (converter.errorMessage != null) { throw new ValueConverterWithValueException(converter.errorMessage, node, result.toString(), converter.errorIndex, converter.errorLength, null); } return result; }
Example #7
Source File: STRINGConverterTest.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
@Test public void testUnicodeSequenceLength() throws Exception { try { valueConverter.toValue("'\\u123'", null); fail("Illegal short unicode sequence not detected"); } catch(ValueConverterWithValueException e) { String s = (String) e.getValue(); assertEquals("u123", s); assertTrue(e.hasRange()); assertEquals(1, e.getOffset()); assertEquals(2, e.getLength()); } assertEquals("\u1234", valueConverter.toValue("'\\u1234'", null)); }
Example #8
Source File: STRINGConverterTest.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
@Test public void testBrokenStringLiteral_09() throws Exception { String s = "\"\\'"; try { valueConverter.toValue(s, null); fail(); } catch(ValueConverterWithValueException e) { assertEquals("'", e.getValue()); assertFalse(e.hasRange()); } }
Example #9
Source File: STRINGConverterTest.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
@Test public void testBrokenStringLiteral_08() throws Exception { String s = "'\\\""; try { valueConverter.toValue(s, null); fail(); } catch(ValueConverterWithValueException e) { assertEquals("\"", e.getValue()); assertFalse(e.hasRange()); } }
Example #10
Source File: STRINGConverterTest.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
@Test public void testBrokenStringLiteral_07() throws Exception { String s = "\"\\\""; try { valueConverter.toValue(s, null); fail(); } catch(ValueConverterWithValueException e) { assertEquals("\"", e.getValue()); assertFalse(e.hasRange()); } }
Example #11
Source File: STRINGConverterTest.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
@Test public void testBrokenStringLiteral_06() throws Exception { String s = "'\\'"; try { valueConverter.toValue(s, null); fail(); } catch(ValueConverterWithValueException e) { assertEquals("'", e.getValue()); assertFalse(e.hasRange()); } }
Example #12
Source File: STRINGConverterTest.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
@Test public void testBrokenStringLiteral_05() throws Exception { String s = "' \\z "; try { valueConverter.toValue(s, null); fail(); } catch(ValueConverterWithValueException e) { assertEquals(" z ", e.getValue()); assertFalse(e.hasRange()); } }
Example #13
Source File: STRINGConverterTest.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
@Test public void testBrokenStringLiteral_04() throws Exception { String s = "' \\z"; try { valueConverter.toValue(s, null); fail(); } catch(ValueConverterWithValueException e) { assertEquals(" z", e.getValue()); assertTrue(e.hasRange()); } }
Example #14
Source File: STRINGConverterTest.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
@Test public void testBrokenStringLiteral_03() throws Exception { String s = "' \\"; try { valueConverter.toValue(s, null); fail(); } catch(ValueConverterWithValueException e) { assertEquals(" \\", e.getValue()); assertTrue(e.hasRange()); assertEquals(2, e.getOffset()); assertEquals(1, e.getLength()); } }
Example #15
Source File: STRINGConverterTest.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
@Test public void testBrokenStringLiteral_02() throws Exception { String s = "' "; try { valueConverter.toValue(s, null); fail(); } catch(ValueConverterWithValueException e) { assertEquals(" ", e.getValue()); assertFalse(e.hasRange()); } }
Example #16
Source File: STRINGConverterTest.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
@Test public void testBrokenStringLiteral_01() throws Exception { String s = "'"; try { valueConverter.toValue(s, null); fail(); } catch(ValueConverterWithValueException e) { assertEquals("", e.getValue()); assertFalse(e.hasRange()); } }
Example #17
Source File: IdentifierValueConverterTest.java From n4js with Eclipse Public License 1.0 | 5 votes |
public void assertError(String expected, String input) { try { IdentifierValueConverter.convertFromN4JSIdentifier(input, null); fail("expected exception"); } catch (ValueConverterWithValueException e) { String result = (String) e.getValue(); assertEquals(expected, result); } }
Example #18
Source File: STRINGValueConverter.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
@Override public String toValue(String string, INode node) { if (string == null) return null; try { if (string.length() == 1) { throw new ValueConverterWithValueException(getStringNotClosedMessage(), node, "", null); } return convertFromString(string, node); } catch (IllegalArgumentException e) { throw new ValueConverterException(e.getMessage(), node, e); } }
Example #19
Source File: SyntaxErrorMessageProvider.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
@Override public SyntaxErrorMessage getSyntaxErrorMessage(IValueConverterErrorContext context) { ValueConverterException cause = context.getValueConverterException(); if (cause instanceof ValueConverterWithValueException) { ValueConverterWithValueException casted = (ValueConverterWithValueException) cause; if (casted.hasRange()) { return createRangedSyntaxErrorMessage(context, casted.getOffset(), casted.getLength()); } } return new SyntaxErrorMessage(context.getDefaultMessage(), SYNTAX_DIAGNOSTIC); }
Example #20
Source File: RichTextValueConverterTest.java From xtext-xtend with Eclipse Public License 2.0 | 5 votes |
protected void doTestIncompleteRichStringEnd(String text, String expectation) { RichTextEndValueConverter converter = get(RichTextEndValueConverter.class); try { converter.toValue(text, null); fail("Expected ValueConverterWithValueException"); } catch(ValueConverterWithValueException e) { String value = (String) e.getValue(); assertEquals(expectation, value); } }
Example #21
Source File: RichTextValueConverterTest.java From xtext-xtend with Eclipse Public License 2.0 | 5 votes |
protected void doTestIncompleteRichString(String text, String expectation) { RichTextValueConverter converter = get(RichTextValueConverter.class); try { converter.toValue(text, null); fail("Expected ValueConverterWithValueException"); } catch(ValueConverterWithValueException e) { String value = (String) e.getValue(); assertEquals(expectation, value); } }
Example #22
Source File: AbstractRichTextValueConverter.java From xtext-xtend with Eclipse Public License 2.0 | 4 votes |
private ValueConverterWithValueException stringLiteralIsNotClosed(INode node, String value) { return new ValueConverterWithValueException("String literal is not closed", node, value, null); }