cleanup, notnull

This commit is contained in:
Alexey Kudravtsev
2015-05-25 15:41:51 +03:00
parent b946daf16f
commit 6ecec488e1
14 changed files with 226 additions and 213 deletions
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2014 JetBrains s.r.o.
* Copyright 2000-2015 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -32,6 +32,7 @@ import org.jetbrains.annotations.NotNull;
* {@link BaseJavaBatchLocalInspectionTool} instead.
*/
public abstract class BaseJavaLocalInspectionTool extends AbstractBaseJavaLocalInspectionTool implements CustomSuppressableInspectionTool {
@NotNull
@Override
public SuppressIntentionAction[] getSuppressActions(final PsiElement element) {
String shortName = getShortName();
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2014 JetBrains s.r.o.
* Copyright 2000-2015 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -61,10 +61,10 @@ public abstract class InspectionProfileEntry implements BatchSuppressableTool {
private static final Logger LOG = Logger.getInstance("#com.intellij.codeInspection.InspectionProfileEntry");
private static final SkipDefaultValuesSerializationFilters DEFAULT_FILTER = new SkipDefaultValuesSerializationFilters();
private static Set<String> ourBlackList = null;
private static final SerializationFilter DEFAULT_FILTER = new SkipDefaultValuesSerializationFilters();
private static Set<String> ourBlackList;
private static final Object BLACK_LIST_LOCK = new Object();
private Boolean myUseNewSerializer = null;
private Boolean myUseNewSerializer;
@NonNls
@Nullable
@@ -130,11 +130,11 @@ public abstract class InspectionProfileEntry implements BatchSuppressableTool {
return fixes.toArray(new SuppressQuickFix[fixes.size()]);
}
private static void addAllSuppressActions(Set<SuppressQuickFix> fixes,
PsiElement element,
InspectionSuppressor suppressor,
ThreeState appliedToInjectionHost,
String toolId) {
private static void addAllSuppressActions(@NotNull Set<SuppressQuickFix> fixes,
@NotNull PsiElement element,
@NotNull InspectionSuppressor suppressor,
@NotNull ThreeState appliedToInjectionHost,
@NotNull String toolId) {
final SuppressQuickFix[] actions = suppressor.getSuppressActions(element, toolId);
for (SuppressQuickFix action : actions) {
if (action instanceof InjectionAwareSuppressQuickFix) {
@@ -179,7 +179,7 @@ public abstract class InspectionProfileEntry implements BatchSuppressableTool {
: Collections.<InspectionSuppressor>emptySet();
}
public void cleanup(Project project) {
public void cleanup(@NotNull Project project) {
}
@@ -189,7 +189,7 @@ public abstract class InspectionProfileEntry implements BatchSuppressableTool {
@Nullable String getDefaultGroupDisplayName();
}
protected volatile DefaultNameProvider myNameProvider = null;
protected volatile DefaultNameProvider myNameProvider;
/**
* @see InspectionEP#groupDisplayName
@@ -233,7 +233,7 @@ public abstract class InspectionToolWrapper<T extends InspectionProfileEntry, E
return getShortName();
}
public void cleanup(Project project) {
public void cleanup(@NotNull Project project) {
T tool = myTool;
if (tool != null) {
tool.cleanup(project);
@@ -59,7 +59,6 @@ import java.util.List;
public class HighlightInfo implements Segment {
private static final Logger LOG = Logger.getInstance("#com.intellij.codeInsight.daemon.impl.HighlightInfo");
public static final HighlightInfo[] EMPTY_ARRAY = new HighlightInfo[0];
// optimisation: if tooltip contains this marker object, then it replaced with description field in getTooltip()
private static final String DESCRIPTION_PLACEHOLDER = "\u0000";
JComponent fileLevelComponent;
@@ -196,8 +195,8 @@ public class HighlightInfo implements Segment {
}
@Nullable
public Color getErrorStripeMarkColor(@NotNull PsiElement element,
@Nullable final EditorColorsScheme colorsScheme) { // if null global scheme will be used
Color getErrorStripeMarkColor(@NotNull PsiElement element,
@Nullable final EditorColorsScheme colorsScheme) { // if null global scheme will be used
if (forcedTextAttributes != null) {
return forcedTextAttributes.getErrorStripeColor();
}
@@ -251,7 +250,7 @@ public class HighlightInfo implements Segment {
@NotNull
private static final HighlightInfoFilter[] FILTERS = HighlightInfoFilter.EXTENSION_POINT_NAME.getExtensions();
public boolean needUpdateOnTyping() {
boolean needUpdateOnTyping() {
return isFlagSet(NEEDS_UPDATE_ON_TYPING_MASK);
}
@@ -331,7 +330,7 @@ public class HighlightInfo implements Segment {
Comparing.strEqual(info.getDescription(), getDescription());
}
public boolean equalsByActualOffset(@NotNull HighlightInfo info) {
boolean equalsByActualOffset(@NotNull HighlightInfo info) {
if (info == this) return true;
return info.getSeverity() == getSeverity() &&
@@ -445,13 +444,13 @@ public class HighlightInfo implements Segment {
private boolean isAfterEndOfLine;
private boolean isFileLevelAnnotation;
private int navigationShift = 0;
private int navigationShift;
private GutterIconRenderer gutterIconRenderer;
private ProblemGroup problemGroup;
private PsiElement psiElement;
public B(@NotNull HighlightInfoType type) {
private B(@NotNull HighlightInfoType type) {
this.type = type;
}
@@ -635,7 +634,7 @@ public class HighlightInfo implements Segment {
}
@NotNull
public static HighlightInfo fromAnnotation(@NotNull Annotation annotation, @Nullable TextRange fixedRange, boolean batchMode) {
static HighlightInfo fromAnnotation(@NotNull Annotation annotation, @Nullable TextRange fixedRange, boolean batchMode) {
final TextAttributes forcedAttributes = annotation.getEnforcedTextAttributes();
final TextAttributesKey forcedAttributesKey = forcedAttributes == null ? annotation.getTextAttributes() : null;
@@ -649,7 +648,7 @@ public class HighlightInfo implements Segment {
return info;
}
public static final String ANNOTATOR_INSPECTION_SHORT_NAME = "Annotator";
private static final String ANNOTATOR_INSPECTION_SHORT_NAME = "Annotator";
private static void appendFixes(@Nullable TextRange fixedRange, @NotNull HighlightInfo info, @Nullable List<Annotation.QuickFixInfo> fixes) {
if (fixes != null) {
@@ -664,7 +663,7 @@ public class HighlightInfo implements Segment {
}
@NotNull
public static HighlightInfoType convertType(@NotNull Annotation annotation) {
private static HighlightInfoType convertType(@NotNull Annotation annotation) {
ProblemHighlightType type = annotation.getHighlightType();
if (type == ProblemHighlightType.LIKE_UNUSED_SYMBOL) return HighlightInfoType.UNUSED_SYMBOL;
if (type == ProblemHighlightType.LIKE_UNKNOWN_SYMBOL) return HighlightInfoType.WRONG_REF;
@@ -726,7 +725,7 @@ public class HighlightInfo implements Segment {
private final Icon myIcon;
private Boolean myCanCleanup;
public IntentionActionDescriptor(@NotNull IntentionAction action, final List<IntentionAction> options, final String displayName) {
IntentionActionDescriptor(@NotNull IntentionAction action, final List<IntentionAction> options, final String displayName) {
this(action, options, displayName, null);
}
@@ -734,20 +733,20 @@ public class HighlightInfo implements Segment {
this(action, null, null, icon);
}
public IntentionActionDescriptor(@NotNull IntentionAction action,
@Nullable final List<IntentionAction> options,
@Nullable final String displayName,
@Nullable Icon icon) {
IntentionActionDescriptor(@NotNull IntentionAction action,
@Nullable final List<IntentionAction> options,
@Nullable final String displayName,
@Nullable Icon icon) {
this(action, options, displayName, icon, null, null, null);
}
public IntentionActionDescriptor(@NotNull IntentionAction action,
@Nullable final List<IntentionAction> options,
@Nullable final String displayName,
@Nullable Icon icon,
@Nullable HighlightDisplayKey key,
@Nullable ProblemGroup problemGroup,
@Nullable HighlightSeverity severity) {
private IntentionActionDescriptor(@NotNull IntentionAction action,
@Nullable final List<IntentionAction> options,
@Nullable final String displayName,
@Nullable Icon icon,
@Nullable HighlightDisplayKey key,
@Nullable ProblemGroup problemGroup,
@Nullable HighlightSeverity severity) {
myAction = action;
myOptions = options;
myDisplayName = displayName;
@@ -762,11 +761,11 @@ public class HighlightInfo implements Segment {
return myAction;
}
public boolean notError() {
boolean notError() {
return mySeverity != null && mySeverity.compareTo(HighlightSeverity.ERROR) < 0;
}
public boolean canCleanup(@NotNull PsiElement element) {
boolean canCleanup(@NotNull PsiElement element) {
if (myCanCleanup == null) {
InspectionProfile profile = InspectionProjectProfileManager.getInstance(element.getProject()).getInspectionProfile();
final HighlightDisplayKey key = myKey;
@@ -826,7 +825,8 @@ public class HighlightInfo implements Segment {
if (suppressActions != null) {
ContainerUtil.addAll(newOptions, suppressActions);
}
} else {
}
else {
SuppressQuickFix[] suppressFixes = wrappedTool.getBatchSuppressActions(element);
if (suppressFixes.length > 0) {
ContainerUtil.addAll(newOptions, ContainerUtil.map(suppressFixes, new Function<SuppressQuickFix, IntentionAction>() {
@@ -68,6 +68,7 @@ public class GlobalInspectionContextBase extends UserDataHolderBase implements G
private RefManager myRefManager;
private AnalysisScope myCurrentScope;
@NotNull
private final Project myProject;
private final List<JobDescriptor> myJobDescriptors = new ArrayList<JobDescriptor>();
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2014 JetBrains s.r.o.
* Copyright 2000-2015 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -69,8 +69,7 @@ public class InspectionManagerEx extends InspectionManagerBase {
@Override
protected ContentManager compute() {
ToolWindowManager toolWindowManager = ToolWindowManager.getInstance(project);
ToolWindow toolWindow =
toolWindowManager.registerToolWindow(ToolWindowId.INSPECTION, true, ToolWindowAnchor.BOTTOM, project);
ToolWindow toolWindow = toolWindowManager.registerToolWindow(ToolWindowId.INSPECTION, true, ToolWindowAnchor.BOTTOM, project);
ContentManager contentManager = toolWindow.getContentManager();
toolWindow.setIcon(AllIcons.Toolwindows.ToolWindowInspection);
new ContentManagerWatcher(toolWindow, contentManager);
@@ -112,7 +111,7 @@ public class InspectionManagerEx extends InspectionManagerBase {
@NotNull final ProblemHighlightType highlightType,
@Nullable final HintAction hintAction,
boolean onTheFly,
final LocalQuickFix... fixes) {
@Nullable LocalQuickFix... fixes) {
return new ProblemDescriptorImpl(psiElement, psiElement, descriptionTemplate, fixes, highlightType, false, null, hintAction, onTheFly);
}
@@ -135,11 +134,11 @@ public class InspectionManagerEx extends InspectionManagerBase {
return inspectionContext;
}
public void setProfile(final String name) {
public void setProfile(@NotNull String name) {
myCurrentProfileName = name;
}
public void closeRunningContext(GlobalInspectionContextImpl globalInspectionContext){
void closeRunningContext(@NotNull GlobalInspectionContextImpl globalInspectionContext){
myRunningContexts.remove(globalInspectionContext);
}
@@ -148,20 +147,9 @@ public class InspectionManagerEx extends InspectionManagerBase {
return myRunningContexts;
}
@NotNull
@Deprecated
public ProblemDescriptor createProblemDescriptor(@NotNull final PsiElement psiElement,
@NotNull final String descriptionTemplate,
@NotNull final ProblemHighlightType highlightType,
@Nullable final HintAction hintAction,
final LocalQuickFix... fixes) {
return new ProblemDescriptorImpl(psiElement, psiElement, descriptionTemplate, fixes, highlightType, false, null, hintAction, true);
}
@TestOnly
@NotNull
public NotNullLazyValue<ContentManager> getContentManager() {
return myContentManager;
}
}
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2009 JetBrains s.r.o.
* Copyright 2000-2015 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,7 +16,10 @@
package com.intellij.codeInspection.ex;
import com.intellij.codeInspection.*;
import com.intellij.codeInspection.HintAction;
import com.intellij.codeInspection.LocalQuickFix;
import com.intellij.codeInspection.ProblemDescriptorBase;
import com.intellij.codeInspection.ProblemHighlightType;
import com.intellij.openapi.util.TextRange;
import com.intellij.psi.PsiElement;
import org.jetbrains.annotations.NotNull;
@@ -24,8 +27,9 @@ import org.jetbrains.annotations.Nullable;
/**
* @author max
* Extends {@link ProblemDescriptorBase} with {@link HintAction}
*/
public class ProblemDescriptorImpl extends ProblemDescriptorBase implements ProblemDescriptor {
public class ProblemDescriptorImpl extends ProblemDescriptorBase {
private final HintAction myHintAction;
public ProblemDescriptorImpl(@NotNull PsiElement startElement,
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2012 JetBrains s.r.o.
* Copyright 2000-2015 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -19,7 +19,7 @@
*/
package com.intellij.codeInspection.i18n;
import com.intellij.ExtensionPoints;
import com.intellij.ToolExtensionPoints;
import com.intellij.codeInsight.AnnotationUtil;
import com.intellij.codeInsight.CodeInsightBundle;
import com.intellij.codeInsight.daemon.GroupNames;
@@ -76,18 +76,19 @@ import java.util.regex.Pattern;
public class I18nInspection extends BaseLocalInspectionTool {
public boolean ignoreForAssertStatements = true;
public boolean ignoreForExceptionConstructors = true;
@NonNls public String ignoreForSpecifiedExceptionConstructors = "";
@NonNls
public String ignoreForSpecifiedExceptionConstructors = "";
public boolean ignoreForJUnitAsserts = true;
public boolean ignoreForClassReferences = true;
public boolean ignoreForPropertyKeyReferences = true;
public boolean ignoreForNonAlpha = true;
public boolean ignoreAssignedToConstants = false;
public boolean ignoreToString = false;
public boolean ignoreAssignedToConstants;
public boolean ignoreToString;
@NonNls public String nonNlsCommentPattern = "NON-NLS";
private boolean ignoreForEnumConstants = false;
private boolean ignoreForEnumConstants;
private static final LocalQuickFix I18N_QUICK_FIX = new I18nizeQuickFix();
private static final I18nizeConcatenationQuickFix I18N_CONCATENATION_QUICK_FIX = new I18nizeConcatenationQuickFix();
private static final LocalQuickFix I18N_CONCATENATION_QUICK_FIX = new I18nizeConcatenationQuickFix();
@Nullable private Pattern myCachedNonNlsPattern;
@NonNls private static final String TO_STRING = "toString";
@@ -96,6 +97,7 @@ public class I18nInspection extends BaseLocalInspectionTool {
cacheNonNlsCommentPattern();
}
@NotNull
@Override
public SuppressIntentionAction[] getSuppressActions(PsiElement element) {
SuppressIntentionAction[] actions = {};
@@ -157,7 +159,7 @@ public class I18nInspection extends BaseLocalInspectionTool {
final JCheckBox assertStatementsCheckbox = new JCheckBox(CodeInsightBundle.message("inspection.i18n.option.ignore.assert"), ignoreForAssertStatements);
assertStatementsCheckbox.addChangeListener(new ChangeListener() {
@Override
public void stateChanged(ChangeEvent e) {
public void stateChanged(@NotNull ChangeEvent e) {
ignoreForAssertStatements = assertStatementsCheckbox.isSelected();
}
});
@@ -166,7 +168,7 @@ public class I18nInspection extends BaseLocalInspectionTool {
ignoreForExceptionConstructors);
exceptionConstructorCheck.addChangeListener(new ChangeListener() {
@Override
public void stateChanged(ChangeEvent e) {
public void stateChanged(@NotNull ChangeEvent e) {
ignoreForExceptionConstructors = exceptionConstructorCheck.isSelected();
}
});
@@ -183,42 +185,42 @@ public class I18nInspection extends BaseLocalInspectionTool {
CodeInsightBundle.message("inspection.i18n.option.ignore.for.junit.assert.arguments"), ignoreForJUnitAsserts);
junitAssertCheckbox.addChangeListener(new ChangeListener() {
@Override
public void stateChanged(ChangeEvent e) {
public void stateChanged(@NotNull ChangeEvent e) {
ignoreForJUnitAsserts = junitAssertCheckbox.isSelected();
}
});
final JCheckBox classRef = new JCheckBox(CodeInsightBundle.message("inspection.i18n.option.ignore.qualified.class.names"), ignoreForClassReferences);
classRef.addChangeListener(new ChangeListener() {
@Override
public void stateChanged(ChangeEvent e) {
public void stateChanged(@NotNull ChangeEvent e) {
ignoreForClassReferences = classRef.isSelected();
}
});
final JCheckBox propertyRef = new JCheckBox(CodeInsightBundle.message("inspection.i18n.option.ignore.property.keys"), ignoreForPropertyKeyReferences);
propertyRef.addChangeListener(new ChangeListener() {
@Override
public void stateChanged(ChangeEvent e) {
public void stateChanged(@NotNull ChangeEvent e) {
ignoreForPropertyKeyReferences = propertyRef.isSelected();
}
});
final JCheckBox nonAlpha = new JCheckBox(CodeInsightBundle.message("inspection.i18n.option.ignore.nonalphanumerics"), ignoreForNonAlpha);
nonAlpha.addChangeListener(new ChangeListener() {
@Override
public void stateChanged(ChangeEvent e) {
public void stateChanged(@NotNull ChangeEvent e) {
ignoreForNonAlpha = nonAlpha.isSelected();
}
});
final JCheckBox assignedToConstants = new JCheckBox(CodeInsightBundle.message("inspection.i18n.option.ignore.assigned.to.constants"), ignoreAssignedToConstants);
assignedToConstants.addChangeListener(new ChangeListener() {
@Override
public void stateChanged(ChangeEvent e) {
public void stateChanged(@NotNull ChangeEvent e) {
ignoreAssignedToConstants = assignedToConstants.isSelected();
}
});
final JCheckBox chkToString = new JCheckBox(CodeInsightBundle.message("inspection.i18n.option.ignore.tostring"), ignoreToString);
chkToString.addChangeListener(new ChangeListener() {
@Override
public void stateChanged(ChangeEvent e) {
public void stateChanged(@NotNull ChangeEvent e) {
ignoreToString = chkToString.isSelected();
}
});
@@ -226,7 +228,7 @@ public class I18nInspection extends BaseLocalInspectionTool {
final JCheckBox ignoreEnumConstants = new JCheckBox("Ignore enum constants", ignoreForEnumConstants);
ignoreEnumConstants.addChangeListener(new ChangeListener() {
@Override
public void stateChanged(ChangeEvent e) {
public void stateChanged(@NotNull ChangeEvent e) {
ignoreForEnumConstants = ignoreEnumConstants.isSelected();
}
});
@@ -255,7 +257,7 @@ public class I18nInspection extends BaseLocalInspectionTool {
openProjects.length == 0 ? null :
new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
public void actionPerformed(@NotNull ActionEvent e) {
createIgnoreExceptionsConfigurationDialog(openProjects[0], specifiedExceptions).show();
}
},
@@ -304,7 +306,7 @@ public class I18nInspection extends BaseLocalInspectionTool {
return scrollPane;
}
@SuppressWarnings({"NonStaticInitializer"})
@SuppressWarnings("NonStaticInitializer")
private DialogWrapper createIgnoreExceptionsConfigurationDialog(final Project project, final JTextField specifiedExceptions) {
return new DialogWrapper(true) {
private AddDeleteListPanel myPanel;
@@ -318,10 +320,8 @@ public class I18nInspection extends BaseLocalInspectionTool {
protected JComponent createCenterPanel() {
final String[] ignored = ignoreForSpecifiedExceptionConstructors.split(",");
final List<String> initialList = new ArrayList<String>();
if (ignored != null){
for (String e : ignored) {
if (e.length() > 0) initialList.add(e);
}
for (String e : ignored) {
if (!e.isEmpty()) initialList.add(e);
}
myPanel = new AddDeleteListPanel<String>(null, initialList) {
@Override
@@ -412,7 +412,7 @@ public class I18nInspection extends BaseLocalInspectionTool {
@Override
@Nullable
public ProblemDescriptor[] checkFile(@NotNull PsiFile file, @NotNull InspectionManager manager, boolean isOnTheFly) {
ExtensionPoint<FileCheckingInspection> point = Extensions.getRootArea().getExtensionPoint(ExtensionPoints.I18N_INSPECTION_TOOL);
ExtensionPoint<FileCheckingInspection> point = Extensions.getRootArea().getExtensionPoint(ToolExtensionPoints.I18N_INSPECTION_TOOL);
final FileCheckingInspection[] fileCheckingInspections = point.getExtensions();
for(FileCheckingInspection obj: fileCheckingInspections) {
ProblemDescriptor[] descriptors = obj.checkFile(file, manager, isOnTheFly);
@@ -467,7 +467,7 @@ public class I18nInspection extends BaseLocalInspectionTool {
private final InspectionManager myManager;
private final boolean myOnTheFly;
public StringI18nVisitor(final InspectionManager manager, boolean onTheFly) {
private StringI18nVisitor(final InspectionManager manager, boolean onTheFly) {
myManager = manager;
myOnTheFly = onTheFly;
}
@@ -489,7 +489,7 @@ public class I18nInspection extends BaseLocalInspectionTool {
Object value = expression.getValue();
if (!(value instanceof String)) return;
String stringValue = (String)value;
if (stringValue.trim().length() == 0) {
if (stringValue.trim().isEmpty()) {
return;
}
@@ -547,7 +547,7 @@ public class I18nInspection extends BaseLocalInspectionTool {
}
}
public List<ProblemDescriptor> getProblems() {
private List<ProblemDescriptor> getProblems() {
return myProblems;
}
}
@@ -627,7 +627,7 @@ public class I18nInspection extends BaseLocalInspectionTool {
return true;
}
private boolean isArgOfEnumConstant(PsiLiteralExpression expression) {
private static boolean isArgOfEnumConstant(PsiLiteralExpression expression) {
final PsiElement parent = PsiTreeUtil.getParentOfType(expression, PsiExpressionList.class, PsiClass.class);
if (!(parent instanceof PsiExpressionList)) {
return false;
@@ -637,7 +637,7 @@ public class I18nInspection extends BaseLocalInspectionTool {
}
public void cacheNonNlsCommentPattern() {
myCachedNonNlsPattern = nonNlsCommentPattern.trim().length() == 0 ? null : Pattern.compile(nonNlsCommentPattern);
myCachedNonNlsPattern = nonNlsCommentPattern.trim().isEmpty() ? null : Pattern.compile(nonNlsCommentPattern);
}
private static boolean isClassRef(final PsiLiteralExpression expression, String value) {
@@ -842,7 +842,7 @@ public class I18nInspection extends BaseLocalInspectionTool {
}
else {
final PsiElement returnStmt = PsiTreeUtil.getParentOfType(expression, PsiReturnStatement.class, PsiMethodCallExpression.class);
if (returnStmt == null || !(returnStmt instanceof PsiReturnStatement)) {
if (!(returnStmt instanceof PsiReturnStatement)) {
return false;
}
method = PsiTreeUtil.getParentOfType(expression, PsiMethod.class);
@@ -24,7 +24,6 @@ package org.intellij.lang.xpath.context;
import com.intellij.codeInspection.SuppressIntentionAction;
import com.intellij.psi.PsiElement;
import org.intellij.lang.xpath.psi.XPathExpression;
import org.intellij.lang.xpath.psi.XPathNodeTest;
import org.intellij.lang.xpath.psi.XPathType;
@@ -33,6 +32,7 @@ import org.intellij.lang.xpath.validation.inspections.quickfix.MakeTypeExplicitF
import org.intellij.lang.xpath.validation.inspections.quickfix.RemoveExplicitConversionFix;
import org.intellij.lang.xpath.validation.inspections.quickfix.RemoveRedundantConversionFix;
import org.intellij.lang.xpath.validation.inspections.quickfix.XPathQuickFixFactory;
import org.jetbrains.annotations.NotNull;
public class XPathQuickFixFactoryImpl implements XPathQuickFixFactory {
public static final XPathQuickFixFactory INSTANCE = new XPathQuickFixFactoryImpl();
@@ -62,6 +62,7 @@ public class XPathQuickFixFactoryImpl implements XPathQuickFixFactory {
return new Fix[0];
}
@NotNull
public SuppressIntentionAction[] getSuppressActions(XPathInspection inspection) {
return new SuppressIntentionAction[0];
}
@@ -33,83 +33,94 @@ import org.jetbrains.annotations.Nullable;
public abstract class XPathInspection extends LocalInspectionTool implements CustomSuppressableInspectionTool {
@NotNull
public String getGroupDisplayName() {
return "XPath";
}
@Override
@NotNull
public String getGroupDisplayName() {
return "XPath";
}
public SuppressIntentionAction[] getSuppressActions(@Nullable PsiElement element) {
final XPathElement e = PsiTreeUtil.getContextOfType(element, XPathElement.class, false);
return ContextProvider.getContextProvider(e != null ? e : element).getQuickFixFactory().getSuppressActions(this);
}
@Override
@NotNull
public SuppressIntentionAction[] getSuppressActions(@Nullable PsiElement element) {
final XPathElement e = PsiTreeUtil.getContextOfType(element, XPathElement.class, false);
return ContextProvider.getContextProvider(e != null ? e : element).getQuickFixFactory().getSuppressActions(this);
}
public boolean isSuppressedFor(@NotNull PsiElement element) {
return ContextProvider.getContextProvider(element.getContainingFile()).getQuickFixFactory().isSuppressedFor(element, this);
}
@Override
public boolean isSuppressedFor(@NotNull PsiElement element) {
return ContextProvider.getContextProvider(element.getContainingFile()).getQuickFixFactory().isSuppressedFor(element, this);
}
protected abstract Visitor createVisitor(InspectionManager manager, boolean isOnTheFly);
protected abstract Visitor createVisitor(InspectionManager manager, boolean isOnTheFly);
@Nullable
public ProblemDescriptor[] checkFile(@NotNull PsiFile file, @NotNull InspectionManager manager, boolean isOnTheFly) {
final Language language = file.getLanguage();
if (!acceptsLanguage(language)) return null;
@Override
@Nullable
public ProblemDescriptor[] checkFile(@NotNull PsiFile file, @NotNull InspectionManager manager, boolean isOnTheFly) {
final Language language = file.getLanguage();
if (!acceptsLanguage(language)) return null;
final Visitor visitor = createVisitor(manager, isOnTheFly);
final Visitor visitor = createVisitor(manager, isOnTheFly);
file.accept(visitor);
file.accept(visitor);
return visitor.getProblems();
}
return visitor.getProblems();
}
protected abstract boolean acceptsLanguage(Language language);
protected static abstract class Visitor extends PsiRecursiveElementVisitor {
protected final InspectionManager myManager;
protected boolean myOnTheFly;
private SmartList<ProblemDescriptor> myProblems;
abstract static class Visitor extends PsiRecursiveElementVisitor {
protected final InspectionManager myManager;
protected boolean myOnTheFly;
private SmartList<ProblemDescriptor> myProblems;
public Visitor(InspectionManager manager, boolean isOnTheFly) {
myManager = manager;
this.myOnTheFly = isOnTheFly;
}
public void visitElement(PsiElement psiElement) {
super.visitElement(psiElement);
if (myProblems != null) {
final TextRange textRange = psiElement.getTextRange();
for (ProblemDescriptor problem : myProblems) {
if (textRange.contains(problem.getPsiElement().getTextRange())) {
return;
}
}
}
if (psiElement instanceof XPathExpression) {
checkExpression(((XPathExpression)psiElement));
} else if (psiElement instanceof XPathNodeTest) {
checkNodeTest(((XPathNodeTest)psiElement));
} else if (psiElement instanceof XPathPredicate) {
checkPredicate((XPathPredicate)psiElement);
}
}
protected void checkExpression(XPathExpression expression) { }
protected void checkPredicate(XPathPredicate predicate) { }
protected void checkNodeTest(XPathNodeTest nodeTest) { }
@Nullable
public ProblemDescriptor[] getProblems() {
return myProblems == null ? null : myProblems.toArray(new ProblemDescriptor[myProblems.size()]);
}
protected void addProblem(ProblemDescriptor problem) {
if (myProblems == null) {
myProblems = new SmartList<ProblemDescriptor>();
}
myProblems.add(problem);
}
Visitor(InspectionManager manager, boolean isOnTheFly) {
myManager = manager;
myOnTheFly = isOnTheFly;
}
@Override
public void visitElement(PsiElement psiElement) {
super.visitElement(psiElement);
if (myProblems != null) {
final TextRange textRange = psiElement.getTextRange();
for (ProblemDescriptor problem : myProblems) {
if (textRange.contains(problem.getPsiElement().getTextRange())) {
return;
}
}
}
if (psiElement instanceof XPathExpression) {
checkExpression((XPathExpression)psiElement);
}
else if (psiElement instanceof XPathNodeTest) {
checkNodeTest((XPathNodeTest)psiElement);
}
else if (psiElement instanceof XPathPredicate) {
checkPredicate((XPathPredicate)psiElement);
}
}
protected void checkExpression(XPathExpression expression) {
}
protected void checkPredicate(XPathPredicate predicate) {
}
protected void checkNodeTest(XPathNodeTest nodeTest) {
}
@Nullable
private ProblemDescriptor[] getProblems() {
return myProblems == null ? null : myProblems.toArray(new ProblemDescriptor[myProblems.size()]);
}
void addProblem(ProblemDescriptor problem) {
if (myProblems == null) {
myProblems = new SmartList<ProblemDescriptor>();
}
myProblems.add(problem);
}
}
}
@@ -38,50 +38,48 @@ import org.intellij.lang.xpath.validation.inspections.XPathInspection;
import org.jetbrains.annotations.NotNull;
public interface XPathQuickFixFactory {
Fix<XPathExpression>[] createImplicitTypeConversionFixes(XPathExpression expression, XPathType type, boolean explicit);
Fix<XPathExpression>[] createImplicitTypeConversionFixes(XPathExpression expression, XPathType type, boolean explicit);
Fix<XPathExpression>[] createRedundantTypeConversionFixes(XPathExpression expression);
Fix<XPathExpression>[] createRedundantTypeConversionFixes(XPathExpression expression);
Fix<XPathNodeTest>[] createUnknownNodeTestFixes(XPathNodeTest test);
Fix<XPathNodeTest>[] createUnknownNodeTestFixes(XPathNodeTest test);
SuppressIntentionAction[] getSuppressActions(XPathInspection inspection);
@NotNull
SuppressIntentionAction[] getSuppressActions(XPathInspection inspection);
boolean isSuppressedFor(PsiElement element, XPathInspection inspection);
boolean isSuppressedFor(PsiElement element, XPathInspection inspection);
abstract class Fix<E extends PsiElement> extends LocalQuickFixAndIntentionActionOnPsiElement {
protected Fix(E element) {
super(element);
}
public boolean startInWriteAction() {
return true;
}
@Override
public boolean isAvailable(@NotNull Project project,
@NotNull PsiFile file,
@NotNull PsiElement startElement,
@NotNull PsiElement endElement) {
return startElement.isValid() && startElement.getParent().isValid();
}
@Override
public void invoke(@NotNull Project project,
@NotNull PsiFile file,
Editor editor, @NotNull PsiElement startElement,
@NotNull PsiElement endElement) {
if(!FileModificationService.getInstance().prepareFileForWrite(file)) {
return;
}
try {
invokeImpl(project, file);
} catch (IncorrectOperationException e) {
Logger.getInstance(getClass().getName()).error(e);
}
}
protected abstract void invokeImpl(Project project, PsiFile file) throws IncorrectOperationException;
abstract class Fix<E extends PsiElement> extends LocalQuickFixAndIntentionActionOnPsiElement {
protected Fix(E element) {
super(element);
}
@Override
public boolean isAvailable(@NotNull Project project,
@NotNull PsiFile file,
@NotNull PsiElement startElement,
@NotNull PsiElement endElement) {
return startElement.isValid() && startElement.getParent().isValid();
}
@Override
public void invoke(@NotNull Project project,
@NotNull PsiFile file,
Editor editor, @NotNull PsiElement startElement,
@NotNull PsiElement endElement) {
if (!FileModificationService.getInstance().prepareFileForWrite(file)) {
return;
}
try {
invokeImpl(project, file);
}
catch (IncorrectOperationException e) {
Logger.getInstance(getClass().getName()).error(e);
}
}
protected abstract void invokeImpl(Project project, PsiFile file) throws IncorrectOperationException;
}
}
@@ -67,6 +67,7 @@ public class XsltQuickFixFactory implements XPathQuickFixFactory {
};
}
@NotNull
public SuppressIntentionAction[] getSuppressActions(XPathInspection inspection) {
final List<SuppressIntentionAction> actions = InspectionUtil.getSuppressActions(inspection, true);
return actions.toArray(new SuppressIntentionAction[actions.size()]);
@@ -100,18 +100,21 @@ public class InspectionUtil {
final List<SuppressIntentionAction> actions = new ArrayList<SuppressIntentionAction>(4);
actions.add(new SuppressInspectionAction(inspection.getID(), "Suppress for Instruction") {
@Override
protected XmlTag getAnchor(@NotNull PsiElement element) {
return PsiTreeUtil.getContextOfType(element, XmlTag.class, isXPath);
}
});
actions.add(new SuppressInspectionAction(inspection.getID(), "Suppress for Template") {
@Override
protected XmlTag getAnchor(@NotNull PsiElement element) {
return XsltCodeInsightUtil.getTemplateTag(element, isXPath);
}
});
actions.add(new SuppressInspectionAction(inspection.getID(), "Suppress for Stylesheet") {
@Override
protected XmlTag getAnchor(@NotNull PsiElement element) {
final XmlDocument document = PsiTreeUtil.getContextOfType(element, XmlDocument.class, isXPath);
return document != null ? document.getRootTag() : null;
@@ -119,6 +122,7 @@ public class InspectionUtil {
});
actions.add(new SuppressInspectionAction(ALL_ID, "Suppress all for Stylesheet") {
@Override
protected XmlTag getAnchor(@NotNull PsiElement element) {
final XmlDocument document = PsiTreeUtil.getContextOfType(element, XmlDocument.class, isXPath);
return document != null ? document.getRootTag() : null;
@@ -15,7 +15,6 @@
*/
package org.intellij.lang.xpath.xslt.validation.inspections;
import com.intellij.codeInsight.intention.IntentionAction;
import com.intellij.codeInspection.CustomSuppressableInspectionTool;
import com.intellij.codeInspection.LocalInspectionTool;
import com.intellij.codeInspection.SuppressIntentionAction;
@@ -26,23 +25,28 @@ import org.jetbrains.annotations.Nullable;
import java.util.List;
public abstract class XsltInspection extends LocalInspectionTool implements CustomSuppressableInspectionTool {
public boolean isEnabledByDefault() {
return true;
}
abstract class XsltInspection extends LocalInspectionTool implements CustomSuppressableInspectionTool {
@Override
public boolean isEnabledByDefault() {
return true;
}
public SuppressIntentionAction[] getSuppressActions(@Nullable PsiElement psiElement) {
final List<? extends IntentionAction> actions = InspectionUtil.getSuppressActions(this, false);
return actions.toArray(new SuppressInspectionAction[actions.size()]);
}
@Override
@NotNull
public SuppressIntentionAction[] getSuppressActions(@Nullable PsiElement psiElement) {
final List<SuppressIntentionAction> actions = InspectionUtil.getSuppressActions(this, false);
return actions.toArray(new SuppressIntentionAction[actions.size()]);
}
public boolean isSuppressedFor(@NotNull PsiElement element) {
return InspectionUtil.isSuppressed(this, element);
}
@Override
public boolean isSuppressedFor(@NotNull PsiElement element) {
return InspectionUtil.isSuppressed(this, element);
}
@Nls
@NotNull
public String getGroupDisplayName() {
return "XSLT";
}
@Override
@Nls
@NotNull
public String getGroupDisplayName() {
return "XSLT";
}
}