mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Merge remote-tracking branch 'origin/master'
This commit is contained in:
+23
-17
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2003-2007 Dave Griffith, Bas Leijdekkers
|
||||
* Copyright 2003-2014 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.
|
||||
@@ -57,26 +57,29 @@ public class SuppressionAnnotationInspectionBase extends BaseInspection {
|
||||
@Override
|
||||
public void visitComment(PsiComment comment) {
|
||||
super.visitComment(comment);
|
||||
final String commentText = comment.getText();
|
||||
final IElementType tokenType = comment.getTokenType();
|
||||
if (!tokenType.equals(JavaTokenType.END_OF_LINE_COMMENT)
|
||||
&& !tokenType.equals(JavaTokenType.C_STYLE_COMMENT)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (commentText.length() > 2) {
|
||||
@NonNls final String strippedComment = commentText.substring(2).trim();
|
||||
if (strippedComment.startsWith(SuppressionUtilCore.SUPPRESS_INSPECTIONS_TAG_NAME)) {
|
||||
final String suppressedIds = JavaSuppressionUtil.getSuppressedInspectionIdsIn(comment);
|
||||
final Iterable<String> ids = suppressedIds != null ? StringUtil.tokenize(suppressedIds, "[, ]") : null;
|
||||
if (ids != null) {
|
||||
for (String id : ids) {
|
||||
if (!myAllowedSuppressions.contains(id)) {
|
||||
registerError(comment, comment);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
final String commentText = comment.getText();
|
||||
if (commentText.length() <= 2) {
|
||||
return;
|
||||
}
|
||||
@NonNls final String strippedComment = commentText.substring(2).trim();
|
||||
if (!strippedComment.startsWith(SuppressionUtilCore.SUPPRESS_INSPECTIONS_TAG_NAME)) {
|
||||
return;
|
||||
}
|
||||
final String suppressedIds = JavaSuppressionUtil.getSuppressedInspectionIdsIn(comment);
|
||||
if (suppressedIds == null) {
|
||||
registerError(comment, comment, Boolean.FALSE);
|
||||
return;
|
||||
}
|
||||
final Iterable<String> ids = StringUtil.tokenize(suppressedIds, ",");
|
||||
for (String id : ids) {
|
||||
if (!myAllowedSuppressions.contains(id)) {
|
||||
registerError(comment, comment, Boolean.TRUE);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -95,7 +98,10 @@ public class SuppressionAnnotationInspectionBase extends BaseInspection {
|
||||
if (annotationParent instanceof PsiModifierList) {
|
||||
final Collection<String> ids = JavaSuppressionUtil.getInspectionIdsSuppressedInAnnotation((PsiModifierList)annotationParent);
|
||||
if (!myAllowedSuppressions.containsAll(ids)) {
|
||||
registerError(annotation, annotation);
|
||||
registerError(annotation, annotation, Boolean.TRUE);
|
||||
}
|
||||
else if (ids.isEmpty()) {
|
||||
registerError(annotation, annotation, Boolean.FALSE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+32
-27
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2013 JetBrains s.r.o.
|
||||
* Copyright 2000-2014 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.
|
||||
@@ -15,8 +15,6 @@
|
||||
*/
|
||||
package com.siyeh.ig.maturity;
|
||||
|
||||
import com.intellij.codeInsight.FileModificationService;
|
||||
import com.intellij.codeInsight.daemon.impl.RemoveSuppressWarningAction;
|
||||
import com.intellij.codeInspection.*;
|
||||
import com.intellij.codeInspection.ui.ListEditForm;
|
||||
import com.intellij.openapi.project.Project;
|
||||
@@ -32,7 +30,7 @@ import com.siyeh.ig.InspectionGadgetsFix;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.util.Collection;
|
||||
import java.awt.*;
|
||||
|
||||
/**
|
||||
* User: anna
|
||||
@@ -42,23 +40,24 @@ public class SuppressionAnnotationInspection extends SuppressionAnnotationInspec
|
||||
@Override
|
||||
public JComponent createOptionsPanel() {
|
||||
final ListEditForm form = new ListEditForm("Ignore suppressions", myAllowedSuppressions);
|
||||
return form.getContentPanel();
|
||||
final JComponent panel = form.getContentPanel();
|
||||
panel.setPreferredSize(new Dimension(150, 100));
|
||||
return panel;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
protected InspectionGadgetsFix[] buildFixes(Object... infos) {
|
||||
if (infos.length == 1) {
|
||||
if (infos[0] instanceof PsiAnnotation) {
|
||||
final PsiAnnotation annotation = (PsiAnnotation)infos[0];
|
||||
PsiElement parent = annotation.getParent();
|
||||
final Collection<String> ids = JavaSuppressionUtil.getInspectionIdsSuppressedInAnnotation((PsiModifierList)parent);
|
||||
if (!ids.isEmpty()) {
|
||||
return new InspectionGadgetsFix[]{new DelegatingFix(new RemoveAnnotationQuickFix(annotation, null)), new AllowSuppressionsFix()};
|
||||
}
|
||||
} else if (infos[0] instanceof PsiComment) {
|
||||
return new InspectionGadgetsFix[]{new RemoveSuppressCommentFix(), new AllowSuppressionsFix()};
|
||||
}
|
||||
protected InspectionGadgetsFix[] buildFixes(Object... infos) {
|
||||
final boolean suppressionIdPresent = ((Boolean)infos[1]).booleanValue();
|
||||
if (infos[0] instanceof PsiAnnotation) {
|
||||
final PsiAnnotation annotation = (PsiAnnotation)infos[0];
|
||||
return suppressionIdPresent
|
||||
? new InspectionGadgetsFix[]{new DelegatingFix(new RemoveAnnotationQuickFix(annotation, null)), new AllowSuppressionsFix()}
|
||||
: new InspectionGadgetsFix[]{new DelegatingFix(new RemoveAnnotationQuickFix(annotation, null))};
|
||||
} else if (infos[0] instanceof PsiComment) {
|
||||
return suppressionIdPresent
|
||||
? new InspectionGadgetsFix[]{new RemoveSuppressCommentFix(), new AllowSuppressionsFix()}
|
||||
: new InspectionGadgetsFix[]{new RemoveSuppressCommentFix()};
|
||||
}
|
||||
return InspectionGadgetsFix.EMPTY_ARRAY;
|
||||
}
|
||||
@@ -68,7 +67,6 @@ public class SuppressionAnnotationInspection extends SuppressionAnnotationInspec
|
||||
protected void doFix(Project project, ProblemDescriptor descriptor) {
|
||||
PsiElement psiElement = descriptor.getPsiElement();
|
||||
if (psiElement != null) {
|
||||
if (!FileModificationService.getInstance().preparePsiElementForWrite(psiElement)) return;
|
||||
psiElement.delete();
|
||||
}
|
||||
}
|
||||
@@ -90,16 +88,23 @@ public class SuppressionAnnotationInspection extends SuppressionAnnotationInspec
|
||||
@Override
|
||||
protected void doFix(Project project, ProblemDescriptor descriptor) {
|
||||
final PsiElement psiElement = descriptor.getPsiElement();
|
||||
final String suppressedIds = JavaSuppressionUtil.getSuppressedInspectionIdsIn(psiElement);
|
||||
final Iterable<String> ids = suppressedIds != null ? StringUtil.tokenize(suppressedIds, "[, ]") : null;
|
||||
if (ids != null) {
|
||||
for (String id : ids) {
|
||||
if (!myAllowedSuppressions.contains(id)) {
|
||||
myAllowedSuppressions.add(id);
|
||||
}
|
||||
}
|
||||
saveProfile(project);
|
||||
final Iterable<String> ids;
|
||||
if (psiElement instanceof PsiAnnotation) {
|
||||
ids = JavaSuppressionUtil.getInspectionIdsSuppressedInAnnotation((PsiModifierList)psiElement.getParent());
|
||||
}
|
||||
else {
|
||||
final String suppressedIds = JavaSuppressionUtil.getSuppressedInspectionIdsIn(psiElement);
|
||||
if (suppressedIds == null) {
|
||||
return;
|
||||
}
|
||||
ids = StringUtil.tokenize(suppressedIds, ",");
|
||||
}
|
||||
for (String id : ids) {
|
||||
if (!myAllowedSuppressions.contains(id)) {
|
||||
myAllowedSuppressions.add(id);
|
||||
}
|
||||
}
|
||||
saveProfile(project);
|
||||
}
|
||||
|
||||
private void saveProfile(Project project) {
|
||||
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
public class SuppressionAnnotation {
|
||||
|
||||
<warning descr="Inspection suppression annotation '@SuppressWarnings(\\"PublicField\\")'">@SuppressWarnings("PublicField")</warning>
|
||||
public String s;
|
||||
|
||||
<warning descr="Inspection suppression annotation '@SuppressWarnings({})'">@SuppressWarnings({})</warning>
|
||||
public String t;
|
||||
|
||||
void foo() {
|
||||
<warning descr="Inspection suppression annotation '//noinspection HardCodedStringLiteral'">//noinspection HardCodedStringLiteral</warning>
|
||||
System.out.println("hello");
|
||||
<warning descr="Inspection suppression annotation '//noinspection'">//noinspection</warning>
|
||||
System.out.println();
|
||||
}
|
||||
|
||||
@SuppressWarnings("FreeSpeech")
|
||||
void bar() {
|
||||
//noinspection FreeSpeech
|
||||
System.out.println();
|
||||
}
|
||||
}
|
||||
+36
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
* Copyright 2000-2014 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.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.siyeh.ig.maturity;
|
||||
|
||||
import com.intellij.codeInspection.InspectionProfileEntry;
|
||||
import com.siyeh.ig.LightInspectionTestCase;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* @author Bas Leijdekkers
|
||||
*/
|
||||
public class SuppressionAnnotationInspectionTest extends LightInspectionTestCase {
|
||||
|
||||
public void testSuppressionAnnotation() { doTest(); }
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
protected InspectionProfileEntry getInspection() {
|
||||
final SuppressionAnnotationInspection inspection = new SuppressionAnnotationInspection();
|
||||
inspection.myAllowedSuppressions.add("FreeSpeech");
|
||||
return inspection;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user