From e5f6841ac368ff8fa50b1791d9073eeb91f86e09 Mon Sep 17 00:00:00 2001 From: Daniel Espendiller Date: Mon, 13 May 2024 20:09:04 +0200 Subject: [PATCH] some language feature migration and code related code cleanup --- .../action/ServiceActionUtil.java | 1 - .../ui/ServiceArgumentSelectionDialog.java | 2 +- .../action/ui/ServiceBuilder.java | 2 +- .../idea/symfony2plugin/asset/AssetFile.java | 5 +- .../asset/AssetGoToDeclarationHandler.java | 2 +- .../xml/XmlGotoCompletionRegistrar.java | 2 +- .../completion/ConfigCompletionProvider.java | 3 - .../idea/symfony2plugin/dic/ServiceMap.java | 2 +- ...eAnnotationReferencedColumnReferences.java | 55 ++++++++----------- .../symfony2plugin/doctrine/DoctrineUtil.java | 2 +- .../symfony2plugin/doctrine/EntityHelper.java | 8 +-- ...RepositoryFindGotoCompletionRegistrar.java | 2 +- .../metadata/util/DoctrineMetadataUtil.java | 2 +- .../QueryBuilderCompletionContributor.java | 2 +- .../QueryBuilderGotoDeclarationHandler.java | 6 -- ...DoctrineDbalQbGotoCompletionRegistrar.java | 2 +- .../form/FormTypeReferenceContributor.java | 4 -- .../form/FormUnderscoreMethodReference.java | 2 +- .../form/util/FormOptionsUtil.java | 1 - .../xml/XmlServiceTagIntention.java | 5 +- .../yaml/YamlServiceTagIntention.java | 4 +- .../navigation/NavigationItemEx.java | 2 +- .../navigation/TwigFoldingBuilder.java | 13 +---- .../navigation/TwigGotoRelatedProvider.java | 4 +- .../symfony2plugin/routing/RouteHelper.java | 53 ++++++++---------- .../stubs/dict/TemplateUsage.java | 2 +- .../stubs/indexes/FormDataClassStubIndex.java | 2 +- .../PhpTwigTemplateUsageStubIndex.java | 2 - .../AssetPackageGotoCompletionRegistrar.java | 2 +- .../templating/TemplateLookupElement.java | 12 ---- .../TwigTemplateGoToDeclarationHandler.java | 2 - .../templating/util/TwigExtensionParser.java | 4 +- .../templating/util/TwigUtil.java | 2 +- .../TranslationDomainReference.java | 2 +- .../translation/TranslationReference.java | 2 +- .../translation/dict/DomainFileMap.java | 10 +--- .../translation/dict/TranslationUtil.java | 4 +- .../assets/TwigNamedAssetsServiceParser.java | 6 +- .../ui/ContainerSettingsForm.java | 4 -- .../symfony2plugin/ui/TwigSettingsForm.java | 7 --- .../idea/symfony2plugin/util/CommandUtil.java | 1 - .../util/EventDispatcherTypeProvider.java | 2 +- .../symfony2plugin/util/PhpElementsUtil.java | 15 ++--- .../PhpStringLiteralExpressionReference.java | 2 +- .../util/PhpTypeProviderUtil.java | 2 +- .../symfony2plugin/util/PsiElementUtils.java | 3 - .../util/SymfonyBundleUtil.java | 1 - .../PhpConstGotoCompletionProvider.java | 2 +- .../util/dict/ResourceFileInsertHandler.java | 2 +- .../util/psi/PhpBundleFileFactory.java | 6 +- ...ayValueWithKeyAndNewExpressionMatcher.java | 2 +- .../symfony2plugin/util/yaml/YamlHelper.java | 6 +- ...ymfonyLightCodeInsightFixtureTestCase.java | 1 - ...QueryBuilderCompletionContributorTest.java | 2 - 54 files changed, 102 insertions(+), 194 deletions(-) diff --git a/src/main/java/fr/adrienbrault/idea/symfony2plugin/action/ServiceActionUtil.java b/src/main/java/fr/adrienbrault/idea/symfony2plugin/action/ServiceActionUtil.java index bfd7e099b..04bf29339 100644 --- a/src/main/java/fr/adrienbrault/idea/symfony2plugin/action/ServiceActionUtil.java +++ b/src/main/java/fr/adrienbrault/idea/symfony2plugin/action/ServiceActionUtil.java @@ -26,7 +26,6 @@ import fr.adrienbrault.idea.symfony2plugin.stubs.ContainerCollectionResolver; import fr.adrienbrault.idea.symfony2plugin.util.PhpElementsUtil; import fr.adrienbrault.idea.symfony2plugin.util.dict.ServiceUtil; -import fr.adrienbrault.idea.symfony2plugin.util.psi.PhpBundleFileFactory; import fr.adrienbrault.idea.symfony2plugin.util.yaml.YamlHelper; import org.apache.commons.lang3.StringUtils; import org.jetbrains.annotations.NotNull; diff --git a/src/main/java/fr/adrienbrault/idea/symfony2plugin/action/ui/ServiceArgumentSelectionDialog.java b/src/main/java/fr/adrienbrault/idea/symfony2plugin/action/ui/ServiceArgumentSelectionDialog.java index 4507e5b61..3c9247036 100644 --- a/src/main/java/fr/adrienbrault/idea/symfony2plugin/action/ui/ServiceArgumentSelectionDialog.java +++ b/src/main/java/fr/adrienbrault/idea/symfony2plugin/action/ui/ServiceArgumentSelectionDialog.java @@ -170,7 +170,7 @@ public String valueOf(ServiceParameter modelParameter) { int i = classFqn.lastIndexOf("\\"); if(i > 0) { String ns = classFqn.substring(0, i); - String clazz = classFqn.substring(i + 1, classFqn.length()); + String clazz = classFqn.substring(i + 1); classFqn = String.format("%s [%s]", clazz, ns); } diff --git a/src/main/java/fr/adrienbrault/idea/symfony2plugin/action/ui/ServiceBuilder.java b/src/main/java/fr/adrienbrault/idea/symfony2plugin/action/ui/ServiceBuilder.java index af34dd33c..5df176682 100644 --- a/src/main/java/fr/adrienbrault/idea/symfony2plugin/action/ui/ServiceBuilder.java +++ b/src/main/java/fr/adrienbrault/idea/symfony2plugin/action/ui/ServiceBuilder.java @@ -117,7 +117,7 @@ private List getParameters(List me } - if(!hasCall || methodCalls.isEmpty()) { + if(!hasCall) { return null; } diff --git a/src/main/java/fr/adrienbrault/idea/symfony2plugin/asset/AssetFile.java b/src/main/java/fr/adrienbrault/idea/symfony2plugin/asset/AssetFile.java index 612476b2a..15a40c2d6 100644 --- a/src/main/java/fr/adrienbrault/idea/symfony2plugin/asset/AssetFile.java +++ b/src/main/java/fr/adrienbrault/idea/symfony2plugin/asset/AssetFile.java @@ -3,6 +3,7 @@ import com.intellij.openapi.vfs.VfsUtil; import com.intellij.openapi.vfs.VirtualFile; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; /** * @author Daniel Espendiller @@ -14,7 +15,7 @@ public class AssetFile { @NotNull private final AssetEnum.Position assetPosition; - @NotNull + @Nullable private VirtualFile relativeFolder; private String prefix = ""; @@ -58,6 +59,6 @@ public AssetEnum.Position getAssetPosition() { public String toString() { return this.string != null ? this.string - : this.prefix + VfsUtil.getRelativePath(assetFile, relativeFolder, '/'); + : this.prefix + (relativeFolder != null ? VfsUtil.getRelativePath(assetFile, relativeFolder, '/') : ""); } } diff --git a/src/main/java/fr/adrienbrault/idea/symfony2plugin/asset/AssetGoToDeclarationHandler.java b/src/main/java/fr/adrienbrault/idea/symfony2plugin/asset/AssetGoToDeclarationHandler.java index 381469d8a..e6f89a7be 100644 --- a/src/main/java/fr/adrienbrault/idea/symfony2plugin/asset/AssetGoToDeclarationHandler.java +++ b/src/main/java/fr/adrienbrault/idea/symfony2plugin/asset/AssetGoToDeclarationHandler.java @@ -59,7 +59,7 @@ private String[] findValidAssetFilter(PsiElement psiElement) { // asset / absolute_url dont have pre filter if(TwigPattern.getPrintBlockOrTagFunctionPattern("asset", "absolute_url").accepts(psiElement)) { - return (String[]) ArrayUtils.addAll(TwigUtil.CSS_FILES_EXTENSIONS, TwigUtil.JS_FILES_EXTENSIONS); + return ArrayUtils.addAll(TwigUtil.CSS_FILES_EXTENSIONS, TwigUtil.JS_FILES_EXTENSIONS); } return null; diff --git a/src/main/java/fr/adrienbrault/idea/symfony2plugin/completion/xml/XmlGotoCompletionRegistrar.java b/src/main/java/fr/adrienbrault/idea/symfony2plugin/completion/xml/XmlGotoCompletionRegistrar.java index f7ff2ee9c..4d6b560d7 100644 --- a/src/main/java/fr/adrienbrault/idea/symfony2plugin/completion/xml/XmlGotoCompletionRegistrar.java +++ b/src/main/java/fr/adrienbrault/idea/symfony2plugin/completion/xml/XmlGotoCompletionRegistrar.java @@ -248,7 +248,7 @@ public Collection getLookupElements() { for (PhpClass phpClass : phpClasses) { lookupElements.addAll(PhpElementsUtil.getClassPublicMethod(phpClass).stream() .map(PhpLookupElement::new) - .collect(Collectors.toList()) + .toList() ); } diff --git a/src/main/java/fr/adrienbrault/idea/symfony2plugin/config/yaml/completion/ConfigCompletionProvider.java b/src/main/java/fr/adrienbrault/idea/symfony2plugin/config/yaml/completion/ConfigCompletionProvider.java index 0fafa5409..6390e3285 100644 --- a/src/main/java/fr/adrienbrault/idea/symfony2plugin/config/yaml/completion/ConfigCompletionProvider.java +++ b/src/main/java/fr/adrienbrault/idea/symfony2plugin/config/yaml/completion/ConfigCompletionProvider.java @@ -303,9 +303,6 @@ private Map getNodeCommentVars(@Nullable Node node) { if(node == null) return comments; Node previousSibling = node.getPreviousSibling(); - if(previousSibling == comments) { - return comments; - } // get variable decl: "foo: test" Pattern compile = Pattern.compile("^\\s*([\\w_-]+)\\s*:\\s*(.*?)$"); diff --git a/src/main/java/fr/adrienbrault/idea/symfony2plugin/dic/ServiceMap.java b/src/main/java/fr/adrienbrault/idea/symfony2plugin/dic/ServiceMap.java index 33ba9a437..5e992d0df 100644 --- a/src/main/java/fr/adrienbrault/idea/symfony2plugin/dic/ServiceMap.java +++ b/src/main/java/fr/adrienbrault/idea/symfony2plugin/dic/ServiceMap.java @@ -16,7 +16,7 @@ public class ServiceMap { private Collection ids; ServiceMap() { - this.services = Collections.unmodifiableCollection(Collections.emptyList()); + this.services = Collections.emptyList(); } ServiceMap(@NotNull Collection services) { diff --git a/src/main/java/fr/adrienbrault/idea/symfony2plugin/doctrine/DoctrineAnnotationReferencedColumnReferences.java b/src/main/java/fr/adrienbrault/idea/symfony2plugin/doctrine/DoctrineAnnotationReferencedColumnReferences.java index f2369a669..debd0da5f 100644 --- a/src/main/java/fr/adrienbrault/idea/symfony2plugin/doctrine/DoctrineAnnotationReferencedColumnReferences.java +++ b/src/main/java/fr/adrienbrault/idea/symfony2plugin/doctrine/DoctrineAnnotationReferencedColumnReferences.java @@ -50,45 +50,36 @@ public PsiReference[] getPropertyReferences(AnnotationPropertyParameter annotati PhpDocComment phpDocComment = PsiTreeUtil.getParentOfType(element, PhpDocComment.class); if(phpDocComment != null) { PhpDocCommentAnnotation phpDocCommentAnnotationContainer = AnnotationUtil.getPhpDocCommentAnnotationContainer(phpDocComment); - - if(phpDocCommentAnnotationContainer != null) { - - PhpDocTagAnnotation phpDocTagAnnotation = phpDocCommentAnnotationContainer.getFirstPhpDocBlock( - "\\Doctrine\\ORM\\Mapping\\ManyToOne", - "\\Doctrine\\ORM\\Mapping\\ManyToMany", - "\\Doctrine\\ORM\\Mapping\\OneToOne", - "\\Doctrine\\ORM\\Mapping\\OneToMany" - ); - - if(phpDocTagAnnotation != null) { - - PhpPsiElement phpDocAttrList = phpDocTagAnnotation.getPhpDocTag().getFirstPsiChild(); - - // @TODO: remove nested on Annotation plugin update - if(phpDocAttrList != null) { - if(phpDocAttrList.getNode().getElementType() == PhpDocElementTypes.phpDocAttributeList) { - PhpPsiElement phpPsiElement = phpDocAttrList.getFirstPsiChild(); - if(phpPsiElement instanceof StringLiteralExpression) { - PhpClass phpClass = de.espend.idea.php.annotation.util.PhpElementsUtil.getClassInsideAnnotation(((StringLiteralExpression) phpPsiElement)); - if(phpClass != null) { - Collection lists = EntityHelper.getModelFields(phpClass); - if(!lists.isEmpty()) { - return new PsiReference[] { - new EntityReference((StringLiteralExpression) element, lists) - }; - } + PhpDocTagAnnotation phpDocTagAnnotation = phpDocCommentAnnotationContainer.getFirstPhpDocBlock( + "\\Doctrine\\ORM\\Mapping\\ManyToOne", + "\\Doctrine\\ORM\\Mapping\\ManyToMany", + "\\Doctrine\\ORM\\Mapping\\OneToOne", + "\\Doctrine\\ORM\\Mapping\\OneToMany" + ); + + if(phpDocTagAnnotation != null) { + + PhpPsiElement phpDocAttrList = phpDocTagAnnotation.getPhpDocTag().getFirstPsiChild(); + + // @TODO: remove nested on Annotation plugin update + if(phpDocAttrList != null) { + if(phpDocAttrList.getNode().getElementType() == PhpDocElementTypes.phpDocAttributeList) { + PhpPsiElement phpPsiElement = phpDocAttrList.getFirstPsiChild(); + if(phpPsiElement instanceof StringLiteralExpression) { + PhpClass phpClass = de.espend.idea.php.annotation.util.PhpElementsUtil.getClassInsideAnnotation(((StringLiteralExpression) phpPsiElement)); + if(phpClass != null) { + Collection lists = EntityHelper.getModelFields(phpClass); + if(!lists.isEmpty()) { + return new PsiReference[] { + new EntityReference((StringLiteralExpression) element, lists) + }; } } } } - - } - } - } - } return new PsiReference[0]; diff --git a/src/main/java/fr/adrienbrault/idea/symfony2plugin/doctrine/DoctrineUtil.java b/src/main/java/fr/adrienbrault/idea/symfony2plugin/doctrine/DoctrineUtil.java index a11745c7a..d3687ac23 100644 --- a/src/main/java/fr/adrienbrault/idea/symfony2plugin/doctrine/DoctrineUtil.java +++ b/src/main/java/fr/adrienbrault/idea/symfony2plugin/doctrine/DoctrineUtil.java @@ -84,7 +84,7 @@ private static Collection> getClassRepositoryPair(@NotNull Collection> pairs = new ArrayList<>(); - for (XmlTag xmlTag : (XmlTag[]) ArrayUtils.addAll(rootTag.findSubTags("document"), rootTag.findSubTags("entity"))) { + for (XmlTag xmlTag : ArrayUtils.addAll(rootTag.findSubTags("document"), rootTag.findSubTags("entity"))) { XmlAttribute attr = xmlTag.getAttribute("name"); if(attr == null) { diff --git a/src/main/java/fr/adrienbrault/idea/symfony2plugin/doctrine/EntityHelper.java b/src/main/java/fr/adrienbrault/idea/symfony2plugin/doctrine/EntityHelper.java index 6b2f2de8c..11dbbfb2b 100644 --- a/src/main/java/fr/adrienbrault/idea/symfony2plugin/doctrine/EntityHelper.java +++ b/src/main/java/fr/adrienbrault/idea/symfony2plugin/doctrine/EntityHelper.java @@ -259,7 +259,7 @@ public static PsiElement[] getModelFieldTargets(@NotNull PhpClass phpClass,@NotN if(modelFields != null) { for (DoctrineModelField field : modelFields.getFields()) { if(field.getName().equals(fieldName) && !field.getTargets().isEmpty()) { - return field.getTargets().toArray(new PsiElement[psiElements.size()]); + return field.getTargets().toArray(new PsiElement[0]); } } } @@ -377,11 +377,11 @@ public static Collection getModelFields(@NotNull PhpClass ph // @TODO: old deprecated code PsiFile psiFile = getModelConfigFile(phpClass); - if(psiFile == null) { - Collections.emptyList(); + if (psiFile == null) { + return Collections.emptyList(); } - if(psiFile instanceof YAMLFile) { + if (psiFile instanceof YAMLFile) { List modelFields = new ArrayList<>(); PsiElement yamlDocument = psiFile.getFirstChild(); diff --git a/src/main/java/fr/adrienbrault/idea/symfony2plugin/doctrine/metadata/ObjectRepositoryFindGotoCompletionRegistrar.java b/src/main/java/fr/adrienbrault/idea/symfony2plugin/doctrine/metadata/ObjectRepositoryFindGotoCompletionRegistrar.java index 0d082e1a0..4a7bcef36 100644 --- a/src/main/java/fr/adrienbrault/idea/symfony2plugin/doctrine/metadata/ObjectRepositoryFindGotoCompletionRegistrar.java +++ b/src/main/java/fr/adrienbrault/idea/symfony2plugin/doctrine/metadata/ObjectRepositoryFindGotoCompletionRegistrar.java @@ -103,7 +103,7 @@ public Collection getLookupElements() { phpClasses.forEach(phpClass -> results.addAll(EntityHelper.getModelFields(phpClass).stream() .map((Function) DoctrineModelFieldLookupElement::new) - .collect(Collectors.toList()) + .toList() ) ); diff --git a/src/main/java/fr/adrienbrault/idea/symfony2plugin/doctrine/metadata/util/DoctrineMetadataUtil.java b/src/main/java/fr/adrienbrault/idea/symfony2plugin/doctrine/metadata/util/DoctrineMetadataUtil.java index 9a746a239..ba7a837f3 100644 --- a/src/main/java/fr/adrienbrault/idea/symfony2plugin/doctrine/metadata/util/DoctrineMetadataUtil.java +++ b/src/main/java/fr/adrienbrault/idea/symfony2plugin/doctrine/metadata/util/DoctrineMetadataUtil.java @@ -238,7 +238,7 @@ public static DoctrineMetadataModel getMetadataByTable(@NotNull Project project, } String table = metadata.getTable(); - if(table != null && tableName.equals(table)) { + if(tableName.equals(table)) { return metadata; } } diff --git a/src/main/java/fr/adrienbrault/idea/symfony2plugin/doctrine/querybuilder/QueryBuilderCompletionContributor.java b/src/main/java/fr/adrienbrault/idea/symfony2plugin/doctrine/querybuilder/QueryBuilderCompletionContributor.java index 73a91d1bd..68086f7e6 100644 --- a/src/main/java/fr/adrienbrault/idea/symfony2plugin/doctrine/querybuilder/QueryBuilderCompletionContributor.java +++ b/src/main/java/fr/adrienbrault/idea/symfony2plugin/doctrine/querybuilder/QueryBuilderCompletionContributor.java @@ -29,7 +29,6 @@ import fr.adrienbrault.idea.symfony2plugin.util.PsiElementUtils; import org.apache.commons.lang3.StringUtils; import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; import java.util.*; import java.util.regex.Matcher; @@ -526,6 +525,7 @@ private void buildLookupElements(CompletionResultSet completionResultSet, QueryB } } + @NotNull public static QueryBuilderMethodReferenceParser getQueryBuilderParser(MethodReference methodReference) { final QueryBuilderChainProcessor processor = new QueryBuilderChainProcessor(methodReference); processor.collectMethods(); diff --git a/src/main/java/fr/adrienbrault/idea/symfony2plugin/doctrine/querybuilder/QueryBuilderGotoDeclarationHandler.java b/src/main/java/fr/adrienbrault/idea/symfony2plugin/doctrine/querybuilder/QueryBuilderGotoDeclarationHandler.java index 2edd886c6..ce881c751 100644 --- a/src/main/java/fr/adrienbrault/idea/symfony2plugin/doctrine/querybuilder/QueryBuilderGotoDeclarationHandler.java +++ b/src/main/java/fr/adrienbrault/idea/symfony2plugin/doctrine/querybuilder/QueryBuilderGotoDeclarationHandler.java @@ -86,9 +86,6 @@ private void attachJoinGoto(StringLiteralExpression psiElement, List } QueryBuilderMethodReferenceParser qb = QueryBuilderCompletionContributor.getQueryBuilderParser(methodMatchParameter.getMethodReference()); - if(qb == null) { - return; - } String[] joinSplit = StringUtils.split(psiElement.getContents(), "."); if(joinSplit.length != 2) { @@ -151,9 +148,6 @@ private void attachFromIndexGoto(StringLiteralExpression psiElement, List getLookupElements() { if(underscore.contains("_")) { String[] split = underscore.split("_"); if(split.length > 1) { - aliasSet.add(split[0].substring(0, 1) + split[1].substring(0, 1)); + aliasSet.add(split[0].charAt(0) + split[1].substring(0, 1)); } List i = new ArrayList<>(); diff --git a/src/main/java/fr/adrienbrault/idea/symfony2plugin/form/FormTypeReferenceContributor.java b/src/main/java/fr/adrienbrault/idea/symfony2plugin/form/FormTypeReferenceContributor.java index ef34ebc75..65ad068b0 100644 --- a/src/main/java/fr/adrienbrault/idea/symfony2plugin/form/FormTypeReferenceContributor.java +++ b/src/main/java/fr/adrienbrault/idea/symfony2plugin/form/FormTypeReferenceContributor.java @@ -72,10 +72,6 @@ public PsiReference[] getReferencesByElement(@NotNull PsiElement psiElement, @No return new PsiReference[0]; } - if(key == null) { - return new PsiReference[0]; - } - String keyString = key.getContents(); // @TODO: how to handle custom bundle fields like help_block diff --git a/src/main/java/fr/adrienbrault/idea/symfony2plugin/form/FormUnderscoreMethodReference.java b/src/main/java/fr/adrienbrault/idea/symfony2plugin/form/FormUnderscoreMethodReference.java index 40c28cc37..9250d1524 100644 --- a/src/main/java/fr/adrienbrault/idea/symfony2plugin/form/FormUnderscoreMethodReference.java +++ b/src/main/java/fr/adrienbrault/idea/symfony2plugin/form/FormUnderscoreMethodReference.java @@ -49,7 +49,7 @@ public ResolveResult[] multiResolve(boolean incompleteCode) { // property path psiElements.addAll(this.phpClass.getFields().stream() .filter(field -> !field.isConstant() && field.getModifier().isPublic() && methods.contains(field.getName())) - .collect(Collectors.toList()) + .toList() ); return PsiElementResolveResult.createResults(psiElements); diff --git a/src/main/java/fr/adrienbrault/idea/symfony2plugin/form/util/FormOptionsUtil.java b/src/main/java/fr/adrienbrault/idea/symfony2plugin/form/util/FormOptionsUtil.java index cda3b11a3..b4657290f 100644 --- a/src/main/java/fr/adrienbrault/idea/symfony2plugin/form/util/FormOptionsUtil.java +++ b/src/main/java/fr/adrienbrault/idea/symfony2plugin/form/util/FormOptionsUtil.java @@ -7,7 +7,6 @@ import com.intellij.psi.PsiElement; import com.intellij.psi.util.PsiTreeUtil; import com.intellij.util.containers.ContainerUtil; -import com.jetbrains.php.PhpIndex; import com.jetbrains.php.lang.psi.elements.*; import fr.adrienbrault.idea.symfony2plugin.Symfony2Icons; import fr.adrienbrault.idea.symfony2plugin.form.dict.*; diff --git a/src/main/java/fr/adrienbrault/idea/symfony2plugin/intentions/xml/XmlServiceTagIntention.java b/src/main/java/fr/adrienbrault/idea/symfony2plugin/intentions/xml/XmlServiceTagIntention.java index 13352a36b..470ab9fa5 100644 --- a/src/main/java/fr/adrienbrault/idea/symfony2plugin/intentions/xml/XmlServiceTagIntention.java +++ b/src/main/java/fr/adrienbrault/idea/symfony2plugin/intentions/xml/XmlServiceTagIntention.java @@ -66,10 +66,7 @@ public void invoke(@NotNull final Project project, final Editor editor, @NotNull } String value = name.getValue(); - if(phpServiceTags.contains(value)) { - phpServiceTags.remove(value); - } - + phpServiceTags.remove(value); } ServiceUtil.insertTagWithPopupDecision(editor, phpServiceTags, tag -> { diff --git a/src/main/java/fr/adrienbrault/idea/symfony2plugin/intentions/yaml/YamlServiceTagIntention.java b/src/main/java/fr/adrienbrault/idea/symfony2plugin/intentions/yaml/YamlServiceTagIntention.java index a75e2f57c..cffb36d70 100644 --- a/src/main/java/fr/adrienbrault/idea/symfony2plugin/intentions/yaml/YamlServiceTagIntention.java +++ b/src/main/java/fr/adrienbrault/idea/symfony2plugin/intentions/yaml/YamlServiceTagIntention.java @@ -172,9 +172,7 @@ private static Pair> invoke(@NotNull Project project, @Not Set strings = YamlHelper.collectServiceTags(serviceKeyValue); if(!strings.isEmpty()) { for (String s : strings) { - if(phpClassServiceTags.contains(s)) { - phpClassServiceTags.remove(s); - } + phpClassServiceTags.remove(s); } } diff --git a/src/main/java/fr/adrienbrault/idea/symfony2plugin/navigation/NavigationItemEx.java b/src/main/java/fr/adrienbrault/idea/symfony2plugin/navigation/NavigationItemEx.java index cce88afdb..60f2aa04a 100644 --- a/src/main/java/fr/adrienbrault/idea/symfony2plugin/navigation/NavigationItemEx.java +++ b/src/main/java/fr/adrienbrault/idea/symfony2plugin/navigation/NavigationItemEx.java @@ -96,7 +96,7 @@ public String getLocationString() { if(bundleName.contains("Bundle")) { bundleName = bundleName.substring(0, bundleName.lastIndexOf("Bundle")); if(bundleName.length() > 1 && bundleName.contains("/")) { - return locationPathString + " " + bundleName.substring(bundleName.lastIndexOf("/") + 1, bundleName.length()) + "::" + psiFile.getName(); + return locationPathString + " " + bundleName.substring(bundleName.lastIndexOf("/") + 1) + "::" + psiFile.getName(); } } diff --git a/src/main/java/fr/adrienbrault/idea/symfony2plugin/navigation/TwigFoldingBuilder.java b/src/main/java/fr/adrienbrault/idea/symfony2plugin/navigation/TwigFoldingBuilder.java index 0904dfab9..f79f8a780 100644 --- a/src/main/java/fr/adrienbrault/idea/symfony2plugin/navigation/TwigFoldingBuilder.java +++ b/src/main/java/fr/adrienbrault/idea/symfony2plugin/navigation/TwigFoldingBuilder.java @@ -125,15 +125,11 @@ private void attachConstantFoldingDescriptors(PsiElement psiElement, List getItems(@NotNull PsiElement psiElement2) gotoRelatedItems.addAll(TwigBlockUtil.getBlockOverwriteTargets(childrenOfType).stream().map((Function) psiElement1 -> new RelatedPopupGotoLineMarker.PopupGotoRelatedItem(psiElement1, blockName).withIcon(Symfony2Icons.TWIG_BLOCK_OVERWRITE, Symfony2Icons.TWIG_BLOCK_OVERWRITE) - ).collect(Collectors.toList())); + ).toList()); gotoRelatedItems.addAll(TwigBlockUtil.getBlockImplementationTargets(childrenOfType).stream().map((Function) psiElement1 -> new RelatedPopupGotoLineMarker.PopupGotoRelatedItem(psiElement1, blockName).withIcon(Symfony2Icons.TWIG_BLOCK_OVERWRITE, Symfony2Icons.TWIG_BLOCK_OVERWRITE) - ).collect(Collectors.toList())); + ).toList()); } } } diff --git a/src/main/java/fr/adrienbrault/idea/symfony2plugin/routing/RouteHelper.java b/src/main/java/fr/adrienbrault/idea/symfony2plugin/routing/RouteHelper.java index 1cc560cf2..4d3394497 100644 --- a/src/main/java/fr/adrienbrault/idea/symfony2plugin/routing/RouteHelper.java +++ b/src/main/java/fr/adrienbrault/idea/symfony2plugin/routing/RouteHelper.java @@ -779,50 +779,41 @@ private static Route convertRouteConfig(@NotNull String routeName, @NotNull Arra hashValue.getHashElements().forEach(hashElementCollection::add); Set variables = new HashSet<>(); - if(!hashElementCollection.isEmpty() && hashElementCollection.get(0).getValue() instanceof ArrayCreationExpression value) { - if(value != null) { - variables.addAll(PhpElementsUtil.getArrayKeyValueMap(value).values()); - } + if (!hashElementCollection.isEmpty() && hashElementCollection.get(0).getValue() instanceof ArrayCreationExpression value) { + variables.addAll(PhpElementsUtil.getArrayKeyValueMap(value).values()); } Map defaults = new HashMap<>(); - if(hashElementCollection.size() >= 2 && hashElementCollection.get(1).getValue() instanceof ArrayCreationExpression value) { - if(value != null) { - defaults = PhpElementsUtil.getArrayKeyValueMap(value); - } + if (hashElementCollection.size() >= 2 && hashElementCollection.get(1).getValue() instanceof ArrayCreationExpression value) { + defaults = PhpElementsUtil.getArrayKeyValueMap(value); } Maprequirements = new HashMap<>(); - if(hashElementCollection.size() >= 3 && hashElementCollection.get(2).getValue() instanceof ArrayCreationExpression value) { - if(value != null) { - requirements = PhpElementsUtil.getArrayKeyValueMap(value); - } + if (hashElementCollection.size() >= 3 && hashElementCollection.get(2).getValue() instanceof ArrayCreationExpression value) { + requirements = PhpElementsUtil.getArrayKeyValueMap(value); } StringBuilder path = new StringBuilder(); List> tokens = new ArrayList<>(); - if(hashElementCollection.size() >= 4 && hashElementCollection.get(3).getValue() instanceof ArrayCreationExpression tokenArray) { - if(tokenArray != null) { - List result = StreamSupport.stream(tokenArray.getHashElements().spliterator(), false) - .collect(Collectors.toList()); + if (hashElementCollection.size() >= 4 && hashElementCollection.get(3).getValue() instanceof ArrayCreationExpression tokenArray) { + List result = StreamSupport.stream(tokenArray.getHashElements().spliterator(), false) + .collect(Collectors.toList()); - Collections.reverse(result); + Collections.reverse(result); - for(ArrayHashElement tokenArrayConfig: result) { - if(tokenArrayConfig.getValue() instanceof ArrayCreationExpression) { - Map arrayKeyValueMap = PhpElementsUtil.getArrayKeyValueMap((ArrayCreationExpression) tokenArrayConfig.getValue()); - path.append(arrayKeyValueMap.getOrDefault("1", null)); - - String var = arrayKeyValueMap.getOrDefault("3", null); - if (var != null) { - path.append("{").append(var).append("}"); - } + for (ArrayHashElement tokenArrayConfig: result) { + if (tokenArrayConfig.getValue() instanceof ArrayCreationExpression) { + Map arrayKeyValueMap = PhpElementsUtil.getArrayKeyValueMap((ArrayCreationExpression) tokenArrayConfig.getValue()); + path.append(arrayKeyValueMap.getOrDefault("1", null)); - tokens.add(arrayKeyValueMap.values()); + String var = arrayKeyValueMap.getOrDefault("3", null); + if (var != null) { + path.append("{").append(var).append("}"); } + + tokens.add(arrayKeyValueMap.values()); } } - } // hostTokens = 4 need them? @@ -1049,9 +1040,9 @@ public static Collection getXmlRouteDefinitions(XmlFile psiFil @Nullable public static String getXmlController(@NotNull XmlTag serviceTag) { for(XmlTag subTag :serviceTag.getSubTags()) { - if("default".equalsIgnoreCase(subTag.getName())) { + if ("default".equalsIgnoreCase(subTag.getName())) { String keyValue = subTag.getAttributeValue("key"); - if(keyValue != null && "_controller".equals(keyValue)) { + if ("_controller".equals(keyValue)) { String actionName = subTag.getValue().getTrimmedText(); if(StringUtils.isNotBlank(actionName)) { return actionName; @@ -1061,7 +1052,7 @@ public static String getXmlController(@NotNull XmlTag serviceTag) { } String controller = serviceTag.getAttributeValue("controller"); - if(controller != null && StringUtils.isNotBlank(controller)) { + if (StringUtils.isNotBlank(controller)) { return controller; } diff --git a/src/main/java/fr/adrienbrault/idea/symfony2plugin/stubs/dict/TemplateUsage.java b/src/main/java/fr/adrienbrault/idea/symfony2plugin/stubs/dict/TemplateUsage.java index 21aac5c70..40311a8fa 100644 --- a/src/main/java/fr/adrienbrault/idea/symfony2plugin/stubs/dict/TemplateUsage.java +++ b/src/main/java/fr/adrienbrault/idea/symfony2plugin/stubs/dict/TemplateUsage.java @@ -16,7 +16,7 @@ public class TemplateUsage implements Serializable { private final String template; @NotNull - private Collection scopes = new HashSet<>(); + private Collection scopes; public TemplateUsage(@NotNull String template, @NotNull Collection scopes) { this.template = template; diff --git a/src/main/java/fr/adrienbrault/idea/symfony2plugin/stubs/indexes/FormDataClassStubIndex.java b/src/main/java/fr/adrienbrault/idea/symfony2plugin/stubs/indexes/FormDataClassStubIndex.java index af5585030..d2c9faa77 100644 --- a/src/main/java/fr/adrienbrault/idea/symfony2plugin/stubs/indexes/FormDataClassStubIndex.java +++ b/src/main/java/fr/adrienbrault/idea/symfony2plugin/stubs/indexes/FormDataClassStubIndex.java @@ -97,7 +97,7 @@ public void visitElement(@NotNull MethodReference element, @NotNull Map s.toLowerCase().contains("optionsresolver"))) { // $resolver->setDefaults(['data_class' => XXX]); - ParameterList parameterList = ((MethodReference) element).getParameterList(); + ParameterList parameterList = element.getParameterList(); if (parameterList != null) { PsiElement parameter = parameterList.getParameter(0); if (parameter instanceof ArrayCreationExpression) { diff --git a/src/main/java/fr/adrienbrault/idea/symfony2plugin/stubs/indexes/PhpTwigTemplateUsageStubIndex.java b/src/main/java/fr/adrienbrault/idea/symfony2plugin/stubs/indexes/PhpTwigTemplateUsageStubIndex.java index c4ee3d915..944155274 100644 --- a/src/main/java/fr/adrienbrault/idea/symfony2plugin/stubs/indexes/PhpTwigTemplateUsageStubIndex.java +++ b/src/main/java/fr/adrienbrault/idea/symfony2plugin/stubs/indexes/PhpTwigTemplateUsageStubIndex.java @@ -11,7 +11,6 @@ import com.jetbrains.php.codeInsight.controlFlow.instructions.PhpCallInstruction; import com.jetbrains.php.lang.documentation.phpdoc.PhpDocUtil; import com.jetbrains.php.lang.documentation.phpdoc.psi.PhpDocComment; -import com.jetbrains.php.lang.documentation.phpdoc.psi.tags.PhpDocTag; import com.jetbrains.php.lang.psi.PhpFile; import com.jetbrains.php.lang.psi.elements.*; import com.jetbrains.php.lang.psi.stubs.indexes.PhpConstantNameIndex; @@ -25,7 +24,6 @@ import java.util.*; import java.util.function.Consumer; -import java.util.function.Predicate; /** * @author Daniel Espendiller diff --git a/src/main/java/fr/adrienbrault/idea/symfony2plugin/templating/AssetPackageGotoCompletionRegistrar.java b/src/main/java/fr/adrienbrault/idea/symfony2plugin/templating/AssetPackageGotoCompletionRegistrar.java index dc6fcac1d..39463a08e 100644 --- a/src/main/java/fr/adrienbrault/idea/symfony2plugin/templating/AssetPackageGotoCompletionRegistrar.java +++ b/src/main/java/fr/adrienbrault/idea/symfony2plugin/templating/AssetPackageGotoCompletionRegistrar.java @@ -101,7 +101,7 @@ public Collection getPsiTargets(PsiElement element) { Collection psiElements = new HashSet<>(); - for (VirtualFile virtualFile : TwigUtil.resolveAssetsFiles(element.getProject() ,contents, (String[]) ArrayUtils.addAll(TwigUtil.CSS_FILES_EXTENSIONS, TwigUtil.JS_FILES_EXTENSIONS))) { + for (VirtualFile virtualFile : TwigUtil.resolveAssetsFiles(element.getProject() ,contents, ArrayUtils.addAll(TwigUtil.CSS_FILES_EXTENSIONS, TwigUtil.JS_FILES_EXTENSIONS))) { PsiElement target; if(virtualFile.isDirectory()) { target = PsiManager.getInstance(element.getProject()).findDirectory(virtualFile); diff --git a/src/main/java/fr/adrienbrault/idea/symfony2plugin/templating/TemplateLookupElement.java b/src/main/java/fr/adrienbrault/idea/symfony2plugin/templating/TemplateLookupElement.java index 026782fba..3d6bb2643 100644 --- a/src/main/java/fr/adrienbrault/idea/symfony2plugin/templating/TemplateLookupElement.java +++ b/src/main/java/fr/adrienbrault/idea/symfony2plugin/templating/TemplateLookupElement.java @@ -1,13 +1,10 @@ package fr.adrienbrault.idea.symfony2plugin.templating; -import com.intellij.codeInsight.completion.InsertHandler; -import com.intellij.codeInsight.completion.InsertionContext; import com.intellij.codeInsight.lookup.LookupElement; import com.intellij.codeInsight.lookup.LookupElementPresentation; import com.intellij.openapi.vfs.VfsUtil; import com.intellij.openapi.vfs.VirtualFile; import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; /** * @author Adrien Brault @@ -25,9 +22,6 @@ public class TemplateLookupElement extends LookupElement { private boolean bold = false; - @Nullable - private final InsertHandler insertHandler = null; - public TemplateLookupElement(@NotNull String templateName, @NotNull VirtualFile virtualFile, @NotNull VirtualFile projectBaseDir) { this.templateName = templateName; this.virtualFile = virtualFile; @@ -45,12 +39,6 @@ public String getLookupString() { return templateName; } - public void handleInsert(InsertionContext context) { - if (this.insertHandler != null) { - this.insertHandler.handleInsert(context, this); - } - } - public void renderElement(LookupElementPresentation presentation) { presentation.setItemText(getLookupString()); presentation.setIcon(this.virtualFile.getFileType().getIcon()); diff --git a/src/main/java/fr/adrienbrault/idea/symfony2plugin/templating/TwigTemplateGoToDeclarationHandler.java b/src/main/java/fr/adrienbrault/idea/symfony2plugin/templating/TwigTemplateGoToDeclarationHandler.java index 040cb4508..285cd0660 100644 --- a/src/main/java/fr/adrienbrault/idea/symfony2plugin/templating/TwigTemplateGoToDeclarationHandler.java +++ b/src/main/java/fr/adrienbrault/idea/symfony2plugin/templating/TwigTemplateGoToDeclarationHandler.java @@ -13,7 +13,6 @@ import com.jetbrains.php.PhpIndex; import com.jetbrains.php.lang.psi.elements.Field; import com.jetbrains.php.lang.psi.elements.PhpClass; -import com.jetbrains.php.lang.psi.elements.PhpEnumCase; import com.jetbrains.twig.TwigLanguage; import com.jetbrains.twig.TwigTokenTypes; import com.jetbrains.twig.elements.TwigBlockTag; @@ -40,7 +39,6 @@ import org.jetbrains.annotations.Nullable; import java.util.*; -import java.util.function.Predicate; import java.util.regex.Matcher; import java.util.regex.Pattern; diff --git a/src/main/java/fr/adrienbrault/idea/symfony2plugin/templating/util/TwigExtensionParser.java b/src/main/java/fr/adrienbrault/idea/symfony2plugin/templating/util/TwigExtensionParser.java index ed6d97f3d..ada0ec5f2 100644 --- a/src/main/java/fr/adrienbrault/idea/symfony2plugin/templating/util/TwigExtensionParser.java +++ b/src/main/java/fr/adrienbrault/idea/symfony2plugin/templating/util/TwigExtensionParser.java @@ -411,7 +411,7 @@ static private Map getOptions(@NotNull ArrayCreationExpression a PhpPsiElement phpPsiElement = PhpElementsUtil.getArrayValue(arrayCreationExpression, optionTrue); if (phpPsiElement instanceof ConstantReference) { String value = phpPsiElement.getName(); - if (value != null && value.toLowerCase().equals("true")) { + if (value != null && value.equalsIgnoreCase("true")) { options.put(optionTrue, "true"); } } @@ -436,7 +436,7 @@ private static void visitNewExpression(@NotNull NewExpression element, @NotNull } // creation options like: needs_environment - Map options = new HashMap<>(); + Map options; if (psiElement.length > 2 && psiElement[2] instanceof ArrayCreationExpression) { options = getOptions((ArrayCreationExpression) psiElement[2]); } else { diff --git a/src/main/java/fr/adrienbrault/idea/symfony2plugin/templating/util/TwigUtil.java b/src/main/java/fr/adrienbrault/idea/symfony2plugin/templating/util/TwigUtil.java index b1c237202..defb4b182 100644 --- a/src/main/java/fr/adrienbrault/idea/symfony2plugin/templating/util/TwigUtil.java +++ b/src/main/java/fr/adrienbrault/idea/symfony2plugin/templating/util/TwigUtil.java @@ -1419,7 +1419,7 @@ public static Collection getTemplateNamesForFile(@NotNull Project projec List collect = getTwigNamespaces(project, true) .stream() .filter(TwigPath::isEnabled) - .collect(Collectors.toList()); + .toList(); return collect.stream() .map(twigPath -> getTemplateNameForTwigPath(project, twigPath, virtualFile)) diff --git a/src/main/java/fr/adrienbrault/idea/symfony2plugin/translation/TranslationDomainReference.java b/src/main/java/fr/adrienbrault/idea/symfony2plugin/translation/TranslationDomainReference.java index a261c6f98..cc3d2d6cf 100644 --- a/src/main/java/fr/adrienbrault/idea/symfony2plugin/translation/TranslationDomainReference.java +++ b/src/main/java/fr/adrienbrault/idea/symfony2plugin/translation/TranslationDomainReference.java @@ -11,7 +11,7 @@ */ public class TranslationDomainReference extends PsiReferenceBase implements PsiPolyVariantReference { - private String domainName = null; + private String domainName; public TranslationDomainReference(@NotNull StringLiteralExpression element) { super(element); diff --git a/src/main/java/fr/adrienbrault/idea/symfony2plugin/translation/TranslationReference.java b/src/main/java/fr/adrienbrault/idea/symfony2plugin/translation/TranslationReference.java index 548fac70c..1535dd524 100644 --- a/src/main/java/fr/adrienbrault/idea/symfony2plugin/translation/TranslationReference.java +++ b/src/main/java/fr/adrienbrault/idea/symfony2plugin/translation/TranslationReference.java @@ -16,7 +16,7 @@ */ public class TranslationReference extends PsiPolyVariantReferenceBase { - private String domainName = null; + private String domainName; private final StringLiteralExpression element; public TranslationReference(@NotNull StringLiteralExpression element, String domain) { diff --git a/src/main/java/fr/adrienbrault/idea/symfony2plugin/translation/dict/DomainFileMap.java b/src/main/java/fr/adrienbrault/idea/symfony2plugin/translation/dict/DomainFileMap.java index 7dd452bec..48ed178f6 100644 --- a/src/main/java/fr/adrienbrault/idea/symfony2plugin/translation/dict/DomainFileMap.java +++ b/src/main/java/fr/adrienbrault/idea/symfony2plugin/translation/dict/DomainFileMap.java @@ -5,6 +5,7 @@ import com.intellij.openapi.vfs.VirtualFile; import com.intellij.psi.PsiFile; import com.intellij.psi.PsiManager; +import fr.adrienbrault.idea.symfony2plugin.util.PsiElementUtils; import org.jetbrains.annotations.Nullable; import java.io.File; @@ -56,13 +57,6 @@ public VirtualFile getFile() { @Nullable public PsiFile getPsiFile(Project project) { VirtualFile virtualFile = this.getFile(); - if(virtualFile == null) { - return null; - } - - return PsiManager.getInstance(project).findFile(virtualFile); - + return PsiElementUtils.virtualFileToPsiFile(project, virtualFile); } - - } diff --git a/src/main/java/fr/adrienbrault/idea/symfony2plugin/translation/dict/TranslationUtil.java b/src/main/java/fr/adrienbrault/idea/symfony2plugin/translation/dict/TranslationUtil.java index c82408c25..0136ff278 100644 --- a/src/main/java/fr/adrienbrault/idea/symfony2plugin/translation/dict/TranslationUtil.java +++ b/src/main/java/fr/adrienbrault/idea/symfony2plugin/translation/dict/TranslationUtil.java @@ -167,7 +167,7 @@ public static Collection getTranslationKeyTargetInsideFile(@NotNull elements.addAll(FileBasedIndex.getInstance() .getValues(TranslationStubIndex.KEY, domain, GlobalSearchScope.filesScope(project, Collections.singletonList(psiFile.getVirtualFile()))).stream() .filter(string -> string.contains(translationKey)).map(string -> psiFile) - .collect(Collectors.toList()) + .toList() ); } @@ -230,7 +230,7 @@ public static Collection getTargetForXlfAsXmlFile(@NotNull XmlFile x // String resname = transUnit.getAttributeValue("resname"); - if(resname != null && key.equals(resname)) { + if(key.equals(resname)) { psiElements.add(transUnit); } } diff --git a/src/main/java/fr/adrienbrault/idea/symfony2plugin/twig/assets/TwigNamedAssetsServiceParser.java b/src/main/java/fr/adrienbrault/idea/symfony2plugin/twig/assets/TwigNamedAssetsServiceParser.java index 072c5e4eb..6f11e7e9f 100644 --- a/src/main/java/fr/adrienbrault/idea/symfony2plugin/twig/assets/TwigNamedAssetsServiceParser.java +++ b/src/main/java/fr/adrienbrault/idea/symfony2plugin/twig/assets/TwigNamedAssetsServiceParser.java @@ -33,17 +33,17 @@ public void parser(InputStream file) { for (int i = 0; i < nodeList.getLength(); i++) { Element node = (Element) nodeList.item(i); String key = node.getAttribute("key"); - if(key != null && StringUtils.isNotBlank(key)) { + if (StringUtils.isNotBlank(key)) { Set files = new HashSet<>(); NodeList argument1 = node.getElementsByTagName("argument"); - if(argument1.getLength() > 1) { + if (argument1.getLength() > 1) { Element argument = (Element) argument1.item(0); NodeList firstChild = argument.getElementsByTagName("argument"); for (int x = 0; x < firstChild.getLength(); x++) { String textContent = firstChild.item(x).getTextContent(); - if(StringUtils.isNotBlank(textContent)) { + if (StringUtils.isNotBlank(textContent)) { files.add(textContent); } } diff --git a/src/main/java/fr/adrienbrault/idea/symfony2plugin/ui/ContainerSettingsForm.java b/src/main/java/fr/adrienbrault/idea/symfony2plugin/ui/ContainerSettingsForm.java index e6b465fce..33a357f26 100644 --- a/src/main/java/fr/adrienbrault/idea/symfony2plugin/ui/ContainerSettingsForm.java +++ b/src/main/java/fr/adrienbrault/idea/symfony2plugin/ui/ContainerSettingsForm.java @@ -196,8 +196,4 @@ private void resetContainerList() { this.modelList.removeRow(0); } } - - @Override - public void disposeUIResources() { - } } diff --git a/src/main/java/fr/adrienbrault/idea/symfony2plugin/ui/TwigSettingsForm.java b/src/main/java/fr/adrienbrault/idea/symfony2plugin/ui/TwigSettingsForm.java index be6abdf26..a63e69142 100644 --- a/src/main/java/fr/adrienbrault/idea/symfony2plugin/ui/TwigSettingsForm.java +++ b/src/main/java/fr/adrienbrault/idea/symfony2plugin/ui/TwigSettingsForm.java @@ -44,13 +44,6 @@ public TwigSettingsForm(@NotNull Project project) { } private void attachItems() { - - // @TODO: remove this check, moved init stuff out of constructor - // dont load on project less context - if(this.project == null) { - return; - } - if (DumbService.getInstance(project).isDumb()) { this.tableView.getEmptyText().setText("Not available while indexing. Please re-open this screen when ready."); diff --git a/src/main/java/fr/adrienbrault/idea/symfony2plugin/util/CommandUtil.java b/src/main/java/fr/adrienbrault/idea/symfony2plugin/util/CommandUtil.java index 35d5acfa9..abbea6b68 100644 --- a/src/main/java/fr/adrienbrault/idea/symfony2plugin/util/CommandUtil.java +++ b/src/main/java/fr/adrienbrault/idea/symfony2plugin/util/CommandUtil.java @@ -1,7 +1,6 @@ package fr.adrienbrault.idea.symfony2plugin.util; import com.intellij.openapi.project.Project; -import com.jetbrains.php.PhpIndex; import com.jetbrains.php.lang.psi.elements.PhpClass; import org.jetbrains.annotations.NotNull; diff --git a/src/main/java/fr/adrienbrault/idea/symfony2plugin/util/EventDispatcherTypeProvider.java b/src/main/java/fr/adrienbrault/idea/symfony2plugin/util/EventDispatcherTypeProvider.java index 178de05eb..6ce3313fd 100644 --- a/src/main/java/fr/adrienbrault/idea/symfony2plugin/util/EventDispatcherTypeProvider.java +++ b/src/main/java/fr/adrienbrault/idea/symfony2plugin/util/EventDispatcherTypeProvider.java @@ -53,7 +53,7 @@ public PhpType getType(PsiElement e) { return null; } - String signature = null; + String signature; if(parameters[1] instanceof NewExpression) { // dispatch('foo', new FooEvent()); ClassReference classReference = ((NewExpression) parameters[1]).getClassReference(); diff --git a/src/main/java/fr/adrienbrault/idea/symfony2plugin/util/PhpElementsUtil.java b/src/main/java/fr/adrienbrault/idea/symfony2plugin/util/PhpElementsUtil.java index 84556f351..48a42e59a 100644 --- a/src/main/java/fr/adrienbrault/idea/symfony2plugin/util/PhpElementsUtil.java +++ b/src/main/java/fr/adrienbrault/idea/symfony2plugin/util/PhpElementsUtil.java @@ -884,12 +884,7 @@ static public String getArrayHashValue(ArrayCreationExpression arrayCreationExpr return null; } - if(valueString == null) { - return null; - } - return valueString.getContents(); - } static public boolean isEqualMethodReferenceName(MethodReference methodReference, String methodName) { @@ -1562,7 +1557,7 @@ public static boolean isMethodReferenceInstanceOf(@NotNull MethodReference metho .stream() .flatMap((fqn) -> instance.getAnyByFQN(fqn).stream()) .distinct() - .collect(Collectors.toList()); + .toList(); for (PhpClass phpClass : instanceClasses) { Method method = phpClass.findMethodByName(methodReference.getName()); @@ -1647,7 +1642,7 @@ public static void replaceElementWithClassConstant(@NotNull PhpClass phpClass, @ throw new Exception("Class fqn error"); } - if(!PhpCodeInsightUtil.getAliasesInScope(scopeForUseOperator).values().contains(fqn)) { + if(!PhpCodeInsightUtil.getAliasesInScope(scopeForUseOperator).containsValue(fqn)) { PhpAliasImporter.insertUseStatement(fqn, scopeForUseOperator); } @@ -1731,7 +1726,7 @@ public static String insertUseIfNecessary(@NotNull PsiElement phpClass, @NotNull return null; } - if(!PhpCodeInsightUtil.getAliasesInScope(scopeForUseOperator).values().contains(fqnClasName)) { + if(!PhpCodeInsightUtil.getAliasesInScope(scopeForUseOperator).containsValue(fqnClasName)) { PhpAliasImporter.insertUseStatement(fqnClasName, scopeForUseOperator); } @@ -1896,7 +1891,7 @@ public static Collection getMultiResolvedMethod(@NotNull MethodReference .stream() .flatMap((fqn) -> instance.getAnyByFQN(fqn).stream()) .distinct() - .collect(Collectors.toList()); + .toList(); Set methods = new HashSet<>(); for (PhpClass phpClass : instanceClasses) { @@ -2148,7 +2143,7 @@ private static String resolveString(@NotNull StringLiteralExpression parameter) @Nullable private static String resolvePhpReference(@NotNull PhpReference parameter) { - for (PhpNamedElement phpNamedElement : ((PhpReference) parameter).resolveLocal()) { + for (PhpNamedElement phpNamedElement : parameter.resolveLocal()) { // foo(self::foo) // foo($this->foo) if (phpNamedElement instanceof Field) { diff --git a/src/main/java/fr/adrienbrault/idea/symfony2plugin/util/PhpStringLiteralExpressionReference.java b/src/main/java/fr/adrienbrault/idea/symfony2plugin/util/PhpStringLiteralExpressionReference.java index a17c484f9..ddd77f622 100644 --- a/src/main/java/fr/adrienbrault/idea/symfony2plugin/util/PhpStringLiteralExpressionReference.java +++ b/src/main/java/fr/adrienbrault/idea/symfony2plugin/util/PhpStringLiteralExpressionReference.java @@ -60,7 +60,7 @@ public PsiReference[] getReferencesByElement(@NotNull PsiElement psiElement, @No private PsiReference[] getPsiReferenceBase(PsiElement psiElement) { try { - PsiReferenceBase referenceClassInstance = (PsiReferenceBase) this.referenceClass.getDeclaredConstructor(StringLiteralExpression.class).newInstance((StringLiteralExpression) psiElement); + PsiReferenceBase referenceClassInstance = (PsiReferenceBase) this.referenceClass.getDeclaredConstructor(StringLiteralExpression.class).newInstance(psiElement); return new PsiReference[]{ referenceClassInstance }; } catch (InstantiationException | IllegalAccessException | InvocationTargetException | NoSuchMethodException ignored) { } diff --git a/src/main/java/fr/adrienbrault/idea/symfony2plugin/util/PhpTypeProviderUtil.java b/src/main/java/fr/adrienbrault/idea/symfony2plugin/util/PhpTypeProviderUtil.java index 0c0ee11aa..e8496e21c 100644 --- a/src/main/java/fr/adrienbrault/idea/symfony2plugin/util/PhpTypeProviderUtil.java +++ b/src/main/java/fr/adrienbrault/idea/symfony2plugin/util/PhpTypeProviderUtil.java @@ -66,7 +66,7 @@ public static String getReferenceSignatureByFirstParameter(@NotNull FunctionRefe // whitelist here; we can also provide some more but think of performance // Service::NAME, $this->name and Entity::CLASS; - if (parameter instanceof PhpReference && (parameter instanceof ClassConstantReference || parameter instanceof FieldReference)) { + if ((parameter instanceof ClassConstantReference || parameter instanceof FieldReference)) { String signature = ((PhpReference) parameter).getSignature(); if (StringUtil.isNotEmpty(signature)) { return refSignature + trimKey + signature; diff --git a/src/main/java/fr/adrienbrault/idea/symfony2plugin/util/PsiElementUtils.java b/src/main/java/fr/adrienbrault/idea/symfony2plugin/util/PsiElementUtils.java index 4b9285f16..28da3c5e8 100644 --- a/src/main/java/fr/adrienbrault/idea/symfony2plugin/util/PsiElementUtils.java +++ b/src/main/java/fr/adrienbrault/idea/symfony2plugin/util/PsiElementUtils.java @@ -337,9 +337,7 @@ public static PsiElement getParentOfTypeFirstChild(@Nullable PsiElement element, public static PsiElement getParentOfType(@Nullable PsiElement element, @NotNull IElementType iElementType) { if (element == null) return null; - PsiElement lastElement = null; while (element != null) { - IElementType elementType = element.getNode().getElementType(); if (elementType == iElementType) { return element; @@ -349,7 +347,6 @@ public static PsiElement getParentOfType(@Nullable PsiElement element, @NotNull return null; } - lastElement = element; element = element.getParent(); } diff --git a/src/main/java/fr/adrienbrault/idea/symfony2plugin/util/SymfonyBundleUtil.java b/src/main/java/fr/adrienbrault/idea/symfony2plugin/util/SymfonyBundleUtil.java index 5a3452435..7ab35d5b6 100644 --- a/src/main/java/fr/adrienbrault/idea/symfony2plugin/util/SymfonyBundleUtil.java +++ b/src/main/java/fr/adrienbrault/idea/symfony2plugin/util/SymfonyBundleUtil.java @@ -4,7 +4,6 @@ import com.intellij.openapi.vfs.VirtualFile; import com.intellij.psi.PsiDirectory; import com.intellij.psi.PsiFile; -import com.jetbrains.php.PhpIndex; import com.jetbrains.php.lang.psi.elements.PhpClass; import fr.adrienbrault.idea.symfony2plugin.util.dict.SymfonyBundle; import org.jetbrains.annotations.NotNull; diff --git a/src/main/java/fr/adrienbrault/idea/symfony2plugin/util/completion/PhpConstGotoCompletionProvider.java b/src/main/java/fr/adrienbrault/idea/symfony2plugin/util/completion/PhpConstGotoCompletionProvider.java index 8f1d842f1..5cf1b1963 100644 --- a/src/main/java/fr/adrienbrault/idea/symfony2plugin/util/completion/PhpConstGotoCompletionProvider.java +++ b/src/main/java/fr/adrienbrault/idea/symfony2plugin/util/completion/PhpConstGotoCompletionProvider.java @@ -102,7 +102,7 @@ private void addAllClasses(Collection elements, Collection elements, Collection classes) { for (PhpClass phpClass : classes) { // All class constants - List fields = Arrays.stream(phpClass.getOwnFields()).filter(f -> f.isConstant() && f.getModifier().isPublic()).collect(Collectors.toList()); + List fields = Arrays.stream(phpClass.getOwnFields()).filter(f -> f.isConstant() && f.getModifier().isPublic()).toList(); for (PhpNamedElement field : fields) { // Foo::BAR String lookupString = phpClass.getName() + SCOPE_OPERATOR + field.getName(); diff --git a/src/main/java/fr/adrienbrault/idea/symfony2plugin/util/dict/ResourceFileInsertHandler.java b/src/main/java/fr/adrienbrault/idea/symfony2plugin/util/dict/ResourceFileInsertHandler.java index 695c29523..80a628298 100644 --- a/src/main/java/fr/adrienbrault/idea/symfony2plugin/util/dict/ResourceFileInsertHandler.java +++ b/src/main/java/fr/adrienbrault/idea/symfony2plugin/util/dict/ResourceFileInsertHandler.java @@ -30,7 +30,7 @@ public static boolean isStringBeforeCaret(@NotNull Editor editor, InsertionConte return false; } - return fileText.substring(context.getStartOffset() - string.length(), context.getStartOffset()).equals(string); + return fileText.startsWith(string, context.getStartOffset() - string.length()); } diff --git a/src/main/java/fr/adrienbrault/idea/symfony2plugin/util/psi/PhpBundleFileFactory.java b/src/main/java/fr/adrienbrault/idea/symfony2plugin/util/psi/PhpBundleFileFactory.java index bc692f0ce..32eeb0516 100644 --- a/src/main/java/fr/adrienbrault/idea/symfony2plugin/util/psi/PhpBundleFileFactory.java +++ b/src/main/java/fr/adrienbrault/idea/symfony2plugin/util/psi/PhpBundleFileFactory.java @@ -3,7 +3,6 @@ import com.intellij.openapi.editor.Editor; import com.intellij.openapi.project.Project; import com.intellij.openapi.ui.Messages; -import com.intellij.openapi.util.io.StreamUtil; import com.intellij.openapi.vfs.VfsUtil; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.psi.PsiElement; @@ -200,8 +199,7 @@ public static PhpClass getPhpClassForCreateCompilerScope(@Nullable PhpClass phpC @Nullable public static PhpClass getPhpClassForCreateCompilerScope(@NotNull Editor editor, @Nullable PsiFile file) { - - if(file == null || !(file instanceof PhpFile)) { + if(!(file instanceof PhpFile)) { return null; } @@ -209,7 +207,7 @@ public static PhpClass getPhpClassForCreateCompilerScope(@NotNull Editor editor, } private static void insertUseIfNecessary(PhpPsiElement scopeForUseOperator, String nsClass) { - if(!PhpCodeInsightUtil.getAliasesInScope(scopeForUseOperator).values().contains(nsClass)) { + if(!PhpCodeInsightUtil.getAliasesInScope(scopeForUseOperator).containsValue(nsClass)) { PhpAliasImporter.insertUseStatement(nsClass, scopeForUseOperator); } } diff --git a/src/main/java/fr/adrienbrault/idea/symfony2plugin/util/psi/matcher/ArrayValueWithKeyAndNewExpressionMatcher.java b/src/main/java/fr/adrienbrault/idea/symfony2plugin/util/psi/matcher/ArrayValueWithKeyAndNewExpressionMatcher.java index 5923f91a7..60871a42e 100644 --- a/src/main/java/fr/adrienbrault/idea/symfony2plugin/util/psi/matcher/ArrayValueWithKeyAndNewExpressionMatcher.java +++ b/src/main/java/fr/adrienbrault/idea/symfony2plugin/util/psi/matcher/ArrayValueWithKeyAndNewExpressionMatcher.java @@ -172,7 +172,7 @@ public static class NewExpressionCall { @NotNull private final String clazz; - private int index = 0; + private int index; public NewExpressionCall(@NotNull String clazz) { this(clazz, 0); diff --git a/src/main/java/fr/adrienbrault/idea/symfony2plugin/util/yaml/YamlHelper.java b/src/main/java/fr/adrienbrault/idea/symfony2plugin/util/yaml/YamlHelper.java index 828de46e8..4462b0d96 100644 --- a/src/main/java/fr/adrienbrault/idea/symfony2plugin/util/yaml/YamlHelper.java +++ b/src/main/java/fr/adrienbrault/idea/symfony2plugin/util/yaml/YamlHelper.java @@ -246,7 +246,7 @@ public static String trimSpecialSyntaxServiceName(@NotNull String serviceName) { // optional syntax if(serviceName.startsWith("?")) { - serviceName = serviceName.substring(1, serviceName.length()); + serviceName = serviceName.substring(1); } return serviceName; @@ -894,12 +894,12 @@ public static PsiElement insertKeyIntoFile(final @NotNull YAMLFile yamlFile, fin // split content of array value object; // drop first item as getValueText() removes our key indent - String[] remove = (String[]) ArrayUtils.remove(text.split("\\r?\\n"), 0); + String[] remove = ArrayUtils.remove(text.split("\\r?\\n"), 0); List map = ContainerUtil.map(remove, s -> previousIndent + s); return "\n" + StringUtils.strip(StringUtils.join(map, "\n"), "\n"); - }, (String[]) ArrayUtils.add(keys, keyText)); + }, ArrayUtils.add(keys, keyText)); } public static PsiElement insertKeyIntoFile(final @NotNull YAMLFile yamlFile, final @Nullable String value, @NotNull String... keys) { diff --git a/src/test/java/fr/adrienbrault/idea/symfony2plugin/tests/SymfonyLightCodeInsightFixtureTestCase.java b/src/test/java/fr/adrienbrault/idea/symfony2plugin/tests/SymfonyLightCodeInsightFixtureTestCase.java index 96fe5e0a3..82e12816c 100644 --- a/src/test/java/fr/adrienbrault/idea/symfony2plugin/tests/SymfonyLightCodeInsightFixtureTestCase.java +++ b/src/test/java/fr/adrienbrault/idea/symfony2plugin/tests/SymfonyLightCodeInsightFixtureTestCase.java @@ -18,7 +18,6 @@ import com.intellij.navigation.GotoRelatedItem; import com.intellij.openapi.command.CommandProcessor; import com.intellij.openapi.editor.Editor; -import com.intellij.openapi.extensions.Extensions; import com.intellij.openapi.fileTypes.FileType; import com.intellij.openapi.fileTypes.LanguageFileType; import com.intellij.openapi.util.Pair; diff --git a/src/test/java/fr/adrienbrault/idea/symfony2plugin/tests/doctrine/querybuilder/QueryBuilderCompletionContributorTest.java b/src/test/java/fr/adrienbrault/idea/symfony2plugin/tests/doctrine/querybuilder/QueryBuilderCompletionContributorTest.java index f747a598a..a496e5699 100644 --- a/src/test/java/fr/adrienbrault/idea/symfony2plugin/tests/doctrine/querybuilder/QueryBuilderCompletionContributorTest.java +++ b/src/test/java/fr/adrienbrault/idea/symfony2plugin/tests/doctrine/querybuilder/QueryBuilderCompletionContributorTest.java @@ -1,7 +1,5 @@ package fr.adrienbrault.idea.symfony2plugin.tests.doctrine.querybuilder; -import com.intellij.codeInsight.lookup.LookupElementPresentation; -import com.jetbrains.php.lang.PhpFileType; import fr.adrienbrault.idea.symfony2plugin.doctrine.querybuilder.QueryBuilderCompletionContributor; import fr.adrienbrault.idea.symfony2plugin.tests.SymfonyLightCodeInsightFixtureTestCase; import org.jetbrains.annotations.NotNull;