use of com.intellij.lang.annotation.Annotation in project intellij-community by JetBrains.
the class GroovyPostHighlightingPass method doApplyInformationToEditor.
@Override
public void doApplyInformationToEditor() {
if (myUnusedDeclarations == null || myUnusedImports == null) {
return;
}
AnnotationHolder annotationHolder = new AnnotationHolderImpl(new AnnotationSession(myFile));
List<HighlightInfo> infos = new ArrayList<>(myUnusedDeclarations);
for (GrImportStatement unusedImport : myUnusedImports) {
Annotation annotation = annotationHolder.createWarningAnnotation(calculateRangeToUse(unusedImport), GroovyInspectionBundle.message("unused.import"));
annotation.setHighlightType(ProblemHighlightType.LIKE_UNUSED_SYMBOL);
annotation.registerFix(GroovyQuickFixFactory.getInstance().createOptimizeImportsFix(false));
infos.add(HighlightInfo.fromAnnotation(annotation));
}
UpdateHighlightersUtil.setHighlightersToEditor(myProject, myDocument, 0, myFile.getTextLength(), infos, getColorsScheme(), getId());
if (myUnusedImports != null && !myUnusedImports.isEmpty()) {
IntentionAction fix = GroovyQuickFixFactory.getInstance().createOptimizeImportsFix(true);
if (fix.isAvailable(myProject, myEditor, myFile) && myFile.isWritable()) {
fix.invoke(myProject, myEditor, myFile);
}
}
}
use of com.intellij.lang.annotation.Annotation in project intellij-community by JetBrains.
the class XsltAnnotator method visitXPathToken.
@Override
public void visitXPathToken(XPathToken token) {
if (XPathTokenTypes.REL_OPS.contains(token.getTokenType())) {
if (token.textContains('<')) {
final Annotation ann = myHolder.createErrorAnnotation(token, "'<' must be escaped as '<' in XSLT documents");
ann.registerFix(new ConvertToEntityFix(token));
ann.registerFix(new FlipOperandsFix(token));
}
}
}
use of com.intellij.lang.annotation.Annotation in project intellij-community by JetBrains.
the class GroovyAnnotator method checkMethodDefinitionModifiers.
private static void checkMethodDefinitionModifiers(AnnotationHolder holder, GrMethod method) {
final GrModifierList modifiersList = method.getModifierList();
checkAccessModifiers(holder, modifiersList, method);
checkDuplicateModifiers(holder, modifiersList, method);
checkOverrideAnnotation(holder, modifiersList, method);
checkModifierIsNotAllowed(modifiersList, PsiModifier.VOLATILE, GroovyBundle.message("method.has.incorrect.modifier.volatile"), holder);
checkForAbstractAndFinalCombination(holder, method, modifiersList);
//script methods
boolean isMethodAbstract = modifiersList.hasExplicitModifier(PsiModifier.ABSTRACT);
if (method.getParent() instanceof GroovyFileBase) {
if (isMethodAbstract) {
final Annotation annotation = holder.createErrorAnnotation(getModifierOrList(modifiersList, PsiModifier.ABSTRACT), GroovyBundle.message("script.method.cannot.have.modifier.abstract"));
registerMakeAbstractMethodNotAbstractFix(annotation, method, false);
}
checkModifierIsNotAllowed(modifiersList, PsiModifier.NATIVE, GroovyBundle.message("script.cannot.have.modifier.native"), holder);
} else //type definition methods
if (method.getParent() != null && method.getParent().getParent() instanceof GrTypeDefinition) {
GrTypeDefinition containingTypeDef = ((GrTypeDefinition) method.getParent().getParent());
if (containingTypeDef.isTrait()) {
checkModifierIsNotAllowed(modifiersList, PsiModifier.PROTECTED, GroovyBundle.message("trait.method.cannot.be.protected"), holder);
} else //interface
if (containingTypeDef.isInterface()) {
checkModifierIsNotAllowed(modifiersList, PsiModifier.STATIC, GroovyBundle.message("interface.must.have.no.static.method"), holder);
checkModifierIsNotAllowed(modifiersList, PsiModifier.PRIVATE, GroovyBundle.message("interface.members.are.not.allowed.to.be", PsiModifier.PRIVATE), holder);
checkModifierIsNotAllowed(modifiersList, PsiModifier.PROTECTED, GroovyBundle.message("interface.members.are.not.allowed.to.be", PsiModifier.PROTECTED), holder);
} else if (containingTypeDef.isAnonymous()) {
if (isMethodAbstract) {
final Annotation annotation = holder.createErrorAnnotation(getModifierOrList(modifiersList, PsiModifier.ABSTRACT), GroovyBundle.message("anonymous.class.cannot.have.abstract.method"));
registerMakeAbstractMethodNotAbstractFix(annotation, method, false);
}
} else //class
{
PsiModifierList typeDefModifiersList = containingTypeDef.getModifierList();
LOG.assertTrue(typeDefModifiersList != null, "modifiers list must be not null");
if (!typeDefModifiersList.hasModifierProperty(PsiModifier.ABSTRACT) && isMethodAbstract) {
final Annotation annotation = holder.createErrorAnnotation(modifiersList, GroovyBundle.message("only.abstract.class.can.have.abstract.method"));
registerMakeAbstractMethodNotAbstractFix(annotation, method, true);
}
}
if (method.isConstructor()) {
checkModifierIsNotAllowed(modifiersList, PsiModifier.STATIC, GroovyBundle.message("constructor.cannot.have.static.modifier"), holder);
}
}
if (method.hasModifierProperty(PsiModifier.NATIVE) && method.getBlock() != null) {
final Annotation annotation = holder.createErrorAnnotation(getModifierOrList(modifiersList, PsiModifier.NATIVE), GroovyBundle.message("native.methods.cannot.have.body"));
registerFix(annotation, new GrModifierFix((PsiMember) modifiersList.getParent(), PsiModifier.NATIVE, true, false, GrModifierFix.MODIFIER_LIST), modifiersList);
annotation.registerFix(QuickFixFactory.getInstance().createDeleteMethodBodyFix(method));
}
}
use of com.intellij.lang.annotation.Annotation in project intellij-community by JetBrains.
the class GroovyAnnotator method checkAccessModifiers.
private static void checkAccessModifiers(AnnotationHolder holder, @NotNull GrModifierList modifierList, PsiMember member) {
boolean hasPrivate = modifierList.hasExplicitModifier(PsiModifier.PRIVATE);
boolean hasPublic = modifierList.hasExplicitModifier(PsiModifier.PUBLIC);
boolean hasProtected = modifierList.hasExplicitModifier(PsiModifier.PROTECTED);
if (hasPrivate && hasPublic || hasPrivate && hasProtected || hasPublic && hasProtected) {
final Annotation annotation = holder.createErrorAnnotation(modifierList, GroovyBundle.message("illegal.combination.of.modifiers"));
if (hasPrivate) {
registerFix(annotation, new GrModifierFix(member, PsiModifier.PRIVATE, false, false, GrModifierFix.MODIFIER_LIST), modifierList);
}
if (hasProtected) {
registerFix(annotation, new GrModifierFix(member, PsiModifier.PROTECTED, false, false, GrModifierFix.MODIFIER_LIST), modifierList);
}
if (hasPublic) {
registerFix(annotation, new GrModifierFix(member, PsiModifier.PUBLIC, false, false, GrModifierFix.MODIFIER_LIST), modifierList);
}
} else if (member instanceof PsiClass && member.getContainingClass() == null && GroovyConfigUtils.getInstance().isVersionAtLeast(member, GroovyConfigUtils.GROOVY2_0)) {
checkModifierIsNotAllowed(modifierList, PsiModifier.PRIVATE, GroovyBundle.message("top.level.class.maynot.have.private.modifier"), holder);
checkModifierIsNotAllowed(modifierList, PsiModifier.PROTECTED, GroovyBundle.message("top.level.class.maynot.have.protected.modifier"), holder);
}
}
use of com.intellij.lang.annotation.Annotation in project intellij-community by JetBrains.
the class GroovyAnnotator method checkTypeArgForPrimitive.
private void checkTypeArgForPrimitive(@Nullable GrTypeElement element, String message) {
if (element == null || !(element.getType() instanceof PsiPrimitiveType))
return;
final Annotation annotation = myHolder.createErrorAnnotation(element, message);
registerFix(annotation, new GrReplacePrimitiveTypeWithWrapperFix(element), element);
}
Aggregations