NonNls annotations; using PsiKeyword constants

GitOrigin-RevId: 52f8ed1371f46bbd175d78fb78acde5c331078a0
This commit is contained in:
Tagir Valeev
2020-07-22 05:58:26 +00:00
committed by intellij-monorepo-bot
parent db881b2c99
commit 3e7725fee7
15 changed files with 101 additions and 89 deletions
@@ -262,7 +262,7 @@ public final class HighlightUtil {
}
final List<PsiType> typeList = ContainerUtil.map(conjList, PsiTypeElement::getType);
final Ref<String> differentArgumentsMessage = new Ref<>();
final Ref<@Nls String> differentArgumentsMessage = new Ref<>();
final PsiClass sameGenericParameterization =
InferenceSession.findParameterizationOfTheSameGenericClass(typeList, pair -> {
if (!TypesDistinctProver.provablyDistinct(pair.first, pair.second)) {
@@ -594,12 +594,12 @@ public final class HighlightUtil {
}
@NotNull
public static String getUnhandledExceptionsDescriptor(@NotNull final Collection<? extends PsiClassType> unhandled) {
public static String getUnhandledExceptionsDescriptor(@NotNull Collection<? extends PsiClassType> unhandled) {
return getUnhandledExceptionsDescriptor(unhandled, null);
}
@NotNull
private static String getUnhandledExceptionsDescriptor(@NotNull final Collection<? extends PsiClassType> unhandled, @Nullable final String source) {
private static String getUnhandledExceptionsDescriptor(@NotNull Collection<? extends PsiClassType> unhandled, @Nullable @Nls String source) {
final String exceptions = formatTypes(unhandled);
return source == null
? JavaErrorBundle.message("unhandled.exceptions", exceptions, unhandled.size())
@@ -2473,10 +2473,10 @@ public final class HighlightUtil {
if (thisExpression.getQualifier() != null) {
resolvedName = referencedClass == null
? null
: PsiFormatUtil.formatClass(referencedClass, PsiFormatUtilBase.SHOW_NAME) + ".this";
: PsiFormatUtil.formatClass(referencedClass, PsiFormatUtilBase.SHOW_NAME) + "." + PsiKeyword.THIS;
}
else {
resolvedName = "this";
resolvedName = PsiKeyword.THIS;
}
}
else {
@@ -83,7 +83,7 @@ public class AddTypeArgumentsConditionalFix implements IntentionAction {
withTypeArgsText = aClass.getQualifiedName();
}
else {
withTypeArgsText = "this";
withTypeArgsText = PsiKeyword.THIS;
}
}
withTypeArgsText += "." + typeArguments + myExpression.getMethodExpression().getReferenceName();
@@ -30,7 +30,7 @@ public class QualifySuperArgumentFix extends QualifyThisOrSuperArgumentFix {
@Override
protected String getQualifierText() {
return "super";
return PsiKeyword.SUPER;
}
@Override
@@ -36,7 +36,7 @@ public class QualifyThisArgumentFix extends QualifyThisOrSuperArgumentFix{
@Override
protected String getQualifierText() {
return "this";
return PsiKeyword.THIS;
}
@Override
@@ -46,7 +46,7 @@ public class ReplaceGetClassWithClassLiteralFix extends LocalQuickFixAndIntentio
if (aClass == null) return false;
String className = aClass.getName();
if (className == null) return false;
myText = "Replace with " + className + ".class";
myText = "Replace with " + className + "." + PsiKeyword.CLASS;
return super.isAvailable(project, file, startElement, endElement);
}
@@ -37,6 +37,7 @@ import com.intellij.util.IncorrectOperationException;
import com.intellij.util.ObjectUtils;
import com.intellij.util.containers.ContainerUtil;
import org.jetbrains.annotations.Nls;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -57,7 +58,7 @@ public final class WrapWithAdapterMethodCallFix extends LocalQuickFixAndIntentio
* It's allowed to check imprecisely (return true even if output type is not acceptable) as more
* expensive type check will be performed automatically.
*/
Wrapper(String template, Predicate<? super PsiType> inTypeFilter, Predicate<? super PsiType> outTypeFilter) {
Wrapper(@NonNls String template, Predicate<? super PsiType> inTypeFilter, Predicate<? super PsiType> outTypeFilter) {
myInTypeFilter = inTypeFilter;
myOutTypeFilter = outTypeFilter;
myTemplate = template;
@@ -114,7 +115,7 @@ public final class WrapWithAdapterMethodCallFix extends LocalQuickFixAndIntentio
}
@NotNull
private PsiExpression createReplacement(PsiElement context, String replacement) {
private PsiExpression createReplacement(PsiElement context, @NonNls String replacement) {
return JavaPsiFacade.getElementFactory(context.getProject()).createExpressionFromText(
myTemplate.replace("{0}", replacement), context);
}
@@ -283,7 +283,7 @@ public class AddAnnotationPsiFix extends LocalQuickFixOnPsiElement {
int index = ArrayUtil.indexOf(parameters, parameter);
PsiParameterList newList;
if (PsiUtil.isLanguageLevel11OrHigher(list)) {
String newListText = StreamEx.of(parameters).map(p -> "var " + p.getName()).joining(",", "(", ")");
String newListText = StreamEx.of(parameters).map(p -> PsiKeyword.VAR + " " + p.getName()).joining(",", "(", ")");
newList = ((PsiLambdaExpression)JavaPsiFacade.getElementFactory(list.getProject())
.createExpressionFromText(newListText+" -> {}", null)).getParameterList();
newList = (PsiParameterList)new CommentTracker().replaceAndRestoreComments(list, newList);
@@ -170,7 +170,7 @@ public final class SplitConditionUtil {
}
}
else {
thenString = "{" + createIfString(leave, thenBranch, String.join("\nelse ", elseChain), tracker) + "\n}";
thenString = "{" + createIfString(leave, thenBranch, String.join("\n" + PsiKeyword.ELSE + " ", elseChain), tracker) + "\n}";
}
String ifString = createIfString(extract, thenString, elseBranch, tracker);
return (PsiIfStatement)factory.createStatementFromText(ifString, thenBranch);
@@ -222,8 +222,8 @@ public final class SplitConditionUtil {
private static String createIfString(@NotNull String condition,
@NotNull String thenBranch,
@Nullable String elseBranch) {
final String elsePart = elseBranch != null ? "\n else " + elseBranch : "";
return "if (" + condition + ")\n" + thenBranch + elsePart;
final String elsePart = elseBranch != null ? "\n " + PsiKeyword.ELSE + " " + elseBranch : "";
return PsiKeyword.IF + " (" + condition + ")\n" + thenBranch + elsePart;
}
@NotNull
@@ -10,6 +10,7 @@ import com.intellij.psi.*;
import com.intellij.psi.util.PsiTreeUtil;
import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.Nls;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import java.util.Collections;
@@ -24,7 +25,10 @@ public class AnonymousHasLambdaAlternativeInspection extends AbstractBaseJavaLoc
final String myLambdaAlternative;
final String myReplacementMessage;
AnonymousLambdaAlternative(String className, String methodName, String lambdaAlternative, String replacementMessage) {
AnonymousLambdaAlternative(@NonNls String className,
@NonNls String methodName,
@NonNls String lambdaAlternative,
@NonNls String replacementMessage) {
myClassName = className;
myMethodName = methodName;
myLambdaAlternative = lambdaAlternative;
@@ -9,13 +9,14 @@ import com.intellij.psi.*;
import com.intellij.psi.util.PsiTreeUtil;
import com.intellij.psi.util.PsiUtil;
import org.jetbrains.annotations.Nls;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import java.util.Collection;
public class RedundantLambdaCodeBlockInspection extends AbstractBaseJavaLocalInspectionTool {
public static final Logger LOG = Logger.getInstance(RedundantLambdaCodeBlockInspection.class);
private static final String SHORT_NAME = "CodeBlock2Expr";
private static final @NonNls String SHORT_NAME = "CodeBlock2Expr";
@Nls
@NotNull
@@ -6,6 +6,7 @@ import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.psi.*;
import gnu.trove.THashSet;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import java.util.LinkedHashSet;
@@ -16,7 +17,9 @@ import java.util.Set;
*/
public class StringTokenizerDelimiterInspection extends AbstractBaseJavaLocalInspectionTool {
@NonNls
private final static String NEXT_TOKEN = "nextToken";
@NonNls
private final static String STRING_TOKENIZER = "java.util.StringTokenizer";
@NotNull
@@ -1,13 +1,14 @@
// Copyright 2000-2018 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.codeInspection.bytecodeAnalysis;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.org.objectweb.asm.tree.MethodInsnNode;
public final class Member implements MemberDescriptor {
final String internalClassName;
final String methodName;
final String methodDesc;
@NonNls final String internalClassName;
@NonNls final String methodName;
@NonNls final String methodDesc;
/**
* Primary constructor
@@ -16,7 +17,7 @@ public final class Member implements MemberDescriptor {
* @param methodName method name
* @param methodDesc method descriptor in asm format
*/
public Member(@NotNull String internalClassName, @NotNull String methodName, @NotNull String methodDesc) {
public Member(@NotNull @NonNls String internalClassName, @NotNull @NonNls String methodName, @NotNull @NonNls String methodDesc) {
this.internalClassName = internalClassName;
this.methodName = methodName;
this.methodDesc = methodDesc;
@@ -7,78 +7,78 @@ import com.intellij.openapi.util.NlsSafe;
* Represents a Java keyword. Constants defined in this interface represent all keywords and literals of the Java language.
*/
public interface PsiKeyword extends PsiJavaToken {
String ABSTRACT = "abstract";
String ASSERT = "assert";
String BOOLEAN = "boolean";
String BREAK = "break";
String BYTE = "byte";
String CASE = "case";
String CATCH = "catch";
String CHAR = "char";
String CLASS = "class";
String CONST = "const";
String CONTINUE = "continue";
String DEFAULT = "default";
String DO = "do";
String DOUBLE = "double";
String ELSE = "else";
String ENUM = "enum";
String EXTENDS = "extends";
String FINAL = "final";
String FINALLY = "finally";
String FLOAT = "float";
String FOR = "for";
String GOTO = "goto";
String IF = "if";
String IMPLEMENTS = "implements";
String IMPORT = "import";
String INSTANCEOF = "instanceof";
String INT = "int";
String INTERFACE = "interface";
String LONG = "long";
String NATIVE = "native";
String NEW = "new";
@NlsSafe String ABSTRACT = "abstract";
@NlsSafe String ASSERT = "assert";
@NlsSafe String BOOLEAN = "boolean";
@NlsSafe String BREAK = "break";
@NlsSafe String BYTE = "byte";
@NlsSafe String CASE = "case";
@NlsSafe String CATCH = "catch";
@NlsSafe String CHAR = "char";
@NlsSafe String CLASS = "class";
@NlsSafe String CONST = "const";
@NlsSafe String CONTINUE = "continue";
@NlsSafe String DEFAULT = "default";
@NlsSafe String DO = "do";
@NlsSafe String DOUBLE = "double";
@NlsSafe String ELSE = "else";
@NlsSafe String ENUM = "enum";
@NlsSafe String EXTENDS = "extends";
@NlsSafe String FINAL = "final";
@NlsSafe String FINALLY = "finally";
@NlsSafe String FLOAT = "float";
@NlsSafe String FOR = "for";
@NlsSafe String GOTO = "goto";
@NlsSafe String IF = "if";
@NlsSafe String IMPLEMENTS = "implements";
@NlsSafe String IMPORT = "import";
@NlsSafe String INSTANCEOF = "instanceof";
@NlsSafe String INT = "int";
@NlsSafe String INTERFACE = "interface";
@NlsSafe String LONG = "long";
@NlsSafe String NATIVE = "native";
@NlsSafe String NEW = "new";
@NlsSafe String PACKAGE = "package";
@NlsSafe String PRIVATE = "private";
@NlsSafe String PROTECTED = "protected";
@NlsSafe String PUBLIC = "public";
String RETURN = "return";
String SHORT = "short";
String STATIC = "static";
String STRICTFP = "strictfp";
String SUPER = "super";
String SWITCH = "switch";
String SYNCHRONIZED = "synchronized";
String THIS = "this";
String THROW = "throw";
String THROWS = "throws";
String TRANSIENT = "transient";
String TRY = "try";
String VOID = "void";
String VOLATILE = "volatile";
String WHILE = "while";
@NlsSafe String RETURN = "return";
@NlsSafe String SHORT = "short";
@NlsSafe String STATIC = "static";
@NlsSafe String STRICTFP = "strictfp";
@NlsSafe String SUPER = "super";
@NlsSafe String SWITCH = "switch";
@NlsSafe String SYNCHRONIZED = "synchronized";
@NlsSafe String THIS = "this";
@NlsSafe String THROW = "throw";
@NlsSafe String THROWS = "throws";
@NlsSafe String TRANSIENT = "transient";
@NlsSafe String TRY = "try";
@NlsSafe String VOID = "void";
@NlsSafe String VOLATILE = "volatile";
@NlsSafe String WHILE = "while";
String TRUE = "true";
String FALSE = "false";
String NULL = "null";
@NlsSafe String TRUE = "true";
@NlsSafe String FALSE = "false";
@NlsSafe String NULL = "null";
String OPEN = "open";
String MODULE = "module";
String REQUIRES = "requires";
String EXPORTS = "exports";
String OPENS = "opens";
String USES = "uses";
String PROVIDES = "provides";
String TRANSITIVE = "transitive";
String TO = "to";
String WITH = "with";
@NlsSafe String OPEN = "open";
@NlsSafe String MODULE = "module";
@NlsSafe String REQUIRES = "requires";
@NlsSafe String EXPORTS = "exports";
@NlsSafe String OPENS = "opens";
@NlsSafe String USES = "uses";
@NlsSafe String PROVIDES = "provides";
@NlsSafe String TRANSITIVE = "transitive";
@NlsSafe String TO = "to";
@NlsSafe String WITH = "with";
String VAR = "var";
String YIELD = "yield";
@NlsSafe String VAR = "var";
@NlsSafe String YIELD = "yield";
String RECORD = "record";
@NlsSafe String RECORD = "record";
String SEALED = "sealed";
String PERMITS = "permits";
String NON_SEALED = "non-sealed";
@NlsSafe String SEALED = "sealed";
@NlsSafe String PERMITS = "permits";
@NlsSafe String NON_SEALED = "non-sealed";
}
@@ -2,6 +2,7 @@
package com.intellij.jarRepository;
import com.intellij.util.containers.ContainerUtil;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import java.util.List;
@@ -30,7 +31,7 @@ public class RemoteRepositoryDescription {
private final String myUrl;
private final boolean myAllowSnapshots;
public RemoteRepositoryDescription(@NotNull String id, @NotNull String name, @NotNull String url) {
public RemoteRepositoryDescription(@NonNls @NotNull String id, @NotNull String name, @NotNull String url) {
this(id, name, url, true);
}
@@ -6,6 +6,7 @@ import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.psi.PsiFile;
import com.intellij.util.NullableFunction;
import com.intellij.util.io.DataExternalizer;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
/**
@@ -28,7 +29,7 @@ public abstract class GistManager {
* @return the gist object, where {@link VirtualFileGist#getFileData} can later be used to retrieve the cached data
*/
@NotNull
public abstract <Data> VirtualFileGist<Data> newVirtualFileGist(@NotNull String id,
public abstract <Data> VirtualFileGist<Data> newVirtualFileGist(@NotNull @NonNls String id,
int version,
@NotNull DataExternalizer<Data> externalizer,
@NotNull VirtualFileGist.GistCalculator<Data> calcData);
@@ -43,7 +44,7 @@ public abstract class GistManager {
* @return the gist object, where {@link PsiFileGist#getFileData} can later be used to retrieve the cached data
*/
@NotNull
public abstract <Data> PsiFileGist<Data> newPsiFileGist(@NotNull String id,
public abstract <Data> PsiFileGist<Data> newPsiFileGist(@NotNull @NonNls String id,
int version,
@NotNull DataExternalizer<Data> externalizer,
@NotNull NullableFunction<PsiFile, Data> calcData);