@Override public Iterable<AnnotationParameter> getUnknownAttributes(Annotation annotation) { final Iterable<String> parameterNames = Iterables.transform(definedAttributes, new AnnotationDefinitionParameterName()); return Iterables.filter(annotation.getParameters(), new Predicate<AnnotationParameter>() { @Override public boolean apply(AnnotationParameter input) { Preconditions.checkNotNull(input, "input"); return !Iterables.contains(parameterNames, input.getName()); } }); }
/** * Returns all annotation parameters with a selected name * * @param annotation * @param parameterName * @return a lazy collection of annotation parameters with the selected name. May be empty, but is never null. */ public static Collection<ValueReference> getAnnotationParameters(final Annotation annotation, final String parameterName) { return Collections2.transform( Collections2.filter(annotation.getParameters(), new Predicate<AnnotationParameter>() { @Override public boolean apply(AnnotationParameter parameter) { Preconditions.checkArgument(parameter != null); return parameter.getName().equals(parameterName); } }), new Function<AnnotationParameter, ValueReference>() { @Override public ValueReference apply(AnnotationParameter parameter) { Preconditions.checkArgument(parameter != null); return parameter.getValue(); } }); }
private Iterable<String> getParameterNames(Annotation annotation) { return Iterables.transform(annotation.getParameters(), new AnnotationParameterName()); }
public AnnotationParameter getAnnotationParameter(Annotation annotation, String parameterName) { AnnotationParameter parameter = PatternLanguageFactory.eINSTANCE.createAnnotationParameter(); parameter.setName(parameterName); annotation.getParameters().add(parameter); return parameter; }
public static Map<String, Object> evaluateAnnotationParameters(Annotation annotation) { Map<String, Object> result = Maps.newHashMap(); for (AnnotationParameter param : annotation.getParameters()) { String parameterName = param.getName(); ValueReference ref = param.getValue(); if (ref != null) { final Object valueReference = CorePatternLanguageHelper.getValue(ref); if (!Strings.isNullOrEmpty(parameterName) && valueReference != null) { result.put(parameterName, valueReference); } } } return result; }
error(UNKNOWN_ANNOTATION_ATTRIBUTE + unknownParameter.getName(), unknownParameter, PatternLanguagePackage.Literals.ANNOTATION_PARAMETER__NAME, annotation.getParameters().indexOf(unknownParameter), IssueCodes.UNKNOWN_ANNOTATION_PARAMETER); for (AnnotationParameter parameter : annotation.getParameters()) { Class<? extends ValueReference> expectedParameterType = validator.getExpectedParameterType(parameter); if (expectedParameterType != null && parameter.getValue() != null error(String.format(ANNOTATION_PARAMETER_TYPE_ERROR, getTypeName(parameter.getValue().getClass()), getTypeName(expectedParameterType)), parameter, PatternLanguagePackage.Literals.ANNOTATION_PARAMETER__NAME, annotation.getParameters() .indexOf(parameter), IssueCodes.MISTYPED_ANNOTATION_PARAMETER); } else if (parameter.getValue() instanceof VariableValue) { if (value.getValue().getVariable() == null) { error(String.format("Unknown variable %s", value.getValue().getVar()), parameter, PatternLanguagePackage.Literals.ANNOTATION_PARAMETER__VALUE, annotation.getParameters() .indexOf(parameter), IssueCodes.MISTYPED_ANNOTATION_PARAMETER);