private void parseFieldTypeSignature() { // FieldTypeSignature ::= ClassTypeSignature | ArrayTypeSignature | TypeVariableSignature. switch (symbol) { case 'L': parseClassTypeSignature(); break; case '[': // ArrayTypeSignature ::= "[" TypSignature. actions.parsedSymbol(symbol); scanSymbol(); updateTypeSignature(); break; case 'T': updateTypeVariableSignature(); break; default: throw new GenericSignatureFormatError(); } }
Type parseFieldTypeSignature() { // FieldTypeSignature ::= ClassTypeSignature | ArrayTypeSignature // | TypeVariableSignature. switch (symbol) { case 'L': return parseClassTypeSignature(); case '[': // ArrayTypeSignature ::= "[" TypSignature. scanSymbol(); return new GenericArrayTypeImpl(parseTypeSignature()); case 'T': return parseTypeVariableSignature(); default: throw new GenericSignatureFormatError(); } }
Type parseFieldTypeSignature() { // FieldTypeSignature ::= ClassTypeSignature | ArrayTypeSignature // | TypeVariableSignature. switch (symbol) { case 'L': return parseClassTypeSignature(); case '[': // ArrayTypeSignature ::= "[" TypSignature. scanSymbol(); return new ImplForArray(parseTypeSignature()); case 'T': return parseTypeVariableSignature(); default: throw new GenericSignatureFormatError(); } }
public Type getGenericSuperclass() throws GenericSignatureFormatError, TypeNotPresentException, MalformedParameterizedTypeException { String tmp; if (isInterface() || ((tmp = getCanonicalName()) != null && tmp.equals("java.lang.Object")) || isPrimitive()) { return null; } if (isArray()) { return (Type) OBJECT_CLASS; } Class<?> clazz = getSuperclass(); if (clazz.getTypeParameters().length == 0) { return (Type) clazz; } return getCache().getGenericSuperclass(); }
private void expect(char c) { if (symbol == c) { scanSymbol(); } else { throw new GenericSignatureFormatError(); } }
@Test public void parseMessage() { // Assert.assertEquals("操作数据库出错,请稍后重试.", ErrorUtil.parseMessage(new InvalidParamDataAccessException("message"))); Assert.assertEquals("操作数据库出错,请稍后重试.", ErrorUtil.parseMessage(new SQLException("message"))); // Assert.assertEquals("操作数据库出错,请稍后重试.", ErrorUtil.parseMessage(new JedisConnectionException("message"))); // Assert.assertEquals("访问外部接口出错,请稍后重试.", ErrorUtil.parseMessage(new OutSideException("message"))); Assert.assertEquals("更新程序后,还没有重启服务.", ErrorUtil.parseMessage(new GenericSignatureFormatError())); Assert.assertEquals("message", ErrorUtil.parseMessage(new IllegalArgumentException("message"))); // Assert.assertEquals("message", ErrorUtil.parseMessage(new LeopardRuntimeException("message"))); // Assert.assertEquals("message", ErrorUtil.parseMessage(new LeopardException("message"))); Assert.assertEquals("message", ErrorUtil.parseMessage(new RuntimeException("message"))); Assert.assertEquals("未知错误.", ErrorUtil.parseMessage(new Exception("message"))); }
Type readFieldTypeSignature() { switch (peekChar()) { case 'L': return readClassTypeSignature(); case '[': return readArrayTypeSignature(); case 'T': return readTypeVariableSignature(); default: throw new GenericSignatureFormatError(); } }
Type readArrayTypeSignature() { consume('['); switch (peekChar()) { case 'L': case '[': case 'T': return new GenericArrayTypeImpl(readFieldTypeSignature()); case 'Z': consume('Z'); return boolean[].class; case 'B': consume('B'); return byte[].class; case 'S': consume('S'); return short[].class; case 'C': consume('C'); return char[].class; case 'I': consume('I'); return int[].class; case 'F': consume('F'); return float[].class; case 'J': consume('J'); return long[].class; case 'D': consume('D'); return double[].class; default: throw new GenericSignatureFormatError(); } }
void scanSymbol() { if (!eof) { if (pos < buffer.length) { symbol = buffer[pos]; pos++; } else { symbol = 0; eof = true; } } else { throw new GenericSignatureFormatError(); } }
void expect(char c) { if (symbol == c) { scanSymbol(); } else { throw new GenericSignatureFormatError(); } }
void scanIdentifier() { if (!eof) { StringBuilder identBuf = new StringBuilder(32); if (!isStopSymbol(symbol)) { identBuf.append(symbol); do { char ch = buffer[pos]; if ((ch >= 'a') && (ch <= 'z') || (ch >= 'A') && (ch <= 'Z') || !isStopSymbol(ch)) { identBuf.append(ch); pos++; } else { identifier = identBuf.toString(); scanSymbol(); return; } } while (pos != buffer.length); identifier = identBuf.toString(); symbol = 0; eof = true; } else { // Ident starts with incorrect char. symbol = 0; eof = true; throw new GenericSignatureFormatError(); } } else { throw new GenericSignatureFormatError(); } }
void scanIdentifier() { if (!eof) { StringBuilder identBuf = new StringBuilder(32); if (!isStopSymbol(symbol)) { identBuf.append(symbol); do { char ch = buffer[pos]; if ((ch >= 'a') && (ch <= 'z') || (ch >= 'A') && (ch <= 'Z') || !isStopSymbol(ch)) { identBuf.append(buffer[pos]); pos++; } else { identifier = identBuf.toString(); scanSymbol(); return; } } while (pos != buffer.length); identifier = identBuf.toString(); symbol = 0; eof = true; } else { // Ident starts with incorrect char. symbol = 0; eof = true; throw new GenericSignatureFormatError(); } } else { throw new GenericSignatureFormatError(); } }
@TestTargetNew( level = TestLevel.PARTIAL_COMPLETE, notes = "", method = "GenericSignatureFormatError", args = {} ) public void test_Constructor() { assertNotNull(new GenericSignatureFormatError()); }
public Type[] getGenericInterfaces() throws GenericSignatureFormatError, TypeNotPresentException, MalformedParameterizedTypeException { if (isArray()) { return new Type[]{CLONEABLE_CLASS, SERIALIZABLE_CLASS}; } if (isPrimitive()) { return new Type[0]; } return (Type[])getCache().getGenericInterfaces().clone(); }
/** * @tests java.lang.reflect.GenericSignatureFormatError# * GenericSignatureFormatError() */ @Test public void test_GenericSignatureFormatError() { GenericSignatureFormatError e = new GenericSignatureFormatError(); assertNotNull(e); assertNull(e.getMessage()); }
@Override public TypeList.Generic resolveTypeVariables(TypePool typePool, TypeVariableSource typeVariableSource, Map<Integer, Map<String, List<AnnotationToken>>> annotationTokens, Map<Integer, Map<Integer, Map<String, List<AnnotationToken>>>> boundAnnotationTokens) { throw new GenericSignatureFormatError(); }
@Override public String getGenericSignature() { TypeDescription.Generic fieldType = getType(); try { return fieldType.getSort().isNonGeneric() ? NON_GENERIC_SIGNATURE : fieldType.accept(new TypeDescription.Generic.Visitor.ForSignatureVisitor(new SignatureWriter())).toString(); } catch (GenericSignatureFormatError ignored) { return NON_GENERIC_SIGNATURE; } }
@Override public String getGenericSignature() { try { SignatureWriter signatureWriter = new SignatureWriter(); boolean generic = false; for (TypeDescription.Generic typeVariable : getTypeVariables()) { signatureWriter.visitFormalTypeParameter(typeVariable.getSymbol()); boolean classBound = true; for (TypeDescription.Generic upperBound : typeVariable.getUpperBounds()) { upperBound.accept(new TypeDescription.Generic.Visitor.ForSignatureVisitor(classBound ? signatureWriter.visitClassBound() : signatureWriter.visitInterfaceBound())); classBound = false; } generic = true; } for (TypeDescription.Generic parameterType : getParameters().asTypeList()) { parameterType.accept(new TypeDescription.Generic.Visitor.ForSignatureVisitor(signatureWriter.visitParameterType())); generic = generic || !parameterType.getSort().isNonGeneric(); } TypeDescription.Generic returnType = getReturnType(); returnType.accept(new TypeDescription.Generic.Visitor.ForSignatureVisitor(signatureWriter.visitReturnType())); generic = generic || !returnType.getSort().isNonGeneric(); TypeList.Generic exceptionTypes = getExceptionTypes(); if (!exceptionTypes.filter(not(ofSort(TypeDefinition.Sort.NON_GENERIC))).isEmpty()) { for (TypeDescription.Generic exceptionType : exceptionTypes) { exceptionType.accept(new TypeDescription.Generic.Visitor.ForSignatureVisitor(signatureWriter.visitExceptionType())); generic = generic || !exceptionType.getSort().isNonGeneric(); } } return generic ? signatureWriter.toString() : NON_GENERIC_SIGNATURE; } catch (GenericSignatureFormatError ignored) { return NON_GENERIC_SIGNATURE; } }
private Error error(String errorMsg) { if (DEBUG) System.out.println("Parse error:" + errorMsg); return new GenericSignatureFormatError(); }
private Error error(String errorMsg) { return new GenericSignatureFormatError("Signature Parse error: " + errorMsg + "\n\tRemaining input: " + remainder()); }
private static Class classFromSig(ClassLoader loader, String name) { if (name.length() == 1) { switch (name.charAt(0)) { case 'Z': return Boolean.TYPE; case 'B': return Byte.TYPE; case 'C': return Character.TYPE; case 'S': return Short.TYPE; case 'I': return Integer.TYPE; case 'F': return Float.TYPE; case 'J': return Long.TYPE; case 'D': return Double.TYPE; case 'V': return Void.TYPE; default: throw new GenericSignatureFormatError(); } } if (!isValidTypeSig(name, 0, name.length())) { throw new GenericSignatureFormatError(); } if (name.charAt(0) == 'L') { name = name.substring(1, name.length() - 1).replace('/', '.'); } else // must be an array then { name = name.replace('/', '.'); } try { return Class.forName(name, false, loader); } catch (ClassNotFoundException x) { throw new TypeNotPresentException(name, x); } }
/** * 获取异常信息. * * @param e * @return */ public static String parseMessage(Throwable e) { if (e == null) { throw new IllegalArgumentException("exception不能为空?"); } String className = e.getClass().getName(); String message = MESSAGE_MAP.get(className); if (message != null) { return message; } if (e instanceof GenericSignatureFormatError) { printStartupTime(); return "更新程序后,还没有重启服务."; } if (e instanceof NoSuchMethodError) { printStartupTime(); return "NoSuchMethodError:方法找不到."; } if (e instanceof SQLException) { return "操作数据库出错,请稍后重试."; } if (e instanceof DataIntegrityViolationException) { Exception exception = (Exception) e.getCause(); if (exception instanceof MysqlDataTruncation) { return MessageParserImpl.parse((MysqlDataTruncation) exception); } else { return "操作数据库出错,请稍后重试."; } // try { // return parseDataIntegrityViolationException((DataIntegrityViolationException) e); // } // catch (Exception e1) { // e1.printStackTrace(); // return "字段太长,请稍后重试."; // } } message = e.getMessage(); if (message == null) { return null; } return fillterDebugInfo(message); }