private boolean tryAsString(Node val, Class<?> expectedType, List<Object> returnValues) { if (expectedType != String.class) return false; if (val instanceof StringLiteral) { returnValues.add(((StringLiteral)val).astValue()); return true; } throw new ResolutionException(val, "Expected string literal"); }
@Override public String toString() { if (problemNode == null && getMessage() == null) return "ResolutionException (unknown cause)"; if (problemNode == null) return "AstException: " + getMessage(); String nodeDescription = problemNode == null ? "(null)" : (problemNode.getClass().getName() + "(toString failed)"); try { nodeDescription = problemNode.toString(); } catch (Throwable ignore) { //throwing exceptions in toString() is bad. } if (getMessage() == null) return "ResolutionException at " + nodeDescription; return String.format("ResolutionException: %s (at %s)", getMessage(), nodeDescription); } }
private boolean tryAsBoolean(Node val, Class<?> expectedType, List<Object> returnValues) { if (expectedType != boolean.class) return false; if (val instanceof BooleanLiteral) { boolean v = ((BooleanLiteral)val).astValue(); returnValues.add(v); return true; } throw new ResolutionException(val, "Expected boolean literal"); }
@Override public String toString() { if (problemNode == null && getMessage() == null) return "ResolutionException (unknown cause)"; if (problemNode == null) return "AstException: " + getMessage(); String nodeDescription = problemNode == null ? "(null)" : (problemNode.getClass().getName() + "(toString failed)"); try { nodeDescription = problemNode.toString(); } catch (Throwable ignore) { //throwing exceptions in toString() is bad. } if (getMessage() == null) return "ResolutionException at " + nodeDescription; return String.format("ResolutionException: %s (at %s)", getMessage(), nodeDescription); } }
private boolean tryAsString(Node val, Class<?> expectedType, List<Object> returnValues) { if (expectedType != String.class) return false; if (val instanceof StringLiteral) { returnValues.add(((StringLiteral)val).astValue()); return true; } throw new ResolutionException(val, "Expected string literal"); }
@Override public String toString() { if (problemNode == null && getMessage() == null) return "ResolutionException (unknown cause)"; if (problemNode == null) return "AstException: " + getMessage(); String nodeDescription = problemNode == null ? "(null)" : (problemNode.getClass().getName() + "(toString failed)"); try { nodeDescription = problemNode.toString(); } catch (Throwable ignore) { //throwing exceptions in toString() is bad. } if (getMessage() == null) return "ResolutionException at " + nodeDescription; return String.format("ResolutionException: %s (at %s)", getMessage(), nodeDescription); } }
private boolean tryAsBoolean(Node val, Class<?> expectedType, List<Object> returnValues) { if (expectedType != boolean.class) return false; if (val instanceof BooleanLiteral) { boolean v = ((BooleanLiteral)val).astValue(); returnValues.add(v); return true; } throw new ResolutionException(val, "Expected boolean literal"); }
private boolean tryAsBoolean(Node val, Class<?> expectedType, List<Object> returnValues) { if (expectedType != boolean.class) return false; if (val instanceof BooleanLiteral) { boolean v = ((BooleanLiteral)val).astValue(); returnValues.add(v); return true; } throw new ResolutionException(val, "Expected boolean literal"); }
private boolean tryAsString(Node val, Class<?> expectedType, List<Object> returnValues) { if (expectedType != String.class) return false; if (val instanceof StringLiteral) { returnValues.add(((StringLiteral)val).astValue()); return true; } throw new ResolutionException(val, "Expected string literal"); }
switch (chain.size()) { case 0: throw new ResolutionException(value, "empty"); default: packageName = Joiner.on('.').join(chain.subList(0, chain.size() - 2)); if (unexpectedType) throw new ResolutionException(value, "Expected " + enumClass.getName() + " and not " + packageName + "." + typeName); throw new ResolutionException(value, "Not a valid value for enum " + enumClass.getSimpleName() + ": " + enumName);
switch (chain.size()) { case 0: throw new ResolutionException(value, "empty"); default: packageName = Joiner.on('.').join(chain.subList(0, chain.size() - 2)); if (unexpectedType) throw new ResolutionException(value, "Expected " + enumClass.getName() + " and not " + packageName + "." + typeName); throw new ResolutionException(value, "Not a valid value for enum " + enumClass.getSimpleName() + ": " + enumName);
private List<String> unwrapSelectChain(Select s) { List<String> list = Lists.newArrayList(); while (s != null) { list.add(s.astIdentifier().astValue()); Expression parent = s.astOperand(); if (parent instanceof Select) { s = (Select) parent; } else if (parent instanceof Identifier) { s = null; list.add(((Identifier)parent).astValue()); } else if (parent == null) { break; } else { throw new ResolutionException(parent, "Identifies expected here, not a " + parent.getClass().getSimpleName()); } } Collections.reverse(list); return list; } }
switch (chain.size()) { case 0: throw new ResolutionException(value, "empty"); default: packageName = Joiner.on('.').join(chain.subList(0, chain.size() - 2)); if (unexpectedType) throw new ResolutionException(value, "Expected " + enumClass.getName() + " and not " + packageName + "." + typeName); throw new ResolutionException(value, "Not a valid value for enum " + enumClass.getSimpleName() + ": " + enumName);
private List<String> unwrapSelectChain(Select s) { List<String> list = Lists.newArrayList(); while (s != null) { list.add(s.astIdentifier().astValue()); Expression parent = s.astOperand(); if (parent instanceof Select) { s = (Select) parent; } else if (parent instanceof Identifier) { s = null; list.add(((Identifier)parent).astValue()); } else if (parent == null) { break; } else { throw new ResolutionException(parent, "Identifies expected here, not a " + parent.getClass().getSimpleName()); } } Collections.reverse(list); return list; } }
private List<String> unwrapSelectChain(Select s) { List<String> list = Lists.newArrayList(); while (s != null) { list.add(s.astIdentifier().astValue()); Expression parent = s.astOperand(); if (parent instanceof Select) { s = (Select) parent; } else if (parent instanceof Identifier) { s = null; list.add(((Identifier)parent).astValue()); } else if (parent == null) { break; } else { throw new ResolutionException(parent, "Identifies expected here, not a " + parent.getClass().getSimpleName()); } } Collections.reverse(list); return list; } }
throw new ResolutionException(val, "Expected number or character literal");
throw new ResolutionException(val, "Expected number or character literal");
classNames.add(className); } else throw new ResolutionException(val, "Expected class literal"); continue; } else { throw new ResolutionException(val, "Expected an annotation of type " + expectedType); throw new ResolutionException(val, "Not a valid annotation type: " + expectedType); Object def = method.getDefaultValue(); if (def != null) return def; throw new ResolutionException(node, "Missing annotation method: " + method.getName()); case 1: return returnValues.get(0); default: throw new ResolutionException(node, "Multiple values for a single-value annotation method: " + method.getName());
classNames.add(className); } else throw new ResolutionException(val, "Expected class literal"); continue; } else { throw new ResolutionException(val, "Expected an annotation of type " + expectedType); throw new ResolutionException(val, "Not a valid annotation type: " + expectedType); Object def = method.getDefaultValue(); if (def != null) return def; throw new ResolutionException(node, "Missing annotation method: " + method.getName()); case 1: return returnValues.get(0); default: throw new ResolutionException(node, "Multiple values for a single-value annotation method: " + method.getName());
throw new ResolutionException(val, "Expected number or character literal");