Skip to content

Commit 3f19dc2

Browse files
committed
#305_refactor code
1 parent ed4893b commit 3f19dc2

File tree

4 files changed

+38
-15
lines changed

4 files changed

+38
-15
lines changed

resources/META-INF/plugin.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@
125125
<fileBasedIndex implementation="com.magento.idea.magento2plugin.stubs.indexes.js.MagentoLibJsIndex" />
126126
<fileBasedIndex implementation="com.magento.idea.magento2plugin.stubs.indexes.xml.AclResourceIndex" />
127127
<fileBasedIndex implementation="com.magento.idea.magento2plugin.stubs.indexes.xml.MenuIndex" />
128-
<fileBasedIndex implementation="com.magento.idea.magento2plugin.stubs.indexes.xml.UiComponentIndex" />
128+
<fileBasedIndex implementation="com.magento.idea.magento2plugin.stubs.indexes.xml.UIComponentIndex" />
129129

130130
<codeInsight.lineMarkerProvider language="PHP" implementationClass="com.magento.idea.magento2plugin.linemarker.php.PluginLineMarkerProvider"/>
131131
<codeInsight.lineMarkerProvider language="PHP" implementationClass="com.magento.idea.magento2plugin.linemarker.php.PluginTargetLineMarkerProvider"/>

src/com/magento/idea/magento2plugin/completion/provider/UiComponentCompletionProvider.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,25 +13,25 @@
1313
import com.intellij.psi.xml.XmlFile;
1414
import com.intellij.util.ProcessingContext;
1515
import com.jetbrains.php.PhpIcons;
16-
import com.magento.idea.magento2plugin.indexes.UiComponentIndex;
16+
import com.magento.idea.magento2plugin.indexes.UIComponentIndex;
1717
import java.util.List;
1818
import org.jetbrains.annotations.NotNull;
1919

2020

2121
public class UiComponentCompletionProvider extends CompletionProvider<CompletionParameters> {
2222

2323
@Override
24-
protected void addCompletions(@NotNull CompletionParameters parameters,
25-
ProcessingContext context,
26-
@NotNull CompletionResultSet result) {
27-
PsiElement position = parameters.getPosition().getOriginalElement();
24+
protected void addCompletions(@NotNull final CompletionParameters parameters,
25+
final ProcessingContext context,
26+
@NotNull final CompletionResultSet result) {
27+
final PsiElement position = parameters.getPosition().getOriginalElement();
2828
if (position == null) {
2929
return;
3030
}
3131

32-
List<XmlFile> targets = UiComponentIndex.getUiComponentFiles(position.getProject());
33-
if (targets.size() > 0) {
34-
for (XmlFile file : targets) {
32+
final List<XmlFile> targets = UIComponentIndex.getUiComponentFiles(position.getProject());
33+
if (!targets.isEmpty()) {
34+
for (final XmlFile file : targets) {
3535
result.addElement(LookupElementBuilder
3636
.create(file.getVirtualFile().getNameWithoutExtension())
3737
.withIcon(PhpIcons.XML_TAG_ICON)

src/com/magento/idea/magento2plugin/indexes/UiComponentIndex.java renamed to src/com/magento/idea/magento2plugin/indexes/UIComponentIndex.java

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,12 @@
1919
import java.util.List;
2020
import org.jetbrains.annotations.Nullable;
2121

22+
@SuppressWarnings("PMD")
23+
public final class UIComponentIndex {
2224

23-
public class UiComponentIndex {
25+
private UIComponentIndex() {
26+
throw new AssertionError("Instantiating utility class...");
27+
}
2428

2529
/**
2630
* Available ui component file.
@@ -41,7 +45,10 @@ public static boolean isUiComponentFile(final VirtualFile virtualFile) {
4145
* @param fileName String
4246
* @return List
4347
*/
44-
public static List<XmlFile> getUiComponentFiles(final Project project, final @Nullable String fileName) {
48+
public static List<XmlFile> getUiComponentFiles(
49+
final Project project,
50+
final @Nullable String fileName
51+
) {
4552
final List<XmlFile> results = new ArrayList<XmlFile>();//NOPMD
4653
final Collection<VirtualFile> xmlFiles = FilenameIndex.getAllFilesByExt(project, "xml");
4754

@@ -62,11 +69,27 @@ public static List<XmlFile> getUiComponentFiles(final Project project, final @Nu
6269
return results;
6370
}
6471

72+
/**
73+
* Get ui component files.
74+
*
75+
* @param project Project
76+
* @return List
77+
*/
6578
public static List<XmlFile> getUiComponentFiles(final Project project) {
6679
return getUiComponentFiles(project, null);
6780
}
6881

69-
public static Collection<String> getAllKeys(final ID<String, Void> id, final Project project) {
70-
return FileBasedIndex.getInstance().getAllKeys(id, project);
82+
/**
83+
* Get All Keys.
84+
*
85+
* @param identifier ID
86+
* @param project Project
87+
* @return Collection
88+
*/
89+
public static Collection<String> getAllKeys(
90+
final ID<String, Void> identifier,
91+
final Project project
92+
) {
93+
return FileBasedIndex.getInstance().getAllKeys(identifier, project);
7194
}
7295
}

src/com/magento/idea/magento2plugin/stubs/indexes/xml/UiComponentIndex.java renamed to src/com/magento/idea/magento2plugin/stubs/indexes/xml/UIComponentIndex.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
import org.jetbrains.annotations.NotNull;
1919

2020

21-
public class UiComponentIndex extends ScalarIndexExtension<String> {
21+
public class UIComponentIndex extends ScalarIndexExtension<String> {
2222

2323
public static final ID<String, Void> KEY =
2424
ID.create("com.magento.idea.magento2plugin.stubs.indexes.ui_component");
@@ -41,7 +41,7 @@ public DataIndexer<String, Void, FileContent> getIndexer() {
4141
final Map<String, Void> map = new HashMap<>();//NOPMD
4242

4343
final PsiFile psiFile = inputData.getPsiFile();
44-
if (!Settings.isEnabled(psiFile.getProject())) {
44+
if (!Settings.isEnabled(psiFile.getProject() )) {
4545
return map;
4646
}
4747

0 commit comments

Comments
 (0)