public static boolean isPolymorphicSignature(IMethod method) { return method.getAnnotation("java.lang.invoke.MethodHandle$PolymorphicSignature").exists(); //$NON-NLS-1$ }
public static boolean isPolymorphicSignature(IMethod method) { return method.getAnnotation("java.lang.invoke.MethodHandle$PolymorphicSignature").exists(); //$NON-NLS-1$ }
public static boolean isTestMethod(IMethod method, boolean onlyPublicMethod, String[] annotations) { if (isMethod(method, onlyPublicMethod)) { for (String annotation : annotations) { if (method.getAnnotation(annotation).exists()) { return true; } } } return false; }
public static Optional<IAnnotation> getAnnotation(IMethod method, String methodAnnotation) { try { final Optional<IAnnotation> matched = Arrays.stream(method.getAnnotations()) .filter(annotation -> methodAnnotation.endsWith(annotation.getElementName())).findAny(); if (!matched.isPresent()) { return Optional.empty(); } final IAnnotation annotation = matched.get(); if (!annotation.exists()) { return Optional.empty(); } final String name = annotation.getElementName(); final String[][] fullNameArr = method.getDeclaringType().resolveType(name); if (fullNameArr == null) { final ICompilationUnit cu = method.getCompilationUnit(); if (cu != null && cu.getImport(methodAnnotation).exists()) { return Optional.of(annotation); } else { return Optional.empty(); } } final String fullName = Arrays.stream(fullNameArr[0]).collect(Collectors.joining(".")); return fullName.equals(methodAnnotation) ? Optional.of(annotation) : Optional.empty(); } catch (final JavaModelException e) { return Optional.empty(); } }
/** * @param element the element * @return <code>true</code> if the element is a test class annotated with * <code>@RunWith(JUnitPlatform.class)</code> */ public static boolean isRunWithJUnitPlatform(IJavaElement element) { if (element instanceof ICompilationUnit) { element= ((ICompilationUnit) element).findPrimaryType(); } if (element instanceof IType) { IType type= (IType) element; try { IAnnotation runWithAnnotation= type.getAnnotation("RunWith"); //$NON-NLS-1$ if (!runWithAnnotation.exists()) { runWithAnnotation= type.getAnnotation("org.junit.runner.RunWith"); //$NON-NLS-1$ } if (runWithAnnotation.exists()) { IMemberValuePair[] memberValuePairs= runWithAnnotation.getMemberValuePairs(); for (IMemberValuePair memberValuePair : memberValuePairs) { if (memberValuePair.getMemberName().equals("value") && memberValuePair.getValue().equals("JUnitPlatform")) { //$NON-NLS-1$ //$NON-NLS-2$ return true; } } } } catch (JavaModelException e) { // ignore } } return false; }
public static boolean isAccessibleClass(IType type, String testKindId) throws JavaModelException { int flags= type.getFlags(); if (Flags.isInterface(flags)) { return false; } IJavaElement parent= type.getParent(); while (true) { if (parent instanceof ICompilationUnit || parent instanceof IClassFile) { return true; } if (!(parent instanceof IType)) { return false; } if (TestKindRegistry.JUNIT5_TEST_KIND_ID.equals(testKindId)) { // A nested/inner class need not be public in JUnit 5. if (Flags.isPrivate(flags)) { return false; } // If the inner class is non-static, it must be annotated with @Nested. if (!Flags.isStatic(flags) && !type.getAnnotation("Nested").exists()) { //$NON-NLS-1$ return false; } } else if (!Flags.isStatic(flags) || !Flags.isPublic(flags)) { return false; } flags= ((IType) parent).getFlags(); parent= parent.getParent(); } }