Skip to content

Commit 111a982

Browse files
committed
cleanup deprecations
1 parent 68831e7 commit 111a982

25 files changed

+110
-130
lines changed

src/org/intellij/grammar/BnfCompletionContributor.java

+9-9
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
import com.intellij.codeInsight.lookup.LookupElementBuilder;
1010
import com.intellij.codeInsight.lookup.TailTypeDecorator;
1111
import com.intellij.lang.ASTNode;
12-
import com.intellij.openapi.util.Comparing;
1312
import com.intellij.openapi.util.TextRange;
1413
import com.intellij.openapi.util.text.StringUtil;
1514
import com.intellij.patterns.PlatformPatterns;
@@ -35,6 +34,7 @@
3534

3635
import java.util.Collection;
3736
import java.util.List;
37+
import java.util.Objects;
3838
import java.util.Set;
3939

4040
import static com.intellij.patterns.PlatformPatterns.psiElement;
@@ -50,10 +50,10 @@ public BnfCompletionContributor() {
5050
psiElement()
5151
.inFile(PlatformPatterns.instanceOf(BnfFile.class))
5252
.andNot(psiElement().inside(PsiComment.class));
53-
extend(CompletionType.BASIC, placePattern, new CompletionProvider<CompletionParameters>() {
53+
extend(CompletionType.BASIC, placePattern, new CompletionProvider<>() {
5454
@Override
5555
protected void addCompletions(@NotNull CompletionParameters parameters,
56-
ProcessingContext context,
56+
@NotNull ProcessingContext context,
5757
@NotNull CompletionResultSet result) {
5858
PsiElement position = parameters.getPosition();
5959
BnfComposite parent = PsiTreeUtil.getParentOfType(position, BnfAttrs.class, BnfAttr.class, BnfParenExpression.class);
@@ -73,7 +73,7 @@ else if (parent instanceof BnfAttr) {
7373
ASTNode closingBrace = TreeUtil.findSiblingBackward(parent.getNode().getLastChildNode(), BnfTypes.BNF_RIGHT_BRACE);
7474
attrCompletion = closingBrace == null || position.getTextOffset() <= closingBrace.getStartOffset();
7575
if (attrCompletion) {
76-
for (KnownAttribute attribute : KnownAttribute.getAttributes()) {
76+
for (KnownAttribute<?> attribute : KnownAttribute.getAttributes()) {
7777
if (inRule && attribute.isGlobal()) continue;
7878
result.addElement(LookupElementBuilder.create(attribute.getName()).withIcon(BnfIcons.ATTRIBUTE));
7979
}
@@ -86,10 +86,10 @@ else if (parent instanceof BnfAttr) {
8686
}
8787
}
8888
});
89-
extend(CompletionType.BASIC, placePattern.andNot(psiElement().inside(false, psiElement(BnfAttr.class))), new CompletionProvider<CompletionParameters>() {
89+
extend(CompletionType.BASIC, placePattern.andNot(psiElement().inside(false, psiElement(BnfAttr.class))), new CompletionProvider<>() {
9090
@Override
9191
protected void addCompletions(@NotNull CompletionParameters parameters,
92-
ProcessingContext context,
92+
@NotNull ProcessingContext context,
9393
@NotNull final CompletionResultSet result) {
9494
BnfFile file = (BnfFile)parameters.getOriginalFile();
9595
PsiElement positionRefOrToken = PsiTreeUtil.getParentOfType(parameters.getOriginalPosition(), BnfReferenceOrToken.class);
@@ -108,10 +108,10 @@ protected void addCompletions(@NotNull CompletionParameters parameters,
108108
}
109109
});
110110
extend(CompletionType.BASIC, placePattern.withParent(
111-
psiElement(BnfExpression.class).withReference(BnfReferenceImpl.class)), new CompletionProvider<CompletionParameters>() {
111+
psiElement(BnfExpression.class).withReference(BnfReferenceImpl.class)), new CompletionProvider<>() {
112112
@Override
113113
protected void addCompletions(@NotNull CompletionParameters parameters,
114-
ProcessingContext context,
114+
@NotNull ProcessingContext context,
115115
@NotNull CompletionResultSet result) {
116116
BnfFile bnfFile = (BnfFile)parameters.getOriginalFile();
117117
PsiElement posExpression = PsiTreeUtil.getParentOfType(parameters.getPosition(), BnfExpression.class);
@@ -125,7 +125,7 @@ protected void addCompletions(@NotNull CompletionParameters parameters,
125125
.withIcon(rule.getIcon(0))
126126
.withBoldness(!privateRule)
127127
.withStrikeoutness(fakeRule);
128-
if (!Comparing.equal(idText, rule.getName())) {
128+
if (!Objects.equals(idText, rule.getName())) {
129129
e = e.withLookupString(rule.getName());
130130
}
131131
result.addElement(e);

src/org/intellij/grammar/BnfIcons.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* Date: 17.07.11 2:55
1414
*/
1515
public interface BnfIcons {
16-
Icon FILE = IconLoader.getIcon("/resources/bnf.svg");
16+
Icon FILE = IconLoader.getIcon("/resources/bnf.svg", BnfIcons.class);
1717

1818
Icon RULE = AllIcons.Nodes.Method;
1919
Icon EXTERNAL_RULE = AllIcons.Nodes.AbstractMethod;

src/org/intellij/grammar/actions/BnfGenerateLexerAction.java

+12-12
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
import com.intellij.openapi.fileChooser.FileSaverDescriptor;
1717
import com.intellij.openapi.fileEditor.FileEditorManager;
1818
import com.intellij.openapi.fileTypes.FileTypes;
19-
import com.intellij.openapi.fileTypes.StdFileTypes;
19+
import com.intellij.openapi.fileTypes.PlainTextFileType;
2020
import com.intellij.openapi.fileTypes.ex.FileTypeManagerEx;
2121
import com.intellij.openapi.project.Project;
2222
import com.intellij.openapi.ui.Messages;
@@ -115,7 +115,7 @@ private static void associateFileTypeAndNavigate(Project project, VirtualFile vi
115115
String extension = virtualFile.getExtension();
116116
FileTypeManagerEx fileTypeManagerEx = FileTypeManagerEx.getInstanceEx();
117117
if (extension != null && fileTypeManagerEx.getFileTypeByExtension(extension) == FileTypes.UNKNOWN) {
118-
fileTypeManagerEx.associateExtension(StdFileTypes.PLAIN_TEXT, "flex");
118+
fileTypeManagerEx.associateExtension(PlainTextFileType.INSTANCE, "flex");
119119
}
120120
FileEditorManager.getInstance(project).openFile(virtualFile, false, true);
121121
//new OpenFileDescriptor(project, virtualFile).navigate(false);
@@ -138,7 +138,7 @@ private String generateLexerText(final BnfFile bnfFile, @Nullable String package
138138

139139
bnfFile.acceptChildren(new PsiRecursiveElementWalkingVisitor() {
140140
@Override
141-
public void visitElement(PsiElement element) {
141+
public void visitElement(@NotNull PsiElement element) {
142142
if (element instanceof BnfAttrs) return;
143143

144144
if (GrammarUtil.isExternalReference(element)) return;
@@ -185,7 +185,7 @@ public static String token2JFlex(@NotNull String tokenText) {
185185
}
186186

187187
private static String javaPattern2JFlex(String javaRegexp) {
188-
Matcher m = Pattern.compile("\\[(?:[^]\\\\]|\\\\.)*\\]").matcher(javaRegexp);
188+
Matcher m = Pattern.compile("\\[(?:[^]\\\\]|\\\\.)*]").matcher(javaRegexp);
189189
int start = 0;
190190
StringBuilder sb = new StringBuilder();
191191
while (m.find(start)) {
@@ -201,7 +201,7 @@ private static String javaPattern2JFlex(String javaRegexp) {
201201
private static String text2JFlex(String text, boolean isRegexp) {
202202
String s;
203203
if (!isRegexp) {
204-
s = text.replaceAll("(\"|\\\\)", "\\\\$1");
204+
s = text.replaceAll("([\"\\\\])", "\\\\$1");
205205
return s;
206206
}
207207
else {
@@ -214,13 +214,13 @@ private static String text2JFlex(String text, boolean isRegexp) {
214214
s = s.replaceAll("\\\\S", "[^" + spaces + "]");
215215
s = s.replaceAll("\\\\w", "[a-zA-Z_0-9]");
216216
s = s.replaceAll("\\\\W", "[^a-zA-Z_0-9]");
217-
s = s.replaceAll("\\\\p\\{Space\\}", "[" + spaces + "]");
218-
s = s.replaceAll("\\\\p\\{Digit\\}", "[:digit:]");
219-
s = s.replaceAll("\\\\p\\{Alpha\\}", "[:letter:]");
220-
s = s.replaceAll("\\\\p\\{Lower\\}", "[:lowercase:]");
221-
s = s.replaceAll("\\\\p\\{Upper\\}", "[:uppercase:]");
222-
s = s.replaceAll("\\\\p\\{Alnum\\}", "([:letter:]|[:digit:])");
223-
s = s.replaceAll("\\\\p\\{ASCII\\}", "[\\x00-\\x7F]");
217+
s = s.replaceAll("\\\\p\\{Space}", "[" + spaces + "]");
218+
s = s.replaceAll("\\\\p\\{Digit}", "[:digit:]");
219+
s = s.replaceAll("\\\\p\\{Alpha}", "[:letter:]");
220+
s = s.replaceAll("\\\\p\\{Lower}", "[:lowercase:]");
221+
s = s.replaceAll("\\\\p\\{Upper}", "[:uppercase:]");
222+
s = s.replaceAll("\\\\p\\{Alnum}", "([:letter:]|[:digit:])");
223+
s = s.replaceAll("\\\\p\\{ASCII}", "[\\x00-\\x7F]");
224224
return s;
225225
}
226226
}

src/org/intellij/grammar/actions/BnfRunJFlexAction.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ private static List<File> getOrDownload(@NotNull Project project, String... urls
278278
// ensure the order is the same
279279
for (String url : urls) {
280280
for (Pair<VirtualFile, DownloadableFileDescription> pair : pairs) {
281-
if (Comparing.equal(url, pair.second.getDownloadUrl())) {
281+
if (Objects.equals(url, pair.second.getDownloadUrl())) {
282282
result.add(VfsUtil.virtualToIoFile(pair.first));
283283
break;
284284
}

src/org/intellij/grammar/actions/FileGeneratorUtil.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
import com.intellij.openapi.vfs.VirtualFile;
1919
import com.intellij.psi.search.FilenameIndex;
2020
import com.intellij.psi.search.ProjectScope;
21-
import com.intellij.util.ObjectUtils;
2221
import org.intellij.grammar.BnfFileType;
2322
import org.intellij.grammar.config.Options;
2423
import org.intellij.grammar.generator.BnfConstants;
@@ -29,6 +28,7 @@
2928
import java.util.ArrayList;
3029
import java.util.Collection;
3130
import java.util.List;
31+
import java.util.Objects;
3232

3333
import static com.intellij.util.ArrayUtil.getFirstElement;
3434

@@ -96,7 +96,7 @@ public static VirtualFile getTargetDirectoryFor(@NotNull Project project,
9696
else {
9797
VirtualFile result = WriteAction.compute(() -> VfsUtil.createDirectoryIfMissing(virtualRoot, relativePath));
9898
VfsUtil.markDirtyAndRefresh(false, true, true, result);
99-
return returnRoot && newGenRoot ? ObjectUtils.assertNotNull(virtualRoot.findChild(genDirName)) :
99+
return returnRoot && newGenRoot ? Objects.requireNonNull(virtualRoot.findChild(genDirName)) :
100100
returnRoot ? virtualRoot : result;
101101
}
102102
}

src/org/intellij/grammar/actions/GenerateAction.java

+2-3
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
import com.intellij.psi.PsiFile;
2828
import com.intellij.psi.PsiManager;
2929
import com.intellij.util.ExceptionUtil;
30-
import com.intellij.util.PathUtil;
3130
import com.intellij.util.containers.JBIterable;
3231
import org.intellij.grammar.KnownAttribute;
3332
import org.intellij.grammar.generator.BnfConstants;
@@ -102,7 +101,7 @@ public static void doGenerate(@NotNull Project project, @NotNull List<VirtualFil
102101
}
103102
});
104103

105-
ProgressManager.getInstance().run(new Task.Backgroundable(project, "Parser Generation", true, PerformInBackgroundOption.ALWAYS_BACKGROUND) {
104+
ProgressManager.getInstance().run(new Task.Backgroundable(project, "Parser generation", true, PerformInBackgroundOption.ALWAYS_BACKGROUND) {
106105

107106
final List<File> files = new ArrayList<>();
108107
final Set<VirtualFile> targets = new LinkedHashSet<>();
@@ -136,7 +135,7 @@ private void runInner(ProgressIndicator indicator) {
136135
VirtualFile file = bnfFiles.get(i);
137136
indicator.setFraction((double)i / l);
138137
indicator.setText2(file.getPath());
139-
String sourcePath = FileUtil.toSystemDependentName(PathUtil.getCanonicalPath(file.getParent().getPath()));
138+
String sourcePath = FileUtil.toSystemDependentName(FileUtil.toCanonicalPath(file.getParent().getPath()));
140139
VirtualFile target = rootMap.get(file);
141140
if (target == null) return;
142141
targets.add(target);

src/org/intellij/grammar/actions/HighlightGrammarAtCaretAction.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@
1313
import com.intellij.openapi.editor.Editor;
1414
import com.intellij.openapi.project.Project;
1515
import com.intellij.psi.PsiFile;
16-
import com.intellij.util.ObjectUtils;
1716
import org.intellij.grammar.livePreview.GrammarAtCaretPassFactory;
1817
import org.intellij.grammar.livePreview.LivePreviewLanguage;
1918
import org.jetbrains.annotations.NotNull;
2019
import org.jetbrains.annotations.Nullable;
2120

2221
import java.util.List;
22+
import java.util.Objects;
2323

2424
/**
2525
* @author gregsh
@@ -38,7 +38,7 @@ private static Editor getPreviewEditor(@NotNull AnActionEvent e) {
3838
}
3939

4040
@Override
41-
public void update(AnActionEvent e) {
41+
public void update(@NotNull AnActionEvent e) {
4242
Editor editor = getPreviewEditor(e);
4343
boolean enabled = editor != null;
4444
String command = !enabled ? "" : GrammarAtCaretPassFactory.GRAMMAR_AT_CARET_KEY.get(editor) != null ? "Stop " : "Start ";
@@ -47,13 +47,13 @@ public void update(AnActionEvent e) {
4747
}
4848

4949
@Override
50-
public void actionPerformed(AnActionEvent e) {
50+
public void actionPerformed(@NotNull AnActionEvent e) {
5151
Editor editor = getPreviewEditor(e);
5252
if (editor == null) return;
5353
Boolean value = GrammarAtCaretPassFactory.GRAMMAR_AT_CARET_KEY.get(editor);
5454
GrammarAtCaretPassFactory.GRAMMAR_AT_CARET_KEY.set(editor, value == null ? Boolean.TRUE : null);
5555

56-
Project project = ObjectUtils.assertNotNull(e.getProject());
56+
Project project = Objects.requireNonNull(e.getProject());
5757
DaemonCodeAnalyzer.getInstance(project).restart();
5858
}
5959
}

src/org/intellij/grammar/editor/BnfRecursionLineMarkerProvider.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ private MyMarkerInfo(@NotNull PsiElement id) {
6262
@Override
6363
public GutterIconRenderer createGutterRenderer() {
6464
if (myIcon == null) return null;
65-
return new LineMarkerGutterIconRenderer<PsiElement>(this) {
65+
return new LineMarkerGutterIconRenderer<>(this) {
6666
@Override
6767
public AnAction getClickAction() {
6868
return null;

src/org/intellij/grammar/generator/ParserGenerator.java

+8-11
Original file line numberDiff line numberDiff line change
@@ -100,15 +100,12 @@ static class RuleInfo {
100100
this.intfClass = intfPackage + "." + intfClass;
101101
this.implClass = implPackage + "." + implClass;
102102
this.mixin = mixin;
103-
//this.stubName = stubName;
104-
//this.classes = classes;
105-
//this.mixedAST = mixedAST;
106103
}
107104
}
108105

109106
@NotNull
110107
RuleInfo ruleInfo(BnfRule rule) {
111-
return ObjectUtils.notNull(myRuleInfos.get(rule.getName()));
108+
return Objects.requireNonNull(myRuleInfos.get(rule.getName()));
112109
}
113110

114111
private final Map<String, RuleInfo> myRuleInfos = new TreeMap<>();
@@ -430,7 +427,7 @@ private void generateVisitor(String psiClass, Map<String, BnfRule> sortedRules)
430427
String superIntf = ObjectUtils.notNull(ContainerUtil.getFirstItem(getRootAttribute(myFile, KnownAttribute.IMPLEMENTS)),
431428
KnownAttribute.IMPLEMENTS.getDefaultValue().get(0)).second;
432429
Set<String> imports = new LinkedHashSet<>(Arrays.asList("org.jetbrains.annotations.*", PSI_ELEMENT_VISITOR_CLASS, superIntf));
433-
MultiMap<String, String> supers = MultiMap.createSmart();
430+
MultiMap<String, String> supers = new MultiMap<>();
434431
for (BnfRule rule : sortedRules.values()) {
435432
supers.putValues(rule.getName(), getSuperInterfaceNames(myFile, rule, myIntfClassFormat));
436433
}
@@ -559,7 +556,7 @@ else if (!G.generateFQN) {
559556
generateRootParserContent();
560557
}
561558
for (String ruleName : ownRuleNames) {
562-
BnfRule rule = ObjectUtils.assertNotNull(myFile.getRule(ruleName));
559+
BnfRule rule = Objects.requireNonNull(myFile.getRule(ruleName));
563560
if (Rule.isExternal(rule) || Rule.isFake(rule)) continue;
564561
if (myExpressionHelper.getExpressionInfo(rule) != null) continue;
565562
out("/* ********************************************************** */");
@@ -611,7 +608,7 @@ private void generateRootParserContent() {
611608
BnfRule rootRule = myFile.getRule(myGrammarRoot);
612609
List<BnfRule> extraRoots = new ArrayList<>();
613610
for (String ruleName : myRuleInfos.keySet()) {
614-
BnfRule rule = ObjectUtils.assertNotNull(myFile.getRule(ruleName));
611+
BnfRule rule = Objects.requireNonNull(myFile.getRule(ruleName));
615612
if (getAttribute(rule, KnownAttribute.ELEMENT_TYPE) != null) continue;
616613
if (!RuleGraphHelper.hasElementType(rule)) continue;
617614
if (Rule.isFake(rule) || Rule.isMeta(rule)) continue;
@@ -1079,7 +1076,7 @@ public String generateFirstCheck(BnfRule rule, String frameName, boolean skipIfO
10791076
String t = firstToElementType(expressionString);
10801077
if (t == null) return frameName;
10811078

1082-
ConsumeType childConsumeType = getRuleConsumeType(ObjectUtils.notNull(Rule.of(expression)), rule);
1079+
ConsumeType childConsumeType = getRuleConsumeType(Objects.requireNonNull(Rule.of(expression)), rule);
10831080
ConsumeType consumeType = ConsumeType.min(ruleConsumeType, childConsumeType);
10841081
ConsumeType existing = firstElementTypes.get(t);
10851082
firstElementTypes.put(t, ConsumeType.max(existing, consumeType));
@@ -1409,7 +1406,7 @@ else if (nested instanceof BnfLiteralExpression) {
14091406
arguments.add(generateWrappedNodeCall(rule, nested, attributeName));
14101407
}
14111408
else {
1412-
arguments.add(new TextArgument(argument.startsWith("\'") ? GrammarUtil.unquote(argument) : argument));
1409+
arguments.add(new TextArgument(argument.startsWith("'") ? GrammarUtil.unquote(argument) : argument));
14131410
}
14141411
}
14151412
else if (nested instanceof BnfExternalExpression) {
@@ -1562,7 +1559,7 @@ private void generateElementTypesHolder(String className, Map<String, BnfRule> s
15621559
else {
15631560
elementCreateCall = shorten(StringUtil.getPackageName(info.second)) + "." + StringUtil.getShortName(info.second);
15641561
}
1565-
String fieldType = ObjectUtils.notNull(useExactElements ? exactType : IELEMENTTYPE_CLASS);
1562+
String fieldType = Objects.requireNonNull(useExactElements ? exactType : IELEMENTTYPE_CLASS);
15661563
String callFix = elementCreateCall.endsWith("IElementType") ? ", null" : "";
15671564
out("%s %s = %s(\"%s\"%s);", shorten(fieldType), elementType, elementCreateCall, elementType, callFix);
15681565
}
@@ -2020,7 +2017,7 @@ private String generatePsiAccessorImplCall(@NotNull BnfRule rule, @NotNull RuleM
20202017
private String getAccessorType(@NotNull BnfRule rule) {
20212018
if (Rule.isExternal(rule)) {
20222019
Pair<String, String> first = ContainerUtil.getFirstItem(getAttribute(rule, KnownAttribute.IMPLEMENTS));
2023-
return ObjectUtils.assertNotNull(first).second;
2020+
return Objects.requireNonNull(first).second;
20242021
}
20252022
else {
20262023
return ruleInfo(rule).intfClass;

src/org/intellij/grammar/generator/ParserGeneratorUtil.java

+5-6
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import com.intellij.openapi.application.ApplicationManager;
77
import com.intellij.openapi.project.Project;
88
import com.intellij.openapi.ui.MessageType;
9-
import com.intellij.openapi.util.Comparing;
109
import com.intellij.openapi.util.Couple;
1110
import com.intellij.openapi.util.Pair;
1211
import com.intellij.openapi.util.text.StringUtil;
@@ -389,12 +388,12 @@ private static List<NavigatablePsiElement> filterOutShadowedRuleImplMethods(Stri
389388
}
390389
String type1 = helper.getMethodTypes(m1).get(1);
391390
String type2 = types.get(1);
392-
if (Comparing.equal(type1, type2)) continue;
391+
if (Objects.equals(type1, type2)) continue;
393392
for (String s = selectedClass; s != null; s = helper.getSuperClassName(s)) {
394-
if (Comparing.equal(type1, s)) {
393+
if (Objects.equals(type1, s)) {
395394
result.remove(m2);
396395
}
397-
else if (Comparing.equal(type2, s)) {
396+
else if (Objects.equals(type2, s)) {
398397
result.remove(m1);
399398
}
400399
else continue;
@@ -981,15 +980,15 @@ static String staticStarImport(@NotNull String fqn) {
981980
return "static " + fqn + ".*";
982981
}
983982

984-
private static final TObjectHashingStrategy<PsiElement> TEXT_STRATEGY = new TObjectHashingStrategy<PsiElement>() {
983+
private static final TObjectHashingStrategy<PsiElement> TEXT_STRATEGY = new TObjectHashingStrategy<>() {
985984
@Override
986985
public int computeHashCode(PsiElement e) {
987986
return e.getText().hashCode();
988987
}
989988

990989
@Override
991990
public boolean equals(PsiElement e1, PsiElement e2) {
992-
return Comparing.equal(e1.getText(), e2.getText());
991+
return Objects.equals(e1.getText(), e2.getText());
993992
}
994993
};
995994

0 commit comments

Comments
 (0)