Summary: public This adds the following subtyping rules: - methods that are not annotated with Expensive cannot be overwritten by a method annotated with Expensive - methods annotated with PerformanceCritical must be overwitten by method annotated with PerformanceCritical Reviewed By: cristianoc Differential Revision: D2636076 fb-gh-sync-id: eb616c9master
parent
6b6b4d1949
commit
0cd533f892
@ -0,0 +1,38 @@
|
||||
/*
|
||||
* Copyright (c) 2013 - present Facebook, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This source code is licensed under the BSD style license found in the
|
||||
* LICENSE file in the root directory of this source tree. An additional grant
|
||||
* of patent rights can be found in the PATENTS file in the same directory.
|
||||
*/
|
||||
|
||||
package codetoanalyze.java.checkers;
|
||||
|
||||
import com.facebook.infer.annotation.Expensive;
|
||||
import com.facebook.infer.annotation.PerformanceCritical;
|
||||
|
||||
|
||||
public interface ExpensiveInterfaceExample {
|
||||
|
||||
interface I {
|
||||
|
||||
@PerformanceCritical
|
||||
public void m1();
|
||||
|
||||
public void m2();
|
||||
|
||||
}
|
||||
|
||||
class C {
|
||||
|
||||
public void m3() {}
|
||||
|
||||
public void m4() {}
|
||||
|
||||
}
|
||||
|
||||
@Expensive
|
||||
public void m5();
|
||||
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
/*
|
||||
* Copyright (c) 2013 - present Facebook, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This source code is licensed under the BSD style license found in the
|
||||
* LICENSE file in the root directory of this source tree. An additional grant
|
||||
* of patent rights can be found in the PATENTS file in the same directory.
|
||||
*/
|
||||
|
||||
package codetoanalyze.java.checkers;
|
||||
|
||||
import com.facebook.infer.annotation.Expensive;
|
||||
|
||||
public class ExpensiveSubtypingExample extends ExpensiveInterfaceExample.C {
|
||||
|
||||
@Expensive
|
||||
public void m3() {}
|
||||
|
||||
public void m4() {}
|
||||
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
/*
|
||||
* Copyright (c) 2013 - present Facebook, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This source code is licensed under the BSD style license found in the
|
||||
* LICENSE file in the root directory of this source tree. An additional grant
|
||||
* of patent rights can be found in the PATENTS file in the same directory.
|
||||
*/
|
||||
|
||||
package codetoanalyze.java.checkers;
|
||||
|
||||
public class PerformanceCriticalSubtypingExample implements ExpensiveInterfaceExample.I {
|
||||
|
||||
public void m1() {}
|
||||
|
||||
public void m2() {}
|
||||
|
||||
}
|
@ -0,0 +1,54 @@
|
||||
/*
|
||||
* Copyright (c) 2015 - present Facebook, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This source code is licensed under the BSD style license found in the
|
||||
* LICENSE file in the root directory of this source tree. An additional grant
|
||||
* of patent rights can be found in the PATENTS file in the same directory.
|
||||
*/
|
||||
|
||||
package endtoend.java.checkers;
|
||||
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static utils.matchers.ResultContainsExactly.containsExactly;
|
||||
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import utils.InferException;
|
||||
import utils.InferResults;
|
||||
|
||||
public class ExpensiveSubtypingTest {
|
||||
|
||||
public static final String SOURCE_FILE =
|
||||
"infer/tests/codetoanalyze/java/checkers/ExpensiveSubtypingExample.java";
|
||||
|
||||
public static final String EXPENSIVE_OVERRIDES_UNANNOTATED =
|
||||
"CHECKERS_EXPENSIVE_OVERRIDES_UNANNOTATED";
|
||||
|
||||
private static InferResults inferResults;
|
||||
|
||||
@BeforeClass
|
||||
public static void loadResults() throws InterruptedException, IOException {
|
||||
inferResults =
|
||||
InferResults.loadCheckersResults(ExpensiveSubtypingTest.class, SOURCE_FILE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void matchErrors()
|
||||
throws IOException, InterruptedException, InferException {
|
||||
String[] methods = {
|
||||
"m3",
|
||||
};
|
||||
assertThat(
|
||||
"Results should contain " + EXPENSIVE_OVERRIDES_UNANNOTATED,
|
||||
inferResults,
|
||||
containsExactly(
|
||||
EXPENSIVE_OVERRIDES_UNANNOTATED,
|
||||
SOURCE_FILE,
|
||||
methods));
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,54 @@
|
||||
/*
|
||||
* Copyright (c) 2015 - present Facebook, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This source code is licensed under the BSD style license found in the
|
||||
* LICENSE file in the root directory of this source tree. An additional grant
|
||||
* of patent rights can be found in the PATENTS file in the same directory.
|
||||
*/
|
||||
|
||||
package endtoend.java.checkers;
|
||||
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static utils.matchers.ResultContainsExactly.containsExactly;
|
||||
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import utils.InferException;
|
||||
import utils.InferResults;
|
||||
|
||||
public class PerformanceCriticalSubtypingTest {
|
||||
|
||||
public static final String SOURCE_FILE =
|
||||
"infer/tests/codetoanalyze/java/checkers/PerformanceCriticalSubtypingExample.java";
|
||||
|
||||
public static final String UNANNOTATED_OVERRIDES_PERFOMANCE_CRITICAL =
|
||||
"CHECKERS_UNANNOTATED_OVERRIDES_PERFOMANCE_CRITICAL";
|
||||
|
||||
private static InferResults inferResults;
|
||||
|
||||
@BeforeClass
|
||||
public static void loadResults() throws InterruptedException, IOException {
|
||||
inferResults =
|
||||
InferResults.loadCheckersResults(PerformanceCriticalSubtypingTest.class, SOURCE_FILE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void matchErrors()
|
||||
throws IOException, InterruptedException, InferException {
|
||||
String[] methods = {
|
||||
"m1",
|
||||
};
|
||||
assertThat(
|
||||
"Results should contain " + UNANNOTATED_OVERRIDES_PERFOMANCE_CRITICAL,
|
||||
inferResults,
|
||||
containsExactly(
|
||||
UNANNOTATED_OVERRIDES_PERFOMANCE_CRITICAL,
|
||||
SOURCE_FILE,
|
||||
methods));
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in new issue