mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
make IG test light
This commit is contained in:
@@ -1,4 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<problems>
|
||||
|
||||
</problems>
|
||||
@@ -1,115 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<problems>
|
||||
<problem>
|
||||
<file>IOResourceInspection.java</file>
|
||||
<line>7</line>
|
||||
<method>
|
||||
<name>void foo()</name>
|
||||
<display_name>foo()</display_name>
|
||||
<package>com.siyeh.igtest.resources</package>
|
||||
<class>
|
||||
<name>IOResource</name>
|
||||
<display_name>IOResource</display_name>
|
||||
</class>
|
||||
</method>
|
||||
<problem_class>I/O resource opened but not safely closed</problem_class>
|
||||
<description>'FileInputStream' should be opened in front of a try block and closed in the corresponding finally block #loc</description>
|
||||
</problem>
|
||||
|
||||
<problem>
|
||||
<file>IOResourceInspection.java</file>
|
||||
<line>11</line>
|
||||
<method>
|
||||
<name>void foo2()</name>
|
||||
<display_name>foo2()</display_name>
|
||||
<package>com.siyeh.igtest.resources</package>
|
||||
<class>
|
||||
<name>IOResource</name>
|
||||
<display_name>IOResource</display_name>
|
||||
</class>
|
||||
</method>
|
||||
<problem_class>I/O resource opened but not safely closed</problem_class>
|
||||
<description>'FileInputStream' should be opened in front of a try block and closed in the corresponding finally block #loc</description>
|
||||
</problem>
|
||||
|
||||
|
||||
|
||||
<problem>
|
||||
<file>IOResourceInspection.java</file>
|
||||
<line>17</line>
|
||||
<method>
|
||||
<name>void foo25()</name>
|
||||
<display_name>foo25()</display_name>
|
||||
<package>com.siyeh.igtest.resources</package>
|
||||
<class>
|
||||
<name>IOResource</name>
|
||||
<display_name>IOResource</display_name>
|
||||
</class>
|
||||
</method>
|
||||
<problem_class>I/O resource opened but not safely closed</problem_class>
|
||||
<description>'FileInputStream' should be opened in front of a try block and closed in the corresponding finally block #loc</description>
|
||||
</problem>
|
||||
|
||||
<problem>
|
||||
<file>IOResourceInspection.java</file>
|
||||
<line>57</line>
|
||||
<method>
|
||||
<name>void foo6()</name>
|
||||
<display_name>foo6()</display_name>
|
||||
<package>com.siyeh.igtest.resources</package>
|
||||
<class>
|
||||
<name>IOResource</name>
|
||||
<display_name>IOResource</display_name>
|
||||
</class>
|
||||
</method>
|
||||
<problem_class>I/O resource opened but not safely closed</problem_class>
|
||||
<description>'FileInputStream' should be opened in front of a try block and closed in the corresponding finally block #loc</description>
|
||||
</problem>
|
||||
|
||||
<problem>
|
||||
<file>IOResourceInspection.java</file>
|
||||
<line>66</line>
|
||||
<method>
|
||||
<name>void foo7()</name>
|
||||
<display_name>foo7()</display_name>
|
||||
<package>com.siyeh.igtest.resources</package>
|
||||
<class>
|
||||
<name>IOResource</name>
|
||||
<display_name>IOResource</display_name>
|
||||
</class>
|
||||
</method>
|
||||
<problem_class>I/O resource opened but not safely closed</problem_class>
|
||||
<description>'FileInputStream' should be opened in front of a try block and closed in the corresponding finally block #loc</description>
|
||||
</problem>
|
||||
|
||||
<problem>
|
||||
<file>IOResourceInspection.java</file>
|
||||
<line>94</line>
|
||||
<method>
|
||||
<name>void interrupting()</name>
|
||||
<display_name>interrupting()</display_name>
|
||||
<package>com.siyeh.igtest.resources.io</package>
|
||||
<class>
|
||||
<name>IOResource</name>
|
||||
<display_name>IOResource</display_name>
|
||||
</class>
|
||||
</method>
|
||||
<problem_class>I/O resource opened but not safely closed</problem_class>
|
||||
<description>'FileInputStream' should be opened in front of a try block and closed in the corresponding finally block #loc</description>
|
||||
</problem>
|
||||
|
||||
<problem>
|
||||
<file>IOResourceInspection.java</file>
|
||||
<line>148</line>
|
||||
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">I/O resource opened but not safely closed</problem_class>
|
||||
<description>'InputStream' should be opened in front of a 'try' block and closed in the corresponding 'finally' block #loc</description>
|
||||
</problem>
|
||||
|
||||
<problem>
|
||||
<file>IOResourceInspection.java</file>
|
||||
<line>152</line>
|
||||
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">I/O resource opened but not safely closed</problem_class>
|
||||
<description>'FileInputStream' should be opened in front of a 'try' block and closed in the corresponding 'finally' block #loc</description>
|
||||
</problem>
|
||||
</problems>
|
||||
|
||||
+10
-10
@@ -1,20 +1,20 @@
|
||||
package com.siyeh.igtest.resources.io.plain;
|
||||
package com.siyeh.igtest.resources.ioresource;
|
||||
|
||||
import java.io.*;
|
||||
|
||||
public class IOResourceInspection {
|
||||
public class IOResource {
|
||||
public void foo() throws FileNotFoundException {
|
||||
new FileInputStream("bar");
|
||||
new <warning descr="'FileInputStream' should be opened in front of a 'try' block and closed in the corresponding 'finally' block">FileInputStream</warning>("bar");
|
||||
}
|
||||
|
||||
public void foo2() throws FileNotFoundException {
|
||||
final FileInputStream str = new FileInputStream("bar");
|
||||
final FileInputStream str = new <warning descr="'FileInputStream' should be opened in front of a 'try' block and closed in the corresponding 'finally' block">FileInputStream</warning>("bar");
|
||||
|
||||
}
|
||||
|
||||
public void foo25() throws FileNotFoundException {
|
||||
try {
|
||||
final FileInputStream str = new FileInputStream("bar");
|
||||
final FileInputStream str = new <warning descr="'FileInputStream' should be opened in front of a 'try' block and closed in the corresponding 'finally' block">FileInputStream</warning>("bar");
|
||||
} finally {
|
||||
}
|
||||
|
||||
@@ -54,7 +54,7 @@ public class IOResourceInspection {
|
||||
public void foo6() throws IOException {
|
||||
FileInputStream str = null;
|
||||
try {
|
||||
str = new FileInputStream("bar");
|
||||
str = new <warning descr="'FileInputStream' should be opened in front of a 'try' block and closed in the corresponding 'finally' block">FileInputStream</warning>("bar");
|
||||
} finally {
|
||||
}
|
||||
}
|
||||
@@ -63,7 +63,7 @@ public class IOResourceInspection {
|
||||
FileInputStream str = null;
|
||||
BufferedInputStream str2 = null;
|
||||
try {
|
||||
str = new FileInputStream("bar");
|
||||
str = new <warning descr="'FileInputStream' should be opened in front of a 'try' block and closed in the corresponding 'finally' block">FileInputStream</warning>("bar");
|
||||
str2 = new BufferedInputStream(str);
|
||||
} catch (FileNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
@@ -91,7 +91,7 @@ public class IOResourceInspection {
|
||||
}
|
||||
}
|
||||
public void interrupting() throws IOException {
|
||||
FileInputStream str = new FileInputStream("xxxx");
|
||||
FileInputStream str = new <warning descr="'FileInputStream' should be opened in front of a 'try' block and closed in the corresponding 'finally' block">FileInputStream</warning>("xxxx");
|
||||
str.read();
|
||||
try {
|
||||
str.read();
|
||||
@@ -145,11 +145,11 @@ public class IOResourceInspection {
|
||||
}
|
||||
|
||||
void resourceAsStream() {
|
||||
String.class.getResourceAsStream("bla");
|
||||
String.class.<warning descr="'InputStream' should be opened in front of a 'try' block and closed in the corresponding 'finally' block">getResourceAsStream</warning>("bla");
|
||||
}
|
||||
|
||||
public static void c() throws IOException {
|
||||
InputStream in = new FileInputStream("");
|
||||
InputStream in = new <warning descr="'FileInputStream' should be opened in front of a 'try' block and closed in the corresponding 'finally' block">FileInputStream</warning>("");
|
||||
OutputStreamWriter writer = new OutputStreamWriter(new FileOutputStream("asd"));
|
||||
try {
|
||||
writer.write(0);
|
||||
+2
-2
@@ -1,8 +1,8 @@
|
||||
package com.siyeh.igtest.resources.io.inside_try;
|
||||
package com.siyeh.igtest.resources.ioresource;
|
||||
|
||||
import java.io.*;
|
||||
|
||||
public class A {
|
||||
public class InsideTry {
|
||||
|
||||
void foo() throws IOException {
|
||||
InputStream in = null;
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2012 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,32 +15,30 @@
|
||||
*/
|
||||
package com.resources;
|
||||
|
||||
import com.intellij.openapi.projectRoots.Sdk;
|
||||
import com.intellij.openapi.projectRoots.impl.JavaSdkImpl;
|
||||
import com.intellij.openapi.roots.LanguageLevelProjectExtension;
|
||||
import com.intellij.pom.java.LanguageLevel;
|
||||
import com.intellij.testFramework.IdeaTestUtil;
|
||||
import com.siyeh.ig.IGInspectionTestCase;
|
||||
import com.intellij.codeInspection.InspectionProfileEntry;
|
||||
import com.siyeh.ig.LightInspectionTestCase;
|
||||
import com.siyeh.ig.resources.IOResourceInspection;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* @author Alexey
|
||||
*/
|
||||
public class IOResourceInspectionTest extends IGInspectionTestCase {
|
||||
public class IOResourceInspectionTest extends LightInspectionTestCase {
|
||||
|
||||
@Override
|
||||
protected Sdk getTestProjectSdk() {
|
||||
LanguageLevelProjectExtension.getInstance(getProject()).setLanguageLevel(LanguageLevel.JDK_1_7);
|
||||
return IdeaTestUtil.getMockJdk17();
|
||||
}
|
||||
|
||||
public void test() throws Exception {
|
||||
doTest("com/siyeh/igtest/resources/io/plain", new IOResourceInspection());
|
||||
public void testIOResource() {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testInsideTry() throws Exception {
|
||||
final IOResourceInspection inspection = new IOResourceInspection();
|
||||
inspection.insideTryAllowed = true;
|
||||
doTest("com/siyeh/igtest/resources/io/inside_try", inspection);
|
||||
myFixture.enableInspections(inspection);
|
||||
doTest();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
protected InspectionProfileEntry getInspection() {
|
||||
return new IOResourceInspection();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user