Lines 13-18
Link Here
|
13 |
import java.util.ArrayList; |
13 |
import java.util.ArrayList; |
14 |
import java.util.HashMap; |
14 |
import java.util.HashMap; |
15 |
import java.util.Iterator; |
15 |
import java.util.Iterator; |
|
|
16 |
import java.util.Map; |
16 |
|
17 |
|
17 |
import org.eclipse.core.resources.IResource; |
18 |
import org.eclipse.core.resources.IResource; |
18 |
import org.eclipse.core.runtime.IPath; |
19 |
import org.eclipse.core.runtime.IPath; |
Lines 20-25
Link Here
|
20 |
import org.eclipse.core.runtime.Path; |
21 |
import org.eclipse.core.runtime.Path; |
21 |
import org.eclipse.jdt.core.IClassFile; |
22 |
import org.eclipse.jdt.core.IClassFile; |
22 |
import org.eclipse.jdt.core.ICompilationUnit; |
23 |
import org.eclipse.jdt.core.ICompilationUnit; |
|
|
24 |
import org.eclipse.jdt.core.IJarEntryResource; |
23 |
import org.eclipse.jdt.core.IJavaElement; |
25 |
import org.eclipse.jdt.core.IJavaElement; |
24 |
import org.eclipse.jdt.core.IJavaModelStatusConstants; |
26 |
import org.eclipse.jdt.core.IJavaModelStatusConstants; |
25 |
import org.eclipse.jdt.core.JavaModelException; |
27 |
import org.eclipse.jdt.core.JavaModelException; |
Lines 61-67
Link Here
|
61 |
/** |
63 |
/** |
62 |
* Compute all the non-java resources according to the entry name found in the jar file. |
64 |
* Compute all the non-java resources according to the entry name found in the jar file. |
63 |
*/ |
65 |
*/ |
64 |
/* package */ void computeNonJavaResources(String[] resNames, JarPackageFragmentInfo info, String zipName) { |
66 |
/* package */ void computeNonJavaResources(String[] resNames, JarPackageFragment pkg, JarPackageFragmentInfo info, String zipName) { |
65 |
if (resNames == null) { |
67 |
if (resNames == null) { |
66 |
info.setNonJavaResources(null); |
68 |
info.setNonJavaResources(null); |
67 |
return; |
69 |
return; |
Lines 70-88
Link Here
|
70 |
if (max == 0) { |
72 |
if (max == 0) { |
71 |
info.setNonJavaResources(JavaElementInfo.NO_NON_JAVA_RESOURCES); |
73 |
info.setNonJavaResources(JavaElementInfo.NO_NON_JAVA_RESOURCES); |
72 |
} else { |
74 |
} else { |
73 |
Object[] res = new Object[max]; |
75 |
HashMap jarEntries = new HashMap(); // map from IPath to IJarEntryResource |
74 |
int index = 0; |
76 |
HashMap childrenMap = new HashMap(); // map from IPath to ArrayList<IJarEntryResource> |
|
|
77 |
ArrayList topJarEntries = new ArrayList(); |
75 |
for (int i = 0; i < max; i++) { |
78 |
for (int i = 0; i < max; i++) { |
76 |
String resName = resNames[i]; |
79 |
String resName = resNames[i]; |
77 |
// consider that a .java file is not a non-java resource (see bug 12246 Packages view shows .class and .java files when JAR has source) |
80 |
// consider that a .java file is not a non-java resource (see bug 12246 Packages view shows .class and .java files when JAR has source) |
78 |
if (!Util.isJavaLikeFileName(resName)) { |
81 |
if (!Util.isJavaLikeFileName(resName)) { |
79 |
IPath parentRelativePath = new Path(resName).removeFirstSegments(this.names.length); |
82 |
IPath childPath = new Path(resName).removeFirstSegments(this.names.length); |
80 |
res[index++] = new JarEntryFile(resName, zipName, parentRelativePath); |
83 |
JarEntryFile file = new JarEntryFile(resName, zipName, childPath); |
|
|
84 |
jarEntries.put(childPath, file); |
85 |
if (childPath.segmentCount() == 1) { |
86 |
file.setParent(pkg); |
87 |
topJarEntries.add(file); |
88 |
} else { |
89 |
IPath parentPath = childPath.removeLastSegments(1); |
90 |
while (parentPath.segmentCount() > 0) { |
91 |
ArrayList parentChildren = (ArrayList) childrenMap.get(parentPath); |
92 |
if (parentChildren == null) { |
93 |
Object dir = new JarEntryDirectory(parentPath); |
94 |
jarEntries.put(parentPath, dir); |
95 |
childrenMap.put(parentPath, parentChildren = new ArrayList()); |
96 |
parentChildren.add(childPath); |
97 |
if (parentPath.segmentCount() == 1) { |
98 |
topJarEntries.add(dir); |
99 |
break; |
100 |
} |
101 |
childPath = parentPath; |
102 |
parentPath = childPath.removeLastSegments(1); |
103 |
} else { |
104 |
parentChildren.add(childPath); |
105 |
break; // all parents are already registered |
106 |
} |
107 |
} |
108 |
} |
81 |
} |
109 |
} |
82 |
} |
|
|
83 |
if (index != max) { |
84 |
System.arraycopy(res, 0, res = new Object[index], 0, index); |
85 |
} |
110 |
} |
|
|
111 |
Iterator entries = childrenMap.entrySet().iterator(); |
112 |
while (entries.hasNext()) { |
113 |
Map.Entry entry = (Map.Entry) entries.next(); |
114 |
IPath entryPath = (IPath) entry.getKey(); |
115 |
ArrayList entryValue = (ArrayList) entry.getValue(); |
116 |
JarEntryDirectory jarEntryDirectory = (JarEntryDirectory) jarEntries.get(entryPath); |
117 |
int size = entryValue.size(); |
118 |
IJarEntryResource[] children = new IJarEntryResource[size]; |
119 |
for (int i = 0; i < size; i++) { |
120 |
Object child = jarEntries.get(entryValue.get(i)); |
121 |
if (child instanceof JarEntryFile) { |
122 |
((JarEntryFile) child).setParent(jarEntryDirectory); |
123 |
} else { |
124 |
((JarEntryDirectory) child).setParent(jarEntryDirectory); |
125 |
} |
126 |
children[i] = (IJarEntryResource) child; |
127 |
} |
128 |
jarEntryDirectory.setChildren(children); |
129 |
if (entryPath.segmentCount() == 1) { |
130 |
jarEntryDirectory.setParent(pkg); |
131 |
} |
132 |
} |
133 |
Object[] res = topJarEntries.toArray(new Object[topJarEntries.size()]); |
86 |
info.setNonJavaResources(res); |
134 |
info.setNonJavaResources(res); |
87 |
} |
135 |
} |
88 |
} |
136 |
} |