@Override public List<ResolvedReferenceType> getInterfacesExtended() { List<ResolvedReferenceType> res = new ArrayList<>(); for (Class i : clazz.getInterfaces()) { res.add(new ReferenceTypeImpl(new ReflectionInterfaceDeclaration(i, typeSolver), typeSolver)); } return res; }
@Override public boolean equals(Object o) { if (this == o) return true; if (!(o instanceof ReflectionInterfaceDeclaration)) return false; ReflectionInterfaceDeclaration that = (ReflectionInterfaceDeclaration) o; if (!clazz.getCanonicalName().equals(that.clazz.getCanonicalName())) return false; if (!getTypeParameters().equals(that.getTypeParameters())) { return false; } return true; }
@Override public boolean canBeAssignedTo(ResolvedReferenceTypeDeclaration other) { if (other instanceof LambdaArgumentTypePlaceholder) { return isFunctionalInterface(); } if (other.getQualifiedName().equals(getQualifiedName())) { return true; } if (this.clazz.getSuperclass() != null && new ReflectionInterfaceDeclaration(clazz.getSuperclass(), typeSolver).canBeAssignedTo(other)) { return true; } for (Class interfaze : clazz.getInterfaces()) { if (new ReflectionInterfaceDeclaration(interfaze, typeSolver).canBeAssignedTo(other)) { return true; } } if (other.getQualifiedName().equals(Object.class.getCanonicalName())) { return true; } return false; }
@Override public boolean canBeAssignedTo(ResolvedReferenceTypeDeclaration other) { if (other instanceof LambdaArgumentTypePlaceholder) { return isFunctionalInterface(); } if (other.getQualifiedName().equals(getQualifiedName())) { return true; } if (this.clazz.getSuperclass() != null && new ReflectionClassDeclaration(clazz.getSuperclass(), typeSolver).canBeAssignedTo(other)) { return true; } for (Class<?> interfaze : clazz.getInterfaces()) { if (new ReflectionInterfaceDeclaration(interfaze, typeSolver).canBeAssignedTo(other)) { return true; } } return false; }
@Test public void testTypeParametersValues() { TypeSolver typeResolver = new ReflectionTypeSolver(); ResolvedReferenceType stream = new ReferenceTypeImpl(new ReflectionInterfaceDeclaration(Stream.class, typeResolver), typeResolver); assertEquals(1, stream.typeParametersValues().size()); assertEquals(new ResolvedTypeVariable(new ReflectionInterfaceDeclaration(Stream.class, typeResolver).getTypeParameters().get(0)), stream.typeParametersValues().get(0)); }
@Override public boolean isAssignableBy(ResolvedType type) { if (type instanceof NullType) { return true; } if (type instanceof LambdaArgumentTypePlaceholder) { return isFunctionalInterface(); } if (type.isArray()) { return false; } if (type.isPrimitive()) { return false; } if (type.describe().equals(getQualifiedName())) { return true; } if (type instanceof ReferenceTypeImpl) { ReferenceTypeImpl otherTypeDeclaration = (ReferenceTypeImpl) type; return otherTypeDeclaration.getTypeDeclaration().canBeAssignedTo(this); } return false; }
@Override public String getClassName() { String canonicalName = clazz.getCanonicalName(); if (canonicalName != null && getPackageName() != null) { return canonicalName.substring(getPackageName().length() + 1, canonicalName.length()); } return null; }
@Override public boolean isAssignableBy(ResolvedReferenceTypeDeclaration other) { return isAssignableBy(new ReferenceTypeImpl(other, typeSolver)); }
return ((ReflectionInterfaceDeclaration) typeDeclaration).solveSymbol(name, typeSolver);
public static Optional<MethodUsage> solveMethodAsUsage(ResolvedTypeDeclaration typeDeclaration, String name, List<ResolvedType> argumentsTypes, TypeSolver typeSolver, Context invokationContext, List<ResolvedType> typeParameters) { if (typeDeclaration instanceof JavassistClassDeclaration) { return ((JavassistClassDeclaration) typeDeclaration).solveMethodAsUsage(name, argumentsTypes, typeSolver, invokationContext, typeParameters); } else if (typeDeclaration instanceof JavassistInterfaceDeclaration) { return ((JavassistInterfaceDeclaration) typeDeclaration).solveMethodAsUsage(name, argumentsTypes, typeSolver, invokationContext, typeParameters); } else if (typeDeclaration instanceof JavassistEnumDeclaration) { return ((JavassistEnumDeclaration) typeDeclaration).solveMethodAsUsage(name, argumentsTypes, typeSolver, invokationContext, typeParameters); } else if (typeDeclaration instanceof ReflectionClassDeclaration) { return ((ReflectionClassDeclaration) typeDeclaration).solveMethodAsUsage(name, argumentsTypes, typeSolver, invokationContext, typeParameters); } else if (typeDeclaration instanceof ReflectionInterfaceDeclaration) { return ((ReflectionInterfaceDeclaration) typeDeclaration).solveMethodAsUsage(name, argumentsTypes, typeSolver, invokationContext, typeParameters); } else if (typeDeclaration instanceof ReflectionEnumDeclaration) { return ((ReflectionEnumDeclaration) typeDeclaration).solveMethodAsUsage(name, argumentsTypes, typeSolver, invokationContext, typeParameters); } else if (typeDeclaration instanceof JavaParserClassDeclaration) { return ((JavaParserClassDeclaration) typeDeclaration).getContext().solveMethodAsUsage(name, argumentsTypes, typeSolver); } else if (typeDeclaration instanceof JavaParserInterfaceDeclaration) { return ((JavaParserInterfaceDeclaration) typeDeclaration).getContext().solveMethodAsUsage(name, argumentsTypes, typeSolver); } else if (typeDeclaration instanceof JavaParserEnumDeclaration) { return ((JavaParserEnumDeclaration) typeDeclaration).getContext().solveMethodAsUsage(name, argumentsTypes, typeSolver); } else if (typeDeclaration instanceof JavaParserAnonymousClassDeclaration) { return ((JavaParserAnonymousClassDeclaration) typeDeclaration).getContext().solveMethodAsUsage(name, argumentsTypes, typeSolver); } throw new UnsupportedOperationException(typeDeclaration.toString()); }
return ((ReflectionInterfaceDeclaration) typeDeclaration).solveMethod(name, argumentsTypes, staticOnly);
@Override public boolean canBeAssignedTo(ResolvedReferenceTypeDeclaration other) { if (other instanceof LambdaArgumentTypePlaceholder) { return isFunctionalInterface(); } if (other.getQualifiedName().equals(getQualifiedName())) { return true; } if (this.clazz.getSuperclass() != null && new ReflectionClassDeclaration(clazz.getSuperclass(), typeSolver).canBeAssignedTo(other)) { return true; } for (Class<?> interfaze : clazz.getInterfaces()) { if (new ReflectionInterfaceDeclaration(interfaze, typeSolver).canBeAssignedTo(other)) { return true; } } return false; }
@Override public boolean isAssignableBy(ResolvedType type) { if (type instanceof NullType) { return true; } if (type instanceof LambdaArgumentTypePlaceholder) { return isFunctionalInterface(); } if (type.isArray()) { return false; } if (type.isPrimitive()) { return false; } if (type.describe().equals(getQualifiedName())) { return true; } if (type instanceof ReferenceTypeImpl) { ReferenceTypeImpl otherTypeDeclaration = (ReferenceTypeImpl) type; return otherTypeDeclaration.getTypeDeclaration().canBeAssignedTo(this); } return false; }
@Override public String getClassName() { String canonicalName = clazz.getCanonicalName(); if (canonicalName != null && getPackageName() != null) { return canonicalName.substring(getPackageName().length() + 1, canonicalName.length()); } return null; }
@Override public boolean isAssignableBy(ResolvedReferenceTypeDeclaration other) { return isAssignableBy(new ReferenceTypeImpl(other, typeSolver)); }
return ((ReflectionInterfaceDeclaration) typeDeclaration).solveSymbol(name, typeSolver);
public static Optional<MethodUsage> solveMethodAsUsage(ResolvedTypeDeclaration typeDeclaration, String name, List<ResolvedType> argumentsTypes, TypeSolver typeSolver, Context invokationContext, List<ResolvedType> typeParameters) { if (typeDeclaration instanceof JavassistClassDeclaration) { return ((JavassistClassDeclaration) typeDeclaration).solveMethodAsUsage(name, argumentsTypes, typeSolver, invokationContext, typeParameters); } else if (typeDeclaration instanceof JavassistInterfaceDeclaration) { return ((JavassistInterfaceDeclaration) typeDeclaration).solveMethodAsUsage(name, argumentsTypes, typeSolver, invokationContext, typeParameters); } else if (typeDeclaration instanceof JavassistEnumDeclaration) { return ((JavassistEnumDeclaration) typeDeclaration).solveMethodAsUsage(name, argumentsTypes, typeSolver, invokationContext, typeParameters); } else if (typeDeclaration instanceof ReflectionClassDeclaration) { return ((ReflectionClassDeclaration) typeDeclaration).solveMethodAsUsage(name, argumentsTypes, typeSolver, invokationContext, typeParameters); } else if (typeDeclaration instanceof ReflectionInterfaceDeclaration) { return ((ReflectionInterfaceDeclaration) typeDeclaration).solveMethodAsUsage(name, argumentsTypes, typeSolver, invokationContext, typeParameters); } else if (typeDeclaration instanceof ReflectionEnumDeclaration) { return ((ReflectionEnumDeclaration) typeDeclaration).solveMethodAsUsage(name, argumentsTypes, typeSolver, invokationContext, typeParameters); } else if (typeDeclaration instanceof JavaParserClassDeclaration) { return ((JavaParserClassDeclaration) typeDeclaration).getContext().solveMethodAsUsage(name, argumentsTypes, typeSolver); } else if (typeDeclaration instanceof JavaParserInterfaceDeclaration) { return ((JavaParserInterfaceDeclaration) typeDeclaration).getContext().solveMethodAsUsage(name, argumentsTypes, typeSolver); } else if (typeDeclaration instanceof JavaParserEnumDeclaration) { return ((JavaParserEnumDeclaration) typeDeclaration).getContext().solveMethodAsUsage(name, argumentsTypes, typeSolver); } else if (typeDeclaration instanceof JavaParserAnonymousClassDeclaration) { return ((JavaParserAnonymousClassDeclaration) typeDeclaration).getContext().solveMethodAsUsage(name, argumentsTypes, typeSolver); } throw new UnsupportedOperationException(typeDeclaration.toString()); }
return ((ReflectionInterfaceDeclaration) typeDeclaration).solveMethod(name, argumentsTypes, staticOnly);
@Override public List<ResolvedReferenceType> getInterfacesExtended() { List<ResolvedReferenceType> res = new ArrayList<>(); for (Class i : clazz.getInterfaces()) { res.add(new ReferenceTypeImpl(new ReflectionInterfaceDeclaration(i, typeSolver), typeSolver)); } return res; }
@Override public boolean canBeAssignedTo(ResolvedReferenceTypeDeclaration other) { if (other instanceof LambdaArgumentTypePlaceholder) { return isFunctionalInterface(); } if (other.getQualifiedName().equals(getQualifiedName())) { return true; } if (this.clazz.getSuperclass() != null && new ReflectionInterfaceDeclaration(clazz.getSuperclass(), typeSolver).canBeAssignedTo(other)) { return true; } for (Class interfaze : clazz.getInterfaces()) { if (new ReflectionInterfaceDeclaration(interfaze, typeSolver).canBeAssignedTo(other)) { return true; } } if (other.getQualifiedName().equals(Object.class.getCanonicalName())) { return true; } return false; }