Skip to content

Commit 89fb3f1

Browse files
committed
Implemented a small action to test the indexer
1 parent 45a0653 commit 89fb3f1

3 files changed

Lines changed: 69 additions & 2 deletions

File tree

resources/META-INF/plugin.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,9 @@
200200
description="Collapse all named characters into their utf8 counterpart.">
201201
</action>
202202

203+
<action id="Mathematica.PackageExportChecker" class="de.halirutan.mathematica.actions.PackageExportChecker"
204+
text="PackageExportChecker"/>
205+
203206
<!--<separator/>-->
204207

205208
<!--<action id="Mathematica.ShowFormattingBlocks" class="de.halirutan.mathematica.actions.ShowFormattingBlocks"-->
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/*
2+
* Copyright (c) 2016 Patrick Scheibe
3+
* Permission is hereby granted, free of charge, to any person obtaining a copy
4+
* of this software and associated documentation files (the "Software"), to deal
5+
* in the Software without restriction, including without limitation the rights
6+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7+
* copies of the Software, and to permit persons to whom the Software is
8+
* furnished to do so, subject to the following conditions:
9+
*
10+
* The above copyright notice and this permission notice shall be included in
11+
* all copies or substantial portions of the Software.
12+
*
13+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19+
* THE SOFTWARE.
20+
*/
21+
22+
package de.halirutan.mathematica.actions;
23+
24+
import com.intellij.openapi.actionSystem.AnAction;
25+
import com.intellij.openapi.actionSystem.AnActionEvent;
26+
import com.intellij.openapi.project.Project;
27+
import com.intellij.psi.search.GlobalSearchScope;
28+
import com.intellij.util.indexing.FileBasedIndex;
29+
import com.intellij.util.indexing.ID;
30+
import de.halirutan.mathematica.index.MathematicaPackageExportIndex;
31+
import de.halirutan.mathematica.index.MathematicaPackageExportIndex.Key;
32+
import de.halirutan.mathematica.index.PackageExportInfo;
33+
34+
import java.util.Collection;
35+
import java.util.List;
36+
37+
/**
38+
* @author patrick (08.11.16).
39+
*/
40+
public class PackageExportChecker extends AnAction {
41+
42+
@Override
43+
public void actionPerformed(AnActionEvent e) {
44+
45+
final Project project = e.getProject();
46+
if (project == null) {
47+
return;
48+
}
49+
final FileBasedIndex fileBasedIndex = FileBasedIndex.getInstance();
50+
final ID<Key, List<PackageExportInfo>> indexId = MathematicaPackageExportIndex.INDEX_ID;
51+
final Collection<Key> allKeys = fileBasedIndex.getAllKeys(indexId, project);
52+
53+
for (Key next : allKeys) {
54+
final List<List<PackageExportInfo>> values = fileBasedIndex.getValues(indexId, next, GlobalSearchScope.allScope(project));
55+
for (List<PackageExportInfo> list : values) {
56+
for (PackageExportInfo info : list) {
57+
System.out.println("Info: " + info.symbol + " " + info.nameSpace);
58+
}
59+
}
60+
}
61+
}
62+
}

src/de/halirutan/mathematica/index/MathematicaPackageExportIndex.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,11 +144,11 @@ public int getVersion() {
144144
return BASE_VERSION;
145145
}
146146

147-
interface Key {
147+
public interface Key {
148148
void writeValue(DataOutput out) throws IOException;
149149
}
150150

151-
private static class FileKey implements Key {
151+
public static class FileKey implements Key {
152152
private final int myFileId;
153153

154154
private FileKey(int fileId) {
@@ -159,6 +159,8 @@ private FileKey(VirtualFile file) {
159159
myFileId = FileBasedIndex.getFileId(file);
160160
}
161161

162+
163+
162164
@Override
163165
public void writeValue(DataOutput out) throws IOException {
164166
out.writeInt(myFileId);

0 commit comments

Comments
 (0)