mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-05-06 05:10:22 +07:00
keep annotations for explicit to var fixes (IDEA-193876)
This commit is contained in:
@@ -569,7 +569,7 @@
|
||||
groupBundle="messages.InspectionsBundle"
|
||||
groupKey="group.names.declaration.redundancy" enabledByDefault="true" level="INFORMATION"
|
||||
implementationClass="com.intellij.codeInspection.lambda.RedundantLambdaParameterTypeInspection"
|
||||
displayName="Remove redundant lambda parameter types"/>
|
||||
displayName="Redundant lambda parameter types"/>
|
||||
<localInspection groupPath="Java" language="JAVA" shortName="ReplaceInefficientStreamCount"
|
||||
groupBundle="messages.InspectionsBundle"
|
||||
groupKey="group.names.performance.issues" enabledByDefault="true" level="WARNING"
|
||||
|
||||
@@ -71,8 +71,9 @@ public class RedundantLambdaParameterTypeInspection extends AbstractBaseJavaLoca
|
||||
private static void removeTypes(PsiLambdaExpression lambdaExpression) {
|
||||
if (lambdaExpression != null) {
|
||||
final PsiParameter[] parameters = lambdaExpression.getParameterList().getParameters();
|
||||
if (Arrays.stream(parameters).anyMatch(parameter -> parameter.hasModifierProperty(PsiModifier.FINAL) ||
|
||||
AnonymousCanBeLambdaInspection.hasRuntimeAnnotations(parameter,Collections.emptySet()))) {
|
||||
if (PsiUtil.isLanguageLevel11OrHigher(lambdaExpression) &&
|
||||
Arrays.stream(parameters).anyMatch(parameter -> parameter.hasModifierProperty(PsiModifier.FINAL) ||
|
||||
parameter.getAnnotations().length > 0)) {
|
||||
for (PsiParameter parameter : parameters) {
|
||||
PsiTypeElement element = parameter.getTypeElement();
|
||||
if (element != null) {
|
||||
|
||||
@@ -312,7 +312,10 @@ public class PsiTypeElementImpl extends CompositePsiElement implements PsiTypeEl
|
||||
@Override
|
||||
public PsiElement replace(@NotNull PsiElement newElement) throws IncorrectOperationException {
|
||||
// neighbouring type annotations are logical part of this type element and should be dropped
|
||||
PsiImplUtil.markTypeAnnotations(this);
|
||||
//if replacement is `var`, annotations should be left as they are not inferred from the right side of the assignment
|
||||
if (!(newElement instanceof PsiTypeElement) || !((PsiTypeElement)newElement).isInferredType()) {
|
||||
PsiImplUtil.markTypeAnnotations(this);
|
||||
}
|
||||
PsiElement result = super.replace(newElement);
|
||||
if (result instanceof PsiTypeElement) {
|
||||
PsiImplUtil.deleteTypeAnnotations((PsiTypeElement)result);
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
// "Replace explicit type with 'var'" "true"
|
||||
class Main {
|
||||
void m(String[] args) {
|
||||
for (var arg : args) ;
|
||||
for (@Anno var arg : args) ;
|
||||
}
|
||||
}
|
||||
}
|
||||
@interface Anno {}
|
||||
@@ -1,6 +1,7 @@
|
||||
// "Replace explicit type with 'var'" "true"
|
||||
class Main {
|
||||
{
|
||||
var args = new String[42];
|
||||
@Anno var args = new String[42];
|
||||
}
|
||||
}
|
||||
}
|
||||
@interface Anno {}
|
||||
@@ -1,6 +1,7 @@
|
||||
// "Replace explicit type with 'var'" "true"
|
||||
class Main {
|
||||
void m(String[] args) {
|
||||
for (<caret>String arg : args) ;
|
||||
for (@Anno <caret>String arg : args) ;
|
||||
}
|
||||
}
|
||||
}
|
||||
@interface Anno {}
|
||||
@@ -1,6 +1,7 @@
|
||||
// "Replace explicit type with 'var'" "true"
|
||||
class Main {
|
||||
{
|
||||
<caret>String[] args = new String[42];
|
||||
@Anno <caret>String[] args = new String[42];
|
||||
}
|
||||
}
|
||||
}
|
||||
@interface Anno {}
|
||||
Reference in New Issue
Block a user