Skip to content

Commit

Permalink
Merge pull request #2373 from Haehnchen/feature/language-features
Browse files Browse the repository at this point in the history
some language feature migration and code related code cleanup
  • Loading branch information
Haehnchen committed May 13, 2024
2 parents 41d9e05 + e5f6841 commit 530529f
Show file tree
Hide file tree
Showing 54 changed files with 102 additions and 194 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ private List<String> getParameters(List<MethodParameter.MethodModelParameter> me

}

if(!hasCall || methodCalls.isEmpty()) {
if(!hasCall) {
return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 <daniel@espendiller.net>
Expand All @@ -14,7 +15,7 @@ public class AssetFile {
@NotNull
private final AssetEnum.Position assetPosition;

@NotNull
@Nullable
private VirtualFile relativeFolder;

private String prefix = "";
Expand Down Expand Up @@ -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, '/') : "");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ public Collection<LookupElement> getLookupElements() {
for (PhpClass phpClass : phpClasses) {
lookupElements.addAll(PhpElementsUtil.getClassPublicMethod(phpClass).stream()
.map(PhpLookupElement::new)
.collect(Collectors.toList())
.toList()
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -303,9 +303,6 @@ private Map<String, String> 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*(.*?)$");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class ServiceMap {
private Collection<String> ids;

ServiceMap() {
this.services = Collections.unmodifiableCollection(Collections.emptyList());
this.services = Collections.emptyList();
}

ServiceMap(@NotNull Collection<ServiceInterface> services) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<DoctrineModelField> 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<DoctrineModelField> lists = EntityHelper.getModelFields(phpClass);
if(!lists.isEmpty()) {
return new PsiReference[] {
new EntityReference((StringLiteralExpression) element, lists)
};
}
}
}
}


}

}

}

}

return new PsiReference[0];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ private static Collection<Pair<String, String>> getClassRepositoryPair(@NotNull

Collection<Pair<String, String>> 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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
}
}
}
Expand Down Expand Up @@ -377,11 +377,11 @@ public static Collection<DoctrineModelField> 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<DoctrineModelField> modelFields = new ArrayList<>();

PsiElement yamlDocument = psiFile.getFirstChild();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public Collection<LookupElement> getLookupElements() {
phpClasses.forEach(phpClass ->
results.addAll(EntityHelper.getModelFields(phpClass).stream()
.map((Function<DoctrineModelField, LookupElement>) DoctrineModelFieldLookupElement::new)
.collect(Collectors.toList())
.toList()
)
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,6 @@ private void attachJoinGoto(StringLiteralExpression psiElement, List<PsiElement>
}

QueryBuilderMethodReferenceParser qb = QueryBuilderCompletionContributor.getQueryBuilderParser(methodMatchParameter.getMethodReference());
if(qb == null) {
return;
}

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

QueryBuilderMethodReferenceParser qb = QueryBuilderCompletionContributor.getQueryBuilderParser(methodMatchParameter.getMethodReference());
if(qb == null) {
return;
}

QueryBuilderScopeContext collect = qb.collect();
String propertyContent = psiElement.getContents();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ public Collection<LookupElement> 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<String> i = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.*;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,9 +172,7 @@ private static Pair<PhpClass, Set<String>> invoke(@NotNull Project project, @Not
Set<String> strings = YamlHelper.collectServiceTags(serviceKeyValue);
if(!strings.isEmpty()) {
for (String s : strings) {
if(phpClassServiceTags.contains(s)) {
phpClassServiceTags.remove(s);
}
phpClassServiceTags.remove(s);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,15 +125,11 @@ private void attachConstantFoldingDescriptors(PsiElement psiElement, List<Foldin
TwigPattern.getPrintBlockOrTagFunctionPattern("constant").accepts(psiElement1)
);

if(constantReferences.length == 0) {
return;
}

for(PsiElement fileReference: constantReferences) {
for (PsiElement fileReference: constantReferences) {
String contents = fileReference.getText();
if(StringUtils.isNotBlank(contents) && contents.contains(":")) {
if (StringUtils.isNotBlank(contents) && contents.contains(":")) {
final String[] parts = contents.split("::");
if(parts.length == 2) {
if (parts.length == 2) {
descriptors.add(new FoldingDescriptor(fileReference.getNode(),
new TextRange(fileReference.getTextRange().getStartOffset(), fileReference.getTextRange().getEndOffset())) {
@Nullable
Expand All @@ -143,11 +139,8 @@ public String getPlaceholderText() {
}
});
}

}

}

}

@Nullable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,11 @@ public List<? extends GotoRelatedItem> getItems(@NotNull PsiElement psiElement2)

gotoRelatedItems.addAll(TwigBlockUtil.getBlockOverwriteTargets(childrenOfType).stream().map((Function<PsiElement, GotoRelatedItem>) 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<PsiElement, GotoRelatedItem>) psiElement1 ->
new RelatedPopupGotoLineMarker.PopupGotoRelatedItem(psiElement1, blockName).withIcon(Symfony2Icons.TWIG_BLOCK_OVERWRITE, Symfony2Icons.TWIG_BLOCK_OVERWRITE)
).collect(Collectors.toList()));
).toList());
}
}
}
Expand Down

0 comments on commit 530529f

Please sign in to comment.