Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -165,23 +165,7 @@ public void actionPerformed(AnActionEvent event) {

}

private static class MyOnOkCallback implements TranslatorKeyExtractorDialog.OnOkCallback {
private final Project project;
private final Editor editor;
private final String finalDefaultDomain;
private final int finalStartOffset;
private final int finalEndOffset;
private final String finalTranslationText;

MyOnOkCallback(Project project, Editor editor, String finalDefaultDomain, int finalStartOffset, int finalEndOffset, String finalTranslationText) {
this.project = project;
this.editor = editor;
this.finalDefaultDomain = finalDefaultDomain;
this.finalStartOffset = finalStartOffset;
this.finalEndOffset = finalEndOffset;
this.finalTranslationText = finalTranslationText;
}

private record MyOnOkCallback(Project project, Editor editor, String finalDefaultDomain, int finalStartOffset, int finalEndOffset, String finalTranslationText) implements TranslatorKeyExtractorDialog.OnOkCallback {
@Override
public void onClick(List<TranslationFileModel> files, final String keyName, final String domain, boolean navigateTo) {
PsiDocumentManager.getInstance(project).doPostponedOperationsAndUnblockDocument(editor.getDocument());
Expand All @@ -191,7 +175,7 @@ public void onClick(List<TranslationFileModel> files, final String keyName, fina
String insertString;

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

// so finally insert it; first file can be a navigation target
for(TranslationFileModel transPsiFile: files) {
for (TranslationFileModel transPsiFile : files) {
PsiFile psiFile = transPsiFile.getPsiFile();

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

if(navigateTo && targets.size() > 0) {
if (navigateTo && targets.size() > 0) {
PsiDocumentManager.getInstance(project).commitAndRunReadAction(() ->
IdeHelper.navigateToPsiElement(targets.iterator().next())
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public char getKey() {
@Nullable
@Override
public PhpType getType(PsiElement e) {
if (!Settings.getInstance(e.getProject()).pluginEnabled || !(e instanceof MethodReference)) {
if (!Settings.getInstance(e.getProject()).pluginEnabled || !(e instanceof MethodReference methodReference)) {
return null;
}

Expand All @@ -49,7 +49,6 @@ public PhpType getType(PsiElement e) {
return null;
}

MethodReference methodReference = (MethodReference) e;
Collection<MethodSignatureSetting> matchedSignatures = getSignatureSetting(methodReference.getName(), signatures);
if(matchedSignatures.size() == 0) {
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,12 +151,10 @@ protected void addCompletions(@NotNull CompletionParameters completionParameters
return;
}

if (!(psiElement.getParent().getParent() instanceof BinaryExpression)) {
if (!(psiElement.getParent().getParent() instanceof BinaryExpression binaryExpression)) {
return;
}

BinaryExpression binaryExpression = (BinaryExpression) psiElement.getParent().getParent();


// OK: $response->getStatusCode() == Response::HTTP_BAD_GATEWAY
// @TODO: error we are complete outside of context: $response->getStatusCode() == Response::HTTP_BAD_GATEWAY || $response->getStatusCode() ==
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -443,15 +443,7 @@ private String getCompletedText(@NotNull CompletionParameters completionParamete
return null;
}

private static class LookupElementInsertHandler implements InsertHandler<LookupElement> {
private final String propertyName;
private final String typePhpClass;

public LookupElementInsertHandler(String propertyName, String typePhpClass) {
this.propertyName = propertyName;
this.typePhpClass = typePhpClass;
}

private record LookupElementInsertHandler(String propertyName, String typePhpClass) implements InsertHandler<LookupElement> {
@Override
public void handleInsert(@NotNull InsertionContext context, @NotNull LookupElement item) {
SmartPsiElementPointer<PhpClass> parentOfType2 = (SmartPsiElementPointer<PhpClass>) item.getObject();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,16 +221,10 @@ private Map<String, CommandArg> getCommandConfigurationMap(@NotNull PhpClass php
return targets;
}

private static class CommandDefPsiElementFilter implements Processor<PsiElement> {
private final String methodName;

public CommandDefPsiElementFilter(String methodName) {
this.methodName = methodName;
}

private record CommandDefPsiElementFilter(String methodName) implements Processor<PsiElement> {
@Override
public boolean process(PsiElement psiElement) {
if(!(psiElement instanceof MethodReference)) {
if (!(psiElement instanceof MethodReference)) {
return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,22 +96,7 @@ private void visitConfigKey(@NotNull Collection<? super LineMarkerInfo<?>> resul
result.add(builder.createLineMarkerInfo(psiElement));
}

private static class MyClassIdLazyValue implements Supplier<Collection<? extends PsiElement>> {
@NotNull
private final Project project;

@NotNull
private final Collection<String> configuration;

@NotNull
private final String root;

MyClassIdLazyValue(@NotNull Project project, @NotNull Collection<String> configuration, @NotNull String root) {
this.project = project;
this.configuration = configuration;
this.root = root;
}

private record MyClassIdLazyValue(@NotNull Project project, @NotNull Collection<String> configuration, @NotNull String root) implements Supplier<Collection<? extends PsiElement>> {
@Override
public Collection<? extends PsiElement> get() {
return ConfigUtil.getTreeSignatureTargets(project, root, configuration);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -387,10 +387,8 @@ private void constraintMessagePropertyMarker(@NotNull PsiElement psiElement, @No
}
}

private static class MyCollectionNotNullLazyValue implements Supplier<Collection<? extends PsiElement>> {
private final Collection<ClassServiceDefinitionTargetLazyValue> targets;

public MyCollectionNotNullLazyValue(@NotNull Collection<ClassServiceDefinitionTargetLazyValue> targets) {
private record MyCollectionNotNullLazyValue(Collection<ClassServiceDefinitionTargetLazyValue> targets) implements Supplier<Collection<? extends PsiElement>> {
private MyCollectionNotNullLazyValue(@NotNull Collection<ClassServiceDefinitionTargetLazyValue> targets) {
this.targets = targets;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,12 +148,10 @@ public boolean acceptsTarget(@NotNull PsiElement target) {
}

ArrayCreationExpression arrayCreationExpression = PhpElementsUtil.getCompletableArrayCreationElement(psiElement);
if(arrayCreationExpression == null || !(arrayCreationExpression.getContext() instanceof PhpReturn)) {
if(arrayCreationExpression == null || !(arrayCreationExpression.getContext() instanceof PhpReturn phpReturn)) {
return new PsiReference[0];
}

PhpReturn phpReturn = (PhpReturn) arrayCreationExpression.getContext();

Method method = PsiTreeUtil.getParentOfType(phpReturn, Method.class);
if(method == null) {
return new PsiReference[0];
Expand All @@ -176,20 +174,18 @@ public boolean acceptsTarget(@NotNull PsiElement target) {

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

if (!(psiElement.getContext() instanceof ParameterList)) {
if (!(psiElement.getContext() instanceof ParameterList parameterList)) {
return false;
}

ParameterList parameterList = (ParameterList) psiElement.getContext();
if (!(parameterList.getContext() instanceof NewExpression)) {
if (!(parameterList.getContext() instanceof NewExpression newExpression)) {
return false;
}

if(PsiElementUtils.getParameterIndexValue(psiElement) != index) {
return false;
}

NewExpression newExpression = (NewExpression) parameterList.getContext();
ClassReference classReference = newExpression.getClassReference();
if(classReference == null) {
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,23 +137,7 @@ private static void visitTreeSignatures(@NotNull Collection<PhpClass> classes, @
}
}

private static class TreeVisitor {
@NotNull
private final PhpClass phpClass;

@NotNull
private final PsiElement psiElement;

@NotNull
private final String contents;

public TreeVisitor(@NotNull PhpClass phpClass, @NotNull PsiElement psiElement, @NotNull String contents) {

this.phpClass = phpClass;
this.psiElement = psiElement;
this.contents = contents;
}
}
private record TreeVisitor(@NotNull PhpClass phpClass, @NotNull PsiElement psiElement, @NotNull String contents) {}

/**
* app/config[..].yml
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,15 +221,5 @@ private String createTypeHintFromParameter(@NotNull Project project, Parameter p
return parameter.getName();
}

private static class Match {
@NotNull
private final String parameter;

private final int targetOffset;

Match(@NotNull String parameter, int targetOffset) {
this.parameter = parameter;
this.targetOffset = targetOffset;
}
}
private record Match(@NotNull String parameter, int targetOffset) {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -530,16 +530,14 @@ public static ServiceTypeHint getYamlConstructorTypeHint(@NotNull YAMLScalar yam
}
}
}
} else if(context instanceof YAMLSequenceItem) {
} else if(context instanceof YAMLSequenceItem sequenceItem) {
// arguments: ['@foobar']

YAMLSequenceItem sequenceItem = (YAMLSequenceItem) context;
PsiElement yamlSequenceItem = sequenceItem.getContext();
if(yamlSequenceItem instanceof YAMLSequence) {
YAMLSequence yamlArray = (YAMLSequence) sequenceItem.getContext();
PsiElement yamlKeyValue = yamlArray.getContext();
if(yamlKeyValue instanceof YAMLKeyValue) {
YAMLKeyValue yamlKeyValueArguments = (YAMLKeyValue) yamlKeyValue;
if(yamlKeyValue instanceof YAMLKeyValue yamlKeyValueArguments) {
if(yamlKeyValueArguments.getKeyText().equals("arguments")) {
YAMLMapping parentMapping = yamlKeyValueArguments.getParentMapping();
if(parentMapping != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,29 +72,17 @@ public void invoke(@NotNull Project project, @NotNull PsiFile psiFile, @Nullable
/**
* This class replace a service name by plain text modification.
* This resolve every crazy yaml use case and lexer styles like:
*
* - @, @?
* - "@foo", '@foo', @foo
* <p>
* - @, @?
* - "@foo", '@foo', @foo
*/
private static class MyInsertCallback implements ServiceSuggestDialog.Callback {

@NotNull
private final Editor editor;

@NotNull
private final PsiElement psiElement;

public MyInsertCallback(@NotNull Editor editor, @NotNull PsiElement psiElement) {
this.editor = editor;
this.psiElement = psiElement;
}

private record MyInsertCallback(@NotNull Editor editor, @NotNull PsiElement psiElement) implements ServiceSuggestDialog.Callback {
@Override
public void insert(@NotNull String selected) {
String text = this.psiElement.getText();

int i = getServiceChar(text);
if(i < 0) {
if (i < 0) {
HintManager.getInstance().showErrorHint(editor, "No valid char in text range");
return;
}
Expand All @@ -113,7 +101,7 @@ public void insert(@NotNull String selected) {

private int getServiceChar(@NotNull String text) {
int i = text.lastIndexOf("@?");
if(i >= 0) {
if (i >= 0) {
return i + 1;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@ public void build(@NotNull Project project, @NotNull Collection<FileObject> file
inputStream = new ResetOnCloseInputStream(new ByteArrayInputStream(
IOUtils.getInputStreamBytes(fileObject.getContent().getInputStream()))
);
} catch (FileSystemException ignored) {
continue;
} catch (IOException ignored) {
continue;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,12 +126,10 @@ public static Collection<Pair<String, String>> getClassRepositoryPair(@NotNull P
}

PhpPsiElement phpClass = phpDocComment.getNextPsiSibling();
if (!(phpClass instanceof PhpClass)) {
if (!(phpClass instanceof PhpClass phpClassScope)) {
return false;
}

PhpClass phpClassScope = (PhpClass) phpClass;

pairs.add(Pair.create(
phpClassScope.getPresentableFQN(),
getAnnotationRepositoryClass(phpDocTag, phpClassScope))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,10 @@ public char getKey() {
@Nullable
@Override
public PhpType getType(PsiElement e) {
if (!(e instanceof MethodReference) || !Settings.getInstance(e.getProject()).pluginEnabled) {
if (!(e instanceof MethodReference methodRef) || !Settings.getInstance(e.getProject()).pluginEnabled) {
return null;
}

MethodReference methodRef = (MethodReference) e;

String refSignature = ((MethodReference)e).getSignature();
if(StringUtil.isEmpty(refSignature)) {
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,10 @@ public char getKey() {
@Nullable
@Override
public PhpType getType(PsiElement e) {
if (!(e instanceof MethodReference) || !Settings.getInstance(e.getProject()).pluginEnabled) {
if (!(e instanceof MethodReference methodRef) || !Settings.getInstance(e.getProject()).pluginEnabled) {
return null;
}

MethodReference methodRef = (MethodReference) e;

String refSignature = ((MethodReference)e).getSignature();
if(StringUtil.isEmpty(refSignature)) {
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,12 @@ public class QueryBuilderGotoDeclarationHandler implements GotoDeclarationHandle
@Override
public PsiElement[] getGotoDeclarationTargets(PsiElement psiElement, int offset, Editor editor) {

if (!Symfony2ProjectComponent.isEnabled(psiElement) || !(psiElement.getContext() instanceof StringLiteralExpression)) {
if (!Symfony2ProjectComponent.isEnabled(psiElement) || !(psiElement.getContext() instanceof StringLiteralExpression context)) {
return new PsiElement[0];
}

List<PsiElement> psiElements = new ArrayList<>();

StringLiteralExpression context = (StringLiteralExpression) psiElement.getContext();
attachPropertyGoto(context, psiElements);
attachJoinGoto(context, psiElements);
attachPartialGoto(context, psiElements, offset);
Expand Down
Loading