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 intellij-community by JetBrains.
the class WebReferencesAnnotatorBase method apply.
@Override
public void apply(@NotNull PsiFile file, MyInfo[] infos, @NotNull AnnotationHolder holder) {
if (infos == null || infos.length == 0) {
return;
}
final HighlightDisplayLevel displayLevel = getHighlightDisplayLevel(file);
for (MyInfo info : infos) {
if (!info.myResult) {
final PsiElement element = info.myAnchor.retrieve();
if (element != null) {
final int start = element.getTextRange().getStartOffset();
final TextRange range = new TextRange(start + info.myRangeInElement.getStartOffset(), start + info.myRangeInElement.getEndOffset());
final String message = getErrorMessage(info.myUrl);
final Annotation annotation;
if (displayLevel == HighlightDisplayLevel.ERROR) {
annotation = holder.createErrorAnnotation(range, message);
} else if (displayLevel == HighlightDisplayLevel.WARNING) {
annotation = holder.createWarningAnnotation(range, message);
} else if (displayLevel == HighlightDisplayLevel.WEAK_WARNING) {
annotation = holder.createInfoAnnotation(range, message);
} else {
annotation = holder.createWarningAnnotation(range, message);
}
for (IntentionAction action : getQuickFixes()) {
annotation.registerFix(action);
}
}
}
}
}
use of com.intellij.lang.annotation.Annotation in project intellij-community by JetBrains.
the class ClassReferenceParser method annotate.
@Override
public boolean annotate(@NotNull Header header, @NotNull AnnotationHolder holder) {
HeaderValue value = header.getHeaderValue();
if (!(value instanceof HeaderValuePart))
return false;
HeaderValuePart valuePart = (HeaderValuePart) value;
String className = valuePart.getUnwrappedText();
if (StringUtil.isEmptyOrSpaces(className)) {
holder.createErrorAnnotation(valuePart.getHighlightingRange(), ManifestBundle.message("header.reference.invalid"));
return true;
}
Project project = header.getProject();
Module module = ModuleUtilCore.findModuleForPsiElement(header);
GlobalSearchScope scope = module != null ? module.getModuleWithDependenciesAndLibrariesScope(false) : ProjectScope.getAllScope(project);
PsiClass aClass = JavaPsiFacade.getInstance(project).findClass(className, scope);
if (aClass == null) {
String message = JavaErrorMessages.message("error.cannot.resolve.class", className);
Annotation anno = holder.createErrorAnnotation(valuePart.getHighlightingRange(), message);
anno.setHighlightType(ProblemHighlightType.LIKE_UNKNOWN_SYMBOL);
return true;
}
return checkClass(valuePart, aClass, holder);
}
use of com.intellij.lang.annotation.Annotation in project intellij-plugins by JetBrains.
the class MarkdownHighlightingAnnotator method annotate.
@Override
public void annotate(@NotNull PsiElement element, @NotNull AnnotationHolder holder) {
final IElementType type = element.getNode().getElementType();
if (type == MarkdownTokenTypes.EMPH) {
final PsiElement parent = element.getParent();
if (parent == null) {
return;
}
final IElementType parentType = parent.getNode().getElementType();
if (parentType == MarkdownElementTypes.EMPH || parentType == MarkdownElementTypes.STRONG) {
final Annotation annotation = holder.createInfoAnnotation(element, null);
annotation.setTextAttributes(parentType == MarkdownElementTypes.EMPH ? MarkdownHighlighterColors.ITALIC_MARKER_ATTR_KEY : MarkdownHighlighterColors.BOLD_MARKER_ATTR_KEY);
}
return;
}
if (element instanceof LeafPsiElement) {
return;
}
final TextAttributesKey[] tokenHighlights = SYNTAX_HIGHLIGHTER.getTokenHighlights(type);
if (tokenHighlights.length > 0 && !MarkdownHighlighterColors.TEXT_ATTR_KEY.equals(tokenHighlights[0])) {
final Annotation annotation = holder.createInfoAnnotation(element, null);
annotation.setTextAttributes(tokenHighlights[0]);
}
}
Aggregations