private static boolean methodHasDependencies(IMethod method) throws JavaModelException { IAnnotation annotation = method.getAnnotation("Test"); return annotation != null && (contains(annotation.getMemberValuePairs(), "dependsOnGroups") || contains(annotation.getMemberValuePairs(), "dependsOnMethods")); }
private void appendAnnotation(IAnnotation annotation) throws JavaModelException { String name= annotation.getElementName(); if (!fStubInvisible && name.startsWith("sun.") || name.startsWith("jdk.internal.")) //$NON-NLS-1$ //$NON-NLS-2$ return; // skip Sun-internal annotations fBuffer.append('@'); fBuffer.append(name.replace('$', '.')); fBuffer.append('('); IMemberValuePair[] memberValuePairs= annotation.getMemberValuePairs(); for (IMemberValuePair pair : memberValuePairs) { fBuffer.append(pair.getMemberName()); fBuffer.append('='); appendAnnotationValue(pair.getValue(), pair.getValueKind()); fBuffer.append(','); } if (memberValuePairs.length > 0) fBuffer.deleteCharAt(fBuffer.length() - 1); fBuffer.append(')').append('\n'); }
private void appendAnnotation(IAnnotation annotation) throws JavaModelException { String name= annotation.getElementName(); if (!fStubInvisible && name.startsWith("sun.")) //$NON-NLS-1$ return; // skip Sun-internal annotations fBuffer.append('@'); fBuffer.append(name); fBuffer.append('('); IMemberValuePair[] memberValuePairs= annotation.getMemberValuePairs(); for (IMemberValuePair pair : memberValuePairs) { fBuffer.append(pair.getMemberName()); fBuffer.append('='); appendAnnotationValue(pair.getValue(), pair.getValueKind()); fBuffer.append(','); } if (memberValuePairs.length > 0) fBuffer.deleteCharAt(fBuffer.length() - 1); fBuffer.append(')').append('\n'); }
private String extractDefaultValue(IMethod operation, IAnnotation annot) throws JavaModelException, IllegalArgumentException { IAnnotation annotation = annot; final Object value = annotation.getMemberValuePairs()[0].getValue(); final String fieldId = (value == null) ? null : value.toString(); if (!Strings.isNullOrEmpty(fieldId)) { final String fieldName = Utils.createNameForHiddenDefaultValueAttribute(fieldId); final IField field = operation.getDeclaringType().getField(fieldName); if (field != null) { annotation = getAnnotation(field, SarlSourceCode.class.getName()); if (annotation != null) { return annotation.getMemberValuePairs()[0].getValue().toString(); } } } return null; }
/** * Gets teh value of the given annotation attribute as {@link String}. * * @param annotation * The {@link IAnnotation} for which the attribute should be converted. * @param name * The name of attribute. * @return A {@link String} with the value of the given attribute or <code>null</code> if the value is <code>null</code> * or could not be found. * @throws JavaModelException */ public static String getAnnotationValueString(IAnnotation annotation, String name) throws JavaModelException { if (!exists(annotation)) { return null; } IMemberValuePair[] memberValues = annotation.getMemberValuePairs(); for (IMemberValuePair p : memberValues) { if (Objects.equals(name, p.getMemberName())) { Object val = p.getValue(); if (val != null) { return val.toString(); } } } return null; }
for (IAnnotation annotation : method.getAnnotations()) { monitor.worked(1); IMemberValuePair[] pairs = annotation.getMemberValuePairs(); if ("Test".equals(annotation.getElementName()) && pairs.length > 0) { for (IMemberValuePair pair : pairs) {
private static boolean isSilencedGeneratedAnnotation(IAnnotation annotation) throws JavaModelException { if ("javax.annotation.Generated".equals(annotation.getElementName()) || "javax.annotation.processing.Generated".equals(annotation.getElementName())) { IMemberValuePair[] memberValuePairs = annotation.getMemberValuePairs(); for (IMemberValuePair m : memberValuePairs) { if ("value".equals(m.getMemberName()) && IMemberValuePair.K_STRING == m.getValueKind()) { if (m.getValue() instanceof String) { return SILENCED_CODEGENS.contains(m.getValue()); } else if (m.getValue() instanceof Object[]) { for (Object val : (Object[])m.getValue()) { if(SILENCED_CODEGENS.contains(val)) { return true; } } } } } } return false; }
return null; IMemberValuePair[] memberValues = annotation.getMemberValuePairs(); for (IMemberValuePair p : memberValues) { if (Objects.equals(name, p.getMemberName())) {
if (annotationType.isBinary()) { if (annotations[i].getElementName().equals(Target.class.getName())) { for (IMemberValuePair valuePair : annotations[i].getMemberValuePairs()) { if (TYPE_USE_NAME.equals(valuePair.getValue())) { return true; if (resolveType != null && resolveType.length == 1 && (resolveType[0][0].equals(Target.class.getPackage().getName()) && resolveType[0][1].equals(Target.class.getSimpleName()))) { for (IMemberValuePair valuePair : annotations[i].getMemberValuePairs()) { final Object value= valuePair.getValue(); if (value instanceof String) {
/** * @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; }
@SuppressWarnings("rawtypes") @Override public TestItem parseTestItem(IMethod method) throws JavaModelException { final TestItem item = super.parseTestItem(method); // Check if the method has annotated with @DisplayName final Optional<IAnnotation> annotation = TestFrameworkUtils.getAnnotation(method, DISPLAY_NAME_ANNOTATION_JUNIT5); if (annotation.isPresent()) { item.setDisplayName((String) annotation.get().getMemberValuePairs()[0].getValue()); } // Get the parameter type information final List<String> result = new LinkedList<>(); final CompilationUnit astRoot = CoreASTProvider.getInstance().getAST( method.getDeclaringType().getCompilationUnit(), CoreASTProvider.WAIT_YES, new NullProgressMonitor()); final ASTNode name = NodeFinder.perform(astRoot, method.getSourceRange()); if (name instanceof MethodDeclaration) { final List parameterList = ((MethodDeclaration) name).parameters(); for (final Object obj : parameterList) { if (obj instanceof SingleVariableDeclaration) { result.add(((SingleVariableDeclaration) obj).getType().resolveBinding().getQualifiedName()); } } } item.setParamTypes(result); return item; } }
public void appendAnnotationLabel(IAnnotation annotation, long flags) throws JavaModelException { fBuilder.append('@'); appendTypeSignatureLabel(annotation, Signature.createTypeSignature(annotation.getElementName(), false), flags); IMemberValuePair[] memberValuePairs= annotation.getMemberValuePairs(); if (memberValuePairs.length == 0) { return; } fBuilder.append('('); for (int i= 0; i < memberValuePairs.length; i++) { if (i > 0) { fBuilder.append(JavaElementLabels.COMMA_STRING); } IMemberValuePair memberValuePair= memberValuePairs[i]; fBuilder.append(getMemberName(annotation, annotation.getElementName(), memberValuePair.getMemberName())); fBuilder.append('='); appendAnnotationValue(annotation, memberValuePair.getValue(), memberValuePair.getValueKind(), flags); } fBuilder.append(')'); }
public void appendAnnotationLabel(IAnnotation annotation, long flags) throws JavaModelException { fBuffer.append('@'); appendTypeSignatureLabel(annotation, Signature.createTypeSignature(annotation.getElementName(), false), flags); IMemberValuePair[] memberValuePairs= annotation.getMemberValuePairs(); if (memberValuePairs.length == 0) return; fBuffer.append('('); for (int i= 0; i < memberValuePairs.length; i++) { if (i > 0) fBuffer.append(JavaElementLabels.COMMA_STRING); IMemberValuePair memberValuePair= memberValuePairs[i]; fBuffer.append(getMemberName(annotation, annotation.getElementName(), memberValuePair.getMemberName())); fBuffer.append('='); appendAnnotationValue(annotation, memberValuePair.getValue(), memberValuePair.getValueKind(), flags); } fBuffer.append(')'); }
public void appendAnnotationLabel(IAnnotation annotation, long flags) throws JavaModelException { fBuffer.append('@'); appendTypeSignatureLabel(annotation, Signature.createTypeSignature(annotation.getElementName(), false), flags); IMemberValuePair[] memberValuePairs= annotation.getMemberValuePairs(); if (memberValuePairs.length == 0) { return; } fBuffer.append('('); for (int i= 0; i < memberValuePairs.length; i++) { if (i > 0) { fBuffer.append(JavaElementLabelsCore.COMMA_STRING); } IMemberValuePair memberValuePair= memberValuePairs[i]; fBuffer.append(getMemberName(annotation, annotation.getElementName(), memberValuePair.getMemberName())); fBuffer.append('='); appendAnnotationValue(annotation, memberValuePair.getValue(), memberValuePair.getValueKind(), flags); } fBuffer.append(')'); }