8000 dropping some redundant code because of higher PhpStorm api level · Koc/idea-php-symfony2-plugin@5247a2a · GitHub
[go: up one dir, main page]

Skip to content

Commit 5247a2a

Browse files
committed
dropping some redundant code because of higher PhpStorm api level
1 parent 729f816 commit 5247a2a

File tree

10 files changed

+26
-57
lines changed

10 files changed

+26
-57
lines changed

src/fr/adrienbrault/idea/symfony2plugin/SettingsForm.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ public void mouseClicked(MouseEvent e) {
119119
}
120120
});
121121

122-
return (JComponent) panel1;
122+
return panel1;
123123
}
124124

125125
@Override

src/fr/adrienbrault/idea/symfony2plugin/action/bundle/WebTestCaseGeneratorAction.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public void actionPerformed(AnActionEvent event) {
6262
return;
6363
}
6464

65-
PhpClass aClass = PhpPsiUtil.findClass((PhpFile) data, Conditions.<PhpClass>alwaysTrue());
65+
PhpClass aClass = PhpPsiUtil.findClass((PhpFile) data, Conditions.alwaysTrue());
6666
if(aClass == null) {
6767
return;
6868
}

src/fr/adrienbrault/idea/symfony2plugin/dic/webDeployment/ServiceContainerRemoteFileStorage.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
public class ServiceContainerRemoteFileStorage implements RemoteFileStorageInterface<ServiceParameterStorage> {
2424

2525
private ServiceParameterStorage storage = new ServiceParameterStorage(
26-
Collections.<InputStream>emptyList()
26+
Collections.emptyList()
2727
);
2828

2929
@NotNull
@@ -65,7 +65,7 @@ public ServiceParameterStorage getState() {
6565
@Override
6666
public void clear() {
6767
storage = new ServiceParameterStorage(
68-
Collections.<InputStream>emptyList()
68+
Collections.emptyList()
6969
);
7070
}
7171

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

Lines changed: 15 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -96,10 +96,6 @@ public static PhpClass getEntityRepositoryClass(@NotNull Project project, @NotNu
9696
}
9797

9898
String presentableFQN = phpClass.getPresentableFQN();
99-
if(presentableFQN == null) {
100-
return null;
101-
}
102-
10399
PhpClass classRepository = DoctrineMetadataUtil.getClassRepository(project, presentableFQN);
104100
if(classRepository != null) {
105101
return classRepository;
@@ -178,7 +174,7 @@ public static void attachYamlFieldTypeName(String keyName, DoctrineModelField do
178174
if("fields".equals(keyName) || "id".equals(keyName)) {
179175

180176
YAMLKeyValue yamlType = YamlHelper.getYamlKeyValue(yamlKeyValue, "type");
181-
if(yamlType != null && yamlType.getValueText() != null) {
177+
if(yamlType != null) {
182178
doctrineModelField.setTypeName(yamlType.getValueText());
183179
}
184180

@@ -194,10 +190,7 @@ public static void attachYamlFieldTypeName(String keyName, DoctrineModelField do
194190
YAMLKeyValue targetEntity = YamlHelper.getYamlKeyValue(yamlKeyValue, "targetEntity");
195191
if(targetEntity != null) {
196192
doctrineModelField.setRelationType(keyName);
197-
String value = targetEntity.getValueText();
198-
if(value != null) {
199-
doctrineModelField.setRelation(getOrmClass(yamlKeyValue.getContainingFile(), value));
200-
}
193+
doctrineModelField.setRelation(getOrmClass(yamlKeyValue.getContainingFile(), targetEntity.getValueText()));
201194
}
202195
}
203196

@@ -273,14 +266,11 @@ public static PsiElement[] getModelFieldTargets(@NotNull PhpClass phpClass,@NotN
273266

274267
Collection<PsiElement> psiElements = new ArrayList<>();
275268

276-
String presentableFQN = phpClass.getPresentableFQN();
277-
if(presentableFQN != null) {
278-
DoctrineMetadataModel modelFields = DoctrineMetadataUtil.getModelFields(phpClass.getProject(), presentableFQN);
279-
if(modelFields != null) {
280-
for (DoctrineModelField field : modelFields.getFields()) {
281-
if(field.getName().equals(fieldName) && field.getTargets().size() > 0) {
282-
return field.getTargets().toArray(new PsiElement[psiElements.size()]);
283-
}
269+
DoctrineMetadataModel modelFields = DoctrineMetadataUtil.getModelFields(phpClass.getProject(), phpClass.getPresentableFQN());
270+
if(modelFields != null) {
271+
for (DoctrineModelField field : modelFields.getFields()) {
272+
if(field.getName().equals(fieldName) && field.getTargets().size() > 0) {
273+
return field.getTargets().toArray(new PsiElement[psiElements.size()]);
284274
}
285275
}
286276
}
@@ -356,29 +346,23 @@ public static PsiFile getModelConfigFile(@NotNull PhpClass phpClass) {
356346

357347
// new code
358348
String presentableFQN = phpClass.getPresentableFQN();
359-
if(presentableFQN != null) {
360-
Collection<VirtualFile> metadataFiles = DoctrineMetadataUtil.findMetadataFiles(phpClass.getProject(), presentableFQN);
361-
if(metadataFiles.size() > 0) {
362-
PsiFile file = PsiManager.getInstance(phpClass.getProject()).findFile(metadataFiles.iterator().next());
363-
if(file != null) {
364-
return file;
365-
}
349+
Collection<VirtualFile> metadataFiles = DoctrineMetadataUtil.findMetadataFiles(phpClass.getProject(), presentableFQN);
350+
if(metadataFiles.size() > 0) {
351+
PsiFile file = PsiManager.getInstance(phpClass.getProject()).findFile(metadataFiles.iterator().next());
352+
if(file != null) {
353+
return file;
366354
}
367355
}
368356

369357
// @TODO: deprecated code
370358
SymfonyBundle symfonyBundle = new SymfonyBundleUtil(phpClass.getProject()).getContainingBundle(phpClass);
371359
if(symfonyBundle != null) {
372360
for(String modelShortcut: new String[] {"orm", "mongodb", "couchdb"}) {
373-
String fqn = presentableFQN;
374-
375361
String className = phpClass.getName();
376362

377-
if(fqn != null) {
378-
int n = fqn.indexOf("\\Entity\\");
379-
if(n > 0) {
380-
className = fqn.substring(n + 8).replace("\\", ".");
381-
}
363+
int n = presentableFQN.indexOf("\\Entity\\");
364+
if(n > 0) {
365+
className = presentableFQN.substring(n + 8).replace("\\", ".");
382366
}
383367

384368
PsiFile entityMetadataFile = getEntityMetadataFile(phpClass.getProject(), symfonyBundle, className, modelShortcut);

src/fr/adrienbrault/idea/symfony2plugin/doctrine/dict/DoctrineEntityLookupElement.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import com.intellij.codeInsight.lookup.LookupElementPresentation;
55
import com.jetbrains.php.lang.psi.elements.PhpClass;
66
import fr.adrienbrault.idea.symfony2plugin.Symfony2Icons;
7+
import org.apache.commons.lang.StringUtils;
78
import org.jetbrains.annotations.NotNull;
89
import org.jetbrains.annotations.Nullable;
910

@@ -45,8 +46,7 @@ public DoctrineEntityLookupElement withManager(DoctrineTypes.Manager manager) {
4546
public String getLookupString() {
4647

4748
if(this.useClassNameAsLookupString) {
48-
String className = this.className.getPresentableFQN();
49-
return className == null ? "" : className;
49+
return StringUtils.stripStart(this.className.getPresentableFQN(), "\\");
5050
}
5151

5252
return entityName;

src/fr/adrienbrault/idea/symfony2plugin/doctrine/metadata/lookup/DoctrineRepositoryLookupElement.java

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import com.intellij.codeInsight.lookup.LookupElementPresentation;
66
import com.jetbrains.php.lang.psi.elements.PhpClass;
77
import fr.adrienbrault.idea.symfony2plugin.Symfony2Icons;
8+
import org.apache.commons.lang.StringUtils;
89
import org.jetbrains.annotations.NotNull;
910

1011
import java.util.ArrayList;
@@ -34,11 +35,7 @@ public void renderElement(LookupElementPresentation presentation) {
3435
@NotNull
3536
@Override
3637
public String getLookupString() {
37-
String presentableFQN = phpClass.getPresentableFQN();
38-
if(presentableFQN == null) {
39-
return phpClass.getName();
40-
}
41-
return presentableFQN;
38+
return StringUtils.stripStart(phpClass.getPresentableFQN(), "\\");
4239
}
4340

4441
public static DoctrineRepositoryLookupElement create(@NotNull PhpClass phpClass) {
@@ -48,11 +45,6 @@ public static DoctrineRepositoryLookupElement create(@NotNull PhpClass phpClass)
4845
public static Collection<DoctrineRepositoryLookupElement> create(@NotNull Collection<PhpClass> phpClasses) {
4946
Collection<DoctrineRepositoryLookupElement> elements = new ArrayList<>();
5047
for(PhpClass phpClass: phpClasses) {
51-
String presentableFQN = phpClass.getPresentableFQN();
52-
if(presentableFQN == null) {
53-
continue;
54-
}
55-
5648
elements.add(DoctrineRepositoryLookupElement.create(phpClass));
5749
}
5850

src/fr/adrienbrault/idea/symfony2plugin/translation/form/TranslatorKeyExtractorDialog.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ private void filterList(String domainName) {
139139

140140
// only one domain; fine preselect it
141141
if(this.listTableModel.getRowCount() == 1) {
142-
((TranslationFileModel) this.listTableModel.getItem(0)).setEnabled(true);
142+
this.listTableModel.getItem(0).setEnabled(true);
143143
}
144144

145145
}

src/fr/adrienbrault/idea/symfony2plugin/util/CommandUtil.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,7 @@ public static Map<String, String> getCommandHelper(@NotNull Project project) {
1616
for(PhpClass phpClass: PhpIndex.getInstance(project).getAllSubclasses("\\Symfony\\Component\\Console\\Helper\\HelperInterface")) {
1717
String helperName = PhpElementsUtil.getMethodReturnAsString(phpClass, "getName");
1818
if(helperName != null) {
19-
String presentableFQN = phpClass.getPresentableFQN();
20-
if(presentableFQN != null) {
21-
map.put(helperName, presentableFQN);
22-
}
19+
map.put(helperName, phpClass.getPresentableFQN());
2320
}
2421
}
2522

src/fr/adrienbrault/idea/symfony2plugin/util/controller/ControllerIndex.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,10 +99,6 @@ private List<ControllerAction> getActionMethods(SymfonyBundle symfonyBundle) {
9999
}
100100

101101
String presentableFQN = phpClass.getPresentableFQN();
102-
if(presentableFQN == null) {
103-
continue;
104-
}
105-
106102
if(!presentableFQN.startsWith("\\")) {
107103
presentableFQN = "\\" + presentableFQN;
108104
}

src/fr/adrienbrault/idea/symfony2plugin/util/dict/DoctrineModel.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public String getRepositoryName() {
4242
return className;
4343
}
4444

45-
if(doctrineNamespace != null && className != null && className.length() > doctrineNamespace.length()) {
45+
if(doctrineNamespace != null && className.length() > doctrineNamespace.length()) {
4646
className = className.substring(doctrineNamespace.length());
4747
return doctrineShortcut + ':' + className;
4848
}

0 commit comments

Comments
 (0)
0