From defc272b54ae44730510c82ea4cfc5d8a9b3b7c1 Mon Sep 17 00:00:00 2001 From: Konstantin Nisht Date: Tue, 18 Aug 2020 18:38:47 +0300 Subject: [PATCH] [groovy] IDEA-247643: Add more NLS annotations to annotator GitOrigin-RevId: c82f7cdb31fc2fbc579ead5911f6151764fcfb05 --- .../psi/impl/light/LightMethodBuilder.java | 29 ++++++++++--------- .../checkers/AnnotationCollectorChecker.java | 3 +- .../codeInspection/BaseInspectionVisitor.java | 14 +++++---- .../codeInspection/GrInspectionUtil.java | 3 +- .../transformations/Transformation.java | 23 +++------------ .../groovy/dsl/CustomMembersGenerator.java | 3 +- .../lang/psi/GroovyPsiElementFactory.java | 7 +++-- .../psi/controlFlow/impl/InstructionImpl.java | 18 ++---------- 8 files changed, 42 insertions(+), 58 deletions(-) diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/light/LightMethodBuilder.java b/java/java-psi-impl/src/com/intellij/psi/impl/light/LightMethodBuilder.java index edf2cafb59ab..fa38bfd6a3d3 100644 --- a/java/java-psi-impl/src/com/intellij/psi/impl/light/LightMethodBuilder.java +++ b/java/java-psi-impl/src/com/intellij/psi/impl/light/LightMethodBuilder.java @@ -1,4 +1,4 @@ -// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.psi.impl.light; import com.intellij.lang.Language; @@ -6,6 +6,7 @@ import com.intellij.lang.java.JavaLanguage; import com.intellij.navigation.ItemPresentation; import com.intellij.navigation.ItemPresentationProviders; import com.intellij.openapi.util.Computable; +import com.intellij.openapi.util.NlsSafe; import com.intellij.psi.*; import com.intellij.psi.impl.ElementPresentationUtil; import com.intellij.psi.impl.PsiClassImplUtil; @@ -20,6 +21,7 @@ import com.intellij.ui.icons.RowIcon; import com.intellij.util.IncorrectOperationException; import com.intellij.util.PlatformIcons; import com.intellij.util.containers.ContainerUtil; +import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -48,17 +50,17 @@ public class LightMethodBuilder extends LightElement implements PsiMethod, Origi setContainingClass(constructedClass); } - public LightMethodBuilder(PsiManager manager, String name) { + public LightMethodBuilder(PsiManager manager, @NlsSafe String name) { this(manager, JavaLanguage.INSTANCE, name); } - public LightMethodBuilder(PsiManager manager, Language language, String name) { + public LightMethodBuilder(PsiManager manager, Language language, @NlsSafe String name) { this(manager, language, name, new LightParameterListBuilder(manager, language), new LightModifierList(manager, language)); } public LightMethodBuilder(PsiManager manager, Language language, - String name, + @NlsSafe String name, PsiParameterList parameterList, PsiModifierList modifierList) { this(manager, language, name, parameterList, modifierList, @@ -68,7 +70,7 @@ public class LightMethodBuilder extends LightElement implements PsiMethod, Origi public LightMethodBuilder(PsiManager manager, Language language, - @NotNull String name, + @NlsSafe @NotNull String name, PsiParameterList parameterList, PsiModifierList modifierList, PsiReferenceList throwsList, @@ -151,12 +153,12 @@ public class LightMethodBuilder extends LightElement implements PsiMethod, Origi return this; } - public LightMethodBuilder addModifier(String modifier) { + public LightMethodBuilder addModifier(@NlsSafe String modifier) { ((LightModifierList)myModifierList).addModifier(modifier); return this; } - public LightMethodBuilder setModifiers(String... modifiers) { + public LightMethodBuilder setModifiers(@NlsSafe String... modifiers) { ((LightModifierList)myModifierList).clearModifiers(); addModifiers(modifiers); return this; @@ -176,7 +178,7 @@ public class LightMethodBuilder extends LightElement implements PsiMethod, Origi return setMethodReturnType(new Computable.PredefinedValueComputable<>(returnType)); } - public LightMethodBuilder setMethodReturnType(@NotNull final String returnType) { + public LightMethodBuilder setMethodReturnType(@NlsSafe @NotNull final String returnType) { return setMethodReturnType(new Computable.NotNullCachedComputable() { @NotNull @Override @@ -202,15 +204,15 @@ public class LightMethodBuilder extends LightElement implements PsiMethod, Origi return this; } - public LightMethodBuilder addParameter(@NotNull String name, @NotNull String type) { + public LightMethodBuilder addParameter(@NlsSafe @NotNull String name, @NlsSafe @NotNull String type) { return addParameter(name, JavaPsiFacade.getElementFactory(getProject()).createTypeFromText(type, this)); } - public LightMethodBuilder addParameter(@NotNull String name, @NotNull PsiType type) { + public LightMethodBuilder addParameter(@NlsSafe @NotNull String name, @NotNull PsiType type) { return addParameter(new LightParameter(name, type, this, JavaLanguage.INSTANCE)); } - public LightMethodBuilder addParameter(@NotNull String name, @NotNull PsiType type, boolean isVarArgs) { + public LightMethodBuilder addParameter(@NlsSafe @NotNull String name, @NotNull PsiType type, boolean isVarArgs) { if (isVarArgs && !(type instanceof PsiEllipsisType)) { type = new PsiEllipsisType(type); } @@ -222,7 +224,7 @@ public class LightMethodBuilder extends LightElement implements PsiMethod, Origi return this; } - public LightMethodBuilder addException(String fqName) { + public LightMethodBuilder addException(@NlsSafe String fqName) { ((LightReferenceListBuilder)myThrowsList).addReference(fqName); return this; } @@ -408,11 +410,12 @@ public class LightMethodBuilder extends LightElement implements PsiMethod, Origi @Nullable @Override + @NonNls public String getOriginInfo() { return myOriginInfo; } - public void setOriginInfo(@Nullable String originInfo) { + public void setOriginInfo(@Nullable @NonNls String originInfo) { myOriginInfo = originInfo; } diff --git a/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/annotator/checkers/AnnotationCollectorChecker.java b/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/annotator/checkers/AnnotationCollectorChecker.java index d019c2d9c4e5..1010ea592c00 100644 --- a/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/annotator/checkers/AnnotationCollectorChecker.java +++ b/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/annotator/checkers/AnnotationCollectorChecker.java @@ -1,6 +1,7 @@ // Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package org.jetbrains.plugins.groovy.annotator.checkers; +import com.intellij.codeInspection.util.InspectionMessage; import com.intellij.lang.annotation.AnnotationHolder; import com.intellij.lang.annotation.HighlightSeverity; import com.intellij.openapi.util.Pair; @@ -30,7 +31,7 @@ public class AnnotationCollectorChecker extends CustomAnnotationChecker { final PsiClass clazz = (PsiClass)annotation.getClassReference().resolve(); if (clazz == null) return true; final GrAnnotationNameValuePair[] attributes = annotation.getParameterList().getAttributes(); - Pair r = CustomAnnotationChecker.checkAnnotationArguments(clazz, attributes, false); + Pair r = CustomAnnotationChecker.checkAnnotationArguments(clazz, attributes, false); if (r != null && r.getFirst() != null) { holder.newAnnotation(HighlightSeverity.ERROR, r.getSecond()).range(r.getFirst()).create(); } diff --git a/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/codeInspection/BaseInspectionVisitor.java b/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/codeInspection/BaseInspectionVisitor.java index a7a42d52e5c9..dcacba2c2f7f 100644 --- a/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/codeInspection/BaseInspectionVisitor.java +++ b/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/codeInspection/BaseInspectionVisitor.java @@ -47,12 +47,16 @@ public abstract class BaseInspectionVisitor extends GroovyElementVisitor { registerError(statementToken, args); } + private static @InspectionMessage @NotNull String nlsNotNullize(@InspectionMessage @Nullable String s) { + return StringUtil.notNullize(s); // NON-NLS + } + protected void registerError(PsiElement location) { if (location == null) { return; } final LocalQuickFix[] fix = createFixes(location); - String description = StringUtil.notNullize(inspection.buildErrorString(location)); + String description = nlsNotNullize(inspection.buildErrorString(location)); registerError(location, description, fix, ProblemHighlightType.GENERIC_ERROR_OR_WARNING); } @@ -62,7 +66,7 @@ public abstract class BaseInspectionVisitor extends GroovyElementVisitor { return; } final LocalQuickFix[] fixes = createFixes(method); - String description = StringUtil.notNullize(inspection.buildErrorString(args)); + String description = nlsNotNullize(inspection.buildErrorString(args)); registerError(method.getNameIdentifierGroovy(), description, fixes, ProblemHighlightType.GENERIC_ERROR_OR_WARNING); } @@ -72,7 +76,7 @@ public abstract class BaseInspectionVisitor extends GroovyElementVisitor { return; } final LocalQuickFix[] fix = createFixes(variable); - final String description = StringUtil.notNullize(inspection.buildErrorString(args)); + final String description = nlsNotNullize(inspection.buildErrorString(args)); registerError(variable.getNameIdentifierGroovy(), description, fix, ProblemHighlightType.GENERIC_ERROR_OR_WARNING); } @@ -81,7 +85,7 @@ public abstract class BaseInspectionVisitor extends GroovyElementVisitor { return; } final LocalQuickFix[] fixes = createFixes(method); - final String description = StringUtil.notNullize(inspection.buildErrorString(args)); + final String description = nlsNotNullize(inspection.buildErrorString(args)); final GrExpression invoked = method.getInvokedExpression(); final PsiElement nameElement = ((GrReferenceExpression)invoked).getReferenceNameElement(); @@ -104,7 +108,7 @@ public abstract class BaseInspectionVisitor extends GroovyElementVisitor { ProblemHighlightType highlightType, Object... args) { final LocalQuickFix[] fix = createFixes(location); - final String description = StringUtil.notNullize(inspection.buildErrorString(args)); + final String description = nlsNotNullize(inspection.buildErrorString(args)); registerError(location, description, fix, highlightType); } diff --git a/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/codeInspection/GrInspectionUtil.java b/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/codeInspection/GrInspectionUtil.java index ca29f7689987..3401fdfcc561 100644 --- a/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/codeInspection/GrInspectionUtil.java +++ b/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/codeInspection/GrInspectionUtil.java @@ -5,6 +5,7 @@ import com.intellij.codeHighlighting.HighlightDisplayLevel; import com.intellij.codeInsight.daemon.impl.HighlightInfo; import com.intellij.codeInsight.daemon.impl.HighlightInfoType; import com.intellij.openapi.application.ApplicationManager; +import com.intellij.openapi.util.NlsSafe; import com.intellij.psi.PsiElement; import com.intellij.psi.tree.IElementType; import org.jetbrains.annotations.NotNull; @@ -56,7 +57,7 @@ public final class GrInspectionUtil { return HighlightInfo.newHighlightInfo(highlightInfoType).range(refNameElement).descriptionAndTooltip(message).create(); } - public static void replaceExpression(GrExpression expression, String newExpression) { + public static void replaceExpression(GrExpression expression, @NlsSafe String newExpression) { final GroovyPsiElementFactory factory = GroovyPsiElementFactory.getInstance(expression.getProject()); final GrExpression newCall = factory.createExpressionFromText(newExpression, expression.getContext()); expression.replaceWithExpression(newCall, true); diff --git a/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/codeInspection/changeToMethod/transformations/Transformation.java b/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/codeInspection/changeToMethod/transformations/Transformation.java index 732bbcaa9749..42aefdb94073 100644 --- a/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/codeInspection/changeToMethod/transformations/Transformation.java +++ b/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/codeInspection/changeToMethod/transformations/Transformation.java @@ -1,27 +1,12 @@ -/* - * Copyright 2000-2017 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. - * 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. - */ +// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package org.jetbrains.plugins.groovy.codeInspection.changeToMethod.transformations; +import com.intellij.openapi.util.NlsSafe; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression; -import static org.jetbrains.plugins.groovy.lang.psi.impl.utils.ParenthesesUtils.METHOD_CALL_PRECEDENCE; -import static org.jetbrains.plugins.groovy.lang.psi.impl.utils.ParenthesesUtils.checkPrecedenceForNonBinaryOps; -import static org.jetbrains.plugins.groovy.lang.psi.impl.utils.ParenthesesUtils.parenthesize; +import static org.jetbrains.plugins.groovy.lang.psi.impl.utils.ParenthesesUtils.*; public abstract class Transformation { @@ -42,7 +27,7 @@ public abstract class Transformation { protected abstract void apply(@NotNull T expression); - public abstract String getMethod(); + public abstract @NlsSafe String getMethod(); @NotNull GrExpression addParenthesesIfNeeded(@NotNull GrExpression expression) { diff --git a/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/dsl/CustomMembersGenerator.java b/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/dsl/CustomMembersGenerator.java index 7d1379339408..38b7222a7322 100644 --- a/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/dsl/CustomMembersGenerator.java +++ b/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/dsl/CustomMembersGenerator.java @@ -14,6 +14,7 @@ import groovy.lang.GroovyObjectSupport; import groovy.lang.MetaMethod; import org.codehaus.groovy.runtime.DefaultGroovyMethods; import org.codehaus.groovy.runtime.InvokerHelper; +import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.jetbrains.plugins.groovy.dsl.dsltop.GdslMembersProvider; @@ -41,7 +42,7 @@ import java.util.function.Consumer; public class CustomMembersGenerator extends GroovyObjectSupport implements GdslMembersHolderConsumer { private static final Logger LOG = Logger.getInstance(CustomMembersGenerator.class); private static final GdslMembersProvider[] PROVIDERS = GdslMembersProvider.EP_NAME.getExtensions(); - public static final String THROWS = "throws"; + public static final @NonNls String THROWS = "throws"; private FList myDeclarations = FList.emptyList(); private final Project myProject; private final CompoundMembersHolder myDepot = new CompoundMembersHolder(); diff --git a/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/psi/GroovyPsiElementFactory.java b/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/psi/GroovyPsiElementFactory.java index ab80c455bb3a..bd3623492810 100644 --- a/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/psi/GroovyPsiElementFactory.java +++ b/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/psi/GroovyPsiElementFactory.java @@ -1,8 +1,9 @@ -// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package org.jetbrains.plugins.groovy.lang.psi; import com.intellij.openapi.components.ServiceManager; import com.intellij.openapi.project.Project; +import com.intellij.openapi.util.NlsSafe; import com.intellij.psi.*; import com.intellij.util.IncorrectOperationException; import org.jetbrains.annotations.NonNls; @@ -150,13 +151,13 @@ public abstract class GroovyPsiElementFactory implements JVMElementFactory { public abstract GrCodeReferenceElement createCodeReference(@NotNull String text, @Nullable PsiElement context); @NotNull - public GrExpression createExpressionFromText(@NotNull CharSequence exprText) { + public GrExpression createExpressionFromText(@NotNull @NlsSafe CharSequence exprText) { return createExpressionFromText(exprText.toString(), null); } @Override @NotNull - public abstract GrExpression createExpressionFromText(@NotNull String exprText, @Nullable PsiElement context); + public abstract GrExpression createExpressionFromText(@NlsSafe @NotNull String exprText, @Nullable PsiElement context); @NotNull public abstract GrVariableDeclaration createFieldDeclaration(String @NotNull [] modifiers, @NotNull String identifier, @Nullable GrExpression initializer, @Nullable PsiType type); diff --git a/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/psi/controlFlow/impl/InstructionImpl.java b/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/psi/controlFlow/impl/InstructionImpl.java index 88b2d401bc22..6135644e43fc 100644 --- a/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/psi/controlFlow/impl/InstructionImpl.java +++ b/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/psi/controlFlow/impl/InstructionImpl.java @@ -1,21 +1,8 @@ -/* - * Copyright 2000-2017 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. - * 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. - */ +// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package org.jetbrains.plugins.groovy.lang.psi.controlFlow.impl; import com.intellij.psi.PsiElement; +import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.jetbrains.plugins.groovy.lang.psi.controlFlow.CallEnvironment; @@ -94,6 +81,7 @@ public class InstructionImpl implements Instruction { } @NotNull + @NonNls protected String getElementPresentation() { //return "element: " + (myPsiElement != null ? myPsiElement.getText() : null); return "element: " + myPsiElement;