mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-18 09:34:34 +07:00
change how IG registers error on part of psi element
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2003-2010 Dave Griffith, Bas Leijdekkers
|
||||
* Copyright 2003-2011 Dave Griffith, Bas Leijdekkers
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -24,9 +24,7 @@ import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.project.ProjectManager;
|
||||
import com.intellij.openapi.util.TextRange;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiElementVisitor;
|
||||
import com.intellij.ui.DocumentAdapter;
|
||||
import com.siyeh.ig.ui.FormattedTextFieldMacFix;
|
||||
@@ -96,7 +94,7 @@ public abstract class BaseInspection extends BaseJavaLocalInspectionTool {
|
||||
|
||||
private String m_shortName = null;
|
||||
private long timestamp = -1L;
|
||||
private InspectionGadgetsPlugin inspectionGadgetsPlugin;
|
||||
private InspectionGadgetsPlugin inspectionGadgetsPlugin = null;
|
||||
|
||||
|
||||
@Override @NotNull
|
||||
@@ -208,7 +206,8 @@ public abstract class BaseInspection extends BaseJavaLocalInspectionTool {
|
||||
for (List<String> out : outs) {
|
||||
out.clear();
|
||||
}
|
||||
for (int i = 0, iMax = strings.size(); i < iMax; i += outs.length) {
|
||||
int iMax = strings.size();
|
||||
for (int i = 0; i < iMax; i += outs.length) {
|
||||
for (int j = 0; j < outs.length; j++) {
|
||||
final List<String> out = outs[j];
|
||||
if (i + j >= iMax) {
|
||||
@@ -272,6 +271,7 @@ public abstract class BaseInspection extends BaseJavaLocalInspectionTool {
|
||||
if (inspectionGadgetsPlugin != null) {
|
||||
return;
|
||||
}
|
||||
@NonNls
|
||||
final Application application = ApplicationManager.getApplication();
|
||||
inspectionGadgetsPlugin = (InspectionGadgetsPlugin)
|
||||
application.getComponent("InspectionGadgets");
|
||||
@@ -285,9 +285,4 @@ public abstract class BaseInspection extends BaseJavaLocalInspectionTool {
|
||||
inspectionGadgetsPlugin = null;
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public TextRange getProblemTextRange(PsiElement element) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -168,13 +168,21 @@ public abstract class BaseInspectionVisitor extends JavaElementVisitor{
|
||||
fix.setOnTheFly(onTheFly);
|
||||
}
|
||||
final String description = inspection.buildErrorString(infos);
|
||||
TextRange range = inspection.getProblemTextRange(location);
|
||||
if (range != null) {
|
||||
holder.registerProblem(location, range, description, fixes);
|
||||
holder.registerProblem(location, description, fixes);
|
||||
}
|
||||
|
||||
protected final void registerError(@NotNull PsiElement location,
|
||||
int offset, int length, Object... infos){
|
||||
if (location.getTextLength() == 0 || length == 0) {
|
||||
return;
|
||||
}
|
||||
else {
|
||||
holder.registerProblem(location, description, fixes);
|
||||
final InspectionGadgetsFix[] fixes = createFixes(infos);
|
||||
for (InspectionGadgetsFix fix : fixes) {
|
||||
fix.setOnTheFly(onTheFly);
|
||||
}
|
||||
final String description = inspection.buildErrorString(infos);
|
||||
final TextRange range = new TextRange(offset, offset + length);
|
||||
holder.registerProblem(location, range, description, fixes);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -198,6 +206,7 @@ public abstract class BaseInspectionVisitor extends JavaElementVisitor{
|
||||
visitExpression(expression);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void visitWhiteSpace(PsiWhiteSpace space){
|
||||
// none of our inspections need to do anything with white space,
|
||||
// so this is a performance optimization
|
||||
|
||||
+4
-13
@@ -17,7 +17,6 @@ package com.siyeh.ig.errorhandling;
|
||||
|
||||
import com.intellij.codeInspection.ProblemDescriptor;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.TextRange;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.search.LocalSearchScope;
|
||||
import com.intellij.psi.util.PsiUtil;
|
||||
@@ -57,17 +56,6 @@ public class TryWithIdenticalCatchesInspection extends BaseInspection {
|
||||
return InspectionGadgetsBundle.message("try.with.identical.catches.display.name");
|
||||
}
|
||||
|
||||
@Override
|
||||
public TextRange getProblemTextRange(PsiElement element) {
|
||||
if (element instanceof PsiCatchSection) {
|
||||
PsiJavaToken rParenth = ((PsiCatchSection)element).getRParenth();
|
||||
if (rParenth != null) {
|
||||
return new TextRange(0, rParenth.getTextOffset() + 1 - element.getTextOffset());
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected InspectionGadgetsFix buildFix(Object... infos) {
|
||||
return new CollapseCatchSectionsFix((Integer) infos[0]);
|
||||
@@ -100,7 +88,10 @@ public class TryWithIdenticalCatchesInspection extends BaseInspection {
|
||||
if (otherCatchBlock == null) continue;
|
||||
Match match = finder.isDuplicate(otherCatchBlock, true);
|
||||
if (match != null) {
|
||||
registerError(otherSection, i);
|
||||
PsiJavaToken rParenth = otherSection.getRParenth();
|
||||
if (rParenth != null) {
|
||||
registerError(otherSection, 0, rParenth.getStartOffsetInParent() + 1, i);
|
||||
}
|
||||
duplicates[i] = true;
|
||||
duplicates[j] = true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user