Skip to content

Commit 00390d9

Browse files
committed
fix upcoming deprecations
1 parent 87cf39b commit 00390d9

File tree

10 files changed

+49
-50
lines changed

10 files changed

+49
-50
lines changed

src/main/java/fr/adrienbrault/idea/symfony2plugin/codeInspection/command/CommandInvokableReturnValueInspection.java

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,8 @@
77
import com.intellij.psi.PsiElementVisitor;
88
import com.intellij.psi.util.PsiTreeUtil;
99
import com.jetbrains.php.PhpIndex;
10-
import com.jetbrains.php.lang.psi.elements.Method;
11-
import com.jetbrains.php.lang.psi.elements.PhpClass;
12-
import com.jetbrains.php.lang.psi.elements.PhpReturn;
13-
import com.jetbrains.php.lang.psi.elements.PhpTypedElement;
10+
import com.jetbrains.php.lang.psi.PhpPsiUtil;
11+
import com.jetbrains.php.lang.psi.elements.*;
1412
import com.jetbrains.php.lang.psi.resolve.types.PhpType;
1513
import fr.adrienbrault.idea.symfony2plugin.Symfony2ProjectComponent;
1614
import org.jetbrains.annotations.NotNull;
@@ -82,8 +80,13 @@ private void visitPhpReturn(@NotNull PhpReturn phpReturn, @NotNull ProblemsHolde
8280
}
8381

8482
private boolean hasIntReturnType(@NotNull Method method) {
85-
PhpType returnType = method.getReturnType() != null ? method.getReturnType().getType() : null;
86-
if (returnType == null || returnType.isEmpty()) {
83+
PhpReturnType childByCondition = PhpPsiUtil.getChildByCondition(method, PhpReturnType.INSTANCEOF);
84+
if (childByCondition == null) {
85+
return false;
86+
}
87+
88+
PhpType returnType = childByCondition.getType();
89+
if (returnType.isEmpty()) {
8790
return false;
8891
}
8992

src/main/java/fr/adrienbrault/idea/symfony2plugin/dic/intention/PhpPropertyArgumentIntention.java

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
import com.intellij.psi.PsiElement;
1616
import com.intellij.psi.PsiFile;
1717
import com.intellij.psi.util.PsiTreeUtil;
18-
import com.intellij.util.SlowOperations;
1918
import com.intellij.util.ThrowableRunnable;
2019
import com.jetbrains.php.PhpIndex;
2120
import com.jetbrains.php.lang.findUsages.PhpGotoTargetRendererProvider;
@@ -145,16 +144,14 @@ public Component getListCellRendererComponent(JList<? extends String> jList, Str
145144

146145
private static void buildProperty(@NotNull Project project, @NotNull FieldReference fieldReference, @NotNull String classFqn) {
147146
try {
148-
SlowOperations.allowSlowOperations(() -> {
149-
PhpClass phpClassScope = PsiTreeUtil.getParentOfType(fieldReference, PhpClass.class);
150-
if (phpClassScope == null || !ServiceUtil.isPhpClassAService(phpClassScope)) {
151-
return;
152-
}
147+
PhpClass phpClassScope = PsiTreeUtil.getParentOfType(fieldReference, PhpClass.class);
148+
if (phpClassScope == null || !ServiceUtil.isPhpClassAService(phpClassScope)) {
149+
return;
150+
}
153151

154-
WriteCommandAction.writeCommandAction(project)
155-
.withName("Symfony: Add Property Service")
156-
.run((ThrowableRunnable<Throwable>) () -> ServicePropertyInsertUtil.appendPropertyInjection(phpClassScope, fieldReference.getName(), classFqn));
157-
});
152+
WriteCommandAction.writeCommandAction(project)
153+
.withName("Symfony: Add Property Service")
154+
.run((ThrowableRunnable<Throwable>) () -> ServicePropertyInsertUtil.appendPropertyInjection(phpClassScope, fieldReference.getName(), classFqn));
158155
} catch (Throwable ignored) {
159156
}
160157
}

src/main/java/fr/adrienbrault/idea/symfony2plugin/profiler/utils/ProfilerUtil.java

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
import java.io.*;
2323
import java.net.MalformedURLException;
24+
import java.net.URI;
2425
import java.net.URL;
2526
import java.net.URLConnection;
2627
import java.nio.charset.StandardCharsets;
@@ -296,8 +297,8 @@ private static String stripHtmlTags(@NotNull String text)
296297
public static String getProfilerUrlContent(@NotNull String url) {
297298
URLConnection conn;
298299
try {
299-
conn = new URL(url).openConnection();
300-
} catch (IOException e) {
300+
conn = URI.create(url).toURL().openConnection();
301+
} catch (IOException | IllegalArgumentException e) {
301302
e.printStackTrace();
302303
return null;
303304
}
@@ -426,11 +427,11 @@ public static List<ProfilerRequestInterface> getProfilerRequestCollectorDecorate
426427
public static String getBaseProfilerUrlFromRequest(@NotNull ProfilerRequestInterface request) {
427428
URL url = null;
428429
try {
429-
url = new URL(request.getProfilerUrl());
430-
} catch (MalformedURLException e) {
430+
url = URI.create(request.getProfilerUrl()).toURL();
431+
} catch (MalformedURLException | IllegalArgumentException e) {
431432
try {
432-
url = new URL(request.getUrl());
433-
} catch (MalformedURLException ignored) {
433+
url = URI.create(request.getUrl()).toURL();
434+
} catch (MalformedURLException | IllegalArgumentException ignored) {
434435
}
435436
}
436437

@@ -461,15 +462,15 @@ public static String formatProfilerRow(@NotNull ProfilerRequestInterface profile
461462
String path = profilerRequest.getUrl();
462463

463464
try {
464-
URL url = new URL(profilerRequest.getUrl());
465+
URL url = URI.create(profilerRequest.getUrl()).toURL();
465466
path = url.getPath();
466467

467468
Matcher matcher = Pattern.compile(".*(/app_[\\w]{2,6}.php)/").matcher(path);
468469
if(matcher.find()){
469470
path = "/" + path.substring(matcher.end());
470471
}
471472

472-
} catch (MalformedURLException ignored) {
473+
} catch (MalformedURLException | IllegalArgumentException ignored) {
473474
}
474475

475476
return String.format("(%s) %s", statusCode == 0 ? "n/a" : statusCode, StringUtils.abbreviate(path, 35));

src/main/java/fr/adrienbrault/idea/symfony2plugin/profiler/widget/action/SymfonyProfilerWidgetActions.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
import javax.swing.*;
2323
import java.awt.*;
24-
import java.net.URL;
24+
import java.net.URI;
2525
import java.util.Collection;
2626

2727
/**
@@ -164,7 +164,7 @@ public void actionPerformed(AnActionEvent event) {
164164
}
165165

166166
try {
167-
desktop.browse(new URL(urlForRequest).toURI());
167+
desktop.browse(URI.create(urlForRequest));
168168
} catch (Exception ignored) {
169169
}
170170
}

src/main/java/fr/adrienbrault/idea/symfony2plugin/routing/webDeployment/RoutingRemoteFileStorage.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import org.jetbrains.annotations.NotNull;
1414

1515
import java.io.IOException;
16+
import java.nio.charset.StandardCharsets;
1617
import java.util.Collection;
1718
import java.util.HashMap;
1819
import java.util.Map;
@@ -38,7 +39,8 @@ public void build(@NotNull Project project, @NotNull Collection<FileObject> file
3839

3940
String content;
4041
try {
41-
content = StreamUtil.readText(file.getContent().getInputStream(), "UTF-8");
42+
byte[] bytes = StreamUtil.readBytes(file.getContent().getInputStream());
43+
content = new String(bytes, StandardCharsets.UTF_8);
4244
} catch (IOException e) {
4345
continue;
4446
}

src/main/java/fr/adrienbrault/idea/symfony2plugin/stubs/util/IndexUtil.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,7 @@ public static void forceReindex() {
3535
};
3636

3737
for(ID<?,?> id: indexIds) {
38-
FileBasedIndex.getInstance().requestRebuild(id);
39-
FileBasedIndex.getInstance().scheduleRebuild(id, new Throwable());
38+
FileBasedIndex.getInstance().requestRebuild(id, new Throwable());
4039
}
4140
}
4241

src/main/java/fr/adrienbrault/idea/symfony2plugin/templating/webpack/SymfonyWebpackUtil.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import org.jetbrains.annotations.Nullable;
2626

2727
import java.io.IOException;
28+
import java.nio.charset.StandardCharsets;
2829
import java.util.Map;
2930
import java.util.function.Consumer;
3031

@@ -76,14 +77,15 @@ private static void visitEntryPointJson(@NotNull VirtualFile virtualFile, @NotNu
7677
String s;
7778

7879
try {
79-
s = StreamUtil.readText(virtualFile.getInputStream(), "UTF-8");
80+
byte[] bytes = StreamUtil.readBytes(virtualFile.getInputStream());
81+
s = new String(bytes, StandardCharsets.UTF_8);
8082
} catch (IOException e) {
8183
return;
8284
}
8385

8486
JsonObject jsonObject;
8587
try {
86-
jsonObject = new JsonParser().parse(s).getAsJsonObject();
88+
jsonObject = JsonParser.parseString(s).getAsJsonObject();
8789
} catch (JsonSyntaxException e) {
8890
return;
8991
}
@@ -159,7 +161,8 @@ public void visitElement(@NotNull PsiElement element) {
159161
private static void visitManifestJson(@NotNull VirtualFile virtualFile, @NotNull Consumer<Pair<String, String>> consumer) {
160162
JsonElement jsonElement;
161163
try {
162-
String s = StreamUtil.readText(virtualFile.getInputStream(), "UTF-8");
164+
byte[] bytes = StreamUtil.readBytes(virtualFile.getInputStream());
165+
String s = new String(bytes, StandardCharsets.UTF_8);
163166
jsonElement = JsonParser.parseString(s);
164167
} catch (JsonSyntaxException | IOException e) {
165168
return;

src/main/java/fr/adrienbrault/idea/symfony2plugin/translation/parser/TranslationStringMap.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
import java.io.File;
1919
import java.io.IOException;
20+
import java.nio.charset.StandardCharsets;
2021
import java.util.*;
2122
import java.util.concurrent.ConcurrentHashMap;
2223

@@ -90,7 +91,9 @@ private void parse(@NotNull Project project, @NotNull File file) {
9091
public void parse(@NotNull Project project, @NotNull VirtualFile virtualFile) {
9192
PsiFile psiFile;
9293
try {
93-
psiFile = PhpPsiElementFactory.createPsiFileFromText(project, StreamUtil.readText(virtualFile.getInputStream(), "UTF-8"));
94+
byte[] bytes = StreamUtil.readBytes(virtualFile.getInputStream());
95+
String content = new String(bytes, StandardCharsets.UTF_8);
96+
psiFile = PhpPsiElementFactory.createPsiFileFromText(project, content);
9497
} catch (IOException e) {
9598
return;
9699
}

src/main/java/fr/adrienbrault/idea/symfony2plugin/ui/utils/ClassCompletionPanelWrapper.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
package fr.adrienbrault.idea.symfony2plugin.ui.utils;
22

33
import com.intellij.openapi.Disposable;
4-
import com.intellij.openapi.editor.event.DocumentAdapter;
54
import com.intellij.openapi.editor.event.DocumentEvent;
5+
import com.intellij.openapi.editor.event.DocumentListener;
66
import com.intellij.openapi.project.Project;
77
import com.intellij.openapi.util.text.StringUtil;
88
import com.intellij.ui.EditorTextField;
@@ -54,17 +54,17 @@ private void init() {
5454

5555
PhpCompletionUtil.installClassCompletion(this.field, null, getDisposable(), null);
5656

57-
this.field.getDocument().addDocumentListener(new DocumentAdapter() {
57+
this.field.getDocument().addDocumentListener(new DocumentListener() {
5858
@Override
59-
public void documentChanged(DocumentEvent e) {
59+
public void documentChanged(@NotNull DocumentEvent e) {
6060
String text = field.getText();
6161
if (StringUtil.isEmpty(text) || StringUtil.endsWith(text, "\\")) {
6262
return;
6363
}
6464

6565
addUpdateRequest(250, () -> consumer.consume(field.getText()));
6666
}
67-
});
67+
}, getDisposable());
6868

6969
GridBagConstraints gbConstraints = new GridBagConstraints();
7070
gbConstraints.fill = 1;

src/main/java/fr/adrienbrault/idea/symfony2plugin/util/yaml/YamlHelper.java

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package fr.adrienbrault.idea.symfony2plugin.util.yaml;
22

3-
import com.intellij.openapi.application.Result;
43
import com.intellij.openapi.command.WriteCommandAction;
54
import com.intellij.openapi.util.Pair;
65
import com.intellij.openapi.util.text.StringUtil;
@@ -866,19 +865,11 @@ public static PsiElement insertKeyIntoFile(final @NotNull YAMLFile yamlFile, @No
866865
return null;
867866
}
868867

869-
// finally wirte changes
868+
// finally write changes
870869
final YAMLMapping finalChildOfType = childOfType;
871-
new WriteCommandAction(yamlFile.getProject()) {
872-
@Override
873-
protected void run(@NotNull Result result) throws Throwable {
874-
finalChildOfType.putKeyValue(next);
875-
}
876-
877-
@Override
878-
public String getGroupID() {
879-
return "Key insertion";
880-
}
881-
}.execute();
870+
WriteCommandAction.writeCommandAction(yamlFile.getProject())
871+
.withName("Key insertion")
872+
.run(() -> finalChildOfType.putKeyValue(next));
882873

883874
return childOfType;
884875
}

0 commit comments

Comments
 (0)