use of com.intellij.lang.annotation.Annotation in project intellij-plugins by JetBrains.
the class DartAnnotator method createAnnotation.
@Nullable
private static Annotation createAnnotation(@NotNull final AnnotationHolder holder, @NotNull final DartServerData.DartError error, final int fileTextLength) {
int highlightingStart = error.getOffset();
int highlightingEnd = error.getOffset() + error.getLength();
if (highlightingEnd > fileTextLength)
highlightingEnd = fileTextLength;
if (highlightingStart > 0 && highlightingStart >= highlightingEnd)
highlightingStart = highlightingEnd - 1;
final TextRange textRange = new TextRange(highlightingStart, highlightingEnd);
final String severity = error.getSeverity();
final String message = StringUtil.notNullize(error.getMessage());
final ProblemHighlightType specialHighlightType = getSpecialHighlightType(message);
final Annotation annotation;
if (AnalysisErrorSeverity.INFO.equals(severity) && specialHighlightType == null) {
annotation = holder.createWeakWarningAnnotation(textRange, message);
annotation.setTextAttributes(DartSyntaxHighlighterColors.HINT);
} else if (AnalysisErrorSeverity.WARNING.equals(severity) || (AnalysisErrorSeverity.INFO.equals(severity) && specialHighlightType != null)) {
annotation = holder.createWarningAnnotation(textRange, message);
annotation.setTextAttributes(DartSyntaxHighlighterColors.WARNING);
} else if (AnalysisErrorSeverity.ERROR.equals(severity)) {
annotation = holder.createErrorAnnotation(textRange, message);
annotation.setTextAttributes(DartSyntaxHighlighterColors.ERROR);
} else {
annotation = null;
}
if (annotation != null && specialHighlightType != null) {
annotation.setTextAttributes(null);
annotation.setHighlightType(specialHighlightType);
}
return annotation;
}
use of com.intellij.lang.annotation.Annotation in project intellij-plugins by JetBrains.
the class FlexMxmlColorAnnotator method annotate.
@Override
public void annotate(@NotNull PsiElement element, @NotNull AnnotationHolder holder) {
if (!(element instanceof XmlAttribute) || !JavaScriptSupportLoader.isFlexMxmFile(element.getContainingFile())) {
return;
}
if (!LineMarkerSettings.getSettings().isEnabled(new ColorLineMarkerProvider())) {
return;
}
XmlAttribute attribute = (XmlAttribute) element;
XmlAttributeDescriptor descriptor = attribute.getDescriptor();
if (!(descriptor instanceof AnnotationBackedDescriptorImpl)) {
return;
}
AnnotationBackedDescriptorImpl annotationBackedDescriptor = (AnnotationBackedDescriptorImpl) descriptor;
String format = annotationBackedDescriptor.getFormat();
if (!FlexCssPropertyDescriptor.COLOR_FORMAT.equals(format)) {
return;
}
final String value = attribute.getValue();
if (value == null || value.length() == 0) {
return;
}
if (!JSCommonTypeNames.ARRAY_CLASS_NAME.equals(annotationBackedDescriptor.getType())) {
XmlAttributeValue valueElement = attribute.getValueElement();
if (valueElement != null) {
Annotation annotation = holder.createInfoAnnotation(valueElement, null);
annotation.setGutterIconRenderer(new MyRenderer(value, attribute));
}
}
}
use of com.intellij.lang.annotation.Annotation in project intellij-plugins by JetBrains.
the class ActionScriptAnnotatingVisitor method modifierProblem.
private void modifierProblem(JSAttributeList attributeList, JSAttributeList.ModifierType modifierType, String messageKey, String removeFixNameKey) {
PsiElement modifierElement = attributeList.findModifierElement(modifierType);
String message = JSBundle.message(messageKey);
Annotation annotation = myHolder.createErrorAnnotation(modifierElement, message);
annotation.registerFix(new RemoveASTNodeFix(removeFixNameKey, modifierElement.getNode()));
}
use of com.intellij.lang.annotation.Annotation in project intellij-plugins by JetBrains.
the class ActionScriptAnnotatingVisitor method checkNamedObjectIsInCorrespondingFile.
private void checkNamedObjectIsInCorrespondingFile(final JSNamedElement aClass) {
final PsiFile containingFile = aClass.getContainingFile();
if (containingFile.getContext() != null)
return;
final VirtualFile file = containingFile.getVirtualFile();
if (file != null && !file.getNameWithoutExtension().equals(aClass.getName()) && ProjectRootManager.getInstance(containingFile.getProject()).getFileIndex().getSourceRootForFile(file) != null) {
final ASTNode node = aClass.findNameIdentifier();
if (node != null) {
final String name = aClass.getName();
String nameWithExtension = name + "." + file.getExtension();
final String message = JSBundle.message(aClass instanceof JSClass ? "javascript.validation.message.class.should.be.in.file" : aClass instanceof JSNamespaceDeclaration ? "javascript.validation.message.namespace.should.be.in.file" : aClass instanceof JSVariable ? "javascript.validation.message.variable.should.be.in.file" : "javascript.validation.message.function.should.be.in.file", name, nameWithExtension);
final Annotation annotation = myHolder.createErrorAnnotation(node, message);
annotation.registerFix(new RenameFileFix(nameWithExtension));
annotation.registerFix(new RenameElementFix(aClass) {
final String text;
final String familyName;
{
String term = message.substring(0, message.indexOf(' '));
text = super.getText().replace("class", StringUtil.decapitalize(term));
familyName = super.getFamilyName().replace("Class", term);
}
@NotNull
@Override
public String getText() {
return text;
}
@NotNull
@Override
public String getFamilyName() {
return familyName;
}
});
}
}
checkFileUnderSourceRoot(aClass, new SimpleErrorReportingClient());
}
use of com.intellij.lang.annotation.Annotation in project intellij-plugins by JetBrains.
the class ActionScriptAnnotatingVisitor method checkMultipleModifiersProblem.
private void checkMultipleModifiersProblem(JSAttributeList attributeList) {
final ASTNode node = attributeList.getNode();
for (int i = 0; i < ourModifiersList.size(); ++i) {
final ASTNode[] modifiers = node.getChildren(ourModifiersList.get(i));
if (modifiers.length < 2)
continue;
String s = modifiers[0].getElementType().toString().toLowerCase(Locale.ENGLISH);
final String type = s.substring(s.indexOf(':') + 1, s.indexOf('_'));
for (ASTNode a : modifiers) {
final Annotation errorAnnotation = JSAnnotatorProblemReporter.createErrorAnnotation(a.getPsi(), JSBundle.message("javascript.validation.message.attribute.was.specified.multiple.times", type), ProblemHighlightType.ERROR, myHolder);
errorAnnotation.registerFix(new RemoveASTNodeFix(ourModifierFixIds[i], a));
}
}
}
Aggregations