use of com.intellij.lang.annotation.Annotation in project intellij-community by JetBrains.
the class GroovyAnnotator method checkDuplicateModifiers.
private static void checkDuplicateModifiers(AnnotationHolder holder, @NotNull GrModifierList list, PsiMember member) {
final PsiElement[] modifiers = list.getModifiers();
Set<String> set = new THashSet<>(modifiers.length);
for (PsiElement modifier : modifiers) {
if (modifier instanceof GrAnnotation)
continue;
@GrModifier.GrModifierConstant String name = modifier.getText();
if (set.contains(name)) {
final Annotation annotation = holder.createErrorAnnotation(list, GroovyBundle.message("duplicate.modifier", name));
registerFix(annotation, new GrModifierFix(member, name, false, false, GrModifierFix.MODIFIER_LIST), list);
} else {
set.add(name);
}
}
}
use of com.intellij.lang.annotation.Annotation in project intellij-community by JetBrains.
the class GroovyAnnotator method visitMethod.
@Override
public void visitMethod(@NotNull GrMethod method) {
checkDuplicateMethod(method);
checkMethodWithTypeParamsShouldHaveReturnType(myHolder, method);
checkInnerMethod(myHolder, method);
checkOptionalParametersInAbstractMethod(myHolder, method);
checkConstructorOfImmutableClass(myHolder, method);
checkGetterOfImmutable(myHolder, method);
final PsiElement nameIdentifier = method.getNameIdentifierGroovy();
if (nameIdentifier.getNode().getElementType() == GroovyTokenTypes.mSTRING_LITERAL) {
checkStringLiteral(nameIdentifier);
}
GrOpenBlock block = method.getBlock();
if (block != null && TypeInferenceHelper.isTooComplexTooAnalyze(block)) {
myHolder.createWeakWarningAnnotation(nameIdentifier, GroovyBundle.message("method.0.is.too.complex.too.analyze", method.getName()));
}
final PsiClass containingClass = method.getContainingClass();
if (method.isConstructor()) {
if (containingClass instanceof GrAnonymousClassDefinition) {
myHolder.createErrorAnnotation(nameIdentifier, GroovyBundle.message("constructors.are.not.allowed.in.anonymous.class"));
} else if (containingClass != null && containingClass.isInterface()) {
myHolder.createErrorAnnotation(nameIdentifier, GroovyBundle.message("constructors.are.not.allowed.in.interface"));
}
}
if (method.getBlock() == null && !method.hasModifierProperty(PsiModifier.NATIVE) && !GrTraitUtil.isMethodAbstract(method)) {
final Annotation annotation = myHolder.createErrorAnnotation(nameIdentifier, GroovyBundle.message("not.abstract.method.should.have.body"));
//annotation.registerFix(new AddMethodBodyFix(method)); //todo make intentions work
//registerFix(annotation, new GrModifierFix(method, ABSTRACT, false, true, GrModifierFix.MODIFIER_LIST_OWNER), method);
}
checkOverridingMethod(myHolder, method);
}
use of com.intellij.lang.annotation.Annotation in project intellij-community by JetBrains.
the class GroovyAnnotator method visitVariable.
@Override
public void visitVariable(@NotNull GrVariable variable) {
checkName(variable);
PsiElement parent = variable.getParent();
if (parent instanceof GrForInClause) {
PsiElement delimiter = ((GrForInClause) parent).getDelimiter();
if (delimiter.getNode().getElementType() == GroovyTokenTypes.mCOLON) {
GrTypeElement typeElement = variable.getTypeElementGroovy();
GrModifierList modifierList = variable.getModifierList();
if (typeElement == null && StringUtil.isEmptyOrSpaces(modifierList.getText())) {
Annotation annotation = myHolder.createErrorAnnotation(variable.getNameIdentifierGroovy(), GroovyBundle.message("java.style.for.each.statement.requires.a.type.declaration"));
annotation.registerFix(new ReplaceDelimiterFix());
}
}
}
PsiNamedElement duplicate = ResolveUtil.findDuplicate(variable);
if (duplicate instanceof GrVariable && (variable instanceof GrField || ResolveUtil.isScriptField(variable) || !(duplicate instanceof GrField))) {
final String key = duplicate instanceof GrField ? "field.already.defined" : "variable.already.defined";
myHolder.createErrorAnnotation(variable.getNameIdentifierGroovy(), GroovyBundle.message(key, variable.getName()));
}
PsiType type = variable.getDeclaredType();
if (type instanceof PsiEllipsisType && !isLastParameter(variable)) {
TextRange range = getEllipsisRange(variable);
if (range == null) {
range = getTypeRange(variable);
}
if (range != null) {
myHolder.createErrorAnnotation(range, GroovyBundle.message("ellipsis.type.is.not.allowed.here"));
}
}
}
use of com.intellij.lang.annotation.Annotation in project intellij-community by JetBrains.
the class GroovyAnnotator method checkFieldModifiers.
private static void checkFieldModifiers(AnnotationHolder holder, GrVariableDeclaration fieldDeclaration) {
GrVariable[] variables = fieldDeclaration.getVariables();
if (variables.length == 0)
return;
GrVariable variable = variables[0];
if (!(variable instanceof GrField))
return;
final GrField member = (GrField) variable;
final GrModifierList modifierList = fieldDeclaration.getModifierList();
checkAccessModifiers(holder, modifierList, member);
checkDuplicateModifiers(holder, modifierList, member);
if (modifierList.hasExplicitModifier(PsiModifier.VOLATILE) && modifierList.hasExplicitModifier(PsiModifier.FINAL)) {
final Annotation annotation = holder.createErrorAnnotation(modifierList, GroovyBundle.message("illegal.combination.of.modifiers.volatile.and.final"));
registerFix(annotation, new GrModifierFix(member, PsiModifier.VOLATILE, true, false, GrModifierFix.MODIFIER_LIST), modifierList);
registerFix(annotation, new GrModifierFix(member, PsiModifier.FINAL, true, false, GrModifierFix.MODIFIER_LIST), modifierList);
}
if (member.getContainingClass() instanceof GrInterfaceDefinition) {
checkModifierIsNotAllowed(modifierList, PsiModifier.PRIVATE, GroovyBundle.message("interface.members.are.not.allowed.to.be", PsiModifier.PRIVATE), holder);
checkModifierIsNotAllowed(modifierList, PsiModifier.PROTECTED, GroovyBundle.message("interface.members.are.not.allowed.to.be", PsiModifier.PROTECTED), holder);
}
}
use of com.intellij.lang.annotation.Annotation in project android by JetBrains.
the class AndroidColorAnnotator method annotateXml.
private static void annotateXml(PsiElement element, AnnotationHolder holder, String value) {
if (value.startsWith("#")) {
final PsiFile file = element.getContainingFile();
if (file != null && AndroidResourceUtil.isInResourceSubdirectory(file, null)) {
if (element instanceof XmlTag) {
Annotation annotation = holder.createInfoAnnotation(element, null);
annotation.setGutterIconRenderer(new MyRenderer(element, null));
} else {
assert element instanceof XmlAttributeValue;
Color color = ResourceHelper.parseColor(value);
if (color != null) {
Annotation annotation = holder.createInfoAnnotation(element, null);
annotation.setGutterIconRenderer(new MyRenderer(element, null));
}
}
}
} else if (value.startsWith(COLOR_RESOURCE_PREFIX)) {
annotateResourceReference(ResourceType.COLOR, holder, element, value.substring(COLOR_RESOURCE_PREFIX.length()), false);
} else if (value.startsWith(ANDROID_COLOR_RESOURCE_PREFIX)) {
annotateResourceReference(ResourceType.COLOR, holder, element, value.substring(ANDROID_COLOR_RESOURCE_PREFIX.length()), true);
} else if (value.startsWith(DRAWABLE_PREFIX)) {
annotateResourceReference(ResourceType.DRAWABLE, holder, element, value.substring(DRAWABLE_PREFIX.length()), false);
} else if (value.startsWith(ANDROID_DRAWABLE_PREFIX)) {
annotateResourceReference(ResourceType.DRAWABLE, holder, element, value.substring(ANDROID_DRAWABLE_PREFIX.length()), true);
} else if (value.startsWith(MIPMAP_PREFIX)) {
annotateResourceReference(ResourceType.MIPMAP, holder, element, value.substring(MIPMAP_PREFIX.length()), false);
}
}
Aggregations