Skip to content

Commit 530529f

Browse files
authored
Merge pull request #2373 from Haehnchen/feature/language-features
some language feature migration and code related code cleanup
2 parents 41d9e05 + e5f6841 commit 530529f

File tree

54 files changed

+102
-194
lines changed

Some content is hidden

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

54 files changed

+102
-194
lines changed

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
import fr.adrienbrault.idea.symfony2plugin.stubs.ContainerCollectionResolver;
2727
import fr.adrienbrault.idea.symfony2plugin.util.PhpElementsUtil;
2828
import fr.adrienbrault.idea.symfony2plugin.util.dict.ServiceUtil;
29-
import fr.adrienbrault.idea.symfony2plugin.util.psi.PhpBundleFileFactory;
3029
import fr.adrienbrault.idea.symfony2plugin.util.yaml.YamlHelper;
3130
import org.apache.commons.lang3.StringUtils;
3231
import org.jetbrains.annotations.NotNull;

src/main/java/fr/adrienbrault/idea/symfony2plugin/action/ui/ServiceArgumentSelectionDialog.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ public String valueOf(ServiceParameter modelParameter) {
170170
int i = classFqn.lastIndexOf("\\");
171171
if(i > 0) {
172172
String ns = classFqn.substring(0, i);
173-
String clazz = classFqn.substring(i + 1, classFqn.length());
173+
String clazz = classFqn.substring(i + 1);
174174
classFqn = String.format("%s [%s]", clazz, ns);
175175
}
176176

src/main/java/fr/adrienbrault/idea/symfony2plugin/action/ui/ServiceBuilder.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ private List<String> getParameters(List<MethodParameter.MethodModelParameter> me
117117

118118
}
119119

120-
if(!hasCall || methodCalls.isEmpty()) {
120+
if(!hasCall) {
121121
return null;
122122
}
123123

src/main/java/fr/adrienbrault/idea/symfony2plugin/asset/AssetFile.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import com.intellij.openapi.vfs.VfsUtil;
44
import com.intellij.openapi.vfs.VirtualFile;
55
import org.jetbrains.annotations.NotNull;
6+
import org.jetbrains.annotations.Nullable;
67

78
/**
89
* @author Daniel Espendiller <daniel@espendiller.net>
@@ -14,7 +15,7 @@ public class AssetFile {
1415
@NotNull
1516
private final AssetEnum.Position assetPosition;
1617

17-
@NotNull
18+
@Nullable
1819
private VirtualFile relativeFolder;
1920

2021
private String prefix = "";
@@ -58,6 +59,6 @@ public AssetEnum.Position getAssetPosition() {
5859
public String toString() {
5960
return this.string != null
6061
? this.string
61-
: this.prefix + VfsUtil.getRelativePath(assetFile, relativeFolder, '/');
62+
: this.prefix + (relativeFolder != null ? VfsUtil.getRelativePath(assetFile, relativeFolder, '/') : "");
6263
}
6364
}

src/main/java/fr/adrienbrault/idea/symfony2plugin/asset/AssetGoToDeclarationHandler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ private String[] findValidAssetFilter(PsiElement psiElement) {
5959

6060
// asset / absolute_url dont have pre filter
6161
if(TwigPattern.getPrintBlockOrTagFunctionPattern("asset", "absolute_url").accepts(psiElement)) {
62-
return (String[]) ArrayUtils.addAll(TwigUtil.CSS_FILES_EXTENSIONS, TwigUtil.JS_FILES_EXTENSIONS);
62+
return ArrayUtils.addAll(TwigUtil.CSS_FILES_EXTENSIONS, TwigUtil.JS_FILES_EXTENSIONS);
6363
}
6464

6565
return null;

src/main/java/fr/adrienbrault/idea/symfony2plugin/completion/xml/XmlGotoCompletionRegistrar.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ public Collection<LookupElement> getLookupElements() {
248248
for (PhpClass phpClass : phpClasses) {
249249
lookupElements.addAll(PhpElementsUtil.getClassPublicMethod(phpClass).stream()
250250
.map(PhpLookupElement::new)
251-
.collect(Collectors.toList())
251+
.toList()
252252
);
253253
}
254254

src/main/java/fr/adrienbrault/idea/symfony2plugin/config/yaml/completion/ConfigCompletionProvider.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -303,9 +303,6 @@ private Map<String, String> getNodeCommentVars(@Nullable Node node) {
303303
if(node == null) return comments;
304304

305305
Node previousSibling = node.getPreviousSibling();
306-
if(previousSibling == comments) {
307-
return comments;
308-
}
309306

310307
// get variable decl: "foo: test"
311308
Pattern compile = Pattern.compile("^\\s*([\\w_-]+)\\s*:\\s*(.*?)$");

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public class ServiceMap {
1616
private Collection<String> ids;
1717

1818
ServiceMap() {
19-
this.services = Collections.unmodifiableCollection(Collections.emptyList());
19+
this.services = Collections.emptyList();
2020
}
2121

2222
ServiceMap(@NotNull Collection<ServiceInterface> services) {

src/main/java/fr/adrienbrault/idea/symfony2plugin/doctrine/DoctrineAnnotationReferencedColumnReferences.java

Lines changed: 23 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -50,45 +50,36 @@ public PsiReference[] getPropertyReferences(AnnotationPropertyParameter annotati
5050
PhpDocComment phpDocComment = PsiTreeUtil.getParentOfType(element, PhpDocComment.class);
5151
if(phpDocComment != null) {
5252
PhpDocCommentAnnotation phpDocCommentAnnotationContainer = AnnotationUtil.getPhpDocCommentAnnotationContainer(phpDocComment);
53-
54-
if(phpDocCommentAnnotationContainer != null) {
55-
56-
PhpDocTagAnnotation phpDocTagAnnotation = phpDocCommentAnnotationContainer.getFirstPhpDocBlock(
57-
"\\Doctrine\\ORM\\Mapping\\ManyToOne",
58-
"\\Doctrine\\ORM\\Mapping\\ManyToMany",
59-
"\\Doctrine\\ORM\\Mapping\\OneToOne",
60-
"\\Doctrine\\ORM\\Mapping\\OneToMany"
61-
);
62-
63-
if(phpDocTagAnnotation != null) {
64-
65-
PhpPsiElement phpDocAttrList = phpDocTagAnnotation.getPhpDocTag().getFirstPsiChild();
66-
67-
// @TODO: remove nested on Annotation plugin update
68-
if(phpDocAttrList != null) {
69-
if(phpDocAttrList.getNode().getElementType() == PhpDocElementTypes.phpDocAttributeList) {
70-
PhpPsiElement phpPsiElement = phpDocAttrList.getFirstPsiChild();
71-
if(phpPsiElement instanceof StringLiteralExpression) {
72-
PhpClass phpClass = de.espend.idea.php.annotation.util.PhpElementsUtil.getClassInsideAnnotation(((StringLiteralExpression) phpPsiElement));
73-
if(phpClass != null) {
74-
Collection<DoctrineModelField> lists = EntityHelper.getModelFields(phpClass);
75-
if(!lists.isEmpty()) {
76-
return new PsiReference[] {
77-
new EntityReference((StringLiteralExpression) element, lists)
78-
};
79-
}
53+
PhpDocTagAnnotation phpDocTagAnnotation = phpDocCommentAnnotationContainer.getFirstPhpDocBlock(
54+
"\\Doctrine\\ORM\\Mapping\\ManyToOne",
55+
"\\Doctrine\\ORM\\Mapping\\ManyToMany",
56+
"\\Doctrine\\ORM\\Mapping\\OneToOne",
57+
"\\Doctrine\\ORM\\Mapping\\OneToMany"
58+
);
59+
60+
if(phpDocTagAnnotation != null) {
61+
62+
PhpPsiElement phpDocAttrList = phpDocTagAnnotation.getPhpDocTag().getFirstPsiChild();
63+
64+
// @TODO: remove nested on Annotation plugin update
65+
if(phpDocAttrList != null) {
66+
if(phpDocAttrList.getNode().getElementType() == PhpDocElementTypes.phpDocAttributeList) {
67+
PhpPsiElement phpPsiElement = phpDocAttrList.getFirstPsiChild();
68+
if(phpPsiElement instanceof StringLiteralExpression) {
69+
PhpClass phpClass = de.espend.idea.php.annotation.util.PhpElementsUtil.getClassInsideAnnotation(((StringLiteralExpression) phpPsiElement));
70+
if(phpClass != null) {
71+
Collection<DoctrineModelField> lists = EntityHelper.getModelFields(phpClass);
72+
if(!lists.isEmpty()) {
73+
return new PsiReference[] {
74+
new EntityReference((StringLiteralExpression) element, lists)
75+
};
8076
}
8177
}
8278
}
8379
}
84-
85-
8680
}
87-
8881
}
89-
9082
}
91-
9283
}
9384

9485
return new PsiReference[0];

src/main/java/fr/adrienbrault/idea/symfony2plugin/doctrine/DoctrineUtil.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ private static Collection<Pair<String, String>> getClassRepositoryPair(@NotNull
8484

8585
Collection<Pair<String, String>> pairs = new ArrayList<>();
8686

87-
for (XmlTag xmlTag : (XmlTag[]) ArrayUtils.addAll(rootTag.findSubTags("document"), rootTag.findSubTags("entity"))) {
87+
for (XmlTag xmlTag : ArrayUtils.addAll(rootTag.findSubTags("document"), rootTag.findSubTags("entity"))) {
8888

8989
XmlAttribute attr = xmlTag.getAttribute("name");
9090
if(attr == null) {

src/main/java/fr/adrienbrault/idea/symfony2plugin/doctrine/EntityHelper.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ public static PsiElement[] getModelFieldTargets(@NotNull PhpClass phpClass,@NotN
259259
if(modelFields != null) {
260260
for (DoctrineModelField field : modelFields.getFields()) {
261261
if(field.getName().equals(fieldName) && !field.getTargets().isEmpty()) {
262-
return field.getTargets().toArray(new PsiElement[psiElements.size()]);
262+
return field.getTargets().toArray(new PsiElement[0]);
263263
}
264264
}
265265
}
@@ -377,11 +377,11 @@ public static Collection<DoctrineModelField> getModelFields(@NotNull PhpClass ph
377377

378378
// @TODO: old deprecated code
379379
PsiFile psiFile = getModelConfigFile(phpClass);
380-
if(psiFile == null) {
381-
Collections.emptyList();
380+
if (psiFile == null) {
381+
return Collections.emptyList();
382382
}
383383

384-
if(psiFile instanceof YAMLFile) {
384+
if (psiFile instanceof YAMLFile) {
385385
List<DoctrineModelField> modelFields = new ArrayList<>();
386386

387387
PsiElement yamlDocument = psiFile.getFirstChild();

src/main/java/fr/adrienbrault/idea/symfony2plugin/doctrine/metadata/ObjectRepositoryFindGotoCompletionRegistrar.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ public Collection<LookupElement> getLookupElements() {
103103
phpClasses.forEach(phpClass ->
104104
results.addAll(EntityHelper.getModelFields(phpClass).stream()
105105
.map((Function<DoctrineModelField, LookupElement>) DoctrineModelFieldLookupElement::new)
106-
.collect(Collectors.toList())
106+
.toList()
107107
)
108108
);
109109

src/main/java/fr/adrienbrault/idea/symfony2plugin/doctrine/metadata/util/DoctrineMetadataUtil.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ public static DoctrineMetadataModel getMetadataByTable(@NotNull Project project,
238238
}
239239

240240
String table = metadata.getTable();
241-
if(table != null && tableName.equals(table)) {
241+
if(tableName.equals(table)) {
242242
return metadata;
243243
}
244244
}

src/main/java/fr/adrienbrault/idea/symfony2plugin/doctrine/querybuilder/QueryBuilderCompletionContributor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
import fr.adrienbrault.idea.symfony2plugin.util.PsiElementUtils;
3030
import org.apache.commons.lang3.StringUtils;
3131
import org.jetbrains.annotations.NotNull;
32-
import org.jetbrains.annotations.Nullable;
3332

3433
import java.util.*;
3534
import java.util.regex.Matcher;
@@ -526,6 +525,7 @@ private void buildLookupElements(CompletionResultSet completionResultSet, QueryB
526525
}
527526
}
528527

528+
@NotNull
529529
public static QueryBuilderMethodReferenceParser getQueryBuilderParser(MethodReference methodReference) {
530530
final QueryBuilderChainProcessor processor = new QueryBuilderChainProcessor(methodReference);
531531
processor.collectMethods();

src/main/java/fr/adrienbrault/idea/symfony2plugin/doctrine/querybuilder/QueryBuilderGotoDeclarationHandler.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,6 @@ private void attachJoinGoto(StringLiteralExpression psiElement, List<PsiElement>
8686
}
8787

8888
QueryBuilderMethodReferenceParser qb = QueryBuilderCompletionContributor.getQueryBuilderParser(methodMatchParameter.getMethodReference());
89-
if(qb == null) {
90-
return;
91-
}
9289

9390
String[] joinSplit = StringUtils.split(psiElement.getContents(), ".");
9491
if(joinSplit.length != 2) {
@@ -151,9 +148,6 @@ private void attachFromIndexGoto(StringLiteralExpression psiElement, List<PsiEle
151148
}
152149

153150
QueryBuilderMethodReferenceParser qb = QueryBuilderCompletionContributor.getQueryBuilderParser(methodMatchParameter.getMethodReference());
154-
if(qb == null) {
155-
return;
156-
}
157151

158152
QueryBuilderScopeContext collect = qb.collect();
159153
String propertyContent = psiElement.getContents();

src/main/java/fr/adrienbrault/idea/symfony2plugin/doctrine/querybuilder/dbal/DoctrineDbalQbGotoCompletionRegistrar.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ public Collection<LookupElement> getLookupElements() {
141141
if(underscore.contains("_")) {
142142
String[] split = underscore.split("_");
143143
if(split.length > 1) {
144-
aliasSet.add(split[0].substring(0, 1) + split[1].substring(0, 1));
144+
aliasSet.add(split[0].charAt(0) + split[1].substring(0, 1));
145145
}
146146

147147
List<String> i = new ArrayList<>();

src/main/java/fr/adrienbrault/idea/symfony2plugin/form/FormTypeReferenceContributor.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,6 @@ public PsiReference[] getReferencesByElement(@NotNull PsiElement psiElement, @No
7272
return new PsiReference[0];
7373
}
7474

75-
if(key == null) {
76-
return new PsiReference[0];
77-
}
78-
7975
String keyString = key.getContents();
8076

8177
// @TODO: how to handle custom bundle fields like help_block

src/main/java/fr/adrienbrault/idea/symfony2plugin/form/FormUnderscoreMethodReference.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public ResolveResult[] multiResolve(boolean incompleteCode) {
4949
// property path
5050
psiElements.addAll(this.phpClass.getFields().stream()
5151
.filter(field -> !field.isConstant() && field.getModifier().isPublic() && methods.contains(field.getName()))
52-
.collect(Collectors.toList())
52+
.toList()
5353
);
5454

5555
return PsiElementResolveResult.createResults(psiElements);

src/main/java/fr/adrienbrault/idea/symfony2plugin/form/util/FormOptionsUtil.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
import com.intellij.psi.PsiElement;
88
import com.intellij.psi.util.PsiTreeUtil;
99
import com.intellij.util.containers.ContainerUtil;
10-
import com.jetbrains.php.PhpIndex;
1110
import com.jetbrains.php.lang.psi.elements.*;
1211
import fr.adrienbrault.idea.symfony2plugin.Symfony2Icons;
1312
import fr.adrienbrault.idea.symfony2plugin.form.dict.*;

src/main/java/fr/adrienbrault/idea/symfony2plugin/intentions/xml/XmlServiceTagIntention.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,7 @@ public void invoke(@NotNull final Project project, final Editor editor, @NotNull
6666
}
6767

6868
String value = name.getValue();
69-
if(phpServiceTags.contains(value)) {
70-
phpServiceTags.remove(value);
71-
}
72-
69+
phpServiceTags.remove(value);
7370
}
7471

7572
ServiceUtil.insertTagWithPopupDecision(editor, phpServiceTags, tag -> {

src/main/java/fr/adrienbrault/idea/symfony2plugin/intentions/yaml/YamlServiceTagIntention.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -172,9 +172,7 @@ private static Pair<PhpClass, Set<String>> invoke(@NotNull Project project, @Not
172172
Set<String> strings = YamlHelper.collectServiceTags(serviceKeyValue);
173173
if(!strings.isEmpty()) {
174174
for (String s : strings) {
175-
if(phpClassServiceTags.contains(s)) {
176-
phpClassServiceTags.remove(s);
177-
}
175+
phpClassServiceTags.remove(s);
178176
}
179177
}
180178

src/main/java/fr/adrienbrault/idea/symfony2plugin/navigation/NavigationItemEx.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ public String getLocationString() {
9696
if(bundleName.contains("Bundle")) {
9797
bundleName = bundleName.substring(0, bundleName.lastIndexOf("Bundle"));
9898
if(bundleName.length() > 1 && bundleName.contains("/")) {
99-
return locationPathString + " " + bundleName.substring(bundleName.lastIndexOf("/") + 1, bundleName.length()) + "::" + psiFile.getName();
99+
return locationPathString + " " + bundleName.substring(bundleName.lastIndexOf("/") + 1) + "::" + psiFile.getName();
100100
}
101101
}
102102

src/main/java/fr/adrienbrault/idea/symfony2plugin/navigation/TwigFoldingBuilder.java

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -125,15 +125,11 @@ private void attachConstantFoldingDescriptors(PsiElement psiElement, List<Foldin
125125
TwigPattern.getPrintBlockOrTagFunctionPattern("constant").accepts(psiElement1)
126126
);
127127

128-
if(constantReferences.length == 0) {
129-
return;
130-
}
131-
132-
for(PsiElement fileReference: constantReferences) {
128+
for (PsiElement fileReference: constantReferences) {
133129
String contents = fileReference.getText();
134-
if(StringUtils.isNotBlank(contents) && contents.contains(":")) {
130+
if (StringUtils.isNotBlank(contents) && contents.contains(":")) {
135131
final String[] parts = contents.split("::");
136-
if(parts.length == 2) {
132+
if (parts.length == 2) {
137133
descriptors.add(new FoldingDescriptor(fileReference.getNode(),
138134
new TextRange(fileReference.getTextRange().getStartOffset(), fileReference.getTextRange().getEndOffset())) {
139135
@Nullable
@@ -143,11 +139,8 @@ public String getPlaceholderText() {
143139
}
144140
});
145141
}
146-
147142
}
148-
149143
}
150-
151144
}
152145

153146
@Nullable

src/main/java/fr/adrienbrault/idea/symfony2plugin/navigation/TwigGotoRelatedProvider.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,11 @@ public List<? extends GotoRelatedItem> getItems(@NotNull PsiElement psiElement2)
8383

8484
gotoRelatedItems.addAll(TwigBlockUtil.getBlockOverwriteTargets(childrenOfType).stream().map((Function<PsiElement, GotoRelatedItem>) psiElement1 ->
8585
new RelatedPopupGotoLineMarker.PopupGotoRelatedItem(psiElement1, blockName).withIcon(Symfony2Icons.TWIG_BLOCK_OVERWRITE, Symfony2Icons.TWIG_BLOCK_OVERWRITE)
86-
).collect(Collectors.toList()));
86+
).toList());
8787

8888
gotoRelatedItems.addAll(TwigBlockUtil.getBlockImplementationTargets(childrenOfType).stream().map((Function<PsiElement, GotoRelatedItem>) psiElement1 ->
8989
new RelatedPopupGotoLineMarker.PopupGotoRelatedItem(psiElement1, blockName).withIcon(Symfony2Icons.TWIG_BLOCK_OVERWRITE, Symfony2Icons.TWIG_BLOCK_OVERWRITE)
90-
).collect(Collectors.toList()));
90+
).toList());
9191
}
9292
}
9393
}

0 commit comments

Comments
 (0)