use of com.intellij.lang.annotation.Annotation in project android by JetBrains.
the class AndroidColorAnnotator method annotateResourceValue.
/** Annotates the given element with the resolved value of the given {@link ResourceValue} */
private static void annotateResourceValue(@NotNull ResourceType type, @NotNull AnnotationHolder holder, @NotNull PsiElement element, @NotNull ResourceValue value, @NotNull ResourceResolver resourceResolver, @NotNull AndroidFacet facet) {
Project project = element.getProject();
if (type == ResourceType.COLOR) {
Color color = ResourceHelper.resolveColor(resourceResolver, value, project);
if (color != null) {
Annotation annotation = holder.createInfoAnnotation(element, null);
annotation.setGutterIconRenderer(new MyRenderer(element, color));
}
} else {
assert type == ResourceType.DRAWABLE || type == ResourceType.MIPMAP;
File file = ResourceHelper.resolveDrawable(resourceResolver, value, project);
if (file != null && file.getPath().endsWith(DOT_XML)) {
file = pickBitmapFromXml(file, resourceResolver, project, facet, value);
}
File iconFile = pickBestBitmap(file);
if (iconFile != null) {
Annotation annotation = holder.createInfoAnnotation(element, null);
annotation.setGutterIconRenderer(new com.android.tools.idea.rendering.GutterIconRenderer(resourceResolver, element, iconFile));
}
}
}
use of com.intellij.lang.annotation.Annotation in project android by JetBrains.
the class AndroidLintExternalAnnotator method apply.
@Override
public void apply(@NotNull PsiFile file, State state, @NotNull AnnotationHolder holder) {
if (state.isDirty()) {
return;
}
final Project project = file.getProject();
if (DumbService.isDumb(project))
return;
for (ProblemData problemData : state.getProblems()) {
final Issue issue = problemData.getIssue();
final String message = problemData.getMessage();
final TextRange range = problemData.getTextRange();
if (range.getStartOffset() == range.getEndOffset()) {
continue;
}
final Pair<AndroidLintInspectionBase, HighlightDisplayLevel> pair = AndroidLintUtil.getHighlighLevelAndInspection(project, issue, file);
if (pair == null) {
continue;
}
final AndroidLintInspectionBase inspection = pair.getFirst();
HighlightDisplayLevel displayLevel = pair.getSecond();
if (inspection != null) {
final HighlightDisplayKey key = HighlightDisplayKey.find(inspection.getShortName());
if (key != null) {
final PsiElement startElement = file.findElementAt(range.getStartOffset());
final PsiElement endElement = file.findElementAt(range.getEndOffset() - 1);
if (startElement != null && endElement != null && !inspection.isSuppressedFor(startElement)) {
if (problemData.getConfiguredSeverity() != null) {
HighlightDisplayLevel configuredLevel = AndroidLintInspectionBase.toHighlightDisplayLevel(problemData.getConfiguredSeverity());
if (configuredLevel != null) {
displayLevel = configuredLevel;
}
}
final Annotation annotation = createAnnotation(holder, message, range, displayLevel, issue);
for (AndroidLintQuickFix fix : inspection.getQuickFixes(startElement, endElement, message)) {
if (fix.isApplicable(startElement, endElement, AndroidQuickfixContexts.EditorContext.TYPE)) {
annotation.registerFix(new MyFixingIntention(fix, startElement, endElement));
}
}
for (IntentionAction intention : inspection.getIntentions(startElement, endElement)) {
annotation.registerFix(intention);
}
String id = key.getID();
if (LintIdeIssueRegistry.CUSTOM_ERROR == issue || LintIdeIssueRegistry.CUSTOM_WARNING == issue) {
Issue original = LintIdeClient.findCustomIssue(message);
if (original != null) {
id = original.getId();
}
}
annotation.registerFix(new SuppressLintIntentionAction(id, startElement));
annotation.registerFix(new MyDisableInspectionFix(key));
annotation.registerFix(new MyEditInspectionToolsSettingsAction(key, inspection));
if (issue == DeprecationDetector.ISSUE || issue == GradleDetector.DEPRECATED) {
annotation.setHighlightType(ProblemHighlightType.LIKE_DEPRECATED);
}
if (INCLUDE_IDEA_SUPPRESS_ACTIONS) {
final SuppressQuickFix[] suppressActions = inspection.getBatchSuppressActions(startElement);
for (SuppressQuickFix action : suppressActions) {
if (action.isAvailable(project, startElement)) {
ProblemHighlightType type = annotation.getHighlightType();
annotation.registerFix(action, null, key, InspectionManager.getInstance(project).createProblemDescriptor(startElement, endElement, message, type, true, LocalQuickFix.EMPTY_ARRAY));
}
}
}
}
}
}
}
}
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