use of org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.modifiers.annotation.GrAnnotationNameValuePair in project intellij-community by JetBrains.
the class GrAnnotationAttributeCompletionProvider method addCompletions.
@Override
protected void addCompletions(@NotNull CompletionParameters parameters, ProcessingContext context, @NotNull CompletionResultSet result) {
PsiElement position = parameters.getPosition();
PsiElement parent = position.getParent();
if (parent instanceof GrAnnotationNameValuePair && position == ((GrAnnotationNameValuePair) parent).getNameIdentifierGroovy()) {
GrAnnotation annotation = PsiImplUtil.getAnnotation((GrAnnotationNameValuePair) parent);
if (annotation != null) {
new AnnotationAttributeCompletionResultProcessor(annotation).process(result, PrefixMatcher.ALWAYS_TRUE);
}
}
}
use of org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.modifiers.annotation.GrAnnotationNameValuePair in project intellij-community by JetBrains.
the class CustomAnnotationChecker method checkAnnotationArguments.
public static void checkAnnotationArguments(@NotNull AnnotationHolder holder, @NotNull PsiClass annotation, @NotNull GrCodeReferenceElement refToHighlight, @NotNull GrAnnotationNameValuePair[] attributes, boolean checkMissedAttributes) {
Set<String> usedAttrs = new HashSet<>();
if (attributes.length > 0) {
final PsiElement identifier = attributes[0].getNameIdentifierGroovy();
if (attributes.length == 1 && identifier == null) {
checkAnnotationValue(annotation, attributes[0], "value", usedAttrs, attributes[0].getValue(), holder);
} else {
for (GrAnnotationNameValuePair attribute : attributes) {
final String name = attribute.getName();
if (name != null) {
final PsiElement toHighlight = attribute.getNameIdentifierGroovy();
assert toHighlight != null;
checkAnnotationValue(annotation, toHighlight, name, usedAttrs, attribute.getValue(), holder);
}
}
}
}
List<String> missedAttrs = new ArrayList<>();
final PsiMethod[] methods = annotation.getMethods();
for (PsiMethod method : methods) {
final String name = method.getName();
if (usedAttrs.contains(name) || method instanceof PsiAnnotationMethod && ((PsiAnnotationMethod) method).getDefaultValue() != null) {
continue;
}
missedAttrs.add(name);
}
if (checkMissedAttributes && !missedAttrs.isEmpty()) {
holder.createErrorAnnotation(refToHighlight, GroovyBundle.message("missed.attributes", StringUtil.join(missedAttrs, ", ")));
}
}
use of org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.modifiers.annotation.GrAnnotationNameValuePair in project intellij-community by JetBrains.
the class GrAliasAnnotationChecker method checkArgumentList.
@Override
public boolean checkArgumentList(@NotNull AnnotationHolder holder, @NotNull GrAnnotation annotation) {
final PsiAnnotation annotationCollector = GrAnnotationCollector.findAnnotationCollector(annotation);
if (annotationCollector == null) {
return false;
}
final ArrayList<GrAnnotation> annotations = ContainerUtil.newArrayList();
final Set<String> usedAttributes = GrAnnotationCollector.collectAnnotations(annotations, annotation, annotationCollector);
AliasedAnnotationHolder aliasedHolder = new AliasedAnnotationHolder(holder, annotation);
AnnotationChecker checker = new AnnotationChecker(aliasedHolder);
for (GrAnnotation aliased : annotations) {
checker.checkAnnotationArgumentList(aliased);
}
final GrAnnotationNameValuePair[] attributes = annotation.getParameterList().getAttributes();
final String aliasQName = annotation.getQualifiedName();
if (attributes.length == 1 && attributes[0].getNameIdentifierGroovy() == null && !usedAttributes.contains("value")) {
holder.createErrorAnnotation(attributes[0], GroovyBundle.message("at.interface.0.does.not.contain.attribute", aliasQName, "value"));
}
for (GrAnnotationNameValuePair pair : attributes) {
final PsiElement nameIdentifier = pair.getNameIdentifierGroovy();
if (nameIdentifier != null && !usedAttributes.contains(pair.getName())) {
holder.createErrorAnnotation(nameIdentifier, GroovyBundle.message("at.interface.0.does.not.contain.attribute", aliasQName, pair.getName()));
}
}
return true;
}
use of org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.modifiers.annotation.GrAnnotationNameValuePair in project intellij-community by JetBrains.
the class TypeCheckedAnnotationChecker method checkArgumentList.
@Override
public boolean checkArgumentList(@NotNull AnnotationHolder holder, @NotNull GrAnnotation annotation) {
final GrCodeReferenceElement classReference = annotation.getClassReference();
PsiElement resolved = classReference.resolve();
if (!(resolved instanceof PsiClass && GroovyCommonClassNames.GROOVY_TRANSFORM_TYPE_CHECKED.equals(((PsiClass) resolved).getQualifiedName()))) {
return false;
}
String sdkVersion = GroovyConfigUtils.getInstance().getSDKVersion(annotation);
if (!("2.1".equals(sdkVersion) || "2.1.0".equals(sdkVersion)))
return false;
GrAnnotationNameValuePair[] attributes = annotation.getParameterList().getAttributes();
checkAnnotationArguments(holder, (PsiClass) resolved, classReference, attributes, false);
return true;
}
use of org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.modifiers.annotation.GrAnnotationNameValuePair in project intellij-community by JetBrains.
the class SpockUnrollReferenceProvider method getReferencesByElement.
@NotNull
@Override
public PsiReference[] getReferencesByElement(@NotNull PsiElement element, @NotNull ProcessingContext context) {
GrAnnotationNameValuePair nvp = (GrAnnotationNameValuePair) element.getParent();
String name = nvp.getName();
if (name != null && !name.equals("value"))
return PsiReference.EMPTY_ARRAY;
PsiElement argumentList = nvp.getParent();
if (!(argumentList instanceof GrAnnotationArgumentList))
return PsiReference.EMPTY_ARRAY;
PsiElement eAnnotation = argumentList.getParent();
if (!(eAnnotation instanceof GrAnnotation))
return PsiReference.EMPTY_ARRAY;
GrAnnotation annotation = (GrAnnotation) eAnnotation;
String shortName = annotation.getShortName();
if (!shortName.equals("Unroll") && !shortName.equals("spock.lang.Unroll"))
return PsiReference.EMPTY_ARRAY;
PsiElement modifierList = annotation.getParent();
if (!(modifierList instanceof GrModifierList))
return PsiReference.EMPTY_ARRAY;
PsiElement eMethod = modifierList.getParent();
if (!(eMethod instanceof GrMethod))
return PsiReference.EMPTY_ARRAY;
final GrMethod method = (GrMethod) eMethod;
ElementManipulator<PsiElement> manipulator = ElementManipulators.getManipulator(element);
TextRange rangeInElement = manipulator.getRangeInElement(element);
String text = rangeInElement.substring(element.getText());
final List<SpockVariableReference> references = new ArrayList<>();
Matcher matcher = PATTERN.matcher(text);
while (matcher.find()) {
TextRange range = new TextRange(rangeInElement.getStartOffset() + matcher.start(1), rangeInElement.getStartOffset() + matcher.end(1));
references.add(new SpockVariableReference(element, range, references, method));
}
return references.toArray(new PsiReference[references.size()]);
}
Aggregations