Skip to content

Commit 6f317c2

Browse files
authored
Merge pull request #2075 from Haehnchen/feature/java-language
java language level feature migration records syntax on private usages
2 parents c433457 + 36effd1 commit 6f317c2

File tree

53 files changed

+116
-392
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+116
-392
lines changed

src/main/java/fr/adrienbrault/idea/symfony2plugin/action/TwigExtractLanguageAction.java

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -165,23 +165,7 @@ public void actionPerformed(AnActionEvent event) {
165165

166166
}
167167

168-
private static class MyOnOkCallback implements TranslatorKeyExtractorDialog.OnOkCallback {
169-
private final Project project;
170-
private final Editor editor;
171-
private final String finalDefaultDomain;
172-
private final int finalStartOffset;
173-
private final int finalEndOffset;
174-
private final String finalTranslationText;
175-
176-
MyOnOkCallback(Project project, Editor editor, String finalDefaultDomain, int finalStartOffset, int finalEndOffset, String finalTranslationText) {
177-
this.project = project;
178-
this.editor = editor;
179-
this.finalDefaultDomain = finalDefaultDomain;
180-
this.finalStartOffset = finalStartOffset;
181-
this.finalEndOffset = finalEndOffset;
182-
this.finalTranslationText = finalTranslationText;
183-
}
184-
168+
private record MyOnOkCallback(Project project, Editor editor, String finalDefaultDomain, int finalStartOffset, int finalEndOffset, String finalTranslationText) implements TranslatorKeyExtractorDialog.OnOkCallback {
185169
@Override
186170
public void onClick(List<TranslationFileModel> files, final String keyName, final String domain, boolean navigateTo) {
187171
PsiDocumentManager.getInstance(project).doPostponedOperationsAndUnblockDocument(editor.getDocument());
@@ -191,7 +175,7 @@ public void onClick(List<TranslationFileModel> files, final String keyName, fina
191175
String insertString;
192176

193177
// check for file context domain
194-
if(finalDefaultDomain.equals(domain)) {
178+
if (finalDefaultDomain.equals(domain)) {
195179
insertString = String.format("{{ '%s'|trans }}", keyName);
196180
} else {
197181
insertString = String.format("{{ '%s'|trans({}, '%s') }}", keyName, domain);
@@ -204,16 +188,16 @@ public void onClick(List<TranslationFileModel> files, final String keyName, fina
204188
Collection<PsiElement> targets = new ArrayList<>();
205189

206190
// so finally insert it; first file can be a navigation target
207-
for(TranslationFileModel transPsiFile: files) {
191+
for (TranslationFileModel transPsiFile : files) {
208192
PsiFile psiFile = transPsiFile.getPsiFile();
209193

210194
CommandProcessor.getInstance().executeCommand(psiFile.getProject(), () -> ApplicationManager.getApplication().runWriteAction(() ->
211-
ContainerUtil.addIfNotNull(targets, TranslationInsertUtil.invokeTranslation(psiFile, keyName, finalTranslationText))),
195+
ContainerUtil.addIfNotNull(targets, TranslationInsertUtil.invokeTranslation(psiFile, keyName, finalTranslationText))),
212196
"Translation Insert " + psiFile.getName(), null
213197
);
214198
}
215199

216-
if(navigateTo && targets.size() > 0) {
200+
if (navigateTo && targets.size() > 0) {
217201
PsiDocumentManager.getInstance(project).commitAndRunReadAction(() ->
218202
IdeHelper.navigateToPsiElement(targets.iterator().next())
219203
);

src/main/java/fr/adrienbrault/idea/symfony2plugin/assistant/signature/MethodSignatureTypeProvider.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public char getKey() {
4040
@Nullable
4141
@Override
4242
public PhpType getType(PsiElement e) {
43-
if (!Settings.getInstance(e.getProject()).pluginEnabled || !(e instanceof MethodReference)) {
43+
if (!Settings.getInstance(e.getProject()).pluginEnabled || !(e instanceof MethodReference methodReference)) {
4444
return null;
4545
}
4646

@@ -49,7 +49,6 @@ public PhpType getType(PsiElement e) {
4949
return null;
5050
}
5151

52-
MethodReference methodReference = (MethodReference) e;
5352
Collection<MethodSignatureSetting> matchedSignatures = getSignatureSetting(methodReference.getName(), signatures);
5453
if(matchedSignatures.size() == 0) {
5554
return null;

src/main/java/fr/adrienbrault/idea/symfony2plugin/completion/ConstantEnumCompletionContributor.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -151,12 +151,10 @@ protected void addCompletions(@NotNull CompletionParameters completionParameters
151151
return;
152152
}
153153

154-
if (!(psiElement.getParent().getParent() instanceof BinaryExpression)) {
154+
if (!(psiElement.getParent().getParent() instanceof BinaryExpression binaryExpression)) {
155155
return;
156156
}
157157

158-
BinaryExpression binaryExpression = (BinaryExpression) psiElement.getParent().getParent();
159-
160158

161159
// OK: $response->getStatusCode() == Response::HTTP_BAD_GATEWAY
162160
// @TODO: error we are complete outside of context: $response->getStatusCode() == Response::HTTP_BAD_GATEWAY || $response->getStatusCode() ==

src/main/java/fr/adrienbrault/idea/symfony2plugin/completion/IncompletePropertyServiceInjectionContributor.java

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -443,15 +443,7 @@ private String getCompletedText(@NotNull CompletionParameters completionParamete
443443
return null;
444444
}
445445

446-
private static class LookupElementInsertHandler implements InsertHandler<LookupElement> {
447-
private final String propertyName;
448-
private final String typePhpClass;
449-
450-
public LookupElementInsertHandler(String propertyName, String typePhpClass) {
451-
this.propertyName = propertyName;
452-
this.typePhpClass = typePhpClass;
453-
}
454-
446+
private record LookupElementInsertHandler(String propertyName, String typePhpClass) implements InsertHandler<LookupElement> {
455447
@Override
456448
public void handleInsert(@NotNull InsertionContext context, @NotNull LookupElement item) {
457449
SmartPsiElementPointer<PhpClass> parentOfType2 = (SmartPsiElementPointer<PhpClass>) item.getObject();

src/main/java/fr/adrienbrault/idea/symfony2plugin/completion/command/PhpCommandGotoCompletionRegistrar.java

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -221,16 +221,10 @@ private Map<String, CommandArg> getCommandConfigurationMap(@NotNull PhpClass php
221221
return targets;
222222
}
223223

224-
private static class CommandDefPsiElementFilter implements Processor<PsiElement> {
225-
private final String methodName;
226-
227-
public CommandDefPsiElementFilter(String methodName) {
228-
this.methodName = methodName;
229-
}
230-
224+
private record CommandDefPsiElementFilter(String methodName) implements Processor<PsiElement> {
231225
@Override
232226
public boolean process(PsiElement psiElement) {
233-
if(!(psiElement instanceof MethodReference)) {
227+
if (!(psiElement instanceof MethodReference)) {
234228
return false;
235229
}
236230

src/main/java/fr/adrienbrault/idea/symfony2plugin/config/ConfigLineMarkerProvider.java

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -96,22 +96,7 @@ private void visitConfigKey(@NotNull Collection<? super LineMarkerInfo<?>> resul
9696
result.add(builder.createLineMarkerInfo(psiElement));
9797
}
9898

99-
private static class MyClassIdLazyValue implements Supplier<Collection<? extends PsiElement>> {
100-
@NotNull
101-
private final Project project;
102-
103-
@NotNull
104-
private final Collection<String> configuration;
105-
106-
@NotNull
107-
private final String root;
108-
109-
MyClassIdLazyValue(@NotNull Project project, @NotNull Collection<String> configuration, @NotNull String root) {
110-
this.project = project;
111-
this.configuration = configuration;
112-
this.root = root;
113-
}
114-
99+
private record MyClassIdLazyValue(@NotNull Project project, @NotNull Collection<String> configuration, @NotNull String root) implements Supplier<Collection<? extends PsiElement>> {
115100
@Override
116101
public Collection<? extends PsiElement> get() {
117102
return ConfigUtil.getTreeSignatureTargets(project, root, configuration);

src/main/java/fr/adrienbrault/idea/symfony2plugin/config/ServiceLineMarkerProvider.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -387,10 +387,8 @@ private void constraintMessagePropertyMarker(@NotNull PsiElement psiElement, @No
387387
}
388388
}
389389

390-
private static class MyCollectionNotNullLazyValue implements Supplier<Collection<? extends PsiElement>> {
391-
private final Collection<ClassServiceDefinitionTargetLazyValue> targets;
392-
393-
public MyCollectionNotNullLazyValue(@NotNull Collection<ClassServiceDefinitionTargetLazyValue> targets) {
390+
private record MyCollectionNotNullLazyValue(Collection<ClassServiceDefinitionTargetLazyValue> targets) implements Supplier<Collection<? extends PsiElement>> {
391+
private MyCollectionNotNullLazyValue(@NotNull Collection<ClassServiceDefinitionTargetLazyValue> targets) {
394392
this.targets = targets;
395393
}
396394

src/main/java/fr/adrienbrault/idea/symfony2plugin/config/php/PhpConfigReferenceContributor.java

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -148,12 +148,10 @@ public boolean acceptsTarget(@NotNull PsiElement target) {
148148
}
149149

150150
ArrayCreationExpression arrayCreationExpression = PhpElementsUtil.getCompletableArrayCreationElement(psiElement);
151-
if(arrayCreationExpression == null || !(arrayCreationExpression.getContext() instanceof PhpReturn)) {
151+
if(arrayCreationExpression == null || !(arrayCreationExpression.getContext() instanceof PhpReturn phpReturn)) {
152152
return new PsiReference[0];
153153
}
154154

155-
PhpReturn phpReturn = (PhpReturn) arrayCreationExpression.getContext();
156-
157155
Method method = PsiTreeUtil.getParentOfType(phpReturn, Method.class);
158156
if(method == null) {
159157
return new PsiReference[0];
@@ -176,20 +174,18 @@ public boolean acceptsTarget(@NotNull PsiElement target) {
176174

177175
private static boolean phpStringLiteralExpressionClassReference(String signature, int index, PsiElement psiElement) {
178176

179-
if (!(psiElement.getContext() instanceof ParameterList)) {
177+
if (!(psiElement.getContext() instanceof ParameterList parameterList)) {
180178
return false;
181179
}
182180

183-
ParameterList parameterList = (ParameterList) psiElement.getContext();
184-
if (!(parameterList.getContext() instanceof NewExpression)) {
181+
if (!(parameterList.getContext() instanceof NewExpression newExpression)) {
185182
return false;
186183
}
187184

188185
if(PsiElementUtils.getParameterIndexValue(psiElement) != index) {
189186
return false;
190187
}
191188

192-
NewExpression newExpression = (NewExpression) parameterList.getContext();
193189
ClassReference classReference = newExpression.getClassReference();
194190
if(classReference == null) {
195191
return false;

src/main/java/fr/adrienbrault/idea/symfony2plugin/config/utils/ConfigUtil.java

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -137,23 +137,7 @@ private static void visitTreeSignatures(@NotNull Collection<PhpClass> classes, @
137137
}
138138
}
139139

140-
private static class TreeVisitor {
141-
@NotNull
142-
private final PhpClass phpClass;
143-
144-
@NotNull
145-
private final PsiElement psiElement;
146-
147-
@NotNull
148-
private final String contents;
149-
150-
public TreeVisitor(@NotNull PhpClass phpClass, @NotNull PsiElement psiElement, @NotNull String contents) {
151-
152-
this.phpClass = phpClass;
153-
this.psiElement = psiElement;
154-
this.contents = contents;
155-
}
156-
}
140+
private record TreeVisitor(@NotNull PhpClass phpClass, @NotNull PsiElement psiElement, @NotNull String contents) {}
157141

158142
/**
159143
* app/config[..].yml

src/main/java/fr/adrienbrault/idea/symfony2plugin/dic/ServiceArgumentParameterHintsProvider.java

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -221,15 +221,5 @@ private String createTypeHintFromParameter(@NotNull Project project, Parameter p
221221
return parameter.getName();
222222
}
223223

224-
private static class Match {
225-
@NotNull
226-
private final String parameter;
227-
228-
private final int targetOffset;
229-
230-
Match(@NotNull String parameter, int targetOffset) {
231-
this.parameter = parameter;
232-
this.targetOffset = targetOffset;
233-
}
234-
}
224+
private record Match(@NotNull String parameter, int targetOffset) {}
235225
}

0 commit comments

Comments
 (0)