private static String inferMethodTypeName(CtMethod method) { try { if ( method.getMethodInfo2().getAttribute( SignatureAttribute.tag ) == null ) { return method.getReturnType().getName(); } return inferGenericTypeName( method.getReturnType(), SignatureAttribute.toMethodSignature( method.getGenericSignature() ).getReturnType() ); } catch (BadBytecode ignore) { return null; } catch (NotFoundException e) { return null; } }
@Override public List<ResolvedTypeParameterDeclaration> getTypeParameters() { try { if (ctMethod.getGenericSignature() == null) { return Collections.emptyList(); } SignatureAttribute.MethodSignature methodSignature = SignatureAttribute.toMethodSignature(ctMethod.getGenericSignature()); return Arrays.stream(methodSignature.getTypeParameters()).map((jasTp) -> new JavassistTypeParameter(jasTp, this, typeSolver)).collect(Collectors.toList()); } catch (BadBytecode badBytecode) { throw new RuntimeException(badBytecode); } }
@Override public List<ResolvedTypeParameterDeclaration> getTypeParameters() { try { if (ctMethod.getGenericSignature() == null) { return Collections.emptyList(); } SignatureAttribute.MethodSignature methodSignature = SignatureAttribute.toMethodSignature(ctMethod.getGenericSignature()); return Arrays.stream(methodSignature.getTypeParameters()).map((jasTp) -> new JavassistTypeParameter(jasTp, this, typeSolver)).collect(Collectors.toList()); } catch (BadBytecode badBytecode) { throw new RuntimeException(badBytecode); } }
@Override public List<ResolvedTypeParameterDeclaration> getTypeParameters() { try { if (ctMethod.getGenericSignature() == null) { return Collections.emptyList(); } SignatureAttribute.MethodSignature methodSignature = SignatureAttribute.toMethodSignature(ctMethod.getGenericSignature()); return Arrays.stream(methodSignature.getTypeParameters()).map((jasTp) -> new JavassistTypeParameter(jasTp, this, typeSolver)).collect(Collectors.toList()); } catch (BadBytecode badBytecode) { throw new RuntimeException(badBytecode); } }
@Override public ResolvedType getReturnType() { try { if (ctMethod.getGenericSignature() != null) { javassist.bytecode.SignatureAttribute.Type genericSignatureType = SignatureAttribute.toMethodSignature(ctMethod.getGenericSignature()).getReturnType(); return JavassistUtils.signatureTypeToType(genericSignatureType, typeSolver, this); } else { return JavassistFactory.typeUsageFor(ctMethod.getReturnType(), typeSolver); } } catch (NotFoundException | BadBytecode e) { throw new RuntimeException(e); } }
@Override public ResolvedType getReturnType() { try { if (ctMethod.getGenericSignature() != null) { javassist.bytecode.SignatureAttribute.Type genericSignatureType = SignatureAttribute.toMethodSignature(ctMethod.getGenericSignature()).getReturnType(); return JavassistUtils.signatureTypeToType(genericSignatureType, typeSolver, this); } else { return JavassistFactory.typeUsageFor(ctMethod.getReturnType(), typeSolver); } } catch (NotFoundException e) { throw new RuntimeException(e); } catch (BadBytecode e) { throw new RuntimeException(e); } }
@Override public ResolvedType getReturnType() { try { if (ctMethod.getGenericSignature() != null) { javassist.bytecode.SignatureAttribute.Type genericSignatureType = SignatureAttribute.toMethodSignature(ctMethod.getGenericSignature()).getReturnType(); return JavassistUtils.signatureTypeToType(genericSignatureType, typeSolver, this); } else { return JavassistFactory.typeUsageFor(ctMethod.getReturnType(), typeSolver); } } catch (NotFoundException e) { throw new RuntimeException(e); } catch (BadBytecode e) { throw new RuntimeException(e); } }
private static InvokableReferenceTypeUsage typeFor(CtMethod method, SymbolResolver resolver) { try { if (method.getGenericSignature() != null) { SignatureAttribute.MethodSignature methodSignature = SignatureAttribute.toMethodSignature(method.getGenericSignature()); SignatureAttribute.Type[] parameterTypes = methodSignature.getParameterTypes(); List<TypeUsage> paramTypes = Arrays.stream(parameterTypes).map((pt) -> toTypeUsage(pt, resolver, Collections.emptyMap())).collect(Collectors.toList()); InvokableReferenceTypeUsage invokableReferenceTypeUsage = new InvokableReferenceTypeUsage( toInternalMethodDefinition(method, resolver)); return invokableReferenceTypeUsage; } else { CtClass[] parameterTypes = method.getParameterTypes(); List<TypeUsage> paramTypes = Arrays.stream(parameterTypes).map((pt) -> toTypeUsage(pt, resolver)).collect(Collectors.toList()); InvokableReferenceTypeUsage invokableReferenceTypeUsage = new InvokableReferenceTypeUsage( toInternalMethodDefinition(method, resolver)); return invokableReferenceTypeUsage; } } catch (BadBytecode badBytecode) { throw new RuntimeException(badBytecode); } catch (NotFoundException e) { throw new RuntimeException(e); } }
@Override public ResolvedParameterDeclaration getParam(int i) { try { boolean variadic = false; if ((ctMethod.getModifiers() & javassist.Modifier.VARARGS) > 0) { variadic = i == (ctMethod.getParameterTypes().length - 1); } if (ctMethod.getGenericSignature() != null) { SignatureAttribute.MethodSignature methodSignature = SignatureAttribute.toMethodSignature(ctMethod.getGenericSignature()); SignatureAttribute.Type signatureType = methodSignature.getParameterTypes()[i]; return new JavassistParameterDeclaration(JavassistUtils.signatureTypeToType(signatureType, typeSolver, this), typeSolver, variadic); } else { return new JavassistParameterDeclaration(ctMethod.getParameterTypes()[i], typeSolver, variadic); } } catch (NotFoundException e) { throw new RuntimeException(e); } catch (BadBytecode badBytecode) { throw new RuntimeException(badBytecode); } }
@Override public ResolvedParameterDeclaration getParam(int i) { try { boolean variadic = false; if ((ctMethod.getModifiers() & javassist.Modifier.VARARGS) > 0) { variadic = i == (ctMethod.getParameterTypes().length - 1); } Optional<String> paramName = JavassistUtils.extractParameterName(ctMethod, i); if (ctMethod.getGenericSignature() != null) { SignatureAttribute.MethodSignature methodSignature = SignatureAttribute.toMethodSignature(ctMethod.getGenericSignature()); SignatureAttribute.Type signatureType = methodSignature.getParameterTypes()[i]; return new JavassistParameterDeclaration(JavassistUtils.signatureTypeToType(signatureType, typeSolver, this), typeSolver, variadic, paramName.orElse(null)); } else { return new JavassistParameterDeclaration(ctMethod.getParameterTypes()[i], typeSolver, variadic, paramName.orElse(null)); } } catch (NotFoundException | BadBytecode e) { throw new RuntimeException(e); } }
@Override public ResolvedParameterDeclaration getParam(int i) { try { boolean variadic = false; if ((ctMethod.getModifiers() & javassist.Modifier.VARARGS) > 0) { variadic = i == (ctMethod.getParameterTypes().length - 1); } if (ctMethod.getGenericSignature() != null) { SignatureAttribute.MethodSignature methodSignature = SignatureAttribute.toMethodSignature(ctMethod.getGenericSignature()); SignatureAttribute.Type signatureType = methodSignature.getParameterTypes()[i]; return new JavassistParameterDeclaration(JavassistUtils.signatureTypeToType(signatureType, typeSolver, this), typeSolver, variadic); } else { return new JavassistParameterDeclaration(ctMethod.getParameterTypes()[i], typeSolver, variadic); } } catch (NotFoundException e) { throw new RuntimeException(e); } catch (BadBytecode badBytecode) { throw new RuntimeException(badBytecode); } }
private static InternalMethodDefinition toInternalMethodDefinition(CtMethod ctMethod, SymbolResolver resolver) { try { Map<String, TypeUsageNode.TypeVariableData> visibleTypeVariables = getVisibleTypeVariables(ctMethod); TypeUsage returnType = toTypeUsage(ctMethod.getReturnType(), resolver); if (ctMethod.getGenericSignature() != null) { SignatureAttribute.MethodSignature methodSignature = SignatureAttribute.toMethodSignature(ctMethod.getGenericSignature()); returnType = toTypeUsage(methodSignature.getReturnType(), resolver, visibleTypeVariables); } return new InternalMethodDefinition(ctMethod.getName(), formalParameters(ctMethod, resolver), returnType, JavassistTypeDefinitionFactory.toMethodDefinition(ctMethod)); } catch (NotFoundException e) { throw new RuntimeException(e); } catch (BadBytecode badBytecode) { throw new RuntimeException(badBytecode); } }
returnType.substring(1, returnType.length() - 1).replace('/', '.')); } else { String signature = ctMethod.getGenericSignature(); int index = signature.lastIndexOf(')'); ctNewMethod.setGenericSignature(signature.substring(0, index) +
if (method.getGenericSignature() != null) { SignatureAttribute.MethodSignature methodSignature = SignatureAttribute.toMethodSignature(method.getGenericSignature()); List<ResolvedType> parametersOfReturnType = parseTypeParameters(methodSignature.getReturnType().toString(), typeSolver, invokationContext); ResolvedType newReturnType = methodUsage.returnType();
if (method.getGenericSignature() != null) { SignatureAttribute.MethodSignature methodSignature = SignatureAttribute.toMethodSignature(method.getGenericSignature()); List<ResolvedType> parametersOfReturnType = parseTypeParameters(methodSignature.getReturnType().toString(), typeSolver, invokationContext); ResolvedType newReturnType = methodUsage.returnType();
if (method.getGenericSignature() != null) { SignatureAttribute.MethodSignature methodSignature = SignatureAttribute.toMethodSignature(method.getGenericSignature()); List<ResolvedType> parametersOfReturnType = parseTypeParameters(methodSignature.getReturnType().toString(), typeSolver, invokationContext); ResolvedType newReturnType = methodUsage.returnType();
private static String inferMethodTypeName(CtMethod method) { try { if ( method.getMethodInfo2().getAttribute( SignatureAttribute.tag ) == null ) { return method.getReturnType().getName(); } return inferGenericTypeName( method.getReturnType(), SignatureAttribute.toMethodSignature( method.getGenericSignature() ).getReturnType() ); } catch (BadBytecode ignore) { return null; } catch (NotFoundException e) { return null; } }
public static void wrapMethods(CtClass target, CtClass from) throws NotFoundException, CannotCompileException { for (CtMethod method : from.getDeclaredMethods()) { if (Modifier.isStatic(method.getModifiers()) || !Modifier.isAbstract(method.getModifiers())) continue; ClassMap classMap = new ClassMap(); classMap.fix(from); classMap.fix(from.getSuperclass()); CtMethod wrapperMethod = new CtMethod(method, target, classMap); if (method.getGenericSignature() != null) { wrapperMethod.setGenericSignature(method.getGenericSignature()); } wrapperMethod.setBody("return ((" + from.getName() + ")this.wrapped)." + method.getName() + "($$);"); try { target.addMethod(wrapperMethod); } catch (DuplicateMemberException e) { //Skip -- Same member might be declared in various interfaces } } for (CtClass iface : from.getInterfaces()) { wrapMethods(target, iface); } }
classMap.fix(mergedMethod.getDeclaringClass().getSuperclass()); CtMethod mergedMethodCopy = new CtMethod(mergedMethod, merged, classMap); if (mergedMethod.getGenericSignature() != null) { mergedMethodCopy.setGenericSignature(mergedMethod.getGenericSignature());