forked from androidx/androidx
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge changes from topic "193110413_kotlin_optin_parity" into android…
…x-main * changes: Detect method overrides in lambda expressions Add support for detecting usages of annotations in overrides Eliminate duplicate reports, inspect called member's experimental scope
- Loading branch information
Showing
10 changed files
with
1,266 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
97 changes: 97 additions & 0 deletions
97
...mental-lint/integration-tests/src/main/java/sample/optin/RegressionTestJava192562469.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
/* | ||
* Copyright 2021 The Android Open Source Project | ||
* | ||
* 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 sample.optin; | ||
|
||
import androidx.annotation.OptIn; | ||
|
||
/** | ||
* Regression test for b/192562469 where the lint check does not handle annotation usage in lambdas. | ||
*/ | ||
@SuppressWarnings("unused") | ||
public class RegressionTestJava192562469 { | ||
@ExperimentalJavaAnnotation | ||
interface ExperimentalInterface { | ||
void experimentalMethod(); | ||
} | ||
|
||
/** | ||
* Unsafe usage due to implementation of an experimental interface. | ||
*/ | ||
static class ConcreteExperimentalInterface implements ExperimentalInterface { // unsafe | ||
@Override | ||
public void experimentalMethod() {} // unsafe override | ||
} | ||
|
||
/** | ||
* Safe usage due to opt-in. | ||
*/ | ||
@OptIn(markerClass = ExperimentalJavaAnnotation.class) | ||
static class ConcreteExperimentalInterfaceOptIn implements ExperimentalInterface { | ||
@Override | ||
public void experimentalMethod() {} // safe | ||
} | ||
|
||
/** | ||
* Safe usage due to propagation. | ||
*/ | ||
@ExperimentalJavaAnnotation | ||
static class ConcreteExperimentalInterfacePropagate implements ExperimentalInterface { | ||
@Override | ||
public void experimentalMethod() {} // safe | ||
} | ||
|
||
/** | ||
* Unsafe implementations of an experimental interface. | ||
*/ | ||
void regressionTestOverrides() { | ||
@SuppressWarnings("Convert2Lambda") | ||
ExperimentalInterface anonymous = new ExperimentalInterface() { // unsafe | ||
@Override | ||
public void experimentalMethod() {} // unsafe override | ||
}; | ||
|
||
ExperimentalInterface lambda = () -> {}; // unsafe | ||
} | ||
|
||
/** | ||
* Safe implementations of an experimental interface due to opt-in. | ||
*/ | ||
@OptIn(markerClass = ExperimentalJavaAnnotation.class) | ||
void regressionTestOverridesOptIn() { | ||
@SuppressWarnings("Convert2Lambda") | ||
ExperimentalInterface anonymous = new ExperimentalInterface() { // safe | ||
@Override | ||
public void experimentalMethod() {} // safe | ||
}; | ||
|
||
ExperimentalInterface lambda = () -> {}; // safe | ||
} | ||
|
||
/** | ||
* Safe implementations of an experimental interface due to propagation. | ||
*/ | ||
@ExperimentalJavaAnnotation | ||
void regressionTestOverridesPropagate() { | ||
@SuppressWarnings("Convert2Lambda") | ||
ExperimentalInterface anonymous = new ExperimentalInterface() { // safe | ||
@Override | ||
public void experimentalMethod() {} // safe | ||
}; | ||
|
||
ExperimentalInterface lambda = () -> {}; // safe | ||
} | ||
} |
54 changes: 54 additions & 0 deletions
54
...mental-lint/integration-tests/src/main/java/sample/optin/RegressionTestJava192562926.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/* | ||
* Copyright 2021 The Android Open Source Project | ||
* | ||
* 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 sample.optin; | ||
|
||
/** | ||
* Regression test for b/192562926 where the lint check should not flag overrides where there is | ||
* no dependency on the superclass, e.g. calls to super(). | ||
*/ | ||
@SuppressWarnings("unused") | ||
public class RegressionTestJava192562926 { | ||
interface StableInterface { | ||
// This method will show up first in the list provided by PsiClass.allMethods, but it's | ||
// not the method that we want to inspect since it has a concrete implementation. | ||
default void abstractMethodWithDefault() {} | ||
|
||
@ExperimentalJavaAnnotation | ||
void experimentalMethod(); | ||
} | ||
|
||
/** | ||
* Safe override since super is not called. | ||
*/ | ||
static class ConcreteStableInterface implements StableInterface { | ||
@Override | ||
public void experimentalMethod() {} // unsafe override | ||
} | ||
|
||
/** | ||
* Test different approaches to overriding interface methods. | ||
*/ | ||
void regressionTestOverrides() { | ||
@SuppressWarnings("Convert2Lambda") | ||
StableInterface anonymous = new StableInterface() { | ||
@Override | ||
public void experimentalMethod() {} // unsafe override | ||
}; | ||
|
||
StableInterface lambda = () -> {}; // unsafe override | ||
} | ||
} |
Oops, something went wrong.