@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 ResolvedType getType() { Class<?> enumClass = enumConstant.getDeclaringClass(); ResolvedReferenceTypeDeclaration typeDeclaration = new ReflectionEnumDeclaration(enumClass, typeSolver); return new ReferenceTypeImpl(typeDeclaration, typeSolver); } }
@Override public boolean isAssignableBy(ResolvedReferenceTypeDeclaration other) { return isAssignableBy(new ReferenceTypeImpl(other, 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 ((ReflectionEnumDeclaration) typeDeclaration).solveMethod(name, argumentsTypes, staticOnly);
@Test(expected = UnsupportedOperationException.class) public void testAsClass() { ReflectionEnumDeclaration modifier = (ReflectionEnumDeclaration) typeSolver.solveType("com.github.javaparser.ast.Modifier"); modifier.asClass(); }
@Test public void testAsEnum() { ReflectionEnumDeclaration modifier = (ReflectionEnumDeclaration) typeSolver.solveType("com.github.javaparser.ast.Modifier"); assertEquals(modifier, modifier.asEnum()); }
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 ((ReflectionEnumDeclaration) typeDeclaration).solveMethod(name, argumentsTypes, staticOnly);
@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 ResolvedReferenceTypeDeclaration declaringType() { if (method.getDeclaringClass().isInterface()) { return new ReflectionInterfaceDeclaration(method.getDeclaringClass(), typeSolver); } if (method.getDeclaringClass().isEnum()) { return new ReflectionEnumDeclaration(method.getDeclaringClass(), typeSolver); } else { return new ReflectionClassDeclaration(method.getDeclaringClass(), typeSolver); } }
@Override public boolean isAssignableBy(ResolvedReferenceTypeDeclaration other) { return isAssignableBy(new ReferenceTypeImpl(other, typeSolver)); }
@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 ResolvedReferenceTypeDeclaration declaringType() { if (method.getDeclaringClass().isInterface()) { return new ReflectionInterfaceDeclaration(method.getDeclaringClass(), typeSolver); } if (method.getDeclaringClass().isEnum()) { return new ReflectionEnumDeclaration(method.getDeclaringClass(), typeSolver); } else { return new ReflectionClassDeclaration(method.getDeclaringClass(), typeSolver); } }
@Override public boolean isAssignableBy(ResolvedReferenceTypeDeclaration other) { return isAssignableBy(new ReferenceTypeImpl(other, typeSolver)); }
@Test public void testGetPackageName() { ReflectionEnumDeclaration modifier = (ReflectionEnumDeclaration) typeSolver.solveType("com.github.javaparser.ast.Modifier"); assertEquals("com.github.javaparser.ast", modifier.getPackageName()); }
@Override public ResolvedReferenceTypeDeclaration declaringType() { if (method.getDeclaringClass().isInterface()) { return new ReflectionInterfaceDeclaration(method.getDeclaringClass(), typeSolver); } if (method.getDeclaringClass().isEnum()) { return new ReflectionEnumDeclaration(method.getDeclaringClass(), typeSolver); } else { return new ReflectionClassDeclaration(method.getDeclaringClass(), typeSolver); } }
public static ResolvedReferenceTypeDeclaration typeDeclarationFor(Class<?> clazz, TypeSolver typeSolver) { if (clazz.isArray()) { throw new IllegalArgumentException("No type declaration available for an Array"); } else if (clazz.isPrimitive()) { throw new IllegalArgumentException(); } else if (clazz.isInterface()) { return new ReflectionInterfaceDeclaration(clazz, typeSolver); } else if (clazz.isEnum()) { return new ReflectionEnumDeclaration(clazz, typeSolver); } else { return new ReflectionClassDeclaration(clazz, typeSolver); } }
public static ResolvedReferenceTypeDeclaration typeDeclarationFor(Class<?> clazz, TypeSolver typeSolver) { if (clazz.isArray()) { throw new IllegalArgumentException("No type declaration available for an Array"); } else if (clazz.isPrimitive()) { throw new IllegalArgumentException(); } else if (clazz.isInterface()) { return new ReflectionInterfaceDeclaration(clazz, typeSolver); } else if (clazz.isEnum()) { return new ReflectionEnumDeclaration(clazz, typeSolver); } else { return new ReflectionClassDeclaration(clazz, typeSolver); } }
public static ResolvedReferenceTypeDeclaration typeDeclarationFor(Class<?> clazz, TypeSolver typeSolver) { if (clazz.isArray()) { throw new IllegalArgumentException("No type declaration available for an Array"); } else if (clazz.isPrimitive()) { throw new IllegalArgumentException(); } else if (clazz.isAnnotation()) { return new ReflectionAnnotationDeclaration(clazz, typeSolver); } else if (clazz.isInterface()) { return new ReflectionInterfaceDeclaration(clazz, typeSolver); } else if (clazz.isEnum()) { return new ReflectionEnumDeclaration(clazz, typeSolver); } else { return new ReflectionClassDeclaration(clazz, typeSolver); } }