mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
@SuppressWarning for foreach and try-with-resources parameters
This commit is contained in:
+1
-1
@@ -57,7 +57,7 @@ public class SuppressByJavaCommentFix extends SuppressByCommentFix {
|
||||
suppressWithComment(project, element, container);
|
||||
}
|
||||
else {
|
||||
JavaSuppressionUtil.addSuppressAnnotation(project, container, (PsiLocalVariable)declaredElement, myID);
|
||||
JavaSuppressionUtil.addSuppressAnnotation(project, container, (PsiVariable)declaredElement, myID);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -330,14 +330,38 @@ public class JavaSuppressionUtil {
|
||||
|
||||
@Nullable
|
||||
public static PsiElement getElementToAnnotate(PsiElement element, PsiElement container) {
|
||||
if (container instanceof PsiDeclarationStatement && canHave15Suppressions(element)) {
|
||||
final PsiDeclarationStatement declarationStatement = (PsiDeclarationStatement)container;
|
||||
final PsiElement[] declaredElements = declarationStatement.getDeclaredElements();
|
||||
for (PsiElement declaredElement : declaredElements) {
|
||||
if (declaredElement instanceof PsiLocalVariable) {
|
||||
final PsiModifierList modifierList = ((PsiLocalVariable)declaredElement).getModifierList();
|
||||
if (modifierList != null) {
|
||||
return declaredElement;
|
||||
if (container instanceof PsiDeclarationStatement) {
|
||||
if (canHave15Suppressions(element)) {
|
||||
final PsiDeclarationStatement declarationStatement = (PsiDeclarationStatement)container;
|
||||
final PsiElement[] declaredElements = declarationStatement.getDeclaredElements();
|
||||
for (PsiElement declaredElement : declaredElements) {
|
||||
if (declaredElement instanceof PsiLocalVariable) {
|
||||
final PsiModifierList modifierList = ((PsiLocalVariable)declaredElement).getModifierList();
|
||||
if (modifierList != null) {
|
||||
return declaredElement;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (container instanceof PsiForeachStatement) {
|
||||
if (canHave15Suppressions(element)) {
|
||||
final PsiParameter parameter = ((PsiForeachStatement)container).getIterationParameter();
|
||||
final PsiModifierList modifierList = element.getParent() == parameter ? parameter.getModifierList() : null;
|
||||
if (modifierList != null) {
|
||||
return parameter;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (container instanceof PsiTryStatement) {
|
||||
final PsiResourceList resourceList = ((PsiTryStatement)container).getResourceList();
|
||||
if (resourceList != null) {
|
||||
for (PsiResourceListElement listElement : resourceList) {
|
||||
if (listElement instanceof PsiResourceVariable && listElement == element.getParent()) {
|
||||
final PsiModifierList modifierList = ((PsiResourceVariable)listElement).getModifierList();
|
||||
if (modifierList != null) {
|
||||
return listElement;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
// "Suppress for statement" "true"
|
||||
public class Test {
|
||||
{
|
||||
for (@SuppressWarnings("unused") java.lang.Object o : ) {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
// "Suppress for statement" "true"
|
||||
public class Test {
|
||||
{
|
||||
try(@SuppressWarnings("unused") java.lang.Object o) {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
// "Suppress for statement" "true"
|
||||
public class Test {
|
||||
{
|
||||
for (java.lang.Object <caret>o : ) {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
// "Suppress for statement" "true"
|
||||
public class Test {
|
||||
{
|
||||
try(java.lang.Object <caret>o) {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user