GitOrigin-RevId: 3d9909f57e77a8288346381ee121de0b0df8747c
This commit is contained in:
Vladimir Krivosheev
2024-12-26 17:01:13 +00:00
committed by intellij-monorepo-bot
parent e128376b08
commit d3ec3d2f70
870 changed files with 3960 additions and 7075 deletions
@@ -36,8 +36,7 @@ public final class CompletionMLRankingSettings implements PersistentStateCompone
myState = new State();
}
@NotNull
public static CompletionMLRankingSettings getInstance() {
public static @NotNull CompletionMLRankingSettings getInstance() {
return ApplicationManager.getApplication().getService(CompletionMLRankingSettings.class);
}
@@ -14,8 +14,7 @@ import java.util.Map;
public interface AdditionalContextFeatureProvider {
LanguageExtension<AdditionalContextFeatureProvider> EP_NAME = new LanguageExtension<>("com.intellij.completion.ml.additionalContextFeatures");
@NotNull
static List<AdditionalContextFeatureProvider> forLanguage(Language language) {
static @NotNull List<AdditionalContextFeatureProvider> forLanguage(Language language) {
return EP_NAME.allForLanguageOrAny(language);
}
@@ -13,8 +13,7 @@ import java.util.Map;
public interface LookupFeatureProvider {
LanguageExtension<LookupFeatureProvider> EP_NAME = new LanguageExtension<>("com.intellij.completion.ml.lookupFeatures");
@NotNull
static List<LookupFeatureProvider> forLanguage(Language language) {
static @NotNull List<LookupFeatureProvider> forLanguage(Language language) {
return EP_NAME.allForLanguageOrAny(language);
}
@@ -14,9 +14,8 @@ import ru.adelf.idea.dotenv.api.EnvironmentVariablesApi;
import ru.adelf.idea.dotenv.util.EnvironmentVariablesUtil;
public class DockerComposeKeyGotoHandler implements GotoDeclarationHandler {
@Nullable
@Override
public PsiElement[] getGotoDeclarationTargets(@Nullable PsiElement psiElement, int i, Editor editor) {
public @Nullable PsiElement[] getGotoDeclarationTargets(@Nullable PsiElement psiElement, int i, Editor editor) {
if (psiElement == null) {
return PsiElement.EMPTY_ARRAY;
}
@@ -70,9 +69,8 @@ public class DockerComposeKeyGotoHandler implements GotoDeclarationHandler {
return PsiElement.EMPTY_ARRAY;
}
@Nullable
@Override
public String getActionText(@NotNull DataContext dataContext) {
public @Nullable String getActionText(@NotNull DataContext dataContext) {
return null;
}
}
@@ -54,8 +54,7 @@ class DockerComposeYamlPsiElementsVisitor extends PsiRecursiveElementVisitor {
* FOO: [foobar]
*/
@NotNull
private Collection<YAMLSequenceItem> getSequenceItems(@NotNull YAMLKeyValue yamlKeyValue) {
private @NotNull Collection<YAMLSequenceItem> getSequenceItems(@NotNull YAMLKeyValue yamlKeyValue) {
PsiElement yamlSequence = yamlKeyValue.getLastChild();
if (yamlSequence instanceof YAMLSequence) {
@@ -70,8 +69,7 @@ class DockerComposeYamlPsiElementsVisitor extends PsiRecursiveElementVisitor {
* FOO:
* bar: true
*/
@NotNull
private Collection<YAMLKeyValue> getMappingItems(@NotNull YAMLKeyValue yamlKeyValue) {
private @NotNull Collection<YAMLKeyValue> getMappingItems(@NotNull YAMLKeyValue yamlKeyValue) {
PsiElement yamlMapping = yamlKeyValue.getLastChild();
if (yamlMapping instanceof YAMLMapping) {
@@ -13,9 +13,8 @@ import java.util.Collection;
import java.util.Collections;
public class DockerComposeYamlVariablesProvider implements EnvironmentVariablesProvider {
@NotNull
@Override
public FileAcceptResult acceptFile(VirtualFile file) {
public @NotNull FileAcceptResult acceptFile(VirtualFile file) {
if (file.getName().equals("docker-compose.yml") || file.getName().equals("docker-compose.yaml")) {
return file.getFileType().equals(YAMLFileType.YML) ? FileAcceptResult.ACCEPTED : FileAcceptResult.NOT_ACCEPTED;
}
@@ -23,9 +22,8 @@ public class DockerComposeYamlVariablesProvider implements EnvironmentVariablesP
return FileAcceptResult.NOT_ACCEPTED;
}
@NotNull
@Override
public Collection<KeyValuePsiElement> getElements(PsiFile psiFile) {
public @NotNull Collection<KeyValuePsiElement> getElements(PsiFile psiFile) {
if (psiFile instanceof YAMLFile) {
DockerComposeYamlPsiElementsVisitor visitor = new DockerComposeYamlPsiElementsVisitor();
psiFile.acceptChildren(visitor);
@@ -12,9 +12,8 @@ import ru.adelf.idea.dotenv.util.EnvironmentVariablesUtil;
public class DockerfileKeyGotoHandler implements GotoDeclarationHandler {
@Nullable
@Override
public PsiElement[] getGotoDeclarationTargets(@Nullable PsiElement psiElement, int i, Editor editor) {
public @Nullable PsiElement[] getGotoDeclarationTargets(@Nullable PsiElement psiElement, int i, Editor editor) {
if (psiElement == null || psiElement.getParent() == null) {
return PsiElement.EMPTY_ARRAY;
}
@@ -32,9 +31,8 @@ public class DockerfileKeyGotoHandler implements GotoDeclarationHandler {
return EnvironmentVariablesApi.getKeyUsages(psiElement.getProject(), EnvironmentVariablesUtil.getKeyFromString((((DockerFileEnvRegularDeclaration) psiElement).getDeclaredName().getText())));
}
@Nullable
@Override
public String getActionText(@NotNull DataContext dataContext) {
public @Nullable String getActionText(@NotNull DataContext dataContext) {
return null;
}
}
@@ -13,15 +13,13 @@ import java.util.Collection;
import java.util.Collections;
public class DockerfileVariablesProvider implements EnvironmentVariablesProvider {
@NotNull
@Override
public FileAcceptResult acceptFile(VirtualFile file) {
public @NotNull FileAcceptResult acceptFile(VirtualFile file) {
return file.getFileType().equals(DockerFileType.DOCKER_FILE_TYPE) ? FileAcceptResult.ACCEPTED : FileAcceptResult.NOT_ACCEPTED;
}
@NotNull
@Override
public Collection<KeyValuePsiElement> getElements(PsiFile psiFile) {
public @NotNull Collection<KeyValuePsiElement> getElements(PsiFile psiFile) {
if(psiFile instanceof DockerPsiFile) {
DockerfilePsiElementsVisitor visitor = new DockerfilePsiElementsVisitor();
psiFile.acceptChildren(visitor);
@@ -39,9 +39,8 @@ public class GoEnvCompletionProvider extends BaseEnvCompletionProvider implement
});
}
@Nullable
@Override
public PsiElement[] getGotoDeclarationTargets(@Nullable PsiElement psiElement, int i, Editor editor) {
public @Nullable PsiElement[] getGotoDeclarationTargets(@Nullable PsiElement psiElement, int i, Editor editor) {
if (psiElement == null) {
return PsiElement.EMPTY_ARRAY;
}
@@ -55,8 +54,7 @@ public class GoEnvCompletionProvider extends BaseEnvCompletionProvider implement
return EnvironmentVariablesApi.getKeyDeclarations(psiElement.getProject(), stringLiteral.getDecodedText());
}
@Nullable
private GoStringLiteral getStringLiteral(@NotNull PsiElement psiElement) {
private @Nullable GoStringLiteral getStringLiteral(@NotNull PsiElement psiElement) {
PsiElement parent = psiElement.getParent();
if (!(parent instanceof GoStringLiteral)) {
@@ -76,9 +74,8 @@ public class GoEnvCompletionProvider extends BaseEnvCompletionProvider implement
return null;
}
@Nullable
@Override
public String getActionText(@NotNull DataContext dataContext) {
public @Nullable String getActionText(@NotNull DataContext dataContext) {
return null;
}
}
@@ -3,7 +3,6 @@ package ru.adelf.idea.dotenv.go;
import com.goide.psi.GoCallExpr;
import com.goide.psi.GoStringLiteral;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiRecursiveElementVisitor;
import com.intellij.psi.PsiRecursiveElementWalkingVisitor;
import org.jetbrains.annotations.NotNull;
import ru.adelf.idea.dotenv.models.KeyUsagePsiElement;
@@ -12,7 +11,7 @@ import java.util.Collection;
import java.util.HashSet;
class GoEnvironmentCallsVisitor extends PsiRecursiveElementWalkingVisitor {
final private Collection<KeyUsagePsiElement> collectedItems = new HashSet<>();
private final Collection<KeyUsagePsiElement> collectedItems = new HashSet<>();
@Override
public void visitElement(PsiElement element) {
@@ -17,9 +17,8 @@ public class GoEnvironmentVariablesUsagesProvider implements EnvironmentVariable
return file.getFileType().equals(GoFileType.INSTANCE);
}
@NotNull
@Override
public Collection<KeyUsagePsiElement> getUsages(PsiFile psiFile) {
public @NotNull Collection<KeyUsagePsiElement> getUsages(PsiFile psiFile) {
if(psiFile instanceof GoFile) {
GoEnvironmentCallsVisitor visitor = new GoEnvironmentCallsVisitor();
psiFile.acceptChildren(visitor);
@@ -8,9 +8,8 @@ import com.intellij.util.ThreeState;
import org.jetbrains.annotations.NotNull;
public class JavaCompletionConfidence extends CompletionConfidence {
@NotNull
@Override
public ThreeState shouldSkipAutopopup(@NotNull PsiElement contextElement, @NotNull PsiFile psiFile, int offset) {
public @NotNull ThreeState shouldSkipAutopopup(@NotNull PsiElement contextElement, @NotNull PsiFile psiFile, int offset) {
PsiElement literal = contextElement.getContext();
if(!(literal instanceof PsiLiteralExpression)) {
return ThreeState.UNSURE;
@@ -37,9 +37,8 @@ public class JavaEnvCompletionContributor extends BaseEnvCompletionProvider impl
});
}
@Nullable
@Override
public PsiElement[] getGotoDeclarationTargets(@Nullable PsiElement psiElement, int i, Editor editor) {
public @Nullable PsiElement[] getGotoDeclarationTargets(@Nullable PsiElement psiElement, int i, Editor editor) {
if (psiElement == null) {
return PsiElement.EMPTY_ARRAY;
}
@@ -59,8 +58,7 @@ public class JavaEnvCompletionContributor extends BaseEnvCompletionProvider impl
return EnvironmentVariablesApi.getKeyDeclarations(psiElement.getProject(), (String) value);
}
@Nullable
private PsiLiteralExpression getStringLiteral(@NotNull PsiElement psiElement) {
private @Nullable PsiLiteralExpression getStringLiteral(@NotNull PsiElement psiElement) {
PsiElement parent = psiElement.getParent();
if (!(parent instanceof PsiLiteralExpression)) {
@@ -74,9 +72,8 @@ public class JavaEnvCompletionContributor extends BaseEnvCompletionProvider impl
return (PsiLiteralExpression) parent;
}
@Nullable
@Override
public String getActionText(@NotNull DataContext dataContext) {
public @Nullable String getActionText(@NotNull DataContext dataContext) {
return null;
}
}
@@ -11,7 +11,7 @@ import java.util.Collection;
import java.util.HashSet;
class JavaEnvironmentCallsVisitor extends JavaRecursiveElementWalkingVisitor {
final private Collection<KeyUsagePsiElement> collectedItems = new HashSet<>();
private final Collection<KeyUsagePsiElement> collectedItems = new HashSet<>();
@Override
public void visitMethodCallExpression(PsiMethodCallExpression expression) {
@@ -11,8 +11,7 @@ public class JavaEnvironmentClasses {
return methodName.equals("getenv") || methodName.equals("getEnv");
}
@Nullable
public static List<String> getClassNames(String methodName) {
public static @Nullable List<String> getClassNames(String methodName) {
return switch (methodName) {
case "get" -> Arrays.asList("Dotenv", "DotEnv");
case "getProperty" -> Collections.singletonList("System");
@@ -17,9 +17,8 @@ public class JavaEnvironmentVariablesUsagesProvider implements EnvironmentVariab
return file.getFileType().equals(JavaFileType.INSTANCE);
}
@NotNull
@Override
public Collection<KeyUsagePsiElement> getUsages(PsiFile psiFile) {
public @NotNull Collection<KeyUsagePsiElement> getUsages(PsiFile psiFile) {
if (psiFile instanceof PsiJavaFile) {
JavaEnvironmentCallsVisitor visitor = new JavaEnvironmentCallsVisitor();
psiFile.acceptChildren(visitor);
@@ -8,9 +8,8 @@ import org.jetbrains.annotations.NotNull;
import org.jetbrains.kotlin.psi.KtLiteralStringTemplateEntry;
public class KotlinCompletionConfidence extends CompletionConfidence {
@NotNull
@Override
public ThreeState shouldSkipAutopopup(@NotNull PsiElement contextElement, @NotNull PsiFile psiFile, int offset) {
public @NotNull ThreeState shouldSkipAutopopup(@NotNull PsiElement contextElement, @NotNull PsiFile psiFile, int offset) {
PsiElement literal = contextElement.getContext();
if (!(literal instanceof KtLiteralStringTemplateEntry)) {
return ThreeState.UNSURE;
@@ -37,9 +37,8 @@ public class KotlinEnvCompletionContributor extends BaseEnvCompletionProvider im
});
}
@Nullable
@Override
public PsiElement[] getGotoDeclarationTargets(@Nullable PsiElement psiElement, int i, Editor editor) {
public @Nullable PsiElement[] getGotoDeclarationTargets(@Nullable PsiElement psiElement, int i, Editor editor) {
if (psiElement == null) {
return PsiElement.EMPTY_ARRAY;
}
@@ -53,8 +52,7 @@ public class KotlinEnvCompletionContributor extends BaseEnvCompletionProvider im
return EnvironmentVariablesApi.getKeyDeclarations(psiElement.getProject(), stringLiteral.getText());
}
@Nullable
private KtLiteralStringTemplateEntry getStringLiteral(@NotNull PsiElement psiElement) {
private @Nullable KtLiteralStringTemplateEntry getStringLiteral(@NotNull PsiElement psiElement) {
PsiElement parent = psiElement.getParent();
if (!(parent instanceof KtLiteralStringTemplateEntry)) {
@@ -68,9 +66,8 @@ public class KotlinEnvCompletionContributor extends BaseEnvCompletionProvider im
return (KtLiteralStringTemplateEntry) parent;
}
@Nullable
@Override
public String getActionText(@NotNull DataContext dataContext) {
public @Nullable String getActionText(@NotNull DataContext dataContext) {
return null;
}
}
@@ -19,9 +19,8 @@ public class KotlinEnvironmentVariablesUsagesProvider implements EnvironmentVari
return file.getFileType().equals(KotlinFileType.INSTANCE);
}
@NotNull
@Override
public Collection<KeyUsagePsiElement> getUsages(PsiFile psiFile) {
public @NotNull Collection<KeyUsagePsiElement> getUsages(PsiFile psiFile) {
if (psiFile instanceof KtFile) {
Set<KeyUsagePsiElement> result = new HashSet<>();
@@ -90,8 +90,7 @@ class KotlinPsiHelper {
return checkReferences(methodCallExpression.getCalleeExpression(), classNames);
}
@Nullable
static KeyUsagePsiElement getKeyUsageFromCall(@NotNull KtCallExpression expression) {
static @Nullable KeyUsagePsiElement getKeyUsageFromCall(@NotNull KtCallExpression expression) {
if (!isEnvMethodCall(expression)) {
return null;
}
@@ -127,8 +126,7 @@ class KotlinPsiHelper {
return checkReferences(arrayAccess, classNames);
}
@Nullable
static KeyUsagePsiElement getKeyUsageFromArrayAccess(@NotNull KtArrayAccessExpression expression) {
static @Nullable KeyUsagePsiElement getKeyUsageFromArrayAccess(@NotNull KtArrayAccessExpression expression) {
if (!isEnvArrayAccess(expression)) {
return null;
}
@@ -142,8 +140,7 @@ class KotlinPsiHelper {
return getKeyUsageFromStringTemplate(indexExpressions.get(0));
}
@Nullable
private static KeyUsagePsiElement getKeyUsageFromStringTemplate(PsiElement element) {
private static @Nullable KeyUsagePsiElement getKeyUsageFromStringTemplate(PsiElement element) {
if (!(element instanceof KtStringTemplateExpression)) {
return null;
}
@@ -38,9 +38,8 @@ public class PhpEnvCompletionContributor extends BaseEnvCompletionProvider imple
});
}
@Nullable
@Override
public PsiElement[] getGotoDeclarationTargets(@Nullable PsiElement psiElement, int i, Editor editor) {
public @Nullable PsiElement[] getGotoDeclarationTargets(@Nullable PsiElement psiElement, int i, Editor editor) {
if (psiElement == null) {
return PsiElement.EMPTY_ARRAY;
@@ -55,8 +54,7 @@ public class PhpEnvCompletionContributor extends BaseEnvCompletionProvider imple
return EnvironmentVariablesApi.getKeyDeclarations(psiElement.getProject(), stringLiteral.getContents());
}
@Nullable
private StringLiteralExpression getStringLiteral(@NotNull PsiElement psiElement) {
private @Nullable StringLiteralExpression getStringLiteral(@NotNull PsiElement psiElement) {
PsiElement parent = psiElement.getParent();
if (!(parent instanceof StringLiteralExpression)) {
@@ -70,9 +68,8 @@ public class PhpEnvCompletionContributor extends BaseEnvCompletionProvider imple
return (StringLiteralExpression) parent;
}
@Nullable
@Override
public String getActionText(@NotNull DataContext dataContext) {
public @Nullable String getActionText(@NotNull DataContext dataContext) {
return null;
}
}
@@ -13,7 +13,7 @@ import java.util.Collection;
import java.util.HashSet;
class PhpEnvironmentCallsVisitor extends PsiRecursiveElementVisitor {
final private Collection<KeyUsagePsiElement> collectedItems = new HashSet<>();
private final Collection<KeyUsagePsiElement> collectedItems = new HashSet<>();
@Override
public void visitElement(@NotNull PsiElement element) {
@@ -17,9 +17,8 @@ public class PhpEnvironmentVariablesUsagesProvider implements EnvironmentVariabl
return file.getFileType().equals(PhpFileType.INSTANCE);
}
@NotNull
@Override
public Collection<KeyUsagePsiElement> getUsages(PsiFile psiFile) {
public @NotNull Collection<KeyUsagePsiElement> getUsages(PsiFile psiFile) {
if(psiFile instanceof PhpFile) {
PhpEnvironmentCallsVisitor visitor = new PhpEnvironmentCallsVisitor();
psiFile.acceptChildren(visitor);
@@ -9,9 +9,8 @@ import org.jetbrains.annotations.Nullable;
@SuppressWarnings("UnstableApiUsage")
public class PhpFileTypeOverrider implements FileTypeOverrider {
@Nullable
@Override
public FileType getOverriddenFileType(@NotNull VirtualFile virtualFile) {
public @Nullable FileType getOverriddenFileType(@NotNull VirtualFile virtualFile) {
if (virtualFile.getName().startsWith(".env") && virtualFile.getName().endsWith(".php")) {
return PhpFileType.INSTANCE;
}
@@ -46,9 +46,8 @@ public class PhpunitEnvCompletionContributor extends BaseEnvCompletionProvider i
});
}
@Nullable
@Override
public PsiElement[] getGotoDeclarationTargets(@Nullable PsiElement psiElement, int i, Editor editor) {
public @Nullable PsiElement[] getGotoDeclarationTargets(@Nullable PsiElement psiElement, int i, Editor editor) {
if (psiElement == null) {
return PsiElement.EMPTY_ARRAY;
@@ -63,8 +62,7 @@ public class PhpunitEnvCompletionContributor extends BaseEnvCompletionProvider i
return EnvironmentVariablesApi.getKeyDeclarations(psiElement.getProject(), stringLiteral.getValue());
}
@Nullable
private XmlAttributeValue getXmlAttributeValue(@NotNull PsiElement psiElement) {
private @Nullable XmlAttributeValue getXmlAttributeValue(@NotNull PsiElement psiElement) {
PsiElement attributeValue = psiElement.getParent();
if (!(attributeValue instanceof XmlAttributeValue)) return null;
@@ -86,9 +84,8 @@ public class PhpunitEnvCompletionContributor extends BaseEnvCompletionProvider i
return (XmlAttributeValue) attributeValue;
}
@Nullable
@Override
public String getActionText(@NotNull DataContext dataContext) {
public @Nullable String getActionText(@NotNull DataContext dataContext) {
return null;
}
}
@@ -21,9 +21,8 @@ public class PhpunitEnvironmentVariablesUsagesProvider implements EnvironmentVar
return file.getFileType().equals(XmlFileType.INSTANCE) && file.getName().equals("phpunit.xml");
}
@NotNull
@Override
public Collection<KeyUsagePsiElement> getUsages(PsiFile psiFile) {
public @NotNull Collection<KeyUsagePsiElement> getUsages(PsiFile psiFile) {
if (!(psiFile instanceof XmlFile)) return Collections.emptyList();
if (!(psiFile.getFirstChild() instanceof XmlDocument)) return Collections.emptyList();
@@ -38,9 +38,8 @@ public class PythonEnvCompletionProvider extends BaseEnvCompletionProvider imple
});
}
@Nullable
@Override
public PsiElement[] getGotoDeclarationTargets(@Nullable PsiElement psiElement, int i, Editor editor) {
public @Nullable PsiElement[] getGotoDeclarationTargets(@Nullable PsiElement psiElement, int i, Editor editor) {
if (psiElement == null) {
return PsiElement.EMPTY_ARRAY;
@@ -55,8 +54,7 @@ public class PythonEnvCompletionProvider extends BaseEnvCompletionProvider imple
return EnvironmentVariablesApi.getKeyDeclarations(psiElement.getProject(), stringLiteral.getStringValue());
}
@Nullable
private PyStringLiteralExpression getStringLiteral(@NotNull PsiElement psiElement) {
private @Nullable PyStringLiteralExpression getStringLiteral(@NotNull PsiElement psiElement) {
PsiElement parent = psiElement.getParent();
if (!(parent instanceof PyStringLiteralExpression)) {
@@ -96,9 +94,8 @@ public class PythonEnvCompletionProvider extends BaseEnvCompletionProvider imple
return null;
}
@Nullable
@Override
public String getActionText(@NotNull DataContext dataContext) {
public @Nullable String getActionText(@NotNull DataContext dataContext) {
return null;
}
}
@@ -12,7 +12,7 @@ import java.util.Collection;
import java.util.HashSet;
class PythonEnvironmentCallsVisitor extends PsiRecursiveElementVisitor {
final private Collection<KeyUsagePsiElement> collectedItems = new HashSet<>();
private final Collection<KeyUsagePsiElement> collectedItems = new HashSet<>();
@Override
public void visitElement(PsiElement element) {
@@ -17,9 +17,8 @@ public class PythonEnvironmentVariablesUsagesProvider implements EnvironmentVari
return file.getFileType().equals(PythonFileType.INSTANCE);
}
@NotNull
@Override
public Collection<KeyUsagePsiElement> getUsages(PsiFile psiFile) {
public @NotNull Collection<KeyUsagePsiElement> getUsages(PsiFile psiFile) {
if(psiFile instanceof PyFile) {
PythonEnvironmentCallsVisitor visitor = new PythonEnvironmentCallsVisitor();
psiFile.acceptChildren(visitor);
@@ -42,9 +42,8 @@ public class RubyEnvCompletionProvider extends BaseEnvCompletionProvider impleme
});
}
@Nullable
@Override
public PsiElement[] getGotoDeclarationTargets(@Nullable PsiElement psiElement, int i, Editor editor) {
public @Nullable PsiElement[] getGotoDeclarationTargets(@Nullable PsiElement psiElement, int i, Editor editor) {
if (psiElement == null) {
return PsiElement.EMPTY_ARRAY;
@@ -59,8 +58,7 @@ public class RubyEnvCompletionProvider extends BaseEnvCompletionProvider impleme
return EnvironmentVariablesApi.getKeyDeclarations(psiElement.getProject(), stringLiteral.getContent());
}
@Nullable
private RStringLiteral getStringLiteral(@NotNull PsiElement psiElement) {
private @Nullable RStringLiteral getStringLiteral(@NotNull PsiElement psiElement) {
PsiElement parent = psiElement.getParent();
if (!(parent instanceof RStringLiteral)) {
@@ -94,9 +92,8 @@ public class RubyEnvCompletionProvider extends BaseEnvCompletionProvider impleme
return (RStringLiteral) parent;
}
@Nullable
@Override
public String getActionText(@NotNull DataContext dataContext) {
public @Nullable String getActionText(@NotNull DataContext dataContext) {
return null;
}
}
@@ -13,7 +13,7 @@ import java.util.HashSet;
import java.util.Objects;
class RubyEnvironmentCallsVisitor extends PsiRecursiveElementVisitor {
final private Collection<KeyUsagePsiElement> collectedItems = new HashSet<>();
private final Collection<KeyUsagePsiElement> collectedItems = new HashSet<>();
@Override
public void visitElement(PsiElement element) {
@@ -17,9 +17,8 @@ public class RubyEnvironmentVariablesUsagesProvider implements EnvironmentVariab
return file.getFileType().equals(RubyFileType.RUBY);
}
@NotNull
@Override
public Collection<KeyUsagePsiElement> getUsages(PsiFile psiFile) {
public @NotNull Collection<KeyUsagePsiElement> getUsages(PsiFile psiFile) {
if(psiFile instanceof RFile) {
RubyEnvironmentCallsVisitor visitor = new RubyEnvironmentCallsVisitor();
psiFile.acceptChildren(visitor);
@@ -32,8 +32,7 @@ public class DotEnvFactory {
return ret.get();
}
@NotNull
private static PsiFile createDummyFile(Project project, String fileText) {
private static @NotNull PsiFile createDummyFile(Project project, String fileText) {
return PsiFileFactory.getInstance(project).createFileFromText("DUMMY__.env", DotEnvFileType.INSTANCE, fileText, System.currentTimeMillis(), false);
}
}
@@ -14,27 +14,23 @@ public class DotEnvFileType extends LanguageFileType {
super(DotEnvLanguage.INSTANCE);
}
@NotNull
@Override
public String getName() {
public @NotNull String getName() {
return ".env file";
}
@NotNull
@Override
public String getDescription() {
public @NotNull String getDescription() {
return DotEnvBundle.message("label.env.file");
}
@NotNull
@Override
public String getDefaultExtension() {
public @NotNull String getDefaultExtension() {
return "env";
}
@Nullable
@Override
public Icon getIcon() {
public @Nullable Icon getIcon() {
return AllIcons.FileTypes.Text;
}
}
@@ -1,46 +1,47 @@
package ru.adelf.idea.dotenv;
import com.intellij.lang.*;
import com.intellij.lang.ASTNode;
import com.intellij.lang.ParserDefinition;
import com.intellij.lang.PsiParser;
import com.intellij.lexer.Lexer;
import com.intellij.openapi.project.Project;
import com.intellij.psi.*;
import com.intellij.psi.tree.*;
import com.intellij.psi.FileViewProvider;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiFile;
import com.intellij.psi.tree.IFileElementType;
import com.intellij.psi.tree.TokenSet;
import org.jetbrains.annotations.NotNull;
import ru.adelf.idea.dotenv.grammars.DotEnvLexerAdapter;
import ru.adelf.idea.dotenv.parser.DotEnvParser;
import ru.adelf.idea.dotenv.psi.*;
import org.jetbrains.annotations.NotNull;
import ru.adelf.idea.dotenv.psi.DotEnvFile;
import ru.adelf.idea.dotenv.psi.DotEnvTypes;
public class DotEnvParserDefinition implements ParserDefinition {
private static final TokenSet WHITE_SPACES = TokenSet.WHITE_SPACE;
private static final IFileElementType FILE = new IFileElementType(DotEnvLanguage.INSTANCE);
@NotNull
@Override
public Lexer createLexer(Project project) {
public @NotNull Lexer createLexer(Project project) {
return new DotEnvLexerAdapter();
}
@Override
@NotNull
public TokenSet getWhitespaceTokens() {
public @NotNull TokenSet getWhitespaceTokens() {
return WHITE_SPACES;
}
@Override
@NotNull
public TokenSet getCommentTokens() {
public @NotNull TokenSet getCommentTokens() {
return TokenSet.create(DotEnvTypes.COMMENT);
}
@Override
@NotNull
public TokenSet getStringLiteralElements() {
public @NotNull TokenSet getStringLiteralElements() {
return TokenSet.EMPTY;
}
@Override
@NotNull
public PsiParser createParser(final Project project) {
public @NotNull PsiParser createParser(final Project project) {
return new DotEnvParser();
}
@@ -60,8 +61,7 @@ public class DotEnvParserDefinition implements ParserDefinition {
}
@Override
@NotNull
public PsiElement createElement(ASTNode node) {
public @NotNull PsiElement createElement(ASTNode node) {
return DotEnvTypes.Factory.createElement(node);
}
}
@@ -15,9 +15,8 @@ public class DotEnvSettings implements PersistentStateComponent<DotEnvSettings>
public boolean hideValuesInTheFile = false;
@Nullable
@Override
public DotEnvSettings getState() {
public @Nullable DotEnvSettings getState() {
return this;
}
@@ -32,9 +32,8 @@ class DotEnvSyntaxHighlighter extends SyntaxHighlighterBase {
private static final TextAttributesKey[] COMMENT_KEYS = new TextAttributesKey[]{COMMENT};
private static final TextAttributesKey[] EMPTY_KEYS = TextAttributesKey.EMPTY_ARRAY;
@NotNull
@Override
public Lexer getHighlightingLexer() {
public @NotNull Lexer getHighlightingLexer() {
return new DotEnvLexerAdapter();
}
@@ -1,14 +1,14 @@
package ru.adelf.idea.dotenv;
import com.intellij.openapi.fileTypes.*;
import com.intellij.openapi.fileTypes.SyntaxHighlighter;
import com.intellij.openapi.fileTypes.SyntaxHighlighterFactory;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.vfs.VirtualFile;
import org.jetbrains.annotations.NotNull;
public class DotEnvSyntaxHighlighterFactory extends SyntaxHighlighterFactory {
@NotNull
@Override
public SyntaxHighlighter getSyntaxHighlighter(Project project, VirtualFile virtualFile) {
public @NotNull SyntaxHighlighter getSyntaxHighlighter(Project project, VirtualFile virtualFile) {
return new DotEnvSyntaxHighlighter();
}
}
@@ -12,9 +12,8 @@ import java.util.Collection;
import java.util.Collections;
public class DotEnvVariablesProvider implements EnvironmentVariablesProvider {
@NotNull
@Override
public FileAcceptResult acceptFile(VirtualFile file) {
public @NotNull FileAcceptResult acceptFile(VirtualFile file) {
if(!file.getFileType().equals(DotEnvFileType.INSTANCE)) {
return FileAcceptResult.NOT_ACCEPTED;
}
@@ -23,9 +22,8 @@ public class DotEnvVariablesProvider implements EnvironmentVariablesProvider {
return file.getName().equals(".env") ? FileAcceptResult.ACCEPTED : FileAcceptResult.ACCEPTED_SECONDARY;
}
@NotNull
@Override
public Collection<KeyValuePsiElement> getElements(PsiFile psiFile) {
public @NotNull Collection<KeyValuePsiElement> getElements(PsiFile psiFile) {
if(psiFile instanceof DotEnvFile) {
DotEnvPsiElementsVisitor visitor = new DotEnvPsiElementsVisitor();
psiFile.acceptChildren(visitor);
@@ -19,8 +19,7 @@ import java.util.*;
public class EnvironmentVariablesApi {
@NotNull
public static Map<String, String> getAllKeyValues(Project project) {
public static @NotNull Map<String, String> getAllKeyValues(Project project) {
FileBasedIndex fileBasedIndex = FileBasedIndex.getInstance();
Map<String, String> keyValues = new HashMap<>();
Map<String, String> secondaryKeyValues = new HashMap<>();
@@ -76,8 +75,7 @@ public class EnvironmentVariablesApi {
* @param key environment variable key
* @return All key declarations, in .env files, Dockerfile, docker-compose.yml, etc
*/
@NotNull
public static PsiElement[] getKeyDeclarations(Project project, String key) {
public static @NotNull PsiElement[] getKeyDeclarations(Project project, String key) {
List<PsiElement> targets = new ArrayList<>();
List<PsiElement> secondaryTargets = new ArrayList<>();
@@ -107,8 +105,7 @@ public class EnvironmentVariablesApi {
* @param key environment variable key
* @return All key usages, like getenv('KEY')
*/
@NotNull
public static PsiElement[] getKeyUsages(Project project, String key) {
public static @NotNull PsiElement[] getKeyUsages(Project project, String key) {
List<PsiElement> targets = new ArrayList<>();
PsiSearchHelper searchHelper = PsiSearchHelper.getInstance(project);
@@ -1,9 +1,9 @@
package ru.adelf.idea.dotenv.api;
public class FileAcceptResult {
public final static FileAcceptResult ACCEPTED = new FileAcceptResult(true, true);
public final static FileAcceptResult NOT_ACCEPTED = new FileAcceptResult(false, true);
public final static FileAcceptResult ACCEPTED_SECONDARY = new FileAcceptResult(true, false);
public static final FileAcceptResult ACCEPTED = new FileAcceptResult(true, true);
public static final FileAcceptResult NOT_ACCEPTED = new FileAcceptResult(false, true);
public static final FileAcceptResult ACCEPTED_SECONDARY = new FileAcceptResult(true, false);
private final boolean accepted;
private final boolean primary;
@@ -11,7 +11,7 @@ import ru.adelf.idea.dotenv.api.EnvironmentVariablesApi;
import java.util.Map;
abstract public class BaseEnvCompletionProvider extends CompletionContributor implements GotoDeclarationHandler {
public abstract class BaseEnvCompletionProvider extends CompletionContributor implements GotoDeclarationHandler {
protected void fillCompletionResultSet(@NotNull CompletionResultSet completionResultSet, @NotNull Project project) {
for (Map.Entry<String, String> entry : EnvironmentVariablesApi.getAllKeyValues(project).entrySet()) {
@@ -38,18 +38,16 @@ public class DotEnvCommenter implements Commenter, SelfManagingCommenter<Comment
return null;
}
@Nullable
@Override
public CommenterDataHolder createLineCommentingState(int startLine, int endLine, @NotNull Document document, @NotNull PsiFile file) {
public @Nullable CommenterDataHolder createLineCommentingState(int startLine, int endLine, @NotNull Document document, @NotNull PsiFile file) {
return null;
}
@Nullable
@Override
public CommenterDataHolder createBlockCommentingState(int selectionStart,
int selectionEnd,
@NotNull Document document,
@NotNull PsiFile file) {
public @Nullable CommenterDataHolder createBlockCommentingState(int selectionStart,
int selectionEnd,
@NotNull Document document,
@NotNull PsiFile file) {
return null;
}
@@ -68,30 +66,26 @@ public class DotEnvCommenter implements Commenter, SelfManagingCommenter<Comment
return CharArrayUtil.regionMatches(document.getCharsSequence(), offset, HASH_COMMENT_PREFIX);
}
@Nullable
@Override
public String getCommentPrefix(int line, @NotNull Document document, @NotNull CommenterDataHolder data) {
public @Nullable String getCommentPrefix(int line, @NotNull Document document, @NotNull CommenterDataHolder data) {
return HASH_COMMENT_PREFIX;
}
@Nullable
@Override
public TextRange getBlockCommentRange(int selectionStart,
int selectionEnd,
@NotNull Document document,
@NotNull CommenterDataHolder data) {
public @Nullable TextRange getBlockCommentRange(int selectionStart,
int selectionEnd,
@NotNull Document document,
@NotNull CommenterDataHolder data) {
throw new UnsupportedOperationException();
}
@Nullable
@Override
public String getBlockCommentPrefix(int selectionStart, @NotNull Document document, @NotNull CommenterDataHolder data) {
public @Nullable String getBlockCommentPrefix(int selectionStart, @NotNull Document document, @NotNull CommenterDataHolder data) {
return getBlockCommentPrefix();
}
@Nullable
@Override
public String getBlockCommentSuffix(int selectionEnd, @NotNull Document document, @NotNull CommenterDataHolder data) {
public @Nullable String getBlockCommentSuffix(int selectionEnd, @NotNull Document document, @NotNull CommenterDataHolder data) {
return getBlockCommentSuffix();
}
@@ -100,9 +94,8 @@ public class DotEnvCommenter implements Commenter, SelfManagingCommenter<Comment
throw new UnsupportedOperationException();
}
@NotNull
@Override
public TextRange insertBlockComment(int startOffset, int endOffset, Document document, CommenterDataHolder data) {
public @NotNull TextRange insertBlockComment(int startOffset, int endOffset, Document document, CommenterDataHolder data) {
throw new UnsupportedOperationException();
}
}
@@ -10,9 +10,8 @@ import ru.adelf.idea.dotenv.DotEnvBundle;
import ru.adelf.idea.dotenv.psi.DotEnvProperty;
public class DotEnvFindUsagesProvider implements FindUsagesProvider {
@Nullable
@Override
public WordsScanner getWordsScanner() {
public @Nullable WordsScanner getWordsScanner() {
throw new UnsupportedOperationException("Not yet implemented");
/*
TODO commented out because `DefaultWordsScanner` requires intellij.platform.indexing.impl dependency
@@ -29,15 +28,13 @@ public class DotEnvFindUsagesProvider implements FindUsagesProvider {
return psiElement instanceof PsiNamedElement;
}
@Nullable
@Override
public String getHelpId(@NotNull PsiElement psiElement) {
public @Nullable String getHelpId(@NotNull PsiElement psiElement) {
return null;
}
@NotNull
@Override
public String getType(@NotNull PsiElement element) {
public @NotNull String getType(@NotNull PsiElement element) {
if (element instanceof DotEnvProperty) {
return DotEnvBundle.message("environment.variable");
} else {
@@ -45,9 +42,8 @@ public class DotEnvFindUsagesProvider implements FindUsagesProvider {
}
}
@NotNull
@Override
public String getDescriptiveName(@NotNull PsiElement element) {
public @NotNull String getDescriptiveName(@NotNull PsiElement element) {
if (element instanceof DotEnvProperty property) {
return property.getKeyText();
} else {
@@ -55,9 +51,8 @@ public class DotEnvFindUsagesProvider implements FindUsagesProvider {
}
}
@NotNull
@Override
public String getNodeText(@NotNull PsiElement element, boolean useFullName) {
public @NotNull String getNodeText(@NotNull PsiElement element, boolean useFullName) {
if (element instanceof DotEnvProperty property) {
return property.getKeyText() + ":" + property.getValueText();
} else {
@@ -24,9 +24,8 @@ public class DotEnvReference extends PsiReferenceBase<PsiElement> implements Psi
this.key = key;
}
@NotNull
@Override
public ResolveResult[] multiResolve(boolean incompleteCode) {
public @NotNull ResolveResult[] multiResolve(boolean incompleteCode) {
final PsiElement[] elements = EnvironmentVariablesApi.getKeyDeclarations(myElement.getProject(), key);
return Arrays.stream(elements)
@@ -35,16 +34,14 @@ public class DotEnvReference extends PsiReferenceBase<PsiElement> implements Psi
.toArray(ResolveResult[]::new);
}
@Nullable
@Override
public PsiElement resolve() {
public @Nullable PsiElement resolve() {
ResolveResult[] resolveResults = multiResolve(false);
return resolveResults.length == 1 ? resolveResults[0].getElement() : null;
}
@NotNull
@Override
public Object[] getVariants() {
public @NotNull Object[] getVariants() {
Project project = myElement.getProject();
final PsiElement[] elements = EnvironmentVariablesApi.getKeyDeclarations(project, key);
@@ -17,15 +17,13 @@ public class DotEnvKeyValuesIndex extends FileBasedIndexExtension<String, String
public static final ID<String, String> KEY = ID.create("ru.adelf.idea.php.dotenv.keyValues");
@NotNull
@Override
public ID<String, String> getName() {
public @NotNull ID<String, String> getName() {
return KEY;
}
@NotNull
@Override
public DataIndexer<String, String, FileContent> getIndexer() {
public @NotNull DataIndexer<String, String, FileContent> getIndexer() {
return fileContent -> {
final Map<String, String> map = new HashMap<>();
@@ -45,21 +43,18 @@ public class DotEnvKeyValuesIndex extends FileBasedIndexExtension<String, String
};
}
@NotNull
@Override
public KeyDescriptor<String> getKeyDescriptor() {
public @NotNull KeyDescriptor<String> getKeyDescriptor() {
return EnumeratorStringDescriptor.INSTANCE;
}
@NotNull
@Override
public DataExternalizer<String> getValueExternalizer() {
public @NotNull DataExternalizer<String> getValueExternalizer() {
return EnumeratorStringDescriptor.INSTANCE;
}
@NotNull
@Override
public FileBasedIndex.InputFilter getInputFilter() {
public @NotNull FileBasedIndex.InputFilter getInputFilter() {
return file -> {
for (EnvironmentVariablesProvider provider : EnvironmentVariablesProviderUtil.getEnvVariablesProviders()) {
if (provider.acceptFile(file).isAccepted()) return true;
@@ -21,9 +21,8 @@ import java.util.Set;
public class DuplicateKeyInspection extends LocalInspectionTool {
// Change the display name within the plugin.xml
// This needs to be here as otherwise the tests will throw errors.
@NotNull
@Override
public String getDisplayName() {
public @NotNull String getDisplayName() {
return DotEnvBundle.message("inspection.message.duplicate.key");
}
@@ -32,9 +31,8 @@ public class DuplicateKeyInspection extends LocalInspectionTool {
return true;
}
@Nullable
@Override
public ProblemDescriptor[] checkFile(@NotNull PsiFile file, @NotNull InspectionManager manager, boolean isOnTheFly) {
public @Nullable ProblemDescriptor[] checkFile(@NotNull PsiFile file, @NotNull InspectionManager manager, boolean isOnTheFly) {
if(!(file instanceof DotEnvFile)) {
return null;
}
@@ -42,8 +40,7 @@ public class DuplicateKeyInspection extends LocalInspectionTool {
return analyzeFile(file, manager, isOnTheFly).getResultsArray();
}
@NotNull
private static ProblemsHolder analyzeFile(@NotNull PsiFile file, @NotNull InspectionManager manager, boolean isOnTheFly) {
private static @NotNull ProblemsHolder analyzeFile(@NotNull PsiFile file, @NotNull InspectionManager manager, boolean isOnTheFly) {
DotEnvPsiElementsVisitor visitor = new DotEnvPsiElementsVisitor();
file.acceptChildren(visitor);
@@ -21,9 +21,8 @@ import java.util.regex.Pattern;
public class ExtraBlankLineInspection extends LocalInspectionTool {
// Change the display name within the plugin.xml
// This needs to be here as otherwise the tests will throw errors.
@NotNull
@Override
public String getDisplayName() {
public @NotNull String getDisplayName() {
return DotEnvBundle.message("inspection.name.extra.blank.line");
}
@@ -41,8 +40,7 @@ public class ExtraBlankLineInspection extends LocalInspectionTool {
return analyzeFile(file, manager, isOnTheFly).getResultsArray();
}
@NotNull
private static ProblemsHolder analyzeFile(@NotNull PsiFile file, @NotNull InspectionManager manager, boolean isOnTheFly) {
private static @NotNull ProblemsHolder analyzeFile(@NotNull PsiFile file, @NotNull InspectionManager manager, boolean isOnTheFly) {
ProblemsHolder problemsHolder = new ProblemsHolder(manager, file, isOnTheFly);
PsiTreeUtil.findChildrenOfType(file, PsiWhiteSpaceImpl.class).forEach(whiteSpace -> {
@@ -65,9 +63,8 @@ public class ExtraBlankLineInspection extends LocalInspectionTool {
private static class RemoveExtraBlankLineQuickFix implements LocalQuickFix {
@NotNull
@Override
public String getName() {
public @NotNull String getName() {
return DotEnvBundle.message("intention.name.remove.extra.blank.line");
}
@@ -85,8 +82,7 @@ public class ExtraBlankLineInspection extends LocalInspectionTool {
}
@Override
@NotNull
public String getFamilyName() {
public @NotNull String getFamilyName() {
return getName();
}
}
@@ -18,9 +18,8 @@ import ru.adelf.idea.dotenv.psi.impl.DotEnvKeyImpl;
public class IncorrectDelimiterInspection extends LocalInspectionTool {
// Change the display name within the plugin.xml
// This needs to be here as otherwise the tests will throw errors.
@NotNull
@Override
public String getDisplayName() {
public @NotNull String getDisplayName() {
return DotEnvBundle.message("inspection.name.incorrect.delimiter");
}
@@ -29,9 +28,8 @@ public class IncorrectDelimiterInspection extends LocalInspectionTool {
return true;
}
@Nullable
@Override
public ProblemDescriptor[] checkFile(@NotNull PsiFile file, @NotNull InspectionManager manager, boolean isOnTheFly) {
public @Nullable ProblemDescriptor[] checkFile(@NotNull PsiFile file, @NotNull InspectionManager manager, boolean isOnTheFly) {
if (!(file instanceof DotEnvFile)) {
return null;
}
@@ -39,8 +37,7 @@ public class IncorrectDelimiterInspection extends LocalInspectionTool {
return analyzeFile(file, manager, isOnTheFly).getResultsArray();
}
@NotNull
private static ProblemsHolder analyzeFile(@NotNull PsiFile file, @NotNull InspectionManager manager, boolean isOnTheFly) {
private static @NotNull ProblemsHolder analyzeFile(@NotNull PsiFile file, @NotNull InspectionManager manager, boolean isOnTheFly) {
ProblemsHolder problemsHolder = new ProblemsHolder(manager, file, isOnTheFly);
PsiTreeUtil.findChildrenOfType(file, DotEnvKeyImpl.class).forEach(key -> {
@@ -55,9 +52,8 @@ public class IncorrectDelimiterInspection extends LocalInspectionTool {
private static class ReplaceDelimiterQuickFix implements LocalQuickFix {
@NotNull
@Override
public String getName() {
public @NotNull String getName() {
return DotEnvBundle.message("intention.name.replace.delimiter");
}
@@ -76,8 +72,7 @@ public class IncorrectDelimiterInspection extends LocalInspectionTool {
}
@Override
@NotNull
public String getFamilyName() {
public @NotNull String getFamilyName() {
return getName();
}
}
@@ -15,9 +15,8 @@ import ru.adelf.idea.dotenv.psi.DotEnvKey;
public class LeadingCharacterInspection extends LocalInspectionTool {
// Change the display name within the plugin.xml
// This needs to be here as otherwise the tests will throw errors.
@NotNull
@Override
public String getDisplayName() {
public @NotNull String getDisplayName() {
return DotEnvBundle.message("inspection.name.invalid.leading.character");
}
@@ -30,8 +29,7 @@ public class LeadingCharacterInspection extends LocalInspectionTool {
return analyzeFile(file, manager, isOnTheFly).getResultsArray();
}
@NotNull
private static ProblemsHolder analyzeFile(@NotNull PsiFile file, @NotNull InspectionManager manager, boolean isOnTheFly) {
private static @NotNull ProblemsHolder analyzeFile(@NotNull PsiFile file, @NotNull InspectionManager manager, boolean isOnTheFly) {
ProblemsHolder problemsHolder = new ProblemsHolder(manager, file, isOnTheFly);
PsiTreeUtil.findChildrenOfType(file, DotEnvKey.class).forEach(dotEnvKey -> {
@@ -20,9 +20,8 @@ import java.util.Locale;
public class LowercaseKeyInspection extends LocalInspectionTool {
// Change the display name within the plugin.xml
// This needs to be here as otherwise the tests will throw errors.
@NotNull
@Override
public String getDisplayName() {
public @NotNull String getDisplayName() {
return DotEnvBundle.message("inspection.name.key.uses.lowercase.chars");
}
@@ -35,8 +34,7 @@ public class LowercaseKeyInspection extends LocalInspectionTool {
return analyzeFile(file, manager, isOnTheFly).getResultsArray();
}
@NotNull
private static ProblemsHolder analyzeFile(@NotNull PsiFile file, @NotNull InspectionManager manager, boolean isOnTheFly) {
private static @NotNull ProblemsHolder analyzeFile(@NotNull PsiFile file, @NotNull InspectionManager manager, boolean isOnTheFly) {
ProblemsHolder problemsHolder = new ProblemsHolder(manager, file, isOnTheFly);
PsiTreeUtil.findChildrenOfType(file, DotEnvKey.class).forEach(dotEnvKey -> {
@@ -53,9 +51,8 @@ public class LowercaseKeyInspection extends LocalInspectionTool {
private static class ForceUppercaseQuickFix implements LocalQuickFix {
@NotNull
@Override
public String getName() {
public @NotNull String getName() {
return DotEnvBundle.message("intention.name.change.to.uppercase");
}
@@ -74,8 +71,7 @@ public class LowercaseKeyInspection extends LocalInspectionTool {
}
@Override
@NotNull
public String getFamilyName() {
public @NotNull String getFamilyName() {
return getName();
}
}
@@ -21,9 +21,8 @@ import java.util.regex.Pattern;
public class SpaceAroundSeparatorInspection extends LocalInspectionTool {
// Change the display name within the plugin.xml
// This needs to be here as otherwise the tests will throw errors.
@NotNull
@Override
public String getDisplayName() {
public @NotNull String getDisplayName() {
return DotEnvBundle.message("inspection.name.extra.spaces.surrounding");
}
@@ -36,8 +35,7 @@ public class SpaceAroundSeparatorInspection extends LocalInspectionTool {
return analyzeFile(file, manager, isOnTheFly).getResultsArray();
}
@NotNull
private static ProblemsHolder analyzeFile(@NotNull PsiFile file, @NotNull InspectionManager manager, boolean isOnTheFly) {
private static @NotNull ProblemsHolder analyzeFile(@NotNull PsiFile file, @NotNull InspectionManager manager, boolean isOnTheFly) {
ProblemsHolder problemsHolder = new ProblemsHolder(manager, file, isOnTheFly);
PsiTreeUtil.findChildrenOfType(file, DotEnvProperty.class).forEach(dotEnvProperty -> {
@@ -62,9 +60,8 @@ public class SpaceAroundSeparatorInspection extends LocalInspectionTool {
private static class RemoveSpaceAroundSeparatorQuickFix implements LocalQuickFix {
@NotNull
@Override
public String getName() {
public @NotNull String getName() {
return DotEnvBundle.message("intention.name.remove.spaces.surrounding");
}
@@ -89,8 +86,7 @@ public class SpaceAroundSeparatorInspection extends LocalInspectionTool {
}
@Override
@NotNull
public String getFamilyName() {
public @NotNull String getFamilyName() {
return getName();
}
}
@@ -21,9 +21,8 @@ import java.util.stream.Stream;
public class SpaceInsideNonQuotedInspection extends LocalInspectionTool {
// Change the display name within the plugin.xml
// This needs to be here as otherwise the tests will throw errors.
@NotNull
@Override
public String getDisplayName() {
public @NotNull String getDisplayName() {
return DotEnvBundle.message("inspection.name.space.inside.non.quoted.value");
}
@@ -43,8 +42,7 @@ public class SpaceInsideNonQuotedInspection extends LocalInspectionTool {
return analyzeFile(file, manager, isOnTheFly).getResultsArray();
}
@NotNull
private ProblemsHolder analyzeFile(@NotNull PsiFile file, @NotNull InspectionManager manager, boolean isOnTheFly) {
private @NotNull ProblemsHolder analyzeFile(@NotNull PsiFile file, @NotNull InspectionManager manager, boolean isOnTheFly) {
ProblemsHolder problemsHolder = new ProblemsHolder(manager, file, isOnTheFly);
PsiTreeUtil.findChildrenOfType(file, DotEnvValue.class).forEach(dotEnvValue -> {
@@ -63,9 +61,8 @@ public class SpaceInsideNonQuotedInspection extends LocalInspectionTool {
private static class AddQuotesQuickFix implements LocalQuickFix {
@NotNull
@Override
public String getName() {
public @NotNull String getName() {
return DotEnvBundle.message("intention.name.add.quotes");
}
@@ -104,8 +101,7 @@ public class SpaceInsideNonQuotedInspection extends LocalInspectionTool {
}
@Override
@NotNull
public String getFamilyName() {
public @NotNull String getFamilyName() {
return getName();
}
}
@@ -22,9 +22,8 @@ import ru.adelf.idea.dotenv.psi.impl.DotEnvValueImpl;
public class TrailingWhitespaceInspection extends LocalInspectionTool {
// Change the display name within the plugin.xml
// This needs to be here as otherwise the tests will throw errors.
@NotNull
@Override
public String getDisplayName() {
public @NotNull String getDisplayName() {
return DotEnvBundle.message("inspection.name.value.has.trailing.whitespace");
}
@@ -37,8 +36,7 @@ public class TrailingWhitespaceInspection extends LocalInspectionTool {
return analyzeFile(file, manager, isOnTheFly).getResultsArray();
}
@NotNull
private static ProblemsHolder analyzeFile(@NotNull PsiFile file, @NotNull InspectionManager manager, boolean isOnTheFly) {
private static @NotNull ProblemsHolder analyzeFile(@NotNull PsiFile file, @NotNull InspectionManager manager, boolean isOnTheFly) {
ProblemsHolder problemsHolder = new ProblemsHolder(manager, file, isOnTheFly);
PsiTreeUtil.findChildrenOfType(file, DotEnvValue.class).forEach(dotEnvValue -> {
@@ -65,9 +63,8 @@ public class TrailingWhitespaceInspection extends LocalInspectionTool {
private static class RemoveTrailingWhitespaceQuickFix implements LocalQuickFix {
@NotNull
@Override
public String getName() {
public @NotNull String getName() {
return DotEnvBundle.message("intention.name.remove.trailing.whitespace");
}
@@ -91,8 +88,7 @@ public class TrailingWhitespaceInspection extends LocalInspectionTool {
}
@Override
@NotNull
public String getFamilyName() {
public @NotNull String getFamilyName() {
return getName();
}
}
@@ -15,13 +15,11 @@ public class EnvironmentKeyValue {
this.value = value;
}
@NotNull
public String getKey() {
public @NotNull String getKey() {
return key;
}
@NotNull
public String getValue() {
public @NotNull String getValue() {
return value;
}
}
@@ -3,8 +3,9 @@ package ru.adelf.idea.dotenv.psi;
import com.intellij.extapi.psi.PsiFileBase;
import com.intellij.openapi.fileTypes.FileType;
import com.intellij.psi.FileViewProvider;
import ru.adelf.idea.dotenv.*;
import org.jetbrains.annotations.NotNull;
import ru.adelf.idea.dotenv.DotEnvFileType;
import ru.adelf.idea.dotenv.DotEnvLanguage;
import javax.swing.*;
@@ -13,9 +14,8 @@ public class DotEnvFile extends PsiFileBase {
super(viewProvider, DotEnvLanguage.INSTANCE);
}
@NotNull
@Override
public FileType getFileType() {
public @NotNull FileType getFileType() {
return DotEnvFileType.INSTANCE;
}
@@ -16,15 +16,13 @@ public class DotEnvSettingsConfigurable implements Configurable {
private JCheckBox storeValuesCheckbox;
private JCheckBox hideValuesCheckbox;
@Nls
@Override
public String getDisplayName() {
public @Nls String getDisplayName() {
return "DotEnv";
}
@Nullable
@Override
public JComponent createComponent() {
public @Nullable JComponent createComponent() {
DotEnvSettings settings = getSettings();
Border standardBorder = BorderFactory.createEmptyBorder(5, 5, 5, 5);
@@ -11,8 +11,7 @@ import java.util.Set;
import java.util.stream.Collectors;
public class EnvironmentVariablesUtil {
@NotNull
public static EnvironmentKeyValue getKeyValueFromString(@NotNull String s) {
public static @NotNull EnvironmentKeyValue getKeyValueFromString(@NotNull String s) {
int pos = s.indexOf("=");
if(pos == -1) {
@@ -22,8 +21,7 @@ public class EnvironmentVariablesUtil {
}
}
@NotNull
public static String getKeyFromString(@NotNull String s) {
public static @NotNull String getKeyFromString(@NotNull String s) {
int pos = s.indexOf("=");
if(pos == -1) {
@@ -33,13 +31,11 @@ public class EnvironmentVariablesUtil {
}
}
@NotNull
public static Set<PsiElement> getElementsByKey(String key, Collection<KeyValuePsiElement> items) {
public static @NotNull Set<PsiElement> getElementsByKey(String key, Collection<KeyValuePsiElement> items) {
return items.stream().filter(item -> item.getKey().equals(key)).map(KeyValuePsiElement::getElement).collect(Collectors.toSet());
}
@NotNull
public static Set<PsiElement> getUsagesElementsByKey(String key, Collection<KeyUsagePsiElement> items) {
public static @NotNull Set<PsiElement> getUsagesElementsByKey(String key, Collection<KeyUsagePsiElement> items) {
return items.stream().filter(item -> item.getKey().equals(key)).map(KeyUsagePsiElement::getElement).collect(Collectors.toSet());
}
}
@@ -1,4 +1,4 @@
// Copyright 2000-2021 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package org.jetbrains.plugins.gradle.codeInsight.actions;
import com.intellij.codeInsight.CodeInsightActionHandler;
@@ -43,9 +43,8 @@ public class AddGradleDslPluginAction extends CodeInsightAction {
myPlugins.sort(Comparator.comparing(p -> p.name()));
}
@NotNull
@Override
protected CodeInsightActionHandler getHandler() {
protected @NotNull CodeInsightActionHandler getHandler() {
return new AddGradleDslPluginActionHandler(myPlugins);
}
@@ -399,8 +399,7 @@ public class ClassWriter {
}
}
@NotNull
private static AnnotationContainer collectAllAnnotations(@Nullable StructMember mt) {
private static @NotNull AnnotationContainer collectAllAnnotations(@Nullable StructMember mt) {
AnnotationContainer result = new AnnotationContainer(new HashSet<>(), new HashSet<>());
if (mt == null) {
return result;
@@ -1088,8 +1087,7 @@ public class ClassWriter {
record RecordConstructorContext(boolean hideConstructor, boolean compact) { }
@NotNull
private static List<AnnotationExprent> collectParameterAnnotations(StructMethod mt, Type type, int param) {
private static @NotNull List<AnnotationExprent> collectParameterAnnotations(StructMethod mt, Type type, int param) {
List<AnnotationExprent> result = new ArrayList<>();
if (mt == null || type == null) return result;
for (StructGeneralAttribute.Key<?> key : StructGeneralAttribute.PARAMETER_ANNOTATION_ATTRIBUTES) {
@@ -25,20 +25,13 @@ public class DecompilerContext {
public static final String IN_CLASS_TYPE_PARAMS = "IN_CLASS_TYPE_PARAMS";
public static final String RENAMER_FACTORY = "RENAMER_FACTORY";
@NotNull
private final Map<String, Object> properties;
@NotNull
private final IFernflowerLogger logger;
@NotNull
private final StructContext structContext;
@NotNull
private final ClassesProcessor classProcessor;
@Nullable
private final PoolInterceptor poolInterceptor;
@NotNull
private final CancellationManager cancellationManager;
@NotNull
private final IVariableNamingFactory renamerFactory;
private final @NotNull Map<String, Object> properties;
private final @NotNull IFernflowerLogger logger;
private final @NotNull StructContext structContext;
private final @NotNull ClassesProcessor classProcessor;
private final @Nullable PoolInterceptor poolInterceptor;
private final @NotNull CancellationManager cancellationManager;
private final @NotNull IVariableNamingFactory renamerFactory;
private ImportCollector importCollector;
private VarProcessor varProcessor;
private CounterContainer counterContainer;
@@ -1,4 +1,4 @@
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package org.jetbrains.java.decompiler.modules.decompiler;
import org.jetbrains.annotations.NotNull;
@@ -352,8 +352,7 @@ public class FinallyProcessor {
}
}
@NotNull
private static BasicBlock createHeadBlock(ControlFlowGraph graph, int value, int var, int bytecodeVersion, int storeLength) {
private static @NotNull BasicBlock createHeadBlock(ControlFlowGraph graph, int value, int var, int bytecodeVersion, int storeLength) {
SimpleInstructionSequence seq = new SimpleInstructionSequence();
seq.addInstruction(Instruction.create(CodeConstants.opc_bipush, false, CodeConstants.GROUP_GENERAL, bytecodeVersion, new int[]{value}, 1), -1);
seq.addInstruction(Instruction.create(CodeConstants.opc_istore, false, CodeConstants.GROUP_GENERAL, bytecodeVersion, new int[]{var}, storeLength), -1);
@@ -1,4 +1,4 @@
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package org.jetbrains.java.decompiler.modules.decompiler;
import org.jetbrains.annotations.NotNull;
@@ -92,8 +92,7 @@ public final class PatternHelper {
return actions;
}
@Nullable
private static FunctionExprent findInstanceofExprent(@NotNull IfStatement ifStat) {
private static @Nullable FunctionExprent findInstanceofExprent(@NotNull IfStatement ifStat) {
return ifStat.getHeadexprent().getAllExprents(true).stream()
.filter(expr -> expr.type == Exprent.EXPRENT_FUNCTION).map(expr -> (FunctionExprent)expr)
.filter(expr -> expr.getFuncType() == FunctionExprent.FUNCTION_INSTANCEOF)
@@ -126,12 +125,11 @@ public final class PatternHelper {
return null;
}
@Nullable
static PatternVariableCandidate findNextPatternVarCandidate(@NotNull Statement ifBranch,
@NotNull VarExprent operand,
@NotNull ConstExprent checkType,
@NotNull VarTracker varTracker,
@NotNull Statement topLevelStatement) {
static @Nullable PatternVariableCandidate findNextPatternVarCandidate(@NotNull Statement ifBranch,
@NotNull VarExprent operand,
@NotNull ConstExprent checkType,
@NotNull VarTracker varTracker,
@NotNull Statement topLevelStatement) {
if (ifBranch instanceof BasicBlockStatement) {
//check that cast correct and get the last assignment
@@ -162,11 +160,10 @@ public final class PatternHelper {
return null;
}
@Nullable
private static PatternVariableCandidate findSimpleCandidateFromIfStat(@NotNull Statement ifElseStat,
@NotNull VarExprent operand,
@NotNull ConstExprent checkType,
@NotNull Statement topLevelStatement) {
private static @Nullable PatternVariableCandidate findSimpleCandidateFromIfStat(@NotNull Statement ifElseStat,
@NotNull VarExprent operand,
@NotNull ConstExprent checkType,
@NotNull Statement topLevelStatement) {
List<Exprent> ifElseExprents = ifElseStat.getExprents();
if (ifElseExprents==null || ifElseExprents.isEmpty() || ifElseExprents.get(0).type != Exprent.EXPRENT_ASSIGNMENT) return null;
@@ -227,9 +224,8 @@ public final class PatternHelper {
return findRecordPatternCandidate(parentSequenceStatement, varTracker);
}
@Nullable
private static PatternVariableCandidate findRecordPatternCandidate(@NotNull Statement parent,
@NotNull VarTracker varTracker) {
private static @Nullable PatternVariableCandidate findRecordPatternCandidate(@NotNull Statement parent,
@NotNull VarTracker varTracker) {
if (!(parent instanceof SequenceStatement)) {
return null;
}
@@ -552,7 +548,7 @@ public final class PatternHelper {
private final @NotNull Runnable cleaner;
private final @NotNull Set<IfStatement> usedIfStatement = new HashSet<>();
private final @NotNull Statement nextStatement;
@Nullable private Exprent guards;
private @Nullable Exprent guards;
PatternVariableCandidate(@NotNull VarExprent varExprent,
@NotNull Statement nextStatement,
@@ -600,12 +596,9 @@ public final class PatternHelper {
}
static class VarTracker {
@NotNull
private RecordVarExprent root;
@NotNull
private final Map<VarExprent, RecordVarExprent> varRecordTracker = new HashMap<>();
@NotNull
private final List<TempVarAssignmentItem> varTempAssignmentTracker = new ArrayList<>();
private @NotNull RecordVarExprent root;
private final @NotNull Map<VarExprent, RecordVarExprent> varRecordTracker = new HashMap<>();
private final @NotNull List<TempVarAssignmentItem> varTempAssignmentTracker = new ArrayList<>();
VarTracker(@NotNull RecordVarExprent root) { this.root = root; }
@@ -1,4 +1,4 @@
// Copyright 2000-2023 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-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package org.jetbrains.java.decompiler.modules.decompiler;
import org.jetbrains.annotations.NotNull;
@@ -141,9 +141,8 @@ public final class SwitchHelper {
}
}
@NotNull
private static Map<Exprent, Exprent> evaluateCaseLabelsToFieldsMapping(@NotNull List<List<Exprent>> caseValues,
@NotNull ArrayExprent array) {
private static @NotNull Map<Exprent, Exprent> evaluateCaseLabelsToFieldsMapping(@NotNull List<List<Exprent>> caseValues,
@NotNull ArrayExprent array) {
Map<Exprent, Exprent> mapping = new HashMap<>(caseValues.size());
if (array.getArray().type == Exprent.EXPRENT_FIELD) { // Javac compiler
FieldExprent arrayField = (FieldExprent)array.getArray();
@@ -186,9 +185,8 @@ public final class SwitchHelper {
return mapping;
}
@Nullable
private static List<List<@Nullable Exprent>> findRealCaseValues(@NotNull List<List<Exprent>> caseValues,
@NotNull Map<Exprent, Exprent> mapping) {
private static @Nullable List<List<@Nullable Exprent>> findRealCaseValues(@NotNull List<List<Exprent>> caseValues,
@NotNull Map<Exprent, Exprent> mapping) {
List<List<@Nullable Exprent>> result = new ArrayList<>(caseValues.size());
for (List<Exprent> caseValue : caseValues) {
List<@Nullable Exprent> values = new ArrayList<>(caseValue.size());
@@ -371,8 +369,7 @@ public final class SwitchHelper {
private abstract static class StringSwitchRecognizer implements SwitchRecognizer {
@Override
@Nullable
public abstract SwitchOnStringCandidate recognize(@NotNull SwitchStatement statement, @NotNull InvocationExprent switchSelector);
public abstract @Nullable SwitchOnStringCandidate recognize(@NotNull SwitchStatement statement, @NotNull InvocationExprent switchSelector);
@NotNull
Set<Object> findRealCaseValuesHashCodes(@NotNull SwitchStatement switchStatement) {
@@ -430,9 +427,8 @@ public final class SwitchHelper {
* @return recognized a switch candidate
* see Lower.visitStringSwitch(JCTree.JCSwitch) in javac
*/
@Nullable
@Override
public SwitchOnStringCandidate recognize(@NotNull SwitchStatement firstSwitch,
public @Nullable SwitchOnStringCandidate recognize(@NotNull SwitchStatement firstSwitch,
@NotNull InvocationExprent switchSelector) {
if (switchSelector.getInstance() == null || switchSelector.getInstance().type != Exprent.EXPRENT_VAR) return null;
if (!switchSelector.isInstanceCall(ClassNameConstants.JAVA_LANG_STRING, "hashCode", 0)) return null;
@@ -500,9 +496,8 @@ public final class SwitchHelper {
}
private static class EcjStringRecognizer extends StringSwitchRecognizer {
@Nullable
@Override
public SwitchOnStringCandidate recognize(@NotNull SwitchStatement switchStatement, @NotNull InvocationExprent switchSelector) {
public @Nullable SwitchOnStringCandidate recognize(@NotNull SwitchStatement switchStatement, @NotNull InvocationExprent switchSelector) {
if (!switchSelector.isInstanceCall(ClassNameConstants.JAVA_LANG_STRING, "hashCode", 0)) return null;
Set<Object> realCaseValueHashCodes = findRealCaseValuesHashCodes(switchStatement);
Exprent switchSelectorQualifier = switchSelector.getInstance();
@@ -561,11 +556,10 @@ public final class SwitchHelper {
}
private abstract static class SwitchOnStringCandidate implements SwitchOnCandidate {
@Nullable
private static AssignmentExprent addTempVarAssignment(@NotNull Exprent exprent,
@NotNull VarExprent varExprent,
@NotNull Statement statement,
@NotNull List<TempVarAssignmentItem> tempVarAssignments) {
private static @Nullable AssignmentExprent addTempVarAssignment(@NotNull Exprent exprent,
@NotNull VarExprent varExprent,
@NotNull Statement statement,
@NotNull List<TempVarAssignmentItem> tempVarAssignments) {
if (exprent.type != Exprent.EXPRENT_ASSIGNMENT) return null;
AssignmentExprent assignment = (AssignmentExprent)exprent;
if (!varExprent.isDefinition() && varExprent.equals(assignment.getLeft())) {
@@ -576,16 +570,16 @@ public final class SwitchHelper {
}
private static class JavacSwitchCandidate extends SwitchOnStringCandidate {
@NotNull private final SwitchStatement firstSwitch;
@NotNull private final SwitchStatement secondSwitch;
@NotNull private final VarExprent firstSwitchSelector;
@NotNull private final Exprent secondSwitchSelector;
@NotNull private final VarExprent tmpVarInFirstSwitch;
@NotNull private final Map<Integer, @NotNull String> mappedCaseLabelValues;
@NotNull private final List<Exprent> firstSwitchExprents;
@NotNull private final Statement firstStatementInSecondSwitch;
@NotNull private final NewSelector newSelector;
@NotNull private final List<TempVarAssignmentItem> tempVarAssignments = new ArrayList<>();
private final @NotNull SwitchStatement firstSwitch;
private final @NotNull SwitchStatement secondSwitch;
private final @NotNull VarExprent firstSwitchSelector;
private final @NotNull Exprent secondSwitchSelector;
private final @NotNull VarExprent tmpVarInFirstSwitch;
private final @NotNull Map<Integer, @NotNull String> mappedCaseLabelValues;
private final @NotNull List<Exprent> firstSwitchExprents;
private final @NotNull Statement firstStatementInSecondSwitch;
private final @NotNull NewSelector newSelector;
private final @NotNull List<TempVarAssignmentItem> tempVarAssignments = new ArrayList<>();
JavacSwitchCandidate(@NotNull SwitchStatement firstSwitch,
@NotNull VarExprent firstSwitchSelector,
@@ -652,8 +646,7 @@ public final class SwitchHelper {
return Set.of(firstSwitch, secondSwitch);
}
@NotNull
private NewSelector getSelector(@NotNull List<TempVarAssignmentItem> tempVarAssignments, List<Exprent> firstSwitchExprents) {
private @NotNull NewSelector getSelector(@NotNull List<TempVarAssignmentItem> tempVarAssignments, List<Exprent> firstSwitchExprents) {
int lastExprentIndex = firstSwitchExprents.size();
if (lastExprentIndex > 0) {
AssignmentExprent assignment = addTempVarAssignment(firstSwitchExprents.get(lastExprentIndex - 1), tmpVarInFirstSwitch,
@@ -684,11 +677,11 @@ public final class SwitchHelper {
}
private static class EcjSwitchCandidate extends SwitchOnStringCandidate {
@NotNull private final SwitchStatement switchStatement;
@NotNull private final Exprent switchSelector;
@NotNull private final Map<Integer, @NotNull IfStatement> mappedIfStatements;
@NotNull private final Map<Integer, @NotNull String> mappedCaseLabelValues;
@NotNull private final List<TempVarAssignmentItem> tempVarAssignments = new ArrayList<>();
private final @NotNull SwitchStatement switchStatement;
private final @NotNull Exprent switchSelector;
private final @NotNull Map<Integer, @NotNull IfStatement> mappedIfStatements;
private final @NotNull Map<Integer, @NotNull String> mappedCaseLabelValues;
private final @NotNull List<TempVarAssignmentItem> tempVarAssignments = new ArrayList<>();
private EcjSwitchCandidate(@NotNull SwitchStatement switchStatement,
@NotNull Exprent switchSelector,
@@ -1,4 +1,4 @@
// Copyright 2000-2023 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-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package org.jetbrains.java.decompiler.modules.decompiler;
import org.jetbrains.annotations.NotNull;
@@ -99,24 +99,18 @@ public final class SwitchPatternHelper {
/**
* not null for nested switch
*/
@Nullable
private final VarTracker myVarTracker;
private final @Nullable VarTracker myVarTracker;
/**
* Represents a set of type variables, which is used as second parameter in bootstrap call.
*/
@NotNull
private final Set<Exprent> myTypeVars;
@NotNull
private final SwitchStatement myRootSwitchStatement;
@NotNull
private final InvocationExprent mySwitchSelector;
private final @NotNull Set<Exprent> myTypeVars;
private final @NotNull SwitchStatement myRootSwitchStatement;
private final @NotNull InvocationExprent mySwitchSelector;
@NotNull
private final List<TempVarAssignmentItem> myTempVarAssignments = new ArrayList<>();
private final @NotNull List<TempVarAssignmentItem> myTempVarAssignments = new ArrayList<>();
@NotNull
private final Set<SwitchStatement> myUsedSwitch = new HashSet<>();
private final @NotNull Set<SwitchStatement> myUsedSwitch = new HashSet<>();
private JavacReferenceFinder(@Nullable VarTracker tracker,
@NotNull Set<Exprent> typeVars,
@@ -214,8 +208,7 @@ public final class SwitchPatternHelper {
});
}
@NotNull
private SwitchPatternHelper.JavacReferenceFinder.Initializer findInitializer(@NotNull Root root, Exprent typeVar) {
private @NotNull SwitchPatternHelper.JavacReferenceFinder.Initializer findInitializer(@NotNull Root root, Exprent typeVar) {
Exprent instance = Objects.requireNonNull(mySwitchSelector.getInstance());
Exprent nonNullCheck = null;
@@ -263,8 +256,7 @@ public final class SwitchPatternHelper {
*
* @return The `Root` object representing the root `DoStatement` and expression statements, or null if not found.
*/
@Nullable
private Root getRoot() {
private @Nullable Root getRoot() {
Statement first = myRootSwitchStatement.getFirst();
if (first == null) {
return null;
@@ -428,8 +420,7 @@ public final class SwitchPatternHelper {
return false;
}
@Nullable
private static List<FullCase> resortForSwitchBootstrap(@NotNull SwitchStatement statement) {
private static @Nullable List<FullCase> resortForSwitchBootstrap(@NotNull SwitchStatement statement) {
for (Statement caseStatement : statement.getCaseStatements()) {
if (caseStatement == null) {
return null;
@@ -514,8 +505,7 @@ public final class SwitchPatternHelper {
return sortedAll;
}
@NotNull
private static VarExprent createDefaultPatternVal(@NotNull String className) {
private static @NotNull VarExprent createDefaultPatternVal(@NotNull String className) {
VarProcessor processor = DecompilerContext.getVarProcessor();
VarExprent varExprent = new VarExprent(DecompilerContext.getCounterContainer().getCounterAndIncrement(CounterContainer.VAR_COUNTER),
new VarType(CodeConstants.TYPE_OBJECT, 0, className),
@@ -528,8 +518,7 @@ public final class SwitchPatternHelper {
/**
* @return A map of case statements from switch and their pattern variable candidates, or null if the collection fails.
*/
@Nullable
private Map<Statement, List<PatternVariableCandidate>> collectPatterns(@NotNull VarExprent instance,
private @Nullable Map<Statement, List<PatternVariableCandidate>> collectPatterns(@NotNull VarExprent instance,
@Nullable DoStatement doStatement,
@NotNull Set<AssignmentExprent> assignmentExprents) {
@@ -659,8 +648,7 @@ public final class SwitchPatternHelper {
* @param usedAssignments a set of used assignments
* @return a PatternContainer object containing the collected guards
*/
@NotNull
private SwitchPatternHelper.PatternContainer collectGuards(@NotNull Map<Statement, List<PatternVariableCandidate>> candidates,
private @NotNull SwitchPatternHelper.PatternContainer collectGuards(@NotNull Map<Statement, List<PatternVariableCandidate>> candidates,
@NotNull Exprent typeVar,
@Nullable Statement doParentStatement,
@NotNull Set<AssignmentExprent> usedAssignments) {
@@ -791,8 +779,7 @@ public final class SwitchPatternHelper {
* @param assignmentExprent The AssignmentExprent to add (from last).
* @return The normalized PatternVariableCandidate or null if normalization fails.
*/
@Nullable
private PatternVariableCandidate normalizeCandidateWithBrokenEdges(@NotNull PatternVariableCandidate oldCandidate,
private @Nullable PatternVariableCandidate normalizeCandidateWithBrokenEdges(@NotNull PatternVariableCandidate oldCandidate,
@NotNull SequenceStatement newSequence,
@NotNull SequenceStatement previousSequenceStatement,
@NotNull Statement last,
@@ -884,8 +871,7 @@ public final class SwitchPatternHelper {
* @return A list of pattern variable candidates or null, if it is impossible
* List with only previousCandidate can be returned, if nested switch is not found
*/
@Nullable
private List<PatternVariableCandidate> tryToFindNestedSwitch(@NotNull PatternVariableCandidate previousCandidate,
private @Nullable List<PatternVariableCandidate> tryToFindNestedSwitch(@NotNull PatternVariableCandidate previousCandidate,
@NotNull Statement caseStatement,
@NotNull Set<AssignmentExprent> usedAssignmentExprents,
@NotNull VarTracker varTracker) {
@@ -1107,8 +1093,7 @@ public final class SwitchPatternHelper {
}
}
@NotNull
private static Map<Integer, String> getMapCaseClasses(List<PooledConstant> bootstrapArguments) {
private static @NotNull Map<Integer, String> getMapCaseClasses(List<PooledConstant> bootstrapArguments) {
Map<Integer, String> mapCaseClasses = new HashMap<>();
for (int i = 0; i < bootstrapArguments.size(); i++) {
PooledConstant constant = bootstrapArguments.get(i);
@@ -1175,27 +1160,17 @@ public final class SwitchPatternHelper {
* It can convert a usual switch statement to switch a statement with patterns.
*/
private static class SwitchOnReferenceCandidate implements SwitchOnCandidate {
@NotNull
private final SwitchStatement myRootSwitchStatement;
@NotNull
private final InvocationExprent myPreviousSelector;
@NotNull
private final Exprent myNewSwitchSelectorVariant;
@NotNull
private final List<TempVarAssignmentItem> myTempVarAssignments;
@NotNull
private final List<JavacReferenceFinder.FullCase> mySortedCasesFromRoot;
private final @NotNull SwitchStatement myRootSwitchStatement;
private final @NotNull InvocationExprent myPreviousSelector;
private final @NotNull Exprent myNewSwitchSelectorVariant;
private final @NotNull List<TempVarAssignmentItem> myTempVarAssignments;
private final @NotNull List<JavacReferenceFinder.FullCase> mySortedCasesFromRoot;
@NotNull
private final Set<SwitchStatement> myUsedSwitchStatements;
@NotNull
private final Set<AssignmentExprent> myUsedTypeVarAssignments;
@Nullable
private final Runnable myCleaner;
@NotNull
private final SwitchPatternHelper.PatternContainer myPatternContainer;
@Nullable
private final DoStatement myUppedDoStatement;
private final @NotNull Set<SwitchStatement> myUsedSwitchStatements;
private final @NotNull Set<AssignmentExprent> myUsedTypeVarAssignments;
private final @Nullable Runnable myCleaner;
private final @NotNull SwitchPatternHelper.PatternContainer myPatternContainer;
private final @Nullable DoStatement myUppedDoStatement;
private final boolean myMustCleanNonNull;
private SwitchOnReferenceCandidate(@NotNull SwitchStatement rootSwitchStatement,
@@ -1278,8 +1253,7 @@ public final class SwitchPatternHelper {
}
}
@Nullable
private static Statement getStatementWithFirstAssignment(@NotNull Statement statement) {
private static @Nullable Statement getStatementWithFirstAssignment(@NotNull Statement statement) {
if (statement.getExprents() != null && !statement.getExprents().isEmpty()) {
if (statement.getExprents().get(0) instanceof AssignmentExprent) {
return statement;
@@ -1323,8 +1297,7 @@ public final class SwitchPatternHelper {
return this.myTempVarAssignments;
}
@NotNull
private Map<Integer, Exprent> getMapCaseValue(List<PooledConstant> bootstrapArguments) {
private @NotNull Map<Integer, Exprent> getMapCaseValue(List<PooledConstant> bootstrapArguments) {
Map<Integer, Exprent> mapCaseValue = new HashMap<>();
for (int i = 0; i < bootstrapArguments.size(); i++) {
PooledConstant constant = bootstrapArguments.get(i);
@@ -552,8 +552,7 @@ public final class TryHelper
}
}
@Nullable
private static FunctionExprent unwrapNegations(@NotNull FunctionExprent func) {
private static @Nullable FunctionExprent unwrapNegations(@NotNull FunctionExprent func) {
int count = 0;
while (func.getFuncType() == FunctionExprent.FUNCTION_BOOL_NOT) {
Exprent expr = func.getLstOperands().get(0);
@@ -33,9 +33,8 @@ public class ArrayExprent extends Exprent {
return new ArrayExprent(array.copy(), index.copy(), hardType, bytecode);
}
@NotNull
@Override
public VarType getExprType() {
public @NotNull VarType getExprType() {
VarType exprType = array.getExprType();
if (exprType.equals(VarType.VARTYPE_NULL)) {
return hardType.copy();
@@ -47,9 +47,8 @@ public class AssignmentExprent extends Exprent {
addBytecodeOffsets(bytecodeOffsets);
}
@NotNull
@Override
public VarType getExprType() {
public @NotNull VarType getExprType() {
return left.getExprType();
}
@@ -126,8 +126,7 @@ public class ConstExprent extends Exprent {
DOUBLE_CONSTANTS.put((double)Long.MIN_VALUE, "(double)Long.MIN_VALUE");
}
@NotNull
private VarType constType;
private @NotNull VarType constType;
private final Object value;
private final boolean boolPermitted;
@@ -185,9 +184,8 @@ public class ConstExprent extends Exprent {
return new ConstExprent(constType, value, bytecode);
}
@NotNull
@Override
public VarType getExprType() {
public @NotNull VarType getExprType() {
return constType;
}
@@ -47,8 +47,7 @@ public abstract class Exprent implements IMatchable {
public final int type;
public final int id;
@Nullable
public BitSet bytecode = null; // offsets of bytecode instructions decompiled to this exprent
public @Nullable BitSet bytecode = null; // offsets of bytecode instructions decompiled to this exprent
public Exprent(int type) {
this.type = type;
@@ -59,8 +58,7 @@ public abstract class Exprent implements IMatchable {
return 0; // the highest precedence
}
@NotNull
public VarType getExprType() {
public @NotNull VarType getExprType() {
return VarType.VARTYPE_VOID;
}
@@ -30,8 +30,7 @@ public class FieldExprent extends Exprent {
private final boolean isStatic;
private Exprent instance;
private final FieldDescriptor descriptor;
@Nullable
private VarType inferredType;
private @Nullable VarType inferredType;
public FieldExprent(LinkConstant cn, Exprent instance, BitSet bytecodeOffsets) {
this(cn.elementName, cn.className, instance == null, instance, FieldDescriptor.parseDescriptor(cn.descriptor), bytecodeOffsets);
}
@@ -47,9 +46,8 @@ public class FieldExprent extends Exprent {
addBytecodeOffsets(bytecodeOffsets);
}
@NotNull
@Override
public VarType getExprType() {
public @NotNull VarType getExprType() {
VarType variableType = inferredType;
if (variableType == null) {
VarType varType = descriptor.type;
@@ -38,40 +38,40 @@ public class FunctionExprent extends Exprent {
public static final int FUNCTION_BOOL_NOT = 12;
public static final int FUNCTION_NEG = 13;
public final static int FUNCTION_I2L = 14;
public final static int FUNCTION_I2F = 15;
public final static int FUNCTION_I2D = 16;
public final static int FUNCTION_L2I = 17;
public final static int FUNCTION_L2F = 18;
public final static int FUNCTION_L2D = 19;
public final static int FUNCTION_F2I = 20;
public final static int FUNCTION_F2L = 21;
public final static int FUNCTION_F2D = 22;
public final static int FUNCTION_D2I = 23;
public final static int FUNCTION_D2L = 24;
public final static int FUNCTION_D2F = 25;
public final static int FUNCTION_I2B = 26;
public final static int FUNCTION_I2C = 27;
public final static int FUNCTION_I2S = 28;
public static final int FUNCTION_I2L = 14;
public static final int FUNCTION_I2F = 15;
public static final int FUNCTION_I2D = 16;
public static final int FUNCTION_L2I = 17;
public static final int FUNCTION_L2F = 18;
public static final int FUNCTION_L2D = 19;
public static final int FUNCTION_F2I = 20;
public static final int FUNCTION_F2L = 21;
public static final int FUNCTION_F2D = 22;
public static final int FUNCTION_D2I = 23;
public static final int FUNCTION_D2L = 24;
public static final int FUNCTION_D2F = 25;
public static final int FUNCTION_I2B = 26;
public static final int FUNCTION_I2C = 27;
public static final int FUNCTION_I2S = 28;
public final static int FUNCTION_CAST = 29;
public final static int FUNCTION_INSTANCEOF = 30;
public static final int FUNCTION_CAST = 29;
public static final int FUNCTION_INSTANCEOF = 30;
public final static int FUNCTION_ARRAY_LENGTH = 31;
public static final int FUNCTION_ARRAY_LENGTH = 31;
public final static int FUNCTION_IMM = 32;
public final static int FUNCTION_MMI = 33;
public static final int FUNCTION_IMM = 32;
public static final int FUNCTION_MMI = 33;
public final static int FUNCTION_IPP = 34;
public final static int FUNCTION_PPI = 35;
public static final int FUNCTION_IPP = 34;
public static final int FUNCTION_PPI = 35;
public final static int FUNCTION_IIF = 36;
public static final int FUNCTION_IIF = 36;
public final static int FUNCTION_LCMP = 37;
public final static int FUNCTION_FCMPL = 38;
public final static int FUNCTION_FCMPG = 39;
public final static int FUNCTION_DCMPL = 40;
public final static int FUNCTION_DCMPG = 41;
public static final int FUNCTION_LCMP = 37;
public static final int FUNCTION_FCMPL = 38;
public static final int FUNCTION_FCMPG = 39;
public static final int FUNCTION_DCMPL = 40;
public static final int FUNCTION_DCMPG = 41;
public static final int FUNCTION_EQ = 42;
public static final int FUNCTION_NE = 43;
@@ -187,8 +187,7 @@ public class FunctionExprent extends Exprent {
private VarType implicitType;
private final List<Exprent> lstOperands;
private boolean needsCast = true;
@Nullable
private VarType inferredType;
private @Nullable VarType inferredType;
public FunctionExprent(int funcType, ListStack<Exprent> stack, BitSet bytecodeOffsets) {
this(funcType, new ArrayList<>(), bytecodeOffsets);
@@ -219,9 +218,8 @@ public class FunctionExprent extends Exprent {
lstOperands.add(operand);
}
@NotNull
@Override
public VarType getExprType() {
public @NotNull VarType getExprType() {
if(inferredType != null) {
return inferredType;
}
@@ -60,8 +60,7 @@ public class InvocationExprent extends Exprent {
private List<Exprent> parameters = new ArrayList<>();
private List<PooledConstant> bootstrapArguments;
private List<VarType> genericArgs = new ArrayList<>();
@Nullable
private VarType inferredType;
private @Nullable VarType inferredType;
public InvocationExprent() {
super(EXPRENT_INVOCATION);
}
@@ -159,9 +158,8 @@ public class InvocationExprent extends Exprent {
genericArgs = expr.genericArgs;
}
@NotNull
@Override
public VarType getExprType() {
public @NotNull VarType getExprType() {
if (inferredType == null) {
VarType ret = descriptor.ret;
if (ret == null) {
@@ -35,8 +35,7 @@ public class NewExprent extends Exprent {
private boolean methodReference = false;
private boolean enumConst;
private List<VarType> genericArgs = new ArrayList<>();
@Nullable
private VarType inferredType;
private @Nullable VarType inferredType;
public NewExprent(VarType newType, ListStack<Exprent> stack, int arrayDim, BitSet bytecodeOffsets) {
this(newType, getDimensions(arrayDim, stack), bytecodeOffsets);
}
@@ -70,9 +69,8 @@ public class NewExprent extends Exprent {
return lstDims;
}
@NotNull
@Override
public VarType getExprType() {
public @NotNull VarType getExprType() {
if (inferredType != null) {
return inferredType;
}
@@ -1,4 +1,4 @@
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package org.jetbrains.java.decompiler.modules.decompiler.exps;
import org.jetbrains.annotations.NotNull;
@@ -14,8 +14,7 @@ import java.util.List;
*/
public class RecordVarExprent extends VarExprent {
@NotNull
private final List<RecordVarExprent> components = new ArrayList<>();
private final @NotNull List<RecordVarExprent> components = new ArrayList<>();
public RecordVarExprent(VarExprent v) {
super(v.getIndex(), v.getVarType(), v.getProcessor());
@@ -95,8 +94,7 @@ public class RecordVarExprent extends VarExprent {
* @param exprent the Exprent to match
* @return the direct component of the RecordVarExprent that matches the provided Exprent, or null if no match is found
*/
@Nullable
public RecordVarExprent getDirectComponent(@Nullable Exprent exprent) {
public @Nullable RecordVarExprent getDirectComponent(@Nullable Exprent exprent) {
for (RecordVarExprent component : components) {
if (component.equals(exprent)) {
return component;
@@ -42,9 +42,8 @@ public class SwitchExprent extends Exprent {
return swExpr;
}
@NotNull
@Override
public VarType getExprType() {
public @NotNull VarType getExprType() {
return value.getExprType();
}
@@ -49,8 +49,7 @@ public class VarExprent extends Exprent {
private boolean classDef = false;
private boolean stack = false;
private LocalVariable lvtEntry = null;
@Nullable
private VarType inferredType = null;
private @Nullable VarType inferredType = null;
private boolean insideLVT = false;
public VarExprent(int index, VarType varType, VarProcessor processor) {
@@ -65,9 +64,8 @@ public class VarExprent extends Exprent {
this.addBytecodeOffsets(bytecode);
}
@NotNull
@Override
public VarType getExprType() {
public @NotNull VarType getExprType() {
return getVarType();
}
@@ -141,8 +139,7 @@ public class VarExprent extends Exprent {
return bytecode == null ? -1 : bytecode.length();
}
@NotNull
public static String getName(VarVersion versionPair) {
public static @NotNull String getName(VarVersion versionPair) {
return "var" + versionPair.var + (versionPair.version == 0 ? "" : "_" + versionPair.version);
}
@@ -242,8 +239,7 @@ public class VarExprent extends Exprent {
this.insideLVT = insideLVT;
}
@NotNull
public VarType getVarType() {
public @NotNull VarType getVarType() {
if (inferredType != null) {
return inferredType;
}
@@ -1,4 +1,4 @@
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package org.jetbrains.java.decompiler.modules.decompiler.stats;
import org.jetbrains.annotations.Nullable;
@@ -6,8 +6,7 @@ import org.jetbrains.annotations.Nullable;
import java.util.BitSet;
public class DummyExitStatement extends Statement {
@Nullable
public BitSet bytecode = null; // offsets of bytecode instructions mapped to dummy exit
public @Nullable BitSet bytecode = null; // offsets of bytecode instructions mapped to dummy exit
public DummyExitStatement() {
super(StatementType.DUMMY_EXIT);
@@ -452,8 +452,7 @@ public abstract class Statement implements IMatchable {
return new ArrayList<>(stats);
}
@NotNull
public List<? extends IMatchable> getExprentsOrSequentialObjects() {
public @NotNull List<? extends IMatchable> getExprentsOrSequentialObjects() {
List<? extends IMatchable> exprents = getExprents();
if (exprents != null) {
return exprents;
@@ -816,8 +815,7 @@ public abstract class Statement implements IMatchable {
* @return a list of {@link Exprent} objects representing expression statements (can be empty if BlockStatement is empty),
* or null if it is a SequenceStatement or this Block is not processed
*/
@Nullable
public List<Exprent> getExprents() {
public @Nullable List<Exprent> getExprents() {
cancellationManager.checkCanceled();
return exprents;
}
@@ -1,4 +1,4 @@
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package org.jetbrains.java.decompiler.modules.decompiler.stats;
import org.jetbrains.annotations.NotNull;
@@ -142,8 +142,7 @@ public final class SwitchStatement extends Statement {
useCustomDefault = true;
}
@Nullable
public static Statement isHead(@NotNull Statement head) {
public static @Nullable Statement isHead(@NotNull Statement head) {
if (head.type == StatementType.BASIC_BLOCK && head.getLastBasicType() == StatementType.SWITCH) {
List<Statement> statements = new ArrayList<>();
if (DecHelper.isChoiceStatement(head, statements)) {
@@ -162,8 +161,7 @@ public final class SwitchStatement extends Statement {
}
@Override
@NotNull
public TextBuffer toJava(int indent, @NotNull BytecodeMappingTracer tracer) {
public @NotNull TextBuffer toJava(int indent, @NotNull BytecodeMappingTracer tracer) {
SwitchHelper.simplifySwitchOnEnum(this);
TextBuffer buf = new TextBuffer();
buf.append(ExprProcessor.listToJava(varDefinitions, indent, tracer));
@@ -261,8 +259,7 @@ public final class SwitchStatement extends Statement {
}
@Override
@NotNull
public List<IMatchable> getSequentialObjects() {
public @NotNull List<IMatchable> getSequentialObjects() {
List<IMatchable> result = new ArrayList<>(stats);
result.add(1, headExprent);
return result;
@@ -286,8 +283,7 @@ public final class SwitchStatement extends Statement {
}
@Override
@NotNull
public Statement getSimpleCopy() {
public @NotNull Statement getSimpleCopy() {
return new SwitchStatement();
}
@@ -447,33 +443,27 @@ public final class SwitchStatement extends Statement {
}
}
@NotNull
public List<Exprent> getHeadExprentList() {
public @NotNull List<Exprent> getHeadExprentList() {
return Collections.singletonList(headExprent);
}
@Nullable
public Exprent getHeadExprent() {
public @Nullable Exprent getHeadExprent() {
return headExprent;
}
@NotNull
public List<List<StatEdge>> getCaseEdges() {
public @NotNull List<List<StatEdge>> getCaseEdges() {
return caseEdges;
}
@NotNull
public List<Statement> getCaseStatements() {
public @NotNull List<Statement> getCaseStatements() {
return caseStatements;
}
@NotNull
public StatEdge getDefaultEdge() {
public @NotNull StatEdge getDefaultEdge() {
return defaultEdge;
}
@NotNull
public List<List<@Nullable Exprent>> getCaseValues() {
public @NotNull List<List<@Nullable Exprent>> getCaseValues() {
return caseValues;
}
}
@@ -178,8 +178,7 @@ public class VarType implements Type { // TODO: optimize switch
};
}
@NotNull
public VarType decreaseArrayDim() {
public @NotNull VarType decreaseArrayDim() {
if (getArrayDim() > 0) {
return new VarType(getType(), getArrayDim() - 1, getValue());
}
@@ -228,9 +228,8 @@ public class GenericType extends VarType implements Type {
return value.substring(0, index + 1);
}
@NotNull
@Override
public GenericType decreaseArrayDim() {
public @NotNull GenericType decreaseArrayDim() {
assert getArrayDim() > 0 : this;
return new GenericType(getType(), getArrayDim() - 1, getValue(), parent, arguments, wildcard);
}
@@ -1,4 +1,4 @@
// Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.codeInspection;
import com.intellij.codeInspection.options.OptPane;
@@ -28,7 +28,7 @@ import static com.intellij.codeInspection.options.OptPane.pane;
public final class SuspiciousLocalesLanguagesInspection extends LocalInspectionTool {
private static final String ADDITIONAL_LANGUAGES_ATTR_NAME = "additionalLanguages";
private final static Supplier<Set<String>> JAVA_LOCALES = NotNullLazyValue.softLazy(() -> {
private static final Supplier<Set<String>> JAVA_LOCALES = NotNullLazyValue.softLazy(() -> {
final Set<String> result = new HashSet<>();
for (Locale locale : Locale.getAvailableLocales()) {
result.add(locale.getLanguage());
@@ -1,4 +1,4 @@
// 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.
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.codeInspection.capitalization;
import com.intellij.codeInsight.AnnotationUtil;
@@ -37,21 +37,18 @@ public final class AnnotateCapitalizationIntention implements IntentionAction {
return true;
}
@Nls
@NotNull
@Override
public String getText() {
public @Nls @NotNull String getText() {
return getFamilyName();
}
@NotNull
@Override
public String getFamilyName() {
public @NotNull String getFamilyName() {
return JavaI18nBundle.message("intention.family.annotate.capitalization.type");
}
@Override
public void invoke(@NotNull final Project project, final Editor editor, final PsiFile file) throws IncorrectOperationException {
public void invoke(final @NotNull Project project, final Editor editor, final PsiFile file) throws IncorrectOperationException {
final PsiModifierListOwner modifierListOwner = getElement(editor, file);
if (modifierListOwner == null) throw new IncorrectOperationException();
@@ -78,8 +75,7 @@ public final class AnnotateCapitalizationIntention implements IntentionAction {
return false;
}
@Nullable
private static PsiModifierListOwner getElement(Editor editor, PsiFile file) {
private static @Nullable PsiModifierListOwner getElement(Editor editor, PsiFile file) {
PsiElement element = file.findElementAt(editor.getCaretModel().getOffset());
PsiParameter parameter = PsiTreeUtil.getParentOfType(element, PsiParameter.class, false);
if (parameter == null) return null;
@@ -1,4 +1,4 @@
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.codeInspection.duplicateStringLiteral;
import com.intellij.codeInsight.intention.preview.IntentionPreviewInfo;
@@ -55,11 +55,10 @@ public final class DuplicateStringLiteralInspection extends AbstractBaseJavaLoca
@SuppressWarnings("WeakerAccess") public int MIN_STRING_LENGTH = 5;
@SuppressWarnings("WeakerAccess") public boolean IGNORE_PROPERTY_KEYS;
@NonNls private static final String BR = "<br>";
private static final @NonNls String BR = "<br>";
@Override
@NotNull
public PsiElementVisitor buildVisitor(@NotNull final ProblemsHolder holder, final boolean isOnTheFly) {
public @NotNull PsiElementVisitor buildVisitor(final @NotNull ProblemsHolder holder, final boolean isOnTheFly) {
return new JavaElementVisitor() {
@Override
public void visitReferenceExpression(final @NotNull PsiReferenceExpression expression) {
@@ -74,13 +73,11 @@ public final class DuplicateStringLiteralInspection extends AbstractBaseJavaLoca
}
@Override
@NotNull
public String getShortName() {
public @NotNull String getShortName() {
return "DuplicateStringLiteralInspection";
}
@NotNull
private static List<PsiLiteralExpression> findDuplicateLiterals(@NotNull StringLiteralSearchQuery query, @NotNull Project project) {
private static @NotNull List<PsiLiteralExpression> findDuplicateLiterals(@NotNull StringLiteralSearchQuery query, @NotNull Project project) {
final GlobalSearchScope scope = GlobalSearchScope.projectScope(project);
final List<String> words = ContainerUtil.filter(StringUtil.getWordsInStringLongestFirst(query.stringToFind), s -> s.length() >= query.minStringLength);
if (words.isEmpty()) return Collections.emptyList();
@@ -114,8 +111,7 @@ public final class DuplicateStringLiteralInspection extends AbstractBaseJavaLoca
return foundExpressions;
}
@NotNull
private static List<PsiLiteralExpression> findDuplicateLiteralsInFile(@NotNull String stringToFind, boolean ignorePropertyKeys, @NotNull PsiFile file) {
private static @NotNull List<PsiLiteralExpression> findDuplicateLiteralsInFile(@NotNull String stringToFind, boolean ignorePropertyKeys, @NotNull PsiFile file) {
ProgressManager.checkCanceled();
CharSequence text = file.getViewProvider().getContents();
StringSearcher searcher = new StringSearcher(stringToFind, true, true);
@@ -132,7 +128,7 @@ public final class DuplicateStringLiteralInspection extends AbstractBaseJavaLoca
return foundExpr;
}
private void checkStringLiteralExpression(@NotNull final PsiLiteralExpression originalExpression,
private void checkStringLiteralExpression(final @NotNull PsiLiteralExpression originalExpression,
@NotNull ProblemsHolder holder,
final boolean isOnTheFly) {
PsiExpression[] foundExpr = getDuplicateLiterals(holder.getProject(), originalExpression, isOnTheFly);
@@ -222,8 +218,7 @@ public final class DuplicateStringLiteralInspection extends AbstractBaseJavaLoca
}
}
@Nullable
private static PsiReferenceExpression createReferenceTo(@NotNull PsiField constant) throws IncorrectOperationException {
private static @Nullable PsiReferenceExpression createReferenceTo(@NotNull PsiField constant) throws IncorrectOperationException {
PsiElementFactory factory = JavaPsiFacade.getInstance(constant.getProject()).getElementFactory();
PsiReferenceExpression reference = (PsiReferenceExpression)factory.createExpressionFromText("XXX." + constant.getName(), null);
final PsiReferenceExpression classQualifier = (PsiReferenceExpression)reference.getQualifierExpression();
@@ -294,8 +289,7 @@ public final class DuplicateStringLiteralInspection extends AbstractBaseJavaLoca
}
@Override
@NotNull
public String getFamilyName() {
public @NotNull String getFamilyName() {
return JavaI18nBundle.message("inspection.duplicates.replace.family.quickfix");
}
}
@@ -338,16 +332,13 @@ public final class DuplicateStringLiteralInspection extends AbstractBaseJavaLoca
}, JavaI18nBundle.message("introduce.constant.across.the.project"));
}
@NotNull
@Override
public String getText() {
public @NotNull String getText() {
return getFamilyName();
}
@Nls
@NotNull
@Override
public String getFamilyName() {
public @Nls @NotNull String getFamilyName() {
return JavaI18nBundle.message("inspection.duplicates.navigate.to.occurrences");
}
@@ -1,4 +1,4 @@
// 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.
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.codeInspection.i18n;
import com.intellij.codeInsight.CodeInsightUtilCore;
@@ -74,11 +74,11 @@ abstract class AbstractI18nizeQuickFix<T extends UExpression> implements LocalQu
}
@Override
public final void applyFix(@NotNull final Project project, @NotNull final ProblemDescriptor descriptor) {
public final void applyFix(final @NotNull Project project, final @NotNull ProblemDescriptor descriptor) {
doFix(descriptor, project);
}
abstract protected void doReplacement(@NotNull PsiFile psiFile,
protected abstract void doReplacement(@NotNull PsiFile psiFile,
Editor editor,
T literalExpression,
String i18nizedText) throws IncorrectOperationException;
@@ -113,8 +113,7 @@ abstract class AbstractI18nizeQuickFix<T extends UExpression> implements LocalQu
generationPlugin.replace(uElement, uElement, UElement.class);
}
@NotNull
protected I18nizeQuickFixDialog.DialogCustomization getCustomization(String value) {
protected @NotNull I18nizeQuickFixDialog.DialogCustomization getCustomization(String value) {
return new I18nizeQuickFixDialog.DialogCustomization(null, true, false, null, getSuggestedName(value, myInfo));
}
@@ -1,4 +1,4 @@
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.codeInspection.i18n;
import com.intellij.codeInspection.AbstractBaseJavaLocalInspectionTool;
@@ -32,9 +32,8 @@ import java.util.regex.Pattern;
public final class ConvertToBasicLatinInspection extends AbstractBaseJavaLocalInspectionTool {
@NotNull
@Override
public PsiElementVisitor buildVisitor(@NotNull final ProblemsHolder holder, boolean isOnTheFly) {
public @NotNull PsiElementVisitor buildVisitor(final @NotNull ProblemsHolder holder, boolean isOnTheFly) {
return new JavaElementVisitor() {
private void handle(@NotNull PsiElement element) {
if (IOUtil.isAscii(element.getText())) return;
@@ -94,8 +93,7 @@ public final class ConvertToBasicLatinInspection extends AbstractBaseJavaLocalIn
protected abstract void convert(@NotNull StringBuilder sb, char ch);
@NotNull
protected abstract PsiElement buildReplacement(@NotNull PsiElementFactory factory, @NotNull PsiElement element, @NotNull String newText);
protected abstract @NotNull PsiElement buildReplacement(@NotNull PsiElementFactory factory, @NotNull PsiElement element, @NotNull String newText);
}
private static class LiteralHandler extends Handler {
@@ -199,10 +197,8 @@ public final class ConvertToBasicLatinInspection extends AbstractBaseJavaLocalIn
}
private static class ConvertToBasicLatinFix extends PsiUpdateModCommandQuickFix {
@Nls
@NotNull
@Override
public String getFamilyName() {
public @Nls @NotNull String getFamilyName() {
return JavaI18nBundle.message("inspection.non.basic.latin.character.quickfix");
}
@@ -1,4 +1,4 @@
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.codeInspection.i18n;
@@ -106,13 +106,13 @@ public final class I18nInspection extends AbstractBaseUastLocalInspectionTool im
private boolean reportUnannotatedReferences = false;
public boolean ignoreAssignedToConstants;
public boolean ignoreToString;
@NlsSafe private String nonNlsLiteralPattern;
@NlsSafe public String nonNlsCommentPattern;
private @NlsSafe String nonNlsLiteralPattern;
public @NlsSafe String nonNlsCommentPattern;
private boolean ignoreForEnumConstants;
@Nullable private Pattern myCachedCommentPattern;
@Nullable private Pattern myCachedLiteralPattern;
@NonNls private static final String TO_STRING = "toString";
private @Nullable Pattern myCachedCommentPattern;
private @Nullable Pattern myCachedLiteralPattern;
private static final @NonNls String TO_STRING = "toString";
public I18nInspection() {
setNonNlsCommentPattern("NON-NLS");
@@ -194,14 +194,12 @@ public final class I18nInspection extends AbstractBaseUastLocalInspectionTool im
}
@Override
@NotNull
public String getGroupDisplayName() {
public @NotNull String getGroupDisplayName() {
return InspectionsBundle.message("group.names.internationalization.issues");
}
@Override
@NotNull
public String getShortName() {
public @NotNull String getShortName() {
return "HardCodedStringLiteral";
}
@@ -279,8 +277,7 @@ public final class I18nInspection extends AbstractBaseUastLocalInspectionTool im
);
}
@NotNull
private static HtmlChunk exampleDescription(@NlsSafe String exampleText) {
private static @NotNull HtmlChunk exampleDescription(@NlsSafe String exampleText) {
return HtmlChunk.fragment(
HtmlChunk.text(JavaI18nBundle.message("tooltip.example")),
HtmlChunk.br(),
@@ -318,13 +315,11 @@ public final class I18nInspection extends AbstractBaseUastLocalInspectionTool im
return "nls";
}
@NotNull
private static LocalQuickFix createIntroduceConstantFix() {
private static @NotNull LocalQuickFix createIntroduceConstantFix() {
return new IntroduceConstantFix();
}
@Nullable
private static ULocalVariable getVariableToSearch(UExpression passThrough) {
private static @Nullable ULocalVariable getVariableToSearch(UExpression passThrough) {
UElement uastParent = passThrough.getUastParent();
ULocalVariable uVar = null;
if (uastParent instanceof ULocalVariable) {
@@ -346,9 +341,7 @@ public final class I18nInspection extends AbstractBaseUastLocalInspectionTool im
return uVar;
}
@Nullable
@Unmodifiable
private static List<@NotNull UExpression> findUsages(UExpression passThrough, ULocalVariable uVar) {
private static @Nullable @Unmodifiable List<@NotNull UExpression> findUsages(UExpression passThrough, ULocalVariable uVar) {
PsiElement psiVar = uVar.getSourcePsi();
PsiElement psi = passThrough.getSourcePsi();
if (psi != null && psiVar != null) {
@@ -861,7 +854,7 @@ public final class I18nInspection extends AbstractBaseUastLocalInspectionTool im
if (parent == null || !UastExpressionUtils.isMethodCall(parent)) {
return false;
}
@NonNls final String methodName = ((UCallExpression)parent).getMethodName();
final @NonNls String methodName = ((UCallExpression)parent).getMethodName();
if (methodName == null) {
return false;
}
@@ -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-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.codeInspection.i18n;
import com.intellij.codeInsight.FileModificationService;
@@ -48,8 +48,7 @@ public class I18nizeAction extends AnAction {
}
}
@Nullable
public static I18nQuickFixHandler<?> getHandler(final AnActionEvent e) {
public static @Nullable I18nQuickFixHandler<?> getHandler(final AnActionEvent e) {
final Editor editor = getEditor(e);
if (editor == null) return null;
@@ -59,8 +58,7 @@ public class I18nizeAction extends AnAction {
return getHandler(editor, psiFile);
}
@Nullable
public static I18nQuickFixHandler<?> getHandler(@NotNull Editor editor, @NotNull PsiFile psiFile) {
public static @Nullable I18nQuickFixHandler<?> getHandler(@NotNull Editor editor, @NotNull PsiFile psiFile) {
TextRange range = JavaI18nUtil.getSelectedRange(editor, psiFile);
if (range == null) return null;
@@ -90,8 +88,7 @@ public class I18nizeAction extends AnAction {
return null;
}
@Nullable
public static UInjectionHost getEnclosingStringLiteral(final PsiFile psiFile, final Editor editor) {
public static @Nullable UInjectionHost getEnclosingStringLiteral(final PsiFile psiFile, final Editor editor) {
PsiElement psiElement = psiFile.findElementAt(editor.getCaretModel().getOffset());
return getEnclosingStringLiteral(psiElement);
}
@@ -100,8 +97,7 @@ public class I18nizeAction extends AnAction {
* @param psiElement element to search from
* @return UAST element representing an enclosing string literal
*/
@Nullable
public static UInjectionHost getEnclosingStringLiteral(PsiElement psiElement) {
public static @Nullable UInjectionHost getEnclosingStringLiteral(PsiElement psiElement) {
while (psiElement != null) {
UInjectionHost uastStringLiteral = UastContextKt.toUElement(psiElement, UInjectionHost.class);
if (uastStringLiteral != null && uastStringLiteral.isString()) {
@@ -1,4 +1,4 @@
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.codeInspection.i18n;
import com.intellij.codeInspection.BatchQuickFix;
@@ -237,8 +237,7 @@ public class I18nizeBatchQuickFix extends I18nizeQuickFix implements BatchQuickF
return null;
}
@Nullable
private static String suggestKeyByPlace(String value, @NotNull UExpression expression) {
private static @Nullable String suggestKeyByPlace(String value, @NotNull UExpression expression) {
List<UExpression> usages = I18nInspection.findIndirectUsages(expression, true);
if (usages.isEmpty()) {
usages = Collections.singletonList(expression);
@@ -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-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.codeInspection.i18n;
import com.intellij.codeInsight.intention.preview.IntentionPreviewInfo;
@@ -29,7 +29,7 @@ import java.util.Map;
import java.util.Objects;
public class I18nizeConcatenationQuickFix extends AbstractI18nizeQuickFix<UPolyadicExpression> {
@NonNls public static final String PARAMETERS_OPTION_KEY = "PARAMETERS";
public static final @NonNls String PARAMETERS_OPTION_KEY = "PARAMETERS";
public I18nizeConcatenationQuickFix(NlsInfo.Localized info) {
super(info);
@@ -56,14 +56,13 @@ public class I18nizeConcatenationQuickFix extends AbstractI18nizeQuickFix<UPolya
}
@Override
@NotNull
public String getFamilyName() {
public @NotNull String getFamilyName() {
return JavaI18nBundle.message("quickfix.i18n.concatentation");
}
@Override
protected void doReplacement(@NotNull final PsiFile psiFile,
@NotNull final Editor editor,
protected void doReplacement(final @NotNull PsiFile psiFile,
final @NotNull Editor editor,
@Nullable UPolyadicExpression literalExpression,
String i18nizedText) throws IncorrectOperationException {
@Nullable UPolyadicExpression concatenation = getEnclosingLiteralConcatenation(literalExpression);
@@ -82,8 +81,7 @@ public class I18nizeConcatenationQuickFix extends AbstractI18nizeQuickFix<UPolya
return new JavaI18nizeQuickFixDialog<>(project, context, concatenation, formatString, getCustomization(formatString), true, true) {
@Override
@Nullable
protected String getTemplateName() {
protected @Nullable String getTemplateName() {
return myResourceBundleManager.getConcatenationTemplateName();
}
@@ -127,8 +125,7 @@ public class I18nizeConcatenationQuickFix extends AbstractI18nizeQuickFix<UPolya
}
@Nullable
public static UPolyadicExpression getEnclosingLiteralConcatenation(final PsiElement psiElement) {
public static @Nullable UPolyadicExpression getEnclosingLiteralConcatenation(final PsiElement psiElement) {
return getEnclosingLiteralConcatenation(UastContextKt.getUastParentOfType(psiElement, UPolyadicExpression.class));
}
@@ -1,18 +1,4 @@
/*
* Copyright 2000-2010 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-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.codeInspection.i18n;
import com.intellij.openapi.editor.Editor;
@@ -26,7 +12,6 @@ public abstract class I18nizeHandlerProvider {
public static final ExtensionPointName<I18nizeHandlerProvider> EP_NAME = ExtensionPointName.create("com.intellij.java-i18n.i18nizeHandlerProvider");
@Nullable
public abstract I18nQuickFixHandler<?> getHandler(@NotNull final PsiFile psiFile, @NotNull final Editor editor, @NotNull TextRange range);
public abstract @Nullable I18nQuickFixHandler<?> getHandler(final @NotNull PsiFile psiFile, final @NotNull Editor editor, @NotNull TextRange range);
}
@@ -1,6 +1,4 @@
// Copyright 2000-2017 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-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.codeInspection.i18n;
import com.intellij.codeInsight.intention.preview.IntentionPreviewInfo;
@@ -45,8 +43,7 @@ public class I18nizeQuickFix extends AbstractI18nizeQuickFix<UInjectionHost> {
}
@Override
@NotNull
public String getFamilyName() {
public @NotNull String getFamilyName() {
return JavaI18nBundle.message("inspection.i18n.quickfix");
}
@@ -136,11 +133,10 @@ public class I18nizeQuickFix extends AbstractI18nizeQuickFix<UInjectionHost> {
.br().append(HtmlChunk.text(string).code()).toFragment());
}
@Nullable
private static UBinaryExpression breakStringLiteral(@NotNull UInjectionHost literalExpression,
UastCodeGenerationPlugin generationPlugin,
UastElementFactory elementFactory,
int offset) throws IncorrectOperationException {
private static @Nullable UBinaryExpression breakStringLiteral(@NotNull UInjectionHost literalExpression,
UastCodeGenerationPlugin generationPlugin,
UastElementFactory elementFactory,
int offset) throws IncorrectOperationException {
PsiElement sourcePsi = literalExpression.getSourcePsi();
if (sourcePsi == null) {
return null;
@@ -1,4 +1,4 @@
// 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.
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.codeInspection.i18n;
import com.intellij.codeInsight.AnnotationUtil;
@@ -28,8 +28,7 @@ import java.util.*;
public final class InvalidPropertyKeyInspection extends AbstractBaseJavaLocalInspectionTool {
@Override
@NotNull
public String getShortName() {
public @NotNull String getShortName() {
return "UnresolvedPropertyKey";
}
@@ -257,9 +256,8 @@ public final class InvalidPropertyKeyInspection extends AbstractBaseJavaLocalIns
);
}
@NotNull
private static List<PropertiesFile> filterNotInLibrary(@NotNull Project project,
@NotNull List<? extends PropertiesFile> propertiesFiles) {
private static @NotNull List<PropertiesFile> filterNotInLibrary(@NotNull Project project,
@NotNull List<? extends PropertiesFile> propertiesFiles) {
final ProjectFileIndex fileIndex = ProjectRootManager.getInstance(project).getFileIndex();
final List<PropertiesFile> result = new ArrayList<>(propertiesFiles.size());
@@ -1,18 +1,4 @@
/*
* Copyright 2000-2014 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-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.codeInspection.i18n;
import com.intellij.lang.properties.psi.PropertiesFile;
@@ -69,13 +55,12 @@ public class JavaCreatePropertyFix extends CreatePropertyFix {
return result;
}
@Nullable
protected Couple<String> invokeAction(@NotNull final Project project,
@NotNull PsiFile file,
@NotNull PsiElement psiElement,
@Nullable final String suggestedKey,
@Nullable String suggestedValue,
@Nullable final List<PropertiesFile> propertiesFiles) {
protected @Nullable Couple<String> invokeAction(final @NotNull Project project,
@NotNull PsiFile file,
@NotNull PsiElement psiElement,
final @Nullable String suggestedKey,
@Nullable String suggestedValue,
final @Nullable List<PropertiesFile> propertiesFiles) {
final PsiLiteralExpression literalExpression = psiElement instanceof PsiLiteralExpression ? (PsiLiteralExpression)psiElement : null;
final String propertyValue = suggestedValue == null ? "" : suggestedValue;
@@ -1,12 +1,12 @@
// 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.
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.codeInspection.i18n;
import com.intellij.codeInsight.AnnotationUtil;
import com.intellij.codeInsight.template.macro.MacroUtil;
import com.intellij.codeInspection.restriction.AnnotationContext;
import com.intellij.codeInspection.restriction.StringFlowUtil;
import com.intellij.lang.properties.ResourceBundle;
import com.intellij.lang.properties.*;
import com.intellij.lang.properties.ResourceBundle;
import com.intellij.lang.properties.psi.PropertiesFile;
import com.intellij.lang.properties.psi.Property;
import com.intellij.lang.properties.psi.PropertyCreationHandler;
@@ -46,8 +46,7 @@ public final class JavaI18nUtil {
private JavaI18nUtil() {
}
@Nullable
public static TextRange getSelectedRange(Editor editor, @NotNull PsiFile psiFile) {
public static @Nullable TextRange getSelectedRange(Editor editor, @NotNull PsiFile psiFile) {
if (editor == null) return null;
String selectedText = editor.getSelectionModel().getSelectedText();
if (selectedText != null) {
@@ -85,8 +84,7 @@ public final class JavaI18nUtil {
});
}
@NotNull
static UExpression getTopLevelExpression(@NotNull UExpression expression, boolean stopAtCall) {
static @NotNull UExpression getTopLevelExpression(@NotNull UExpression expression, boolean stopAtCall) {
while (expression.getUastParent() instanceof UExpression parent) {
if (parent instanceof UBlockExpression || parent instanceof UReturnExpression) {
break;
@@ -152,8 +150,7 @@ public final class JavaI18nUtil {
return true;
}
@Nullable
private static ResourceBundle resolveResourceBundleByKey(@NotNull final String key, @NotNull final Project project) {
private static @Nullable ResourceBundle resolveResourceBundleByKey(final @NotNull String key, final @NotNull Project project) {
final Ref<ResourceBundle> bundleRef = Ref.create();
final boolean r = PropertiesReferenceManager.getInstance(project).processAllPropertiesFiles((baseName, propertiesFile) -> {
if (propertiesFile.findPropertyByKey(key) != null) {
@@ -225,7 +222,7 @@ public final class JavaI18nUtil {
*
* @return number of parameters from single property or 0 for wrong format
*/
public static int getPropertyValuePlaceholdersCount(@NotNull final String propertyValue) {
public static int getPropertyValuePlaceholdersCount(final @NotNull String propertyValue) {
try {
return countFormatParameters(new MessageFormat(propertyValue));
}
@@ -258,7 +255,7 @@ public final class JavaI18nUtil {
* @param expression i18n literal
* @return number of parameters
*/
public static int getPropertyValueParamsMaxCount(@NotNull final UExpression expression) {
public static int getPropertyValueParamsMaxCount(final @NotNull UExpression expression) {
final SortedSet<Integer> paramsCount = getPropertyValueParamsCount(expression, null);
if (paramsCount.isEmpty()) {
return -1;
@@ -266,17 +263,15 @@ public final class JavaI18nUtil {
return paramsCount.last();
}
@NotNull
static SortedSet<Integer> getPropertyValueParamsCount(@NotNull final PsiExpression expression,
@Nullable final String resourceBundleName) {
static @NotNull SortedSet<Integer> getPropertyValueParamsCount(final @NotNull PsiExpression expression,
final @Nullable String resourceBundleName) {
UExpression uExpression = UastContextKt.toUElement(expression, UExpression.class);
if (uExpression == null) return new TreeSet<>();
return getPropertyValueParamsCount(uExpression, resourceBundleName);
}
@NotNull
private static SortedSet<Integer> getPropertyValueParamsCount(@NotNull final UExpression expression,
@Nullable final String resourceBundleName) {
private static @NotNull SortedSet<Integer> getPropertyValueParamsCount(final @NotNull UExpression expression,
final @Nullable String resourceBundleName) {
final UInjectionHost injectionHost;
if (expression instanceof UInjectionHost) {
injectionHost = (UInjectionHost)expression;
@@ -400,11 +395,10 @@ public final class JavaI18nUtil {
return true;
}
@NotNull
private static String getSideText(@NotNull List<? super UExpression> formatParameters,
@NotNull Project project,
UExpression expression,
boolean nested) {
private static @NotNull String getSideText(@NotNull List<? super UExpression> formatParameters,
@NotNull Project project,
UExpression expression,
boolean nested) {
String elseStr;
if (expression instanceof ULiteralExpression) {
Object elseValue = ((ULiteralExpression)expression).getValue();
@@ -429,8 +423,7 @@ public final class JavaI18nUtil {
return elseStr.replaceAll("([<>|#])", "'$1'");
}
@NotNull
static String composeParametersText(@NotNull List<? extends UExpression> args) {
static @NotNull String composeParametersText(@NotNull List<? extends UExpression> args) {
return args.stream().map(UExpression::getSourcePsi).filter(Objects::nonNull).map(psi -> psi.getText()).collect(Collectors.joining(","));
}
@@ -1,4 +1,4 @@
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.codeInspection.i18n;
import com.intellij.codeInsight.intention.IntentionAction;
@@ -67,13 +67,13 @@ public class JavaI18nizeQuickFixDialog<T extends UExpression> extends I18nizeQui
private final ExecutorService myExecutorPool = AppExecutorUtil.createBoundedApplicationPoolExecutor(
"JavaI18nizeQuickFixDialog Executor Pool", AppExecutorUtil.getAppExecutorService(), 1);
@NonNls public static final String PROPERTY_KEY_OPTION_KEY = "PROPERTY_KEY";
@NonNls public static final String RESOURCE_BUNDLE_OPTION_KEY = "RESOURCE_BUNDLE";
@NonNls public static final String PROPERTY_VALUE_ATTR = "PROPERTY_VALUE";
public static final @NonNls String PROPERTY_KEY_OPTION_KEY = "PROPERTY_KEY";
public static final @NonNls String RESOURCE_BUNDLE_OPTION_KEY = "RESOURCE_BUNDLE";
public static final @NonNls String PROPERTY_VALUE_ATTR = "PROPERTY_VALUE";
public JavaI18nizeQuickFixDialog(@NotNull Project project,
@NotNull final PsiFile context,
@Nullable final T literalExpression,
final @NotNull PsiFile context,
final @Nullable T literalExpression,
@NotNull String defaultPropertyValue,
DialogCustomization customization,
final boolean showJavaCodeInfo,
@@ -241,8 +241,7 @@ public class JavaI18nizeQuickFixDialog<T extends UExpression> extends I18nizeQui
super.somethingChanged();
}
@Nullable
protected String getTemplateName() {
protected @Nullable String getTemplateName() {
return myResourceBundleManager.getTemplateName();
}
@@ -1,4 +1,4 @@
// Copyright 2000-2021 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.codeInspection.i18n;
import com.intellij.codeInsight.AnnotationUtil;
@@ -96,8 +96,7 @@ public abstract class NlsInfo implements RestrictionInfo {
return fromAnnotationContext(expression.getUastParent(), context);
}
@NotNull
private static NlsInfo fromEqualityCheck(@NotNull UExpression expression, boolean allowStringModifications) {
private static @NotNull NlsInfo fromEqualityCheck(@NotNull UExpression expression, boolean allowStringModifications) {
UElement parent = UastUtils.skipParenthesizedExprUp(expression.getUastParent());
if (parent instanceof UCallExpression) {
String name = ((UCallExpression)parent).getMethodName();
@@ -1,18 +1,4 @@
/*
* Copyright 2000-2010 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-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.codeInspection.i18n;
import com.intellij.analysis.AnalysisBundle;
@@ -87,14 +73,12 @@ class SuppressByCommentOutAction extends SuppressIntentionAction {
}
@Override
@NotNull
public String getFamilyName() {
public @NotNull String getFamilyName() {
return AnalysisBundle.message("suppress.inspection.family");
}
@NotNull
@Override
public String getText() {
public @NotNull String getText() {
return JavaI18nBundle.message("intention.text.suppress.with.0.comment", nonNlsCommentPattern);
}
}
@@ -1,4 +1,4 @@
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.codeInspection.i18n;
import com.ibm.icu.text.MessagePattern;
@@ -28,9 +28,8 @@ import java.util.*;
import java.util.stream.IntStream;
public final class TitleCapitalizationInspection extends AbstractBaseJavaLocalInspectionTool {
@NotNull
@Override
public PsiElementVisitor buildVisitor(@NotNull final ProblemsHolder holder, boolean isOnTheFly) {
public @NotNull PsiElementVisitor buildVisitor(final @NotNull ProblemsHolder holder, boolean isOnTheFly) {
return new PsiElementVisitor() {
@SuppressWarnings("unchecked")
private static final Class<? extends UExpression>[] uExpressionClasses = new Class[]
@@ -108,8 +107,7 @@ public final class TitleCapitalizationInspection extends AbstractBaseJavaLocalIn
};
}
@Nullable
private static Value getTitleValue(@Nullable UExpression arg, @Nullable Set<? super UExpression> processed) {
private static @Nullable Value getTitleValue(@Nullable UExpression arg, @Nullable Set<? super UExpression> processed) {
if (arg instanceof UInjectionHost) {
return Value.of((UInjectionHost)arg);
}
@@ -147,8 +145,7 @@ public final class TitleCapitalizationInspection extends AbstractBaseJavaLocalIn
return null;
}
@Nullable
private static Property getPropertyArgument(UCallExpression arg) {
private static @Nullable Property getPropertyArgument(UCallExpression arg) {
List<UExpression> args = arg.getValueArguments();
if (!args.isEmpty()) {
return JavaI18nUtil.resolveProperty(args.get(0));
@@ -165,9 +162,8 @@ public final class TitleCapitalizationInspection extends AbstractBaseJavaLocalIn
myCapitalization = capitalization;
}
@NotNull
@Override
public String getName() {
public @NotNull String getName() {
return JavaI18nBundle.message("quickfix.text.title.capitalization", myTitleValue);
}
@@ -212,9 +208,8 @@ public final class TitleCapitalizationInspection extends AbstractBaseJavaLocalIn
return null;
}
@NotNull
@Override
public String getFamilyName() {
public @NotNull String getFamilyName() {
return JavaI18nBundle.message("quickfix.family.title.capitalization.fix");
}
}
@@ -224,16 +219,14 @@ public final class TitleCapitalizationInspection extends AbstractBaseJavaLocalIn
@NotNull String toString();
boolean isSatisfied(@NotNull Nls.Capitalization capitalization);
@NotNull
default String fixCapitalization(@NotNull Nls.Capitalization capitalization) {
default @NotNull String fixCapitalization(@NotNull Nls.Capitalization capitalization) {
return NlsCapitalizationUtil.fixValue(toString(), capitalization);
}
default boolean canFix() { return true; }
@Contract("null, _ -> null")
@Nullable
static Value of(@Nullable Property property, boolean useFormat) {
static @Nullable Value of(@Nullable Property property, boolean useFormat) {
if (property == null) return null;
String value = property.getUnescapedValue();
if (value == null) return null;
@@ -254,14 +247,12 @@ public final class TitleCapitalizationInspection extends AbstractBaseJavaLocalIn
return value == null ? null : new TextValue(value);
}
@Nullable
static Value of(@NotNull PsiLiteralExpression literal) {
static @Nullable Value of(@NotNull PsiLiteralExpression literal) {
Object value = literal.getValue();
return value instanceof String ? new TextValue((String)value) : null;
}
@Nullable
static Value of(NlsInfo info) {
static @Nullable Value of(NlsInfo info) {
if (info instanceof NlsInfo.Localized) {
Nls.Capitalization capitalization = ((NlsInfo.Localized)info).getCapitalization();
if (capitalization != Nls.Capitalization.NotSpecified) {
@@ -277,9 +268,8 @@ public final class TitleCapitalizationInspection extends AbstractBaseJavaLocalIn
TextValue(String text) { myText = text; }
@NotNull
@Override
public String toString() { return myText;}
public @NotNull String toString() { return myText;}
@Override
public boolean isSatisfied(@NotNull Nls.Capitalization capitalization) {
@@ -304,9 +294,8 @@ public final class TitleCapitalizationInspection extends AbstractBaseJavaLocalIn
return false;
}
@NotNull
@Override
public String toString() { return getCapitalizationName(myDeclared);}
public @NotNull String toString() { return getCapitalizationName(myDeclared);}
}
static class PropertyValue implements Value {
@@ -318,8 +307,8 @@ public final class TitleCapitalizationInspection extends AbstractBaseJavaLocalIn
myPattern = pattern;
}
@NotNull @Override
public String toString() {
@Override
public @NotNull String toString() {
return myPresentation;
}

Some files were not shown because too many files have changed in this diff Show More