Reports for loops which iterate over collections or arrays, and can be replaced with an enhanced for loop (i.e. the foreach iteration syntax). Signed-off-by: Lars Grefer <eclipse@larsgrefer.de>tags/V1_9_7M1
private List<String> getConfigFilesList(String[] configFiles) { | private List<String> getConfigFilesList(String[] configFiles) { | ||||
List<String> configs = new ArrayList<String>(); | List<String> configs = new ArrayList<String>(); | ||||
for (int i = 0; i < configFiles.length; i++) { | |||||
if (configFiles[i].endsWith(BuildConfigManager.CONFIG_FILE_SUFFIX)) { | |||||
configs.add(configFiles[i]); | |||||
for (String configFile : configFiles) { | |||||
if (configFile.endsWith(BuildConfigManager.CONFIG_FILE_SUFFIX)) { | |||||
configs.add(configFile); | |||||
} | } | ||||
} | } | ||||
return configs; | return configs; |
return false; | return false; | ||||
} | } | ||||
int numConfigFiles = 0; | int numConfigFiles = 0; | ||||
for (int i = 0; i < args.length; i++) { | |||||
if ((null != args[i]) && args[i].endsWith(".lst")) { | |||||
for (String arg : args) { | |||||
if ((null != arg) && arg.endsWith(".lst")) { | |||||
numConfigFiles++; | numConfigFiles++; | ||||
} | } | ||||
} | } |
classpath.append(userPath); | classpath.append(userPath); | ||||
} | } | ||||
List<File> outputDirs = getOutputLocationManager().getAllOutputLocations(); | List<File> outputDirs = getOutputLocationManager().getAllOutputLocations(); | ||||
for (Iterator<File> iterator = outputDirs.iterator(); iterator.hasNext();) { | |||||
File dir = (File) iterator.next(); | |||||
for (File dir : outputDirs) { | |||||
classpath.append(File.pathSeparator + dir.getAbsolutePath() + File.pathSeparator); | classpath.append(File.pathSeparator + dir.getAbsolutePath() + File.pathSeparator); | ||||
} | } | ||||
classpath.append(System.getProperty("java.class.path", ".")); | classpath.append(System.getProperty("java.class.path", ".")); |
private void createList(List<IMessage> messages) { | private void createList(List<IMessage> messages) { | ||||
list = new JList(); | list = new JList(); | ||||
listModel = new DefaultListModel(); | listModel = new DefaultListModel(); | ||||
for (Iterator<IMessage> iterator = messages.iterator(); iterator.hasNext();) { | |||||
listModel.addElement(iterator.next()); | |||||
for (IMessage message : messages) { | |||||
listModel.addElement(message); | |||||
} | } | ||||
} | } | ||||
args = new String[l.size() + xmlfiles.size() + 1]; | args = new String[l.size() + xmlfiles.size() + 1]; | ||||
// TODO speedup | // TODO speedup | ||||
int p = 0; | int p = 0; | ||||
for (int i = 0; i < l.size(); i++) { | |||||
args[p++] = l.get(i); | |||||
for (String s : l) { | |||||
args[p++] = s; | |||||
} | } | ||||
for (int i = 0; i < xmlfiles.size(); i++) { | |||||
args[p++] = xmlfiles.get(i); | |||||
for (String xmlfile : xmlfiles) { | |||||
args[p++] = xmlfile; | |||||
} | } | ||||
args[p++] = "-xmlConfigured"; | args[p++] = "-xmlConfigured"; | ||||
} else { | } else { |
String contents[] = from.list(); | String contents[] = from.list(); | ||||
if (contents == null) | if (contents == null) | ||||
return; | return; | ||||
for (int i = 0; i < contents.length; i++) { | |||||
String string = contents[i]; | |||||
for (String string : contents) { | |||||
File f = new File(from, string); | File f = new File(from, string); | ||||
File t = new File(to, string); | File t = new File(to, string); | ||||
public List<String> getSourceFileList(String[] files) { | public List<String> getSourceFileList(String[] files) { | ||||
List<String> sourceFiles = new ArrayList<String>(); | List<String> sourceFiles = new ArrayList<String>(); | ||||
for (int i = 0; i < files.length; i++) { | |||||
sourceFiles.add(getAbsoluteProjectDir() + File.separator + files[i]); | |||||
for (String file : files) { | |||||
sourceFiles.add(getAbsoluteProjectDir() + File.separator + file); | |||||
} | } | ||||
return sourceFiles; | return sourceFiles; | ||||
} | } |
/* Allow the user to override the testProjectPath by using sourceRoots */ | /* Allow the user to override the testProjectPath by using sourceRoots */ | ||||
File[] srcBase = new File[] { new File(projectPath + File.separator + srcDirName) }; | File[] srcBase = new File[] { new File(projectPath + File.separator + srcDirName) }; | ||||
for (int j = 0; j < srcBase.length; j++) { | |||||
File[] fromResources = FileUtil.listFiles(srcBase[j], new FileFilter() { | |||||
for (File file : srcBase) { | |||||
File[] fromResources = FileUtil.listFiles(file, new FileFilter() { | |||||
public boolean accept(File pathname) { | public boolean accept(File pathname) { | ||||
String name = pathname.getName().toLowerCase(); | String name = pathname.getName().toLowerCase(); | ||||
return !name.endsWith(".class") && !name.endsWith(".java") && !name.endsWith(".aj") | return !name.endsWith(".class") && !name.endsWith(".java") && !name.endsWith(".aj") | ||||
&& !name.endsWith(".lst") && !name.endsWith(".jar"); | && !name.endsWith(".lst") && !name.endsWith(".jar"); | ||||
} | } | ||||
}); | }); | ||||
for (int i = 0; i < fromResources.length; i++) { | |||||
String normPath = FileUtil.normalizedPath(fromResources[i], srcBase[j]); | |||||
sourcePathResources.put(normPath, fromResources[i]); | |||||
for (File fromResource : fromResources) { | |||||
String normPath = FileUtil.normalizedPath(fromResource, file); | |||||
sourcePathResources.put(normPath, fromResource); | |||||
} | } | ||||
} | } |
compilerConfig.setSourcePathResources(m); | compilerConfig.setSourcePathResources(m); | ||||
AjBuildConfig buildConfig = genAjBuildConfig(); | AjBuildConfig buildConfig = genAjBuildConfig(); | ||||
Map<String, File> found = buildConfig.getSourcePathResources(); | Map<String, File> found = buildConfig.getSourcePathResources(); | ||||
for (Iterator<String> i = found.keySet().iterator(); i.hasNext();) { | |||||
String resource = i.next(); | |||||
for (String resource : found.keySet()) { | |||||
assertEquals("expected to find resource with name newFile.txt but " + "found " + resource, "newFile.txt", resource); | assertEquals("expected to find resource with name newFile.txt but " + "found " + resource, "newFile.txt", resource); | ||||
File from = buildConfig.getSourcePathResources().get(resource); | File from = buildConfig.getSourcePathResources().get(resource); | ||||
assertEquals("expected to find resource with file " + getWorkingDir() + "but found " + from, getWorkingDir(), from); | assertEquals("expected to find resource with file " + getWorkingDir() + "but found " + from, getWorkingDir(), from); |
File binBase = openFile(outdirName); | File binBase = openFile(outdirName); | ||||
String[] toResources = FileUtil.listFiles(binBase); | String[] toResources = FileUtil.listFiles(binBase); | ||||
for (int i = 0; i < toResources.length; i++) { | |||||
String fileName = toResources[i]; | |||||
for (String fileName : toResources) { | |||||
if (fileName.indexOf("CVS") == -1) { | if (fileName.indexOf("CVS") == -1) { | ||||
boolean b = expectedOutdirContents.remove(fileName); | boolean b = expectedOutdirContents.remove(fileName); | ||||
assertTrue("Extraneous resources: " + fileName, b); | assertTrue("Extraneous resources: " + fileName, b); | ||||
private void listSourceResources(String indirName, Set<String> resources) { | private void listSourceResources(String indirName, Set<String> resources) { | ||||
File srcBase = openFile(indirName); | File srcBase = openFile(indirName); | ||||
File[] fromResources = FileUtil.listFiles(srcBase, aspectjResourceFileFilter); | File[] fromResources = FileUtil.listFiles(srcBase, aspectjResourceFileFilter); | ||||
for (int i = 0; i < fromResources.length; i++) { | |||||
String name = FileUtil.normalizedPath(fromResources[i], srcBase); | |||||
for (File fromResource : fromResources) { | |||||
String name = FileUtil.normalizedPath(fromResource, srcBase); | |||||
// System.err.println("Checking "+name); | // System.err.println("Checking "+name); | ||||
if (!name.startsWith("CVS/") && (-1 == name.indexOf("/CVS/")) && !name.endsWith("/CVS")) { | if (!name.startsWith("CVS/") && (-1 == name.indexOf("/CVS/")) && !name.endsWith("/CVS")) { | ||||
resources.add(name); | resources.add(name); |
HashSet<String> resources = new HashSet<>(); | HashSet<String> resources = new HashSet<>(); | ||||
listSourceResources(indirName, resources); | listSourceResources(indirName, resources); | ||||
for (int i = 0; i < toResources.length; i++) { | |||||
String fileName = FileUtil.normalizedPath(toResources[i], binBase); | |||||
for (File toResource : toResources) { | |||||
String fileName = FileUtil.normalizedPath(toResource, binBase); | |||||
boolean b = resources.remove(fileName); | boolean b = resources.remove(fileName); | ||||
assertTrue("Extraneous resources: " + fileName, b); | assertTrue("Extraneous resources: " + fileName, b); | ||||
} | } | ||||
private void listSourceResources(String indirName, Set<String> resources) { | private void listSourceResources(String indirName, Set<String> resources) { | ||||
File srcBase = openFile(indirName); | File srcBase = openFile(indirName); | ||||
File[] fromResources = FileUtil.listFiles(srcBase, aspectjResourceFileFilter); | File[] fromResources = FileUtil.listFiles(srcBase, aspectjResourceFileFilter); | ||||
for (int i = 0; i < fromResources.length; i++) { | |||||
String name = FileUtil.normalizedPath(fromResources[i], srcBase); | |||||
for (File fromResource : fromResources) { | |||||
String name = FileUtil.normalizedPath(fromResource, srcBase); | |||||
if (!name.startsWith("CVS/") && (-1 == name.indexOf("/CVS/")) && !name.endsWith("/CVS")) { | if (!name.startsWith("CVS/") && (-1 == name.indexOf("/CVS/")) && !name.endsWith("/CVS")) { | ||||
resources.add(name); | resources.add(name); | ||||
} | } | ||||
File binBase = openFile(outdirName); | File binBase = openFile(outdirName); | ||||
File[] toResources = FileUtil.listFiles(binBase, aspectjResourceFileFilter); | File[] toResources = FileUtil.listFiles(binBase, aspectjResourceFileFilter); | ||||
for (int i = 0; i < toResources.length; i++) { | |||||
String fileName = FileUtil.normalizedPath(toResources[i], binBase); | |||||
for (File toResource : toResources) { | |||||
String fileName = FileUtil.normalizedPath(toResource, binBase); | |||||
/* Ensure we copied the right JAR manifest */ | /* Ensure we copied the right JAR manifest */ | ||||
if (fileName.equalsIgnoreCase("meta-inf/Manifest.mf")) { | if (fileName.equalsIgnoreCase("meta-inf/Manifest.mf")) { | ||||
byte[] outManifest = FileUtil.readAsByteArray(toResources[i]); | |||||
byte[] outManifest = FileUtil.readAsByteArray(toResource); | |||||
assertTrue("Wrong manifest has been copied", Arrays.equals(inManifest, outManifest)); | assertTrue("Wrong manifest has been copied", Arrays.equals(inManifest, outManifest)); | ||||
} | } | ||||
boolean b = resources.remove(fileName); | boolean b = resources.remove(fileName); |
// See if the messages match | // See if the messages match | ||||
int msgCount = 0; | int msgCount = 0; | ||||
List<TestMessageHandler.TestMessage> l = handler.getMessages(); | List<TestMessageHandler.TestMessage> l = handler.getMessages(); | ||||
for (Iterator<TestMessageHandler.TestMessage> iter = l.iterator(); iter.hasNext();) { | |||||
IMessage msg = iter.next().getContainedMessage(); | |||||
for (TestMessageHandler.TestMessage testMessage : l) { | |||||
IMessage msg = testMessage.getContainedMessage(); | |||||
if (debugTests) | if (debugTests) | ||||
System.out.println("Looking at [" + msg + "]"); | System.out.println("Looking at [" + msg + "]"); | ||||
if (msg.getKind().equals(IMessage.WEAVEINFO)) { | if (msg.getKind().equals(IMessage.WEAVEINFO)) { | ||||
try { | try { | ||||
fw = new FileWriter(f); | fw = new FileWriter(f); | ||||
List<TestMessageHandler.TestMessage> l = handler.getMessages(); | List<TestMessageHandler.TestMessage> l = handler.getMessages(); | ||||
for (Iterator<TestMessageHandler.TestMessage> iter = l.iterator(); iter.hasNext();) { | |||||
IMessage msg = iter.next().getContainedMessage(); | |||||
for (TestMessageHandler.TestMessage testMessage : l) { | |||||
IMessage msg = testMessage.getContainedMessage(); | |||||
if (msg.getKind().equals(IMessage.WEAVEINFO)) { | if (msg.getKind().equals(IMessage.WEAVEINFO)) { | ||||
fw.write(msg.getMessage() + "\n"); | fw.write(msg.getMessage() + "\n"); | ||||
} | } |
.findElementForLabel(aspect, IProgramElement.Kind.ADVICE, beforeExec); | .findElementForLabel(aspect, IProgramElement.Kind.ADVICE, beforeExec); | ||||
assertNotNull(beforeExecNode); | assertNotNull(beforeExecNode); | ||||
IRelationship rel = manager.getRelationshipMap().get(beforeExecNode, IRelationship.Kind.ADVICE, relName); | IRelationship rel = manager.getRelationshipMap().get(beforeExecNode, IRelationship.Kind.ADVICE, relName); | ||||
for (Iterator<String> it = rel.getTargets().iterator(); it.hasNext();) { | |||||
String currHandle = it.next(); | |||||
for (String currHandle : rel.getTargets()) { | |||||
if (manager.getHierarchy().findElementForHandle(currHandle).toLabelString().equals(to)) | if (manager.getHierarchy().findElementForHandle(currHandle).toLabelString().equals(to)) | ||||
return; | return; | ||||
} | } | ||||
// String set = to; | // String set = to; | ||||
IRelationship rel2 = manager.getRelationshipMap().get(clazz, IRelationship.Kind.DECLARE_INTER_TYPE, backRelName); | IRelationship rel2 = manager.getRelationshipMap().get(clazz, IRelationship.Kind.DECLARE_INTER_TYPE, backRelName); | ||||
// String handle2 = (String)rel2.getTargets().get(0); | // String handle2 = (String)rel2.getTargets().get(0); | ||||
for (Iterator<String> it = rel2.getTargets().iterator(); it.hasNext();) { | |||||
String currHandle = it.next(); | |||||
for (String currHandle : rel2.getTargets()) { | |||||
if (manager.getHierarchy().findElementForHandle(currHandle).toLabelString().equals(from)) | if (manager.getHierarchy().findElementForHandle(currHandle).toLabelString().equals(from)) | ||||
return; | return; | ||||
} | } |
} | } | ||||
private void testModelIntegrityHelper(IProgramElement node) throws Exception { | private void testModelIntegrityHelper(IProgramElement node) throws Exception { | ||||
for (Iterator<IProgramElement> it = node.getChildren().iterator(); it.hasNext();) { | |||||
IProgramElement child = (IProgramElement) it.next(); | |||||
for (IProgramElement child : node.getChildren()) { | |||||
if (node == child.getParent()) { | if (node == child.getParent()) { | ||||
testModelIntegrityHelper(child); | testModelIntegrityHelper(child); | ||||
} else { | } else { | ||||
public void preProcess(IProgramElement node) { | public void preProcess(IProgramElement node) { | ||||
if (node.getChildren() == null) | if (node.getChildren() == null) | ||||
return; | return; | ||||
for (Iterator<IProgramElement> it = node.getChildren().iterator(); it.hasNext();) { | |||||
if (it.next() == null) | |||||
for (IProgramElement iProgramElement : node.getChildren()) { | |||||
if (iProgramElement == null) | |||||
throw new NullPointerException("null child on node: " + node.getName()); | throw new NullPointerException("null child on node: " + node.getName()); | ||||
} | } | ||||
} | } |
} else { | } else { | ||||
StringBuffer sb = new StringBuffer(); | StringBuffer sb = new StringBuffer(); | ||||
List outputDirs = compilerConfig.getOutputLocationManager().getAllOutputLocations(); | List outputDirs = compilerConfig.getOutputLocationManager().getAllOutputLocations(); | ||||
for (Iterator iterator = outputDirs.iterator(); iterator.hasNext();) { | |||||
File dir = (File) iterator.next(); | |||||
for (Object outputDir : outputDirs) { | |||||
File dir = (File) outputDir; | |||||
sb.append(dir.getAbsolutePath() + File.pathSeparator); | sb.append(dir.getAbsolutePath() + File.pathSeparator); | ||||
} | } | ||||
classpath = LangUtil.makeClasspath(null, compilerConfig.getClasspath(), sb.toString(), compilerConfig.getOutJar()); | classpath = LangUtil.makeClasspath(null, compilerConfig.getClasspath(), sb.toString(), compilerConfig.getOutJar()); |
* Adds an entry to multiple build configuration files. | * Adds an entry to multiple build configuration files. | ||||
*/ | */ | ||||
public void updateBuildConfigFiles(List buildConfigFiles, List<String> filesToUpdate, boolean addToConfiguration) { | public void updateBuildConfigFiles(List buildConfigFiles, List<String> filesToUpdate, boolean addToConfiguration) { | ||||
for (int i = 0; i < buildConfigFiles.size(); i++) { | |||||
List<String> fileContents = readConfigFile((String) buildConfigFiles.get(i)); | |||||
for (Object buildConfigFile : buildConfigFiles) { | |||||
List<String> fileContents = readConfigFile((String) buildConfigFile); | |||||
if (addToConfiguration) { | if (addToConfiguration) { | ||||
for (int j = 0; j < filesToUpdate.size(); j++) { | |||||
fileContents.add(filesToUpdate.get(j)); | |||||
for (String s : filesToUpdate) { | |||||
fileContents.add(s); | |||||
} | } | ||||
} else { | } else { | ||||
for (int k = 0; k < filesToUpdate.size(); k++) { | |||||
if (fileContents.contains(filesToUpdate.get(k))) { | |||||
fileContents.remove(filesToUpdate.get(k)); | |||||
for (String s : filesToUpdate) { | |||||
if (fileContents.contains(s)) { | |||||
fileContents.remove(s); | |||||
} | } | ||||
} | } | ||||
} | } | ||||
writeConfigFile((String) buildConfigFiles.get(i), fileContents); | |||||
writeConfigFile((String) buildConfigFile, fileContents); | |||||
} | } | ||||
} | } | ||||
String fileContentsString = ""; | String fileContentsString = ""; | ||||
// List filesToWrite = null; | // List filesToWrite = null; | ||||
Set<String> includedFiles = new HashSet<>(); | Set<String> includedFiles = new HashSet<>(); | ||||
for (Iterator<BuildConfigNode> it = importedNodes.iterator(); it.hasNext();) { | |||||
BuildConfigNode node = it.next(); | |||||
for (BuildConfigNode node : importedNodes) { | |||||
fileContentsString += '@' + node.getResourcePath() + "\n"; | fileContentsString += '@' + node.getResourcePath() + "\n"; | ||||
String parentPath = new File(filePath).getParent(); | String parentPath = new File(filePath).getParent(); | ||||
String importedFilePath = parentPath + File.separator + node.getResourcePath(); | String importedFilePath = parentPath + File.separator + node.getResourcePath(); | ||||
includedFiles.addAll(getIncludedFiles(importedFilePath, parentPath)); | includedFiles.addAll(getIncludedFiles(importedFilePath, parentPath)); | ||||
} | } | ||||
for (Iterator<BuildConfigNode> it = files.iterator(); it.hasNext();) { | |||||
BuildConfigNode node = it.next(); | |||||
for (BuildConfigNode node : files) { | |||||
if (node.getName().endsWith(".lst") && !node.getResourcePath().startsWith("..")) { | if (node.getName().endsWith(".lst") && !node.getResourcePath().startsWith("..")) { | ||||
fileContentsString += '@'; | fileContentsString += '@'; | ||||
fileContentsString += node.getResourcePath() + "\n"; | fileContentsString += node.getResourcePath() + "\n"; | ||||
configParser.parseConfigFile(new File(path)); | configParser.parseConfigFile(new File(path)); | ||||
List<File> files = configParser.getFiles(); | List<File> files = configParser.getFiles(); | ||||
List<String> relativeFiles = new ArrayList<String>(); | List<String> relativeFiles = new ArrayList<String>(); | ||||
for (Iterator<File> it = files.iterator(); it.hasNext();) { | |||||
relativeFiles.add(relativizePath(it.next().getPath(), rootPath)); | |||||
for (File file : files) { | |||||
relativeFiles.add(relativizePath(file.getPath(), rootPath)); | |||||
} | } | ||||
return relativeFiles; | return relativeFiles; | ||||
} catch (ConfigParser.ParseException pe) { | } catch (ConfigParser.ParseException pe) { |
} | } | ||||
node.addChild(dir); | node.addChild(dir); | ||||
// boolean foundMatch = false; | // boolean foundMatch = false; | ||||
for (Iterator it = importedFiles.iterator(); it.hasNext();) { | |||||
File importedFile = (File) it.next(); | |||||
for (Object file : importedFiles) { | |||||
File importedFile = (File) file; | |||||
if (importedFile.getParentFile().getAbsolutePath().equals(dir2.getAbsolutePath())) { | if (importedFile.getParentFile().getAbsolutePath().equals(dir2.getAbsolutePath())) { | ||||
// foundMatch = true; | // foundMatch = true; | ||||
BuildConfigNode importedFileNode = new BuildConfigNode(importedFile.getName(), BuildConfigNode.Kind.FILE_LST, | BuildConfigNode importedFileNode = new BuildConfigNode(importedFile.getName(), BuildConfigNode.Kind.FILE_LST, | ||||
} | } | ||||
private void addFilesToDirTree(BuildConfigModel model, List configFiles, List badEntries) { | private void addFilesToDirTree(BuildConfigModel model, List configFiles, List badEntries) { | ||||
for (Iterator it = configFiles.iterator(); it.hasNext();) { | |||||
String path = (String) it.next(); | |||||
for (Object configFile : configFiles) { | |||||
String path = (String) configFile; | |||||
if (path.startsWith("..")) { | if (path.startsWith("..")) { | ||||
File file = new File(path); | File file = new File(path); | ||||
BuildConfigNode node = new BuildConfigNode(file.getName(), BuildConfigNode.Kind.FILE_JAVA, path); | BuildConfigNode node = new BuildConfigNode(file.getName(), BuildConfigNode.Kind.FILE_JAVA, path); |
} | } | ||||
} | } | ||||
if (node != null && node.getChildren() != null) { | if (node != null && node.getChildren() != null) { | ||||
for (Iterator<IProgramElement> it = node.getChildren().iterator(); it.hasNext();) { | |||||
IProgramElement nextNode = it.next(); | |||||
for (IProgramElement nextNode : node.getChildren()) { | |||||
if (nextNode != null) { | if (nextNode != null) { | ||||
findMatchesHelper(nextNode, pattern, kind, matches); | findMatchesHelper(nextNode, pattern, kind, matches); | ||||
} | } |
} | } | ||||
if (node != null && node.getChildren() != null) { | if (node != null && node.getChildren() != null) { | ||||
for (Iterator it = node.getChildren().iterator(); it.hasNext(); ) { | |||||
IStructureViewNode foundNode = findCorrespondingViewNodeHelper((IStructureViewNode)it.next(), pNode); | |||||
for (Object o : node.getChildren()) { | |||||
IStructureViewNode foundNode = findCorrespondingViewNodeHelper((IStructureViewNode) o, pNode); | |||||
if (foundNode != null) return foundNode; | if (foundNode != null) return foundNode; | ||||
} | } | ||||
} | } |
public void elementsUpdated(IHierarchy model) { | public void elementsUpdated(IHierarchy model) { | ||||
// updating structure views: | // updating structure views: | ||||
for (Iterator it = structureViews.iterator(); it.hasNext();) { | |||||
treeViewBuilder.buildView((StructureView) it.next(), (AspectJElementHierarchy) model); | |||||
for (Object structureView : structureViews) { | |||||
treeViewBuilder.buildView((StructureView) structureView, (AspectJElementHierarchy) model); | |||||
} | } | ||||
} | } | ||||
}; | }; | ||||
} | } | ||||
} | } | ||||
for (Iterator it = structureViews.iterator(); it.hasNext();) { | |||||
StructureView view = (StructureView) it.next(); | |||||
for (Object structureView : structureViews) { | |||||
StructureView view = (StructureView) structureView; | |||||
if (!(view instanceof GlobalStructureView) || !recordHistory || defaultFileView == null) { | if (!(view instanceof GlobalStructureView) || !recordHistory || defaultFileView == null) { | ||||
if (node.getKind().equals(IProgramElement.Kind.CODE)) { | if (node.getKind().equals(IProgramElement.Kind.CODE)) { | ||||
IProgramElement parentNode = node.getParent(); | IProgramElement parentNode = node.getParent(); |
IRelationshipMap relMap = (manager == null ? null : manager.getRelationshipMap()); | IRelationshipMap relMap = (manager == null ? null : manager.getRelationshipMap()); | ||||
List relationships = (relMap == null ? null : relMap.get(nodeHandle)); | List relationships = (relMap == null ? null : relMap.get(nodeHandle)); | ||||
if (relationships != null) { | if (relationships != null) { | ||||
for (Iterator it = relationships.iterator(); it.hasNext();) { | |||||
IRelationship rel = (IRelationship) it.next(); | |||||
for (Object relationship : relationships) { | |||||
IRelationship rel = (IRelationship) relationship; | |||||
if (rel != null && rel.getTargets().size() > 0) { | if (rel != null && rel.getTargets().size() > 0) { | ||||
IStructureViewNode relNode = createRelationship(rel, iconRegistry.getIcon(rel.getKind())); | IStructureViewNode relNode = createRelationship(rel, iconRegistry.getIcon(rel.getKind())); | ||||
if (relNode != null) { | if (relNode != null) { | ||||
svNode.add(relNode, 0); | svNode.add(relNode, 0); | ||||
for (Iterator it2 = rel.getTargets().iterator(); it2.hasNext();) { | |||||
String handle = (String) it2.next(); | |||||
for (String handle : rel.getTargets()) { | |||||
IProgramElement link = Ajde.getDefault().getModel().getHierarchy().findElementForHandle(handle); | IProgramElement link = Ajde.getDefault().getModel().getHierarchy().findElementForHandle(handle); | ||||
if (link != null) { | if (link != null) { | ||||
IStructureViewNode linkNode = createLink(link, iconRegistry.getStructureIcon(link.getKind(), | IStructureViewNode linkNode = createLink(link, iconRegistry.getStructureIcon(link.getKind(), |
private void sortView(IStructureViewNode node, Comparator<IStructureViewNode> comparator) { | private void sortView(IStructureViewNode node, Comparator<IStructureViewNode> comparator) { | ||||
if (node == null || node.getChildren() == null) return; | if (node == null || node.getChildren() == null) return; | ||||
Collections.sort(node.getChildren(), comparator); | Collections.sort(node.getChildren(), comparator); | ||||
for (Iterator it = node.getChildren().iterator(); it.hasNext(); ) { | |||||
IStructureViewNode nextNode = (IStructureViewNode)it.next(); | |||||
for (Object o : node.getChildren()) { | |||||
IStructureViewNode nextNode = (IStructureViewNode) o; | |||||
if (nextNode != null) sortView(nextNode, comparator); | if (nextNode != null) sortView(nextNode, comparator); | ||||
} | } | ||||
} | } |
@Override | @Override | ||||
public void setProjectMultivalPreference(String name, List values) { | public void setProjectMultivalPreference(String name, List values) { | ||||
String valuesString = ""; | String valuesString = ""; | ||||
for (Iterator it = values.iterator(); it.hasNext(); ) { | |||||
valuesString += (String)it.next() + ';'; | |||||
for (Object value : values) { | |||||
valuesString += (String) value + ';'; | |||||
} | } | ||||
properties.setProperty(name, valuesString); | properties.setProperty(name, valuesString); | ||||
saveProperties(); | saveProperties(); |
public void saveOptions() throws IOException { | public void saveOptions() throws IOException { | ||||
Set s = warningComboBoxes.entrySet(); | Set s = warningComboBoxes.entrySet(); | ||||
for (Iterator iterator = s.iterator(); iterator.hasNext();) { | |||||
Map.Entry entry = (Entry) iterator.next(); | |||||
for (Object o : s) { | |||||
Entry entry = (Entry) o; | |||||
String javaOption = (String) entry.getKey(); | String javaOption = (String) entry.getKey(); | ||||
JComboBox combo = (JComboBox)entry.getValue(); | |||||
JComboBox combo = (JComboBox) entry.getValue(); | |||||
String value = (String) combo.getSelectedItem(); | String value = (String) combo.getSelectedItem(); | ||||
javaBuildOptions.setOption(javaOption, value); | javaBuildOptions.setOption(javaOption, value); | ||||
} | } |
view_comboBox = new JComboBox(); | view_comboBox = new JComboBox(); | ||||
view_comboBox.setFont(AjdeWidgetStyles.DEFAULT_LABEL_FONT); | view_comboBox.setFont(AjdeWidgetStyles.DEFAULT_LABEL_FONT); | ||||
for (Iterator it = structureViews.iterator(); it.hasNext(); ) { | |||||
view_comboBox.addItem(it.next()); | |||||
for (Object structureView : structureViews) { | |||||
view_comboBox.addItem(structureView); | |||||
} | } | ||||
try { | try { | ||||
private JPopupMenu createFilterMenu() { | private JPopupMenu createFilterMenu() { | ||||
JPopupMenu filterMenu = new JPopupMenu(); | JPopupMenu filterMenu = new JPopupMenu(); | ||||
IProgramElement.Accessibility[] accessibility = IProgramElement.Accessibility.ALL; | IProgramElement.Accessibility[] accessibility = IProgramElement.Accessibility.ALL; | ||||
for (int i = 0; i < accessibility.length; i++) { | |||||
CheckBoxSelectionMenuButton menuItem = new CheckBoxSelectionMenuButton(accessibility[i]); | |||||
menuItem.setIcon(Ajde.getDefault().getIconRegistry().getAccessibilitySwingIcon(accessibility[i])); | |||||
for (IProgramElement.Accessibility value : accessibility) { | |||||
CheckBoxSelectionMenuButton menuItem = new CheckBoxSelectionMenuButton(value); | |||||
menuItem.setIcon(Ajde.getDefault().getIconRegistry().getAccessibilitySwingIcon(value)); | |||||
filterMenu.add(menuItem); | filterMenu.add(menuItem); | ||||
} | } | ||||
filterMenu.add(new JSeparator()); | filterMenu.add(new JSeparator()); | ||||
IProgramElement.Kind[] kinds = IProgramElement.Kind.ALL; | IProgramElement.Kind[] kinds = IProgramElement.Kind.ALL; | ||||
for (int i = 0; i < kinds.length; i++) { | |||||
if (kinds[i].isMember()) { | |||||
CheckBoxSelectionMenuButton menuItem = new CheckBoxSelectionMenuButton(kinds[i]); | |||||
menuItem.setIcon((Icon)Ajde.getDefault().getIconRegistry().getIcon(kinds[i]).getIconResource()); | |||||
for (IProgramElement.Kind kind : kinds) { | |||||
if (kind.isMember()) { | |||||
CheckBoxSelectionMenuButton menuItem = new CheckBoxSelectionMenuButton(kind); | |||||
menuItem.setIcon((Icon) Ajde.getDefault().getIconRegistry().getIcon(kind).getIconResource()); | |||||
filterMenu.add(menuItem); | filterMenu.add(menuItem); | ||||
} | } | ||||
} | } | ||||
filterMenu.add(new JSeparator()); | filterMenu.add(new JSeparator()); | ||||
IProgramElement.Modifiers[] modifiers = IProgramElement.Modifiers.ALL; | IProgramElement.Modifiers[] modifiers = IProgramElement.Modifiers.ALL; | ||||
for (int i = 0; i < modifiers.length; i++) { | |||||
CheckBoxSelectionMenuButton menuItem = new CheckBoxSelectionMenuButton(modifiers[i]); | |||||
for (IProgramElement.Modifiers modifier : modifiers) { | |||||
CheckBoxSelectionMenuButton menuItem = new CheckBoxSelectionMenuButton(modifier); | |||||
filterMenu.add(menuItem); | filterMenu.add(menuItem); | ||||
} | } | ||||
return filterMenu; | return filterMenu; | ||||
JPopupMenu relationsMenu = new JPopupMenu(); | JPopupMenu relationsMenu = new JPopupMenu(); | ||||
java.util.List relations = Ajde.getDefault().getStructureViewManager().getAvailableRelations(); | java.util.List relations = Ajde.getDefault().getStructureViewManager().getAvailableRelations(); | ||||
for (Iterator it = relations.iterator(); it.hasNext(); ) { | |||||
IRelationship.Kind relation = (IRelationship.Kind)it.next(); | |||||
for (Object o : relations) { | |||||
IRelationship.Kind relation = (IRelationship.Kind) o; | |||||
CheckBoxSelectionMenuButton menuItem = new CheckBoxSelectionMenuButton(relation); | CheckBoxSelectionMenuButton menuItem = new CheckBoxSelectionMenuButton(relation); | ||||
menuItem.setIcon((Icon)Ajde.getDefault().getIconRegistry().getIcon(relation).getIconResource()); | |||||
menuItem.setIcon((Icon) Ajde.getDefault().getIconRegistry().getIcon(relation).getIconResource()); | |||||
relationsMenu.add(menuItem); | relationsMenu.add(menuItem); | ||||
} | } | ||||
StructureViewProperties.Granularity[] granularity = StructureViewProperties.Granularity.ALL; | StructureViewProperties.Granularity[] granularity = StructureViewProperties.Granularity.ALL; | ||||
ButtonGroup group = new ButtonGroup(); | ButtonGroup group = new ButtonGroup(); | ||||
for (int i = 0; i < granularity.length; i++) { | |||||
RadioSelectionMenuButton menuItem = new RadioSelectionMenuButton(granularity[i], group); | |||||
for (StructureViewProperties.Granularity value : granularity) { | |||||
RadioSelectionMenuButton menuItem = new RadioSelectionMenuButton(value, group); | |||||
orderMenu.add(menuItem); | orderMenu.add(menuItem); | ||||
if (granularity[i].equals(StructureViewProperties.Granularity.MEMBER)) { | |||||
if (value.equals(StructureViewProperties.Granularity.MEMBER)) { | |||||
menuItem.setSelected(true); | menuItem.setSelected(true); | ||||
} | } | ||||
} | } |
public void updateConfigs(java.util.List configsList) { | public void updateConfigs(java.util.List configsList) { | ||||
configs_comboBox.removeAllItems(); | configs_comboBox.removeAllItems(); | ||||
for (Iterator it = configsList.iterator(); it.hasNext(); ) { | |||||
configs_comboBox.addItem(it.next()); | |||||
} | |||||
for (Object o : configsList) { | |||||
configs_comboBox.addItem(o); | |||||
} | |||||
} | } | ||||
public void setSelectedConfig(String config) { | public void setSelectedConfig(String config) { |
public BrowserViewPanel(IconRegistry icons, java.util.List views, StructureViewProperties.Hierarchy visibleViewHierarchy) { | public BrowserViewPanel(IconRegistry icons, java.util.List views, StructureViewProperties.Hierarchy visibleViewHierarchy) { | ||||
try { | try { | ||||
view_comboBox = new JComboBox(views.toArray()); | view_comboBox = new JComboBox(views.toArray()); | ||||
for (Iterator it = views.iterator(); it.hasNext(); ) { | |||||
StructureViewProperties.Hierarchy hierarchy = (StructureViewProperties.Hierarchy)it.next(); | |||||
if (hierarchy == visibleViewHierarchy) { | |||||
view_comboBox.setSelectedItem(hierarchy); | |||||
} | |||||
} | |||||
for (Object view : views) { | |||||
StructureViewProperties.Hierarchy hierarchy = (StructureViewProperties.Hierarchy) view; | |||||
if (hierarchy == visibleViewHierarchy) { | |||||
view_comboBox.setSelectedItem(hierarchy); | |||||
} | |||||
} | |||||
//GlobalViewProperties visibleView = (GlobalViewProperties)viewProperties.get(visibleViewHierarchy.toString()); | //GlobalViewProperties visibleView = (GlobalViewProperties)viewProperties.get(visibleViewHierarchy.toString()); | ||||
treeManager = new StructureTreeManager();//, visibleView); | treeManager = new StructureTreeManager();//, visibleView); | ||||
jbInit(); | jbInit(); |
public BuildConfigPopupMenu(final AbstractAction action) { | public BuildConfigPopupMenu(final AbstractAction action) { | ||||
List configFiles = Ajde.getDefault().getBuildConfigManager().getAllBuildConfigFiles(); | List configFiles = Ajde.getDefault().getBuildConfigManager().getAllBuildConfigFiles(); | ||||
for (Iterator it = configFiles.iterator(); it.hasNext(); ) { | |||||
final String buildConfig = (String)it.next(); | |||||
JMenuItem buildItem = new JMenuItem(buildConfig); | |||||
buildItem.setFont(AjdeWidgetStyles.DEFAULT_LABEL_FONT); | |||||
buildItem.addActionListener( | |||||
new ActionListener() { | |||||
public void actionPerformed(ActionEvent e) { | |||||
Ajde.getDefault().getBuildConfigManager().setActiveConfigFile(buildConfig); | |||||
// A separate thread is required here because the buildProgresssMonitor | |||||
// that monitors the build needs to be in a different thread | |||||
// to that which is doing the build (swing threading issues) | |||||
Ajde.getDefault().runBuildInDifferentThread(buildConfig, true); | |||||
action.actionPerformed(e); | |||||
} | |||||
}); | |||||
buildItem.setIcon((Icon)Ajde.getDefault().getIconRegistry().getIcon(IProgramElement.Kind.FILE_LST).getIconResource()); | |||||
this.add(buildItem); | |||||
for (Object configFile : configFiles) { | |||||
final String buildConfig = (String) configFile; | |||||
JMenuItem buildItem = new JMenuItem(buildConfig); | |||||
buildItem.setFont(AjdeWidgetStyles.DEFAULT_LABEL_FONT); | |||||
buildItem.addActionListener( | |||||
new ActionListener() { | |||||
public void actionPerformed(ActionEvent e) { | |||||
Ajde.getDefault().getBuildConfigManager().setActiveConfigFile(buildConfig); | |||||
// A separate thread is required here because the buildProgresssMonitor | |||||
// that monitors the build needs to be in a different thread | |||||
// to that which is doing the build (swing threading issues) | |||||
Ajde.getDefault().runBuildInDifferentThread(buildConfig, true); | |||||
action.actionPerformed(e); | |||||
} | |||||
}); | |||||
buildItem.setIcon((Icon) Ajde.getDefault().getIconRegistry().getIcon(IProgramElement.Kind.FILE_LST).getIconResource()); | |||||
this.add(buildItem); | |||||
} | } | ||||
} | } | ||||
} | } |
private void saveOptions() { | private void saveOptions() { | ||||
try { | try { | ||||
Component[] components = main_tabbedPane.getComponents(); | Component[] components = main_tabbedPane.getComponents(); | ||||
for (int i = 0; i < components.length; i++) { | |||||
if (components[i] instanceof OptionsPanel) { | |||||
((OptionsPanel)components[i]).saveOptions(); | |||||
for (Component component : components) { | |||||
if (component instanceof OptionsPanel) { | |||||
((OptionsPanel) component).saveOptions(); | |||||
} | } | ||||
} | } | ||||
} catch (IOException ioe) { | } catch (IOException ioe) { |
public StructureViewPanel(java.util.List structureViews) { | public StructureViewPanel(java.util.List structureViews) { | ||||
// this.structureViews = structureViews; | // this.structureViews = structureViews; | ||||
for (Iterator it = structureViews.iterator(); it.hasNext(); ) { | |||||
initView((StructureView)it.next()); | |||||
for (Object structureView : structureViews) { | |||||
initView((StructureView) structureView); | |||||
} | } | ||||
currentView = (StructureView)structureViews.get(0); | currentView = (StructureView)structureViews.get(0); | ||||
structureToolBar_panel = new BrowserStructureViewToolPanel(structureViews, currentView, this); | structureToolBar_panel = new BrowserStructureViewToolPanel(structureViews, currentView, this); |
this.kind = Kind.DECLARATION; | this.kind = Kind.DECLARATION; | ||||
if (children != null) { | if (children != null) { | ||||
for (Iterator it = children.iterator(); it.hasNext(); ) { | |||||
SwingTreeViewNode child = (SwingTreeViewNode)it.next(); | |||||
for (Object o : children) { | |||||
SwingTreeViewNode child = (SwingTreeViewNode) o; | |||||
if (StructureViewNodeFactory.acceptNode(programElement, child.getStructureNode())) { | if (StructureViewNodeFactory.acceptNode(programElement, child.getStructureNode())) { | ||||
super.add(child); | |||||
super.add(child); | |||||
} | } | ||||
} | } | ||||
} | } |
private ConfigTreeNode buildTree(BuildConfigNode node) { | private ConfigTreeNode buildTree(BuildConfigNode node) { | ||||
ConfigTreeNode treeNode = new ConfigTreeNode(node); | ConfigTreeNode treeNode = new ConfigTreeNode(node); | ||||
for (Iterator it = node.getChildren().iterator(); it.hasNext(); ) { | |||||
BuildConfigNode childNode = (BuildConfigNode)it.next(); | |||||
treeNode.add(buildTree(childNode)); | |||||
} | |||||
for (BuildConfigNode childNode : node.getChildren()) { | |||||
treeNode.add(buildTree(childNode)); | |||||
} | |||||
return treeNode; | return treeNode; | ||||
} | } | ||||
String contents[] = from.list(); | String contents[] = from.list(); | ||||
if (contents == null) | if (contents == null) | ||||
return; | return; | ||||
for (int i = 0; i < contents.length; i++) { | |||||
String string = contents[i]; | |||||
for (String string : contents) { | |||||
File f = new File(from, string); | File f = new File(from, string); | ||||
File t = new File(to, string); | File t = new File(to, string); | ||||
private IProgramElement getChild(IProgramElement parent, String s) { | private IProgramElement getChild(IProgramElement parent, String s) { | ||||
List<IProgramElement> kids = parent.getChildren(); | List<IProgramElement> kids = parent.getChildren(); | ||||
for (Iterator<IProgramElement> iter = kids.iterator(); iter.hasNext();) { | |||||
IProgramElement element = (IProgramElement) iter.next(); | |||||
for (IProgramElement element : kids) { | |||||
if (element.getName().indexOf(s) != -1) | if (element.getName().indexOf(s) != -1) | ||||
return element; | return element; | ||||
} | } | ||||
} | } | ||||
if (ipe.getChildren() != null) { | if (ipe.getChildren() != null) { | ||||
List kids = ipe.getChildren(); | List kids = ipe.getChildren(); | ||||
for (Iterator iter = kids.iterator(); iter.hasNext();) { | |||||
IProgramElement element = (IProgramElement) iter.next(); | |||||
for (Object kid : kids) { | |||||
IProgramElement element = (IProgramElement) kid; | |||||
findChild(s, element); | findChild(s, element); | ||||
} | } | ||||
} | } | ||||
System.out.println(ipe.toLabelString());// getName()); | System.out.println(ipe.toLabelString());// getName()); | ||||
if (ipe.getChildren() != null) { | if (ipe.getChildren() != null) { | ||||
List kids = ipe.getChildren(); | List kids = ipe.getChildren(); | ||||
for (Iterator iter = kids.iterator(); iter.hasNext();) { | |||||
IProgramElement element = (IProgramElement) iter.next(); | |||||
for (Object kid : kids) { | |||||
IProgramElement element = (IProgramElement) kid; | |||||
walkit(element, indent + 2); | walkit(element, indent + 2); | ||||
} | } | ||||
} | } |
} | } | ||||
private void testModelIntegrityHelper(IProgramElement node) throws Exception { | private void testModelIntegrityHelper(IProgramElement node) throws Exception { | ||||
for (Iterator it = node.getChildren().iterator(); it.hasNext();) { | |||||
IProgramElement child = (IProgramElement) it.next(); | |||||
for (IProgramElement child : node.getChildren()) { | |||||
if (node == child.getParent()) { | if (node == child.getParent()) { | ||||
testModelIntegrityHelper(child); | testModelIntegrityHelper(child); | ||||
} else { | } else { |
} | } | ||||
public boolean containsMessage(String prefix,String distinguishingMarks) { | public boolean containsMessage(String prefix,String distinguishingMarks) { | ||||
for (Iterator iter = messagesReceived.iterator(); iter.hasNext();) { | |||||
String element = (String) iter.next(); | |||||
for (Object o : messagesReceived) { | |||||
String element = (String) o; | |||||
if (element.startsWith(prefix) && | if (element.startsWith(prefix) && | ||||
element.indexOf(distinguishingMarks)!=-1) return true; | |||||
element.indexOf(distinguishingMarks) != -1) return true; | |||||
} | } | ||||
return false; | return false; | ||||
} | } | ||||
public void dumpMessages() { | public void dumpMessages() { | ||||
System.out.println("ProgressMonitorMessages"); | System.out.println("ProgressMonitorMessages"); | ||||
for (Iterator iter = messagesReceived.iterator(); iter.hasNext();) { | |||||
String element = (String) iter.next(); | |||||
for (Object o : messagesReceived) { | |||||
String element = (String) o; | |||||
System.out.println(element); | System.out.println(element); | ||||
} | } | ||||
} | } |
/* Allow the user to override the testProjectPath by using sourceRoots */ | /* Allow the user to override the testProjectPath by using sourceRoots */ | ||||
File[] srcBase = new File[] { new File(projectPath + File.separator + srcDirName) }; | File[] srcBase = new File[] { new File(projectPath + File.separator + srcDirName) }; | ||||
for (int j = 0; j < srcBase.length; j++) { | |||||
File[] fromResources = FileUtil.listFiles(srcBase[j], new FileFilter() { | |||||
for (File file : srcBase) { | |||||
File[] fromResources = FileUtil.listFiles(file, new FileFilter() { | |||||
public boolean accept(File pathname) { | public boolean accept(File pathname) { | ||||
String name = pathname.getName().toLowerCase(); | String name = pathname.getName().toLowerCase(); | ||||
return !name.endsWith(".class") && !name.endsWith(".java") && !name.endsWith(".aj") | return !name.endsWith(".class") && !name.endsWith(".java") && !name.endsWith(".aj") | ||||
&& !name.endsWith(".lst") && !name.endsWith(".jar"); | && !name.endsWith(".lst") && !name.endsWith(".jar"); | ||||
} | } | ||||
}); | }); | ||||
for (int i = 0; i < fromResources.length; i++) { | |||||
String normPath = FileUtil.normalizedPath(fromResources[i], srcBase[j]); | |||||
sourcePathResources.put(normPath, fromResources[i]); | |||||
for (File fromResource : fromResources) { | |||||
String normPath = FileUtil.normalizedPath(fromResource, file); | |||||
sourcePathResources.put(normPath, fromResource); | |||||
} | } | ||||
} | } |
rootDir = newRootDir; | rootDir = newRootDir; | ||||
declIDTable = table; | declIDTable = table; | ||||
docVisibilityModifier = docModifier; | docVisibilityModifier = docModifier; | ||||
for (int i = 0; i < inputFiles.length; i++) { | |||||
decorateHTMLFromIPEs(getProgramElements(model, inputFiles[i].getCanonicalPath()), rootDir.getCanonicalPath() | |||||
for (File inputFile : inputFiles) { | |||||
decorateHTMLFromIPEs(getProgramElements(model, inputFile.getCanonicalPath()), rootDir.getCanonicalPath() | |||||
+ Config.DIR_SEP_CHAR, docModifier, false); | + Config.DIR_SEP_CHAR, docModifier, false); | ||||
} | } | ||||
} | } | ||||
static void decorateHTMLFromIPEs(IProgramElement[] decls, String base, String docModifier, boolean exceededNestingLevel) | static void decorateHTMLFromIPEs(IProgramElement[] decls, String base, String docModifier, boolean exceededNestingLevel) | ||||
throws IOException { | throws IOException { | ||||
if (decls != null) { | if (decls != null) { | ||||
for (int i = 0; i < decls.length; i++) { | |||||
IProgramElement decl = decls[i]; | |||||
for (IProgramElement decl : decls) { | |||||
decorateHTMLFromIPE(decl, base, docModifier, exceededNestingLevel); | decorateHTMLFromIPE(decl, base, docModifier, exceededNestingLevel); | ||||
} | } | ||||
} | } | ||||
if (fieldsDeclaredOn != null && !constDeclaredOn.isEmpty()) { | if (fieldsDeclaredOn != null && !constDeclaredOn.isEmpty()) { | ||||
insertDeclarationsSummary(fileBuffer, constDeclaredOn, ITD_CONSTRUCTOR_SUMMARY, index); | insertDeclarationsSummary(fileBuffer, constDeclaredOn, ITD_CONSTRUCTOR_SUMMARY, index); | ||||
} | } | ||||
for (Iterator<IProgramElement> it = node.getChildren().iterator(); it.hasNext();) { | |||||
IProgramElement member = it.next(); | |||||
for (IProgramElement member : node.getChildren()) { | |||||
if (member.getKind().equals(IProgramElement.Kind.POINTCUT)) { | if (member.getKind().equals(IProgramElement.Kind.POINTCUT)) { | ||||
pointcuts.add(member); | pointcuts.add(member); | ||||
} else if (member.getKind().equals(IProgramElement.Kind.ADVICE)) { | } else if (member.getKind().equals(IProgramElement.Kind.ADVICE)) { | ||||
insertIndex += tableHead.length(); | insertIndex += tableHead.length(); | ||||
// insert the body of the table | // insert the body of the table | ||||
for (int i = 0; i < decls.size(); i++) { | |||||
IProgramElement decl = (IProgramElement) decls.get(i); | |||||
for (Object o : decls) { | |||||
IProgramElement decl = (IProgramElement) o; | |||||
if (isAboveVisibility(decl)) { | if (isAboveVisibility(decl)) { | ||||
// insert the table row accordingly | // insert the table row accordingly | ||||
String comment = generateSummaryComment(decl); | String comment = generateSummaryComment(decl); | ||||
private static boolean declsAboveVisibilityExist(List decls) { | private static boolean declsAboveVisibilityExist(List decls) { | ||||
boolean exist = false; | boolean exist = false; | ||||
for (Iterator it = decls.iterator(); it.hasNext();) { | |||||
IProgramElement element = (IProgramElement) it.next(); | |||||
for (Object decl : decls) { | |||||
IProgramElement element = (IProgramElement) decl; | |||||
if (isAboveVisibility(element)) | if (isAboveVisibility(element)) | ||||
exist = true; | exist = true; | ||||
} | } | ||||
static String generateHREFName(IProgramElement decl) { | static String generateHREFName(IProgramElement decl) { | ||||
StringBuffer hrefLinkBuffer = new StringBuffer(); | StringBuffer hrefLinkBuffer = new StringBuffer(); | ||||
char[] declChars = decl.toLabelString().toCharArray(); | char[] declChars = decl.toLabelString().toCharArray(); | ||||
for (int i = 0; i < declChars.length; i++) { | |||||
if (declChars[i] == '"') { | |||||
for (char declChar : declChars) { | |||||
if (declChar == '"') { | |||||
hrefLinkBuffer.append("quot;"); | hrefLinkBuffer.append("quot;"); | ||||
} else { | } else { | ||||
hrefLinkBuffer.append(declChars[i]); | |||||
hrefLinkBuffer.append(declChar); | |||||
} | } | ||||
} | } | ||||
return hrefLinkBuffer.toString(); | return hrefLinkBuffer.toString(); |
*/ | */ | ||||
private static void packageHTML(AsmManager model, File[] inputFiles) throws IOException { | private static void packageHTML(AsmManager model, File[] inputFiles) throws IOException { | ||||
ArrayList<String> dirList = new ArrayList<String>(); | ArrayList<String> dirList = new ArrayList<String>(); | ||||
for (int i = 0; i < inputFiles.length; i++) { | |||||
String packageName = StructureUtil.getPackageDeclarationFromFile(model, inputFiles[i]); | |||||
for (File inputFile : inputFiles) { | |||||
String packageName = StructureUtil.getPackageDeclarationFromFile(model, inputFile); | |||||
// Only copy the package.html file once. | // Only copy the package.html file once. | ||||
if (dirList.contains(packageName)) | if (dirList.contains(packageName)) | ||||
continue; | continue; | ||||
// Check to see if there exist a package.html file for this package. | // Check to see if there exist a package.html file for this package. | ||||
String dir = inputFiles[i].getAbsolutePath().substring(0, inputFiles[i].getAbsolutePath().lastIndexOf(File.separator)); | |||||
String dir = inputFile.getAbsolutePath().substring(0, inputFile.getAbsolutePath().lastIndexOf(File.separator)); | |||||
File input = new File(dir + Config.DIR_SEP_CHAR + "package.html"); | File input = new File(dir + Config.DIR_SEP_CHAR + "package.html"); | ||||
File inDir = new File(dir + Config.DIR_SEP_CHAR + "doc-files"); | File inDir = new File(dir + Config.DIR_SEP_CHAR + "doc-files"); | ||||
// If it does not exist lets go to the next package. | // If it does not exist lets go to the next package. | ||||
for (; i < ajcOptions.size(); i++) { | for (; i < ajcOptions.size(); i++) { | ||||
argsToCompiler[i] = ajcOptions.elementAt(i); | argsToCompiler[i] = ajcOptions.elementAt(i); | ||||
} | } | ||||
for (int j = 0; j < inputFiles.length; j++) { | |||||
argsToCompiler[i] = inputFiles[j].getAbsolutePath(); | |||||
for (File inputFile : inputFiles) { | |||||
argsToCompiler[i] = inputFile.getAbsolutePath(); | |||||
// System.out.println(">> file to ajc: " + inputFiles[j].getAbsolutePath()); | // System.out.println(">> file to ajc: " + inputFiles[j].getAbsolutePath()); | ||||
i++; | i++; | ||||
} | } | ||||
for (int k = 0; k < signatureFiles.length; k++) { | for (int k = 0; k < signatureFiles.length; k++) { | ||||
javadocargs[options.size() + k] = StructureUtil.translateAjPathName(signatureFiles[k].getCanonicalPath()); | javadocargs[options.size() + k] = StructureUtil.translateAjPathName(signatureFiles[k].getCanonicalPath()); | ||||
} | } | ||||
for (int k = 0; k < signatureFiles.length; k++) { | |||||
files.add(StructureUtil.translateAjPathName(signatureFiles[k].getCanonicalPath())); | |||||
for (File signatureFile : signatureFiles) { | |||||
files.add(StructureUtil.translateAjPathName(signatureFile.getCanonicalPath())); | |||||
} | } | ||||
} | } | ||||
if (LangUtil.is19VMOrGreater()) { | if (LangUtil.is19VMOrGreater()) { | ||||
return f.getName().equals("package-summary.html"); | return f.getName().equals("package-summary.html"); | ||||
} | } | ||||
}); | }); | ||||
for (int j = 0; j < files.length; j++) { | |||||
removeDeclIDsFromFile(files[j].getAbsolutePath(), false); | |||||
for (File file : files) { | |||||
removeDeclIDsFromFile(file.getAbsolutePath(), false); | |||||
} | } | ||||
} | } | ||||
} | } | ||||
// System.err.println(argList); | // System.err.println(argList); | ||||
args = new String[argList.size()]; | args = new String[argList.size()]; | ||||
int counter = 0; | int counter = 0; | ||||
for (Iterator<String> it = argList.iterator(); it.hasNext();) { | |||||
args[counter] = it.next(); | |||||
for (String s : argList) { | |||||
args[counter] = s; | |||||
counter++; | counter++; | ||||
} | } | ||||
} catch (FileNotFoundException e) { | } catch (FileNotFoundException e) { | ||||
if (vargs.size() == 0) { | if (vargs.size() == 0) { | ||||
displayHelpAndExit(null); | displayHelpAndExit(null); | ||||
} | } | ||||
for (int i = 0; i < vargs.size(); i++) { | |||||
String arg = (String) vargs.get(i); | |||||
for (Object varg : vargs) { | |||||
String arg = (String) varg; | |||||
ignoreArg = false; | ignoreArg = false; | ||||
if (addNextAsDocDir) { | if (addNextAsDocDir) { | ||||
docDir = arg; | docDir = arg; | ||||
int index2 = name.length(); | int index2 = name.length(); | ||||
if ((index1 >= 0 && index2 >= 0) | if ((index1 >= 0 && index2 >= 0) | ||||
&& (name.substring(index1, index2).equals(".java") || name.substring(index1, index2) | && (name.substring(index1, index2).equals(".java") || name.substring(index1, index2) | ||||
.equals(".aj"))) { | |||||
.equals(".aj"))) { | |||||
return true; | return true; | ||||
} else { | } else { | ||||
return false; | return false; | ||||
} | } | ||||
} | } | ||||
}); | }); | ||||
for (int j = 0; j < files.length; j++) { | |||||
for (String file : files) { | |||||
filenames.addElement(sourcepath.elementAt(c) + Config.DIR_SEP_CHAR + arg | filenames.addElement(sourcepath.elementAt(c) + Config.DIR_SEP_CHAR + arg | ||||
+ Config.DIR_SEP_CHAR + files[j]); | |||||
+ Config.DIR_SEP_CHAR + file); | |||||
} | } | ||||
} else if (c == sourcepath.size()) { // last element on classpath | } else if (c == sourcepath.size()) { // last element on classpath | ||||
System.out.println("ajdoc: No package, class, or source file " + "found named " + arg + "."); | System.out.println("ajdoc: No package, class, or source file " + "found named " + arg + "."); |
if (rels != null) { | if (rels != null) { | ||||
relations.addAll(rels); | relations.addAll(rels); | ||||
} | } | ||||
for (Iterator<IProgramElement> iter = node.getChildren().iterator(); iter.hasNext();) { | |||||
IProgramElement child = (IProgramElement) iter.next(); | |||||
for (IProgramElement child : node.getChildren()) { | |||||
// if we're not a type, or if we are and the child is code, then | // if we're not a type, or if we are and the child is code, then | ||||
// we want to get the relationships for this child - this means that the | // we want to get the relationships for this child - this means that the | ||||
// correct relationships appear against the type in the ajdoc | // correct relationships appear against the type in the ajdoc | ||||
if (!node.getKind().isType() || child.getKind().equals(IProgramElement.Kind.CODE)) { | if (!node.getKind().isType() || child.getKind().equals(IProgramElement.Kind.CODE)) { | ||||
List<IRelationship> childRelations = node.getModel().getRelationshipMap().get(child); | List<IRelationship> childRelations = node.getModel().getRelationshipMap().get(child); | ||||
if (childRelations != null) { | if (childRelations != null) { | ||||
for (Iterator<IRelationship> iterator = childRelations.iterator(); iterator.hasNext();) { | |||||
IRelationship rel = (IRelationship) iterator.next(); | |||||
for (IRelationship rel : childRelations) { | |||||
if (!relations.contains(rel)) { | if (!relations.contains(rel)) { | ||||
relations.add(rel); | relations.add(rel); | ||||
} | } | ||||
if (relations == null || relations.isEmpty()) | if (relations == null || relations.isEmpty()) | ||||
return null; | return null; | ||||
List<String> targets = new ArrayList<String>(); | List<String> targets = new ArrayList<String>(); | ||||
for (Iterator<IRelationship> it = relations.iterator(); it.hasNext();) { | |||||
IRelationship rtn = (IRelationship) it.next(); | |||||
for (IRelationship rtn : relations) { | |||||
if (rtn.getKind().equals(kind) && ((relName != null && relName.equals(rtn.getName())) || relName == null)) { | if (rtn.getKind().equals(kind) && ((relName != null && relName.equals(rtn.getName())) || relName == null)) { | ||||
List<String> targs = rtn.getTargets(); | List<String> targs = rtn.getTargets(); | ||||
for (String element: targs) { | |||||
for (String element : targs) { | |||||
if (!targets.contains(element)) { | if (!targets.contains(element)) { | ||||
targets.add(element); | targets.add(element); | ||||
} | } | ||||
} | } | ||||
String modifiers = ""; | String modifiers = ""; | ||||
for (Iterator modIt = node.getModifiers().iterator(); modIt.hasNext();) { | |||||
modifiers += modIt.next() + " "; | |||||
for (IProgramElement.Modifiers value : node.getModifiers()) { | |||||
modifiers += value + " "; | |||||
} | } | ||||
if (node.getKind().equals(IProgramElement.Kind.METHOD) || node.getKind().equals(IProgramElement.Kind.FIELD)) { | if (node.getKind().equals(IProgramElement.Kind.METHOD) || node.getKind().equals(IProgramElement.Kind.FIELD)) { |
} | } | ||||
IProgramElement fileNode = model.getHierarchy().findElementForSourceFile(inputFile.getAbsolutePath()); | IProgramElement fileNode = model.getHierarchy().findElementForSourceFile(inputFile.getAbsolutePath()); | ||||
for (Iterator it = fileNode.getChildren().iterator(); it.hasNext();) { | |||||
IProgramElement node = (IProgramElement) it.next(); | |||||
for (IProgramElement node : fileNode.getChildren()) { | |||||
if (node.getKind().isPackageDeclaration()) { | if (node.getKind().isPackageDeclaration()) { | ||||
// skip | // skip | ||||
} else if (node.getKind().equals(IProgramElement.Kind.IMPORT_REFERENCE)) { | } else if (node.getKind().equals(IProgramElement.Kind.IMPORT_REFERENCE)) { | ||||
private static void processImportDeclaration(IProgramElement node, PrintWriter writer) throws IOException { | private static void processImportDeclaration(IProgramElement node, PrintWriter writer) throws IOException { | ||||
List imports = node.getChildren(); | List imports = node.getChildren(); | ||||
for (Iterator i = imports.iterator(); i.hasNext();) { | |||||
IProgramElement importNode = (IProgramElement) i.next(); | |||||
for (Object anImport : imports) { | |||||
IProgramElement importNode = (IProgramElement) anImport; | |||||
writer.println(importNode.getSourceSignature()); | writer.println(importNode.getSourceSignature()); | ||||
} | } | ||||
} | } | ||||
private static void processMembers(List/* IProgramElement */members, PrintWriter writer, boolean declaringTypeIsInterface) | private static void processMembers(List/* IProgramElement */members, PrintWriter writer, boolean declaringTypeIsInterface) | ||||
throws DocException { | throws DocException { | ||||
for (Iterator it = members.iterator(); it.hasNext();) { | |||||
IProgramElement member = (IProgramElement) it.next(); | |||||
for (Object o : members) { | |||||
IProgramElement member = (IProgramElement) o; | |||||
if (member.getKind().isType()) { | if (member.getKind().isType()) { | ||||
if (!member.getParent().getKind().equals(IProgramElement.Kind.METHOD) && !StructureUtil.isAnonymous(member)) {// don't | if (!member.getParent().getKind().equals(IProgramElement.Kind.METHOD) && !StructureUtil.isAnonymous(member)) {// don't |
*/ | */ | ||||
public static List<String> getMissingStringsInFile(File htmlFile, String[] requiredStrings) throws Exception { | public static List<String> getMissingStringsInFile(File htmlFile, String[] requiredStrings) throws Exception { | ||||
List<String> missingStrings = new ArrayList<String>(); | List<String> missingStrings = new ArrayList<String>(); | ||||
for (int i = 0; i < requiredStrings.length; i++) { | |||||
String string = requiredStrings[i]; | |||||
for (String string : requiredStrings) { | |||||
if (!containsString(htmlFile, string)) { | if (!containsString(htmlFile, string)) { | ||||
missingStrings.add(string); | missingStrings.add(string); | ||||
} | } | ||||
public static List<String> getMissingStringsInSection(File htmlFile, | public static List<String> getMissingStringsInSection(File htmlFile, | ||||
String[] requiredStrings, String sectionHeader) throws Exception { | String[] requiredStrings, String sectionHeader) throws Exception { | ||||
List<String> missingStrings = new ArrayList<String>(); | List<String> missingStrings = new ArrayList<String>(); | ||||
for (int i = 0; i < requiredStrings.length; i++) { | |||||
String string = requiredStrings[i]; | |||||
if (!containsStringWithinSection(htmlFile,string,sectionHeader)) { | |||||
for (String string : requiredStrings) { | |||||
if (!containsStringWithinSection(htmlFile, string, sectionHeader)) { | |||||
missingStrings.add(string); | missingStrings.add(string); | ||||
} | } | ||||
} | } |
String contents[] = from.list(); | String contents[] = from.list(); | ||||
if (contents == null) | if (contents == null) | ||||
return; | return; | ||||
for (int i = 0; i < contents.length; i++) { | |||||
String string = contents[i]; | |||||
for (String string : contents) { | |||||
File f = new File(from, string); | File f = new File(from, string); | ||||
File t = new File(to, string); | File t = new File(to, string); | ||||
if (inputFiles.length == 0) { | if (inputFiles.length == 0) { | ||||
fail("need to pass some files into ajdoc"); | fail("need to pass some files into ajdoc"); | ||||
} | } | ||||
for (int i = 0; i < inputFiles.length; i++) { | |||||
if (!inputFiles[i].exists()) { | |||||
fail(inputFiles[i].getAbsolutePath() + " does not exist"); | |||||
for (File inputFile : inputFiles) { | |||||
if (!inputFile.exists()) { | |||||
fail(inputFile.getAbsolutePath() + " does not exist"); | |||||
} | } | ||||
} | } | ||||
public void runAjdoc(List options) { | public void runAjdoc(List options) { | ||||
String[] args = new String[options.size()]; | String[] args = new String[options.size()]; | ||||
int i = 0; | int i = 0; | ||||
for (Iterator iter = options.iterator(); iter.hasNext();) { | |||||
String element = (String) iter.next(); | |||||
for (Object option : options) { | |||||
String element = (String) option; | |||||
args[i] = element; | args[i] = element; | ||||
i++; | i++; | ||||
} | } |
IProgramElement fileNode = node; | IProgramElement fileNode = node; | ||||
ArrayList<IProgramElement> peNodes = new ArrayList<IProgramElement>(); | ArrayList<IProgramElement> peNodes = new ArrayList<IProgramElement>(); | ||||
getAllStructureChildren(fileNode, peNodes, showSubMember, showMemberAndType); | getAllStructureChildren(fileNode, peNodes, showSubMember, showMemberAndType); | ||||
for (Iterator<IProgramElement> it = peNodes.iterator(); it.hasNext();) { | |||||
IProgramElement peNode = it.next(); | |||||
for (IProgramElement peNode : peNodes) { | |||||
List<IProgramElement> entries = new ArrayList<IProgramElement>(); | List<IProgramElement> entries = new ArrayList<IProgramElement>(); | ||||
entries.add(peNode); | entries.add(peNode); | ||||
ISourceLocation sourceLoc = peNode.getSourceLocation(); | ISourceLocation sourceLoc = peNode.getSourceLocation(); | ||||
if (relationshipsToRemove.size() == relationships.size()) { | if (relationshipsToRemove.size() == relationships.size()) { | ||||
sourcesToRemove.add(hid); | sourcesToRemove.add(hid); | ||||
} else { | } else { | ||||
for (int i = 0; i < relationshipsToRemove.size(); i++) { | |||||
relationships.remove(relationshipsToRemove.get(i)); | |||||
for (IRelationship iRelationship : relationshipsToRemove) { | |||||
relationships.remove(iRelationship); | |||||
} | } | ||||
} | } | ||||
} | } | ||||
if (relationshipsToRemove.size() == relationships.size()) { | if (relationshipsToRemove.size() == relationships.size()) { | ||||
sourcesToRemove.add(hid); | sourcesToRemove.add(hid); | ||||
} else { | } else { | ||||
for (int i = 0; i < relationshipsToRemove.size(); i++) { | |||||
relationships.remove(relationshipsToRemove.get(i)); | |||||
for (IRelationship iRelationship : relationshipsToRemove) { | |||||
relationships.remove(iRelationship); | |||||
} | } | ||||
} | } | ||||
} | } | ||||
List<IRelationship> relationshipsToRemove = new ArrayList<IRelationship>(); | List<IRelationship> relationshipsToRemove = new ArrayList<IRelationship>(); | ||||
// Iterate through the relationships against this source | // Iterate through the relationships against this source | ||||
// handle | // handle | ||||
for (Iterator<IRelationship> reliter = relationships.iterator(); reliter.hasNext();) { | |||||
IRelationship rel = reliter.next(); | |||||
for (IRelationship rel : relationships) { | |||||
List<String> targets = rel.getTargets(); | List<String> targets = rel.getTargets(); | ||||
List<String> targetsToRemove = new ArrayList<String>(); | List<String> targetsToRemove = new ArrayList<String>(); | ||||
// Iterate through the targets for this relationship | // Iterate through the targets for this relationship | ||||
for (Iterator<String> targetIter = targets.iterator(); targetIter.hasNext();) { | |||||
String targethid = targetIter.next(); | |||||
// tgthandlecounter++; | |||||
for (String targethid : targets) { | |||||
// tgthandlecounter++; | |||||
// Do we already know it doesn't exist? | // Do we already know it doesn't exist? | ||||
if (nonExistingHandles.contains(targethid)) { | if (nonExistingHandles.contains(targethid)) { | ||||
if (dumpDeltaProcessing) { | if (dumpDeltaProcessing) { | ||||
} else { | } else { | ||||
// MEMORY LEAK - we don't remove the | // MEMORY LEAK - we don't remove the | ||||
// relationships !! | // relationships !! | ||||
for (int i = 0; i < relationshipsToRemove.size(); i++) { | |||||
IRelationship irel = relationshipsToRemove.get(i); | |||||
for (IRelationship irel : relationshipsToRemove) { | |||||
verifyAssumption(mapper.remove(hid, irel), "Failed to remove relationship " + irel.getName() | verifyAssumption(mapper.remove(hid, irel), "Failed to remove relationship " + irel.getName() | ||||
+ " for shid " + hid); | + " for shid " + hid); | ||||
} | } | ||||
} | } | ||||
} | } | ||||
// Remove sources that have no valid relationships any more | // Remove sources that have no valid relationships any more | ||||
for (Iterator<String> srciter = sourcesToRemove.iterator(); srciter.hasNext();) { | |||||
String hid = srciter.next(); | |||||
for (String hid : sourcesToRemove) { | |||||
mapper.removeAll(hid); | mapper.removeAll(hid); | ||||
IProgramElement ipe = hierarchy.getElement(hid); | IProgramElement ipe = hierarchy.getElement(hid); | ||||
if (ipe != null) { | if (ipe != null) { |
}; | }; | ||||
public static Kind getKindForString(String kindString) { | public static Kind getKindForString(String kindString) { | ||||
for (int i = 0; i < ALL.length; i++) { | |||||
if (ALL[i].toString().equals(kindString)) { | |||||
return ALL[i]; | |||||
} | |||||
} | |||||
for (Kind kind : ALL) { | |||||
if (kind.toString().equals(kindString)) { | |||||
return kind; | |||||
} | |||||
} | |||||
return ERROR; | return ERROR; | ||||
} | } | ||||
* @return the Kind instance | * @return the Kind instance | ||||
*/ | */ | ||||
public static Kind getKindFor(String stringFormOfRelationshipKind) { | public static Kind getKindFor(String stringFormOfRelationshipKind) { | ||||
for (int i = 0; i < ALL.length; i++) { | |||||
if (ALL[i].name.equals(stringFormOfRelationshipKind)) { | |||||
return ALL[i]; | |||||
for (Kind kind : ALL) { | |||||
if (kind.name.equals(stringFormOfRelationshipKind)) { | |||||
return kind; | |||||
} | } | ||||
} | } | ||||
return null; | return null; |
List<char[]> parameterTypes = ipe.getParameterSignatures(); | List<char[]> parameterTypes = ipe.getParameterSignatures(); | ||||
StringBuffer sb = new StringBuffer(); | StringBuffer sb = new StringBuffer(); | ||||
if (sourceRefs != null) { | if (sourceRefs != null) { | ||||
for (int i = 0; i < sourceRefs.size(); i++) { | |||||
String sourceRef = sourceRefs.get(i); | |||||
for (String sourceRef : sourceRefs) { | |||||
sb.append(HandleProviderDelimiter.getDelimiter(ipe)); | sb.append(HandleProviderDelimiter.getDelimiter(ipe)); | ||||
sb.append(sourceRef); | sb.append(sourceRef); | ||||
} | } | ||||
if (ipe.getKind().isInterTypeMember()) { | if (ipe.getKind().isInterTypeMember()) { | ||||
int count = 1; | int count = 1; | ||||
List<IProgramElement> kids = ipe.getParent().getChildren(); | List<IProgramElement> kids = ipe.getParent().getChildren(); | ||||
for (Iterator<IProgramElement> iterator = kids.iterator(); iterator.hasNext();) { | |||||
IProgramElement object = iterator.next(); | |||||
for (IProgramElement object : kids) { | |||||
if (object.equals(ipe)) { | if (object.equals(ipe)) { | ||||
break; | break; | ||||
} | } |
if (children == null) { | if (children == null) { | ||||
return; | return; | ||||
} | } | ||||
for (Iterator<IProgramElement> it = children.iterator(); it.hasNext();) { | |||||
(it.next()).setParent(this); | |||||
for (IProgramElement child : children) { | |||||
child.setParent(this); | |||||
} | } | ||||
} | } | ||||
return Collections.emptyList(); | return Collections.emptyList(); | ||||
} | } | ||||
List<char[]> params = new ArrayList<char[]>(); | List<char[]> params = new ArrayList<char[]>(); | ||||
for (Iterator<char[]> iter = l.iterator(); iter.hasNext();) { | |||||
char[] param = iter.next(); | |||||
for (char[] param : l) { | |||||
params.add(NameConvertor.convertFromSignature(param)); | params.add(NameConvertor.convertFromSignature(param)); | ||||
} | } | ||||
return params; | return params; |
super.put(source, relationships); | super.put(source, relationships); | ||||
return rel; | return rel; | ||||
} else { | } else { | ||||
for (Iterator<IRelationship> it = relationships.iterator(); it.hasNext();) { | |||||
IRelationship curr = it.next(); | |||||
for (IRelationship curr : relationships) { | |||||
if (curr.getKind() == kind && curr.getName().equals(relationshipName) && curr.hasRuntimeTest() == runtimeTest) { | if (curr.getKind() == kind && curr.getName().equals(relationshipName) && curr.hasRuntimeTest() == runtimeTest) { | ||||
return curr; | return curr; | ||||
} | } |
file.writeShort(0); | file.writeShort(0); | ||||
} else { | } else { | ||||
file.writeShort(attributes.length); | file.writeShort(attributes.length); | ||||
for (int i = 0; i < attributes.length; i++) { | |||||
attributes[i].dump(file); | |||||
for (Attribute attribute : attributes) { | |||||
attribute.dump(file); | |||||
} | } | ||||
} | } | ||||
} | } | ||||
public static Signature getSignatureAttribute(Attribute[] attributes) { | public static Signature getSignatureAttribute(Attribute[] attributes) { | ||||
for (int i = 0; i < attributes.length; i++) { | |||||
if (attributes[i].tag == Constants.ATTR_SIGNATURE) { | |||||
return (Signature) attributes[i]; | |||||
for (Attribute attribute : attributes) { | |||||
if (attribute.tag == Constants.ATTR_SIGNATURE) { | |||||
return (Signature) attribute; | |||||
} | } | ||||
} | } | ||||
return null; | return null; | ||||
} | } | ||||
public static Code getCodeAttribute(Attribute[] attributes) { | public static Code getCodeAttribute(Attribute[] attributes) { | ||||
for (int i = 0; i < attributes.length; i++) { | |||||
if (attributes[i].tag == Constants.ATTR_CODE) { | |||||
return (Code) attributes[i]; | |||||
for (Attribute attribute : attributes) { | |||||
if (attribute.tag == Constants.ATTR_CODE) { | |||||
return (Code) attribute; | |||||
} | } | ||||
} | } | ||||
return null; | return null; | ||||
} | } | ||||
public static ExceptionTable getExceptionTableAttribute(Attribute[] attributes) { | public static ExceptionTable getExceptionTableAttribute(Attribute[] attributes) { | ||||
for (int i = 0; i < attributes.length; i++) { | |||||
if (attributes[i].tag == Constants.ATTR_EXCEPTIONS) { | |||||
return (ExceptionTable) attributes[i]; | |||||
for (Attribute attribute : attributes) { | |||||
if (attribute.tag == Constants.ATTR_EXCEPTIONS) { | |||||
return (ExceptionTable) attribute; | |||||
} | } | ||||
} | } | ||||
return null; | return null; | ||||
} | } | ||||
public static ConstantValue getConstantValueAttribute(Attribute[] attributes) { | public static ConstantValue getConstantValueAttribute(Attribute[] attributes) { | ||||
for (int i = 0; i < attributes.length; i++) { | |||||
if (attributes[i].getTag() == Constants.ATTR_CONSTANT_VALUE) { | |||||
return (ConstantValue) attributes[i]; | |||||
for (Attribute attribute : attributes) { | |||||
if (attribute.getTag() == Constants.ATTR_CONSTANT_VALUE) { | |||||
return (ConstantValue) attribute; | |||||
} | } | ||||
} | } | ||||
return null; | return null; | ||||
} | } | ||||
public static void accept(Attribute[] attributes, ClassVisitor visitor) { | public static void accept(Attribute[] attributes, ClassVisitor visitor) { | ||||
for (int i = 0; i < attributes.length; i++) { | |||||
attributes[i].accept(visitor); | |||||
for (Attribute attribute : attributes) { | |||||
attribute.accept(visitor); | |||||
} | } | ||||
} | } | ||||
public static boolean hasSyntheticAttribute(Attribute[] attributes) { | public static boolean hasSyntheticAttribute(Attribute[] attributes) { | ||||
for (int i = 0; i < attributes.length; i++) { | |||||
if (attributes[i].tag == Constants.ATTR_SYNTHETIC) { | |||||
for (Attribute attribute : attributes) { | |||||
if (attribute.tag == Constants.ATTR_SYNTHETIC) { | |||||
return true; | return true; | ||||
} | } | ||||
} | } | ||||
} | } | ||||
public static SourceFile getSourceFileAttribute(Attribute[] attributes) { | public static SourceFile getSourceFileAttribute(Attribute[] attributes) { | ||||
for (int i = 0; i < attributes.length; i++) { | |||||
if (attributes[i].tag == Constants.ATTR_SOURCE_FILE) { | |||||
return (SourceFile) attributes[i]; | |||||
for (Attribute attribute : attributes) { | |||||
if (attribute.tag == Constants.ATTR_SOURCE_FILE) { | |||||
return (SourceFile) attribute; | |||||
} | } | ||||
} | } | ||||
return null; | return null; |
file.writeShort(bootstrapMethodRef); | file.writeShort(bootstrapMethodRef); | ||||
int len = bootstrapArguments.length; | int len = bootstrapArguments.length; | ||||
file.writeShort(len); | file.writeShort(len); | ||||
for (int i=0;i<len;i++) { | |||||
file.writeShort(bootstrapArguments[i]); | |||||
for (int bootstrapArgument : bootstrapArguments) { | |||||
file.writeShort(bootstrapArgument); | |||||
} | } | ||||
} | } | ||||
} else { | } else { | ||||
int blen = bootstrapMethods.length; | int blen = bootstrapMethods.length; | ||||
file.writeShort(blen); | file.writeShort(blen); | ||||
for (int i = 0; i < blen; i++) { | |||||
bootstrapMethods[i].dump(file); | |||||
for (BootstrapMethod bootstrapMethod : bootstrapMethods) { | |||||
bootstrapMethod.dump(file); | |||||
} | } | ||||
} | } | ||||
} | } | ||||
int [] args = bm.getBootstrapArguments(); | int [] args = bm.getBootstrapArguments(); | ||||
line.append(" argcount:").append(args==null?0:args.length).append(" "); | line.append(" argcount:").append(args==null?0:args.length).append(" "); | ||||
if (args!=null) { | if (args!=null) { | ||||
for (int a=0;a<args.length;a++) { | |||||
line.append(args[a]).append("(").append(getConstantPool().getConstant(args[a])).append(") "); | |||||
for (int arg : args) { | |||||
line.append(arg).append("(").append(getConstantPool().getConstant(arg)).append(") "); | |||||
} | } | ||||
} | } | ||||
file.write(code, 0, code.length); | file.write(code, 0, code.length); | ||||
file.writeShort(exceptionTable.length); | file.writeShort(exceptionTable.length); | ||||
for (int i = 0; i < exceptionTable.length; i++) { | |||||
exceptionTable[i].dump(file); | |||||
for (CodeException e : exceptionTable) { | |||||
e.dump(file); | |||||
} | } | ||||
file.writeShort(attributes.length); | file.writeShort(attributes.length); | ||||
for (int i = 0; i < attributes.length; i++) { | |||||
attributes[i].dump(file); | |||||
for (Attribute attribute : attributes) { | |||||
attribute.dump(file); | |||||
} | } | ||||
} | } | ||||
* @return LineNumberTable of Code, if it has one | * @return LineNumberTable of Code, if it has one | ||||
*/ | */ | ||||
public LineNumberTable getLineNumberTable() { | public LineNumberTable getLineNumberTable() { | ||||
for (int i = 0; i < attributes.length; i++) { | |||||
if (attributes[i].tag == Constants.ATTR_LINE_NUMBER_TABLE) { | |||||
return (LineNumberTable) attributes[i]; | |||||
for (Attribute attribute : attributes) { | |||||
if (attribute.tag == Constants.ATTR_LINE_NUMBER_TABLE) { | |||||
return (LineNumberTable) attribute; | |||||
} | } | ||||
} | } | ||||
return null; | return null; | ||||
* @return LocalVariableTable of Code, if it has one | * @return LocalVariableTable of Code, if it has one | ||||
*/ | */ | ||||
public LocalVariableTable getLocalVariableTable() { | public LocalVariableTable getLocalVariableTable() { | ||||
for (int i = 0; i < attributes.length; i++) { | |||||
if (attributes[i].tag == Constants.ATTR_LOCAL_VARIABLE_TABLE) { | |||||
return (LocalVariableTable) attributes[i]; | |||||
for (Attribute attribute : attributes) { | |||||
if (attribute.tag == Constants.ATTR_LOCAL_VARIABLE_TABLE) { | |||||
return (LocalVariableTable) attribute; | |||||
} | } | ||||
} | } | ||||
return null; | return null; | ||||
private final int calculateLength() { | private final int calculateLength() { | ||||
int len = 0; | int len = 0; | ||||
if (attributes != null) { | if (attributes != null) { | ||||
for (int i = 0; i < attributes.length; i++) { | |||||
len += attributes[i].length + 6 /* attribute header size */; | |||||
for (Attribute attribute : attributes) { | |||||
len += attribute.length + 6 /* attribute header size */; | |||||
} | } | ||||
} | } | ||||
return len + getInternalLength(); | return len + getInternalLength(); | ||||
if (exceptionTable.length > 0) { | if (exceptionTable.length > 0) { | ||||
buf.append("\nException handler(s) = \n" + "From\tTo\tHandler\tType\n"); | buf.append("\nException handler(s) = \n" + "From\tTo\tHandler\tType\n"); | ||||
for (int i = 0; i < exceptionTable.length; i++) { | |||||
buf.append(exceptionTable[i].toString(cpool, verbose) + "\n"); | |||||
for (CodeException e : exceptionTable) { | |||||
buf.append(e.toString(cpool, verbose) + "\n"); | |||||
} | } | ||||
} | } | ||||
if (attributes.length > 0) { | if (attributes.length > 0) { | ||||
buf.append("\nAttribute(s) = \n"); | buf.append("\nAttribute(s) = \n"); | ||||
for (int i = 0; i < attributes.length; i++) { | |||||
buf.append(attributes[i].toString() + "\n"); | |||||
for (Attribute attribute : attributes) { | |||||
buf.append(attribute.toString() + "\n"); | |||||
} | } | ||||
} | } | ||||
codeString.append(Utility.codeToString(code, cpool, 0, -1, true)); | codeString.append(Utility.codeToString(code, cpool, 0, -1, true)); | ||||
if (exceptionTable.length > 0) { | if (exceptionTable.length > 0) { | ||||
codeString.append("\n").append("Exception entries = ").append(exceptionTable.length).append("\n"); | codeString.append("\n").append("Exception entries = ").append(exceptionTable.length).append("\n"); | ||||
for (int i = 0; i < exceptionTable.length; i++) { | |||||
CodeException exc = exceptionTable[i]; | |||||
for (CodeException exc : exceptionTable) { | |||||
int type = exc.getCatchType(); | int type = exc.getCatchType(); | ||||
String name = "finally"; | String name = "finally"; | ||||
if (type != 0) { | if (type != 0) { |
if (annotations == null) { | if (annotations == null) { | ||||
// Find attributes that contain annotation data | // Find attributes that contain annotation data | ||||
List<AnnotationGen> accumulatedAnnotations = new ArrayList<AnnotationGen>(); | List<AnnotationGen> accumulatedAnnotations = new ArrayList<AnnotationGen>(); | ||||
for (int i = 0; i < attributes.length; i++) { | |||||
Attribute attribute = attributes[i]; | |||||
for (Attribute attribute : attributes) { | |||||
if (attribute instanceof RuntimeAnnos) { | if (attribute instanceof RuntimeAnnos) { | ||||
RuntimeAnnos runtimeAnnotations = (RuntimeAnnos) attribute; | RuntimeAnnos runtimeAnnotations = (RuntimeAnnos) attribute; | ||||
accumulatedAnnotations.addAll(runtimeAnnotations.getAnnotations()); | accumulatedAnnotations.addAll(runtimeAnnotations.getAnnotations()); |
file.writeShort(superclassnameIdx); | file.writeShort(superclassnameIdx); | ||||
file.writeShort(interfaces.length); | file.writeShort(interfaces.length); | ||||
for (int i = 0; i < interfaces.length; i++) { | |||||
file.writeShort(interfaces[i]); | |||||
for (int anInterface : interfaces) { | |||||
file.writeShort(anInterface); | |||||
} | } | ||||
file.writeShort(fields.length); | file.writeShort(fields.length); | ||||
for (int i = 0; i < fields.length; i++) { | |||||
fields[i].dump(file); | |||||
for (Field field : fields) { | |||||
field.dump(file); | |||||
} | } | ||||
file.writeShort(methods.length); | file.writeShort(methods.length); | ||||
for (int i = 0; i < methods.length; i++) { | |||||
methods[i].dump(file); | |||||
for (Method method : methods) { | |||||
method.dump(file); | |||||
} | } | ||||
AttributeUtils.writeAttributes(attributes, file); | AttributeUtils.writeAttributes(attributes, file); | ||||
if (annotationsOutOfDate) { | if (annotationsOutOfDate) { | ||||
// Find attributes that contain annotation data | // Find attributes that contain annotation data | ||||
List<AnnotationGen> accumulatedAnnotations = new ArrayList<AnnotationGen>(); | List<AnnotationGen> accumulatedAnnotations = new ArrayList<AnnotationGen>(); | ||||
for (int i = 0; i < attributes.length; i++) { | |||||
Attribute attribute = attributes[i]; | |||||
for (Attribute attribute : attributes) { | |||||
if (attribute instanceof RuntimeAnnos) { | if (attribute instanceof RuntimeAnnos) { | ||||
RuntimeAnnos runtimeAnnotations = (RuntimeAnnos) attribute; | RuntimeAnnos runtimeAnnotations = (RuntimeAnnos) attribute; | ||||
accumulatedAnnotations.addAll(runtimeAnnotations.getAnnotations()); | accumulatedAnnotations.addAll(runtimeAnnotations.getAnnotations()); | ||||
* @return A org.aspectj.apache.bcel.classfile.Method corresponding to java.lang.reflect.Method if any | * @return A org.aspectj.apache.bcel.classfile.Method corresponding to java.lang.reflect.Method if any | ||||
*/ | */ | ||||
public Method getMethod(java.lang.reflect.Method m) { | public Method getMethod(java.lang.reflect.Method m) { | ||||
for (int i = 0; i < methods.length; i++) { | |||||
Method method = methods[i]; | |||||
for (Method method : methods) { | |||||
if (m.getName().equals(method.getName()) && m.getModifiers() == method.getModifiers() | if (m.getName().equals(method.getName()) && m.getModifiers() == method.getModifiers() | ||||
&& Type.getSignature(m).equals(method.getSignature())) { | && Type.getSignature(m).equals(method.getSignature())) { | ||||
return method; | return method; | ||||
} | } | ||||
public Method getMethod(java.lang.reflect.Constructor<?> c) { | public Method getMethod(java.lang.reflect.Constructor<?> c) { | ||||
for (int i = 0; i < methods.length; i++) { | |||||
Method method = methods[i]; | |||||
for (Method method : methods) { | |||||
if (method.getName().equals("<init>") && c.getModifiers() == method.getModifiers() | if (method.getName().equals("<init>") && c.getModifiers() == method.getModifiers() | ||||
&& Type.getSignature(c).equals(method.getSignature())) { | && Type.getSignature(c).equals(method.getSignature())) { | ||||
return method; | return method; | ||||
if (attributes.length > 0) { | if (attributes.length > 0) { | ||||
buf.append("\nAttribute(s):\n"); | buf.append("\nAttribute(s):\n"); | ||||
for (int i = 0; i < attributes.length; i++) { | |||||
buf.append(indent(attributes[i])); | |||||
for (Attribute attribute : attributes) { | |||||
buf.append(indent(attribute)); | |||||
} | } | ||||
} | } | ||||
if (annotations != null && annotations.length > 0) { | if (annotations != null && annotations.length > 0) { | ||||
buf.append("\nAnnotation(s):\n"); | buf.append("\nAnnotation(s):\n"); | ||||
for (int i = 0; i < annotations.length; i++) { | |||||
buf.append(indent(annotations[i])); | |||||
for (AnnotationGen annotation : annotations) { | |||||
buf.append(indent(annotation)); | |||||
} | } | ||||
} | } | ||||
if (fields.length > 0) { | if (fields.length > 0) { | ||||
buf.append("\n" + fields.length + " fields:\n"); | buf.append("\n" + fields.length + " fields:\n"); | ||||
for (int i = 0; i < fields.length; i++) { | |||||
buf.append("\t" + fields[i] + '\n'); | |||||
for (Field field : fields) { | |||||
buf.append("\t" + field + '\n'); | |||||
} | } | ||||
} | } | ||||
if (methods.length > 0) { | if (methods.length > 0) { | ||||
buf.append("\n" + methods.length + " methods:\n"); | buf.append("\n" + methods.length + " methods:\n"); | ||||
for (int i = 0; i < methods.length; i++) { | |||||
buf.append("\t" + methods[i] + '\n'); | |||||
for (Method method : methods) { | |||||
buf.append("\t" + method + '\n'); | |||||
} | } | ||||
} | } | ||||
return; | return; | ||||
} | } | ||||
// Attribute[] attrs = attributes.getAttributes(); | // Attribute[] attrs = attributes.getAttributes(); | ||||
for (int i = 0; i < attributes.length; i++) { | |||||
if (attributes[i] instanceof InnerClasses) { | |||||
InnerClass[] innerClasses = ((InnerClasses) attributes[i]).getInnerClasses(); | |||||
for (int j = 0; j < innerClasses.length; j++) { | |||||
for (Attribute attribute : attributes) { | |||||
if (attribute instanceof InnerClasses) { | |||||
InnerClass[] innerClasses = ((InnerClasses) attribute).getInnerClasses(); | |||||
for (InnerClass innerClass : innerClasses) { | |||||
boolean innerClassAttributeRefersToMe = false; | boolean innerClassAttributeRefersToMe = false; | ||||
String inner_class_name = cpool.getConstantString(innerClasses[j].getInnerClassIndex(), | |||||
String inner_class_name = cpool.getConstantString(innerClass.getInnerClassIndex(), | |||||
Constants.CONSTANT_Class); | Constants.CONSTANT_Class); | ||||
inner_class_name = Utility.compactClassName(inner_class_name); | inner_class_name = Utility.compactClassName(inner_class_name); | ||||
if (inner_class_name.equals(getClassName())) { | if (inner_class_name.equals(getClassName())) { | ||||
} | } | ||||
if (innerClassAttributeRefersToMe) { | if (innerClassAttributeRefersToMe) { | ||||
this.isNested = true; | this.isNested = true; | ||||
if (innerClasses[j].getInnerNameIndex() == 0) { | |||||
if (innerClass.getInnerNameIndex() == 0) { | |||||
this.isAnonymous = true; | this.isAnonymous = true; | ||||
} | } | ||||
} | } | ||||
JavaClass[] super_classes = getSuperClasses(); | JavaClass[] super_classes = getSuperClasses(); | ||||
for (int i = 0; i < super_classes.length; i++) { | |||||
if (super_classes[i].equals(super_class)) { | |||||
for (JavaClass superClass : super_classes) { | |||||
if (superClass.equals(super_class)) { | |||||
return true; | return true; | ||||
} | } | ||||
} | } | ||||
} | } | ||||
} | } | ||||
for (int i = 0; i < interfaces.length; i++) { | |||||
queue.add(interfaces[i]); | |||||
for (JavaClass anInterface : interfaces) { | |||||
queue.add(anInterface); | |||||
} | } | ||||
} | } | ||||
signature = Utility.methodSignatureToString(signature, name, access, true, getLocalVariableTable()); | signature = Utility.methodSignatureToString(signature, name, access, true, getLocalVariableTable()); | ||||
buf = new StringBuffer(signature); | buf = new StringBuffer(signature); | ||||
for (int i = 0; i < attributes.length; i++) { | |||||
Attribute a = attributes[i]; | |||||
if (!((a instanceof Code) || (a instanceof ExceptionTable))) | |||||
buf.append(" [" + a.toString() + "]"); | |||||
} | |||||
for (Attribute a : attributes) { | |||||
if (!((a instanceof Code) || (a instanceof ExceptionTable))) | |||||
buf.append(" [" + a.toString() + "]"); | |||||
} | |||||
ExceptionTable e = getExceptionTable(); | ExceptionTable e = getExceptionTable(); | ||||
if (e != null) { | if (e != null) { | ||||
// Find attributes that contain annotation data | // Find attributes that contain annotation data | ||||
Attribute[] attrs = getAttributes(); | Attribute[] attrs = getAttributes(); | ||||
for (int i = 0; i < attrs.length; i++) { | |||||
Attribute attribute = attrs[i]; | |||||
if (attribute instanceof RuntimeVisParamAnnos) { | |||||
parameterAnnotationsVis = (RuntimeVisParamAnnos) attribute; | |||||
} else if (attribute instanceof RuntimeInvisParamAnnos) { | |||||
parameterAnnotationsInvis = (RuntimeInvisParamAnnos) attribute; | |||||
} | |||||
} | |||||
for (Attribute attribute : attrs) { | |||||
if (attribute instanceof RuntimeVisParamAnnos) { | |||||
parameterAnnotationsVis = (RuntimeVisParamAnnos) attribute; | |||||
} | |||||
else if (attribute instanceof RuntimeInvisParamAnnos) { | |||||
parameterAnnotationsInvis = (RuntimeInvisParamAnnos) attribute; | |||||
} | |||||
} | |||||
boolean foundSome = false; | boolean foundSome = false; | ||||
// Build a list of annotation arrays, one per argument | // Build a list of annotation arrays, one per argument |
file.writeShort(moduleVersionIndex); | file.writeShort(moduleVersionIndex); | ||||
file.writeShort(requires.length); | file.writeShort(requires.length); | ||||
for (int i = 0; i < requires.length; i++) { | |||||
file.writeShort(requires[i].moduleIndex); | |||||
file.writeShort(requires[i].flags); | |||||
file.writeShort(requires[i].versionIndex); | |||||
for (Require require : requires) { | |||||
file.writeShort(require.moduleIndex); | |||||
file.writeShort(require.flags); | |||||
file.writeShort(require.versionIndex); | |||||
} | } | ||||
file.writeShort(exports.length); | file.writeShort(exports.length); | ||||
for (Export export : exports) { | for (Export export : exports) { |
public final void dump(DataOutputStream stream) throws IOException { | public final void dump(DataOutputStream stream) throws IOException { | ||||
super.dump(stream); | super.dump(stream); | ||||
stream.writeShort(packageIndices.length); | stream.writeShort(packageIndices.length); | ||||
for (int i = 0; i < packageIndices.length; i++) { | |||||
stream.writeShort(packageIndices[i]); | |||||
for (int packageIndex : packageIndices) { | |||||
stream.writeShort(packageIndex); | |||||
} | } | ||||
} | } | ||||
@Override | @Override | ||||
public final String toString() { | public final String toString() { | ||||
StringBuffer buf = new StringBuffer(); | StringBuffer buf = new StringBuffer(); | ||||
for (int i = 0; i < packageIndices.length; i++) { | |||||
buf.append(cpool.getPackageName(packageIndices[i]) + "\n"); | |||||
for (int packageIndex : packageIndices) { | |||||
buf.append(cpool.getPackageName(packageIndex) + "\n"); | |||||
} | } | ||||
return buf.toString(); | return buf.toString(); | ||||
} | } |
char[] ch = label.toCharArray(); | char[] ch = label.toCharArray(); | ||||
StringBuffer buf = new StringBuffer(); | StringBuffer buf = new StringBuffer(); | ||||
for (int i = 0; i < ch.length; i++) { | |||||
switch (ch[i]) { | |||||
case '\n': | |||||
buf.append("\\n"); | |||||
break; | |||||
case '\r': | |||||
buf.append("\\r"); | |||||
break; | |||||
case '\"': | |||||
buf.append("\\\""); | |||||
break; | |||||
case '\'': | |||||
buf.append("\\'"); | |||||
break; | |||||
case '\\': | |||||
buf.append("\\\\"); | |||||
break; | |||||
default: | |||||
buf.append(ch[i]); | |||||
break; | |||||
for (char c : ch) { | |||||
switch (c) { | |||||
case '\n': | |||||
buf.append("\\n"); | |||||
break; | |||||
case '\r': | |||||
buf.append("\\r"); | |||||
break; | |||||
case '\"': | |||||
buf.append("\\\""); | |||||
break; | |||||
case '\'': | |||||
buf.append("\\'"); | |||||
break; | |||||
case '\\': | |||||
buf.append("\\\\"); | |||||
break; | |||||
default: | |||||
buf.append(c); | |||||
break; | |||||
} | } | ||||
} | } | ||||
public void dump(DataOutputStream dos) throws IOException { | public void dump(DataOutputStream dos) throws IOException { | ||||
dos.writeShort(typeIndex); // u2 index of type name in cpool | dos.writeShort(typeIndex); // u2 index of type name in cpool | ||||
dos.writeShort(pairs.size()); // u2 element_value pair count | dos.writeShort(pairs.size()); // u2 element_value pair count | ||||
for (int i = 0; i < pairs.size(); i++) { | |||||
NameValuePair envp = pairs.get(i); | |||||
for (NameValuePair envp : pairs) { | |||||
envp.dump(dos); | envp.dump(dos); | ||||
} | } | ||||
} | } |
public void dump(DataOutputStream dos) throws IOException { | public void dump(DataOutputStream dos) throws IOException { | ||||
dos.writeByte(type); // u1 type of value (ARRAY == '[') | dos.writeByte(type); // u1 type of value (ARRAY == '[') | ||||
dos.writeShort(evalues.length); | dos.writeShort(evalues.length); | ||||
for (int i = 0; i < evalues.length; i++) { | |||||
evalues[i].dump(dos); | |||||
for (ElementValue evalue : evalues) { | |||||
evalue.dump(dos); | |||||
} | } | ||||
} | } | ||||
dos.write(annotation_data, 0, length); | dos.write(annotation_data, 0, length); | ||||
} else { | } else { | ||||
dos.writeShort(annotations.size()); | dos.writeShort(annotations.size()); | ||||
for (Iterator<AnnotationGen> i = annotations.iterator(); i.hasNext();) { | |||||
AnnotationGen ann = i.next(); | |||||
for (AnnotationGen ann : annotations) { | |||||
ann.dump(dos); | ann.dump(dos); | ||||
} | } | ||||
} | } |
dos.write(annotation_data,0,length); | dos.write(annotation_data,0,length); | ||||
} else { | } else { | ||||
dos.writeByte(parameterAnnotations.size()); | dos.writeByte(parameterAnnotations.size()); | ||||
for (int i=0; i<parameterAnnotations.size(); i++) { | |||||
AnnotationGen[] annotations = parameterAnnotations.get(i); | |||||
for (AnnotationGen[] annotations : parameterAnnotations) { | |||||
dos.writeShort(annotations.length); | dos.writeShort(annotations.length); | ||||
for (int j=0; j<annotations.length;j++) { | |||||
annotations[j].dump(dos); | |||||
for (AnnotationGen annotation : annotations) { | |||||
annotation.dump(dos); | |||||
} | } | ||||
} | } | ||||
} | } |
dos.write(annotation_data,0,length); | dos.write(annotation_data,0,length); | ||||
} else { | } else { | ||||
dos.writeShort(typeAnnotations.length); | dos.writeShort(typeAnnotations.length); | ||||
for (int i=0; i<typeAnnotations.length; i++) { | |||||
typeAnnotations[i].dump(dos); | |||||
for (TypeAnnotationGen typeAnnotation : typeAnnotations) { | |||||
typeAnnotation.dump(dos); | |||||
} | } | ||||
} | } | ||||
} | } |
case LOCAL_VARIABLE: | case LOCAL_VARIABLE: | ||||
case RESOURCE_VARIABLE: | case RESOURCE_VARIABLE: | ||||
dos.writeShort(localVarTarget.length/3); | dos.writeShort(localVarTarget.length/3); | ||||
for (int i=0;i<localVarTarget.length;i++) { | |||||
dos.writeShort(localVarTarget[i]); | |||||
for (int j : localVarTarget) { | |||||
dos.writeShort(j); | |||||
} | } | ||||
break; | break; | ||||
case EXCEPTION_PARAMETER: | case EXCEPTION_PARAMETER: | ||||
throw new IllegalStateException("nyi "+targetType); | throw new IllegalStateException("nyi "+targetType); | ||||
} | } | ||||
dos.writeByte(typePath.length); | dos.writeByte(typePath.length); | ||||
for (int i=0;i<typePath.length;i++) { | |||||
dos.writeByte(typePath[i]); | |||||
for (int j : typePath) { | |||||
dos.writeByte(j); | |||||
} | } | ||||
annotation.dump(dos); | annotation.dump(dos); | ||||
} | } |
Field[] fields = clazz.getFields(); | Field[] fields = clazz.getFields(); | ||||
String[] interfaces = clazz.getInterfaceNames(); | String[] interfaces = clazz.getInterfaceNames(); | ||||
for (int i = 0; i < interfaces.length; i++) { | |||||
addInterface(interfaces[i]); | |||||
for (String anInterface : interfaces) { | |||||
addInterface(anInterface); | |||||
} | } | ||||
// OPTIMIZE Could make unpacking lazy, done on first reference | // OPTIMIZE Could make unpacking lazy, done on first reference | ||||
} | } | ||||
} | } | ||||
for (int i = 0; i < methods.length; i++) { | |||||
addMethod(methods[i]); | |||||
for (Method method : methods) { | |||||
addMethod(method); | |||||
} | } | ||||
for (int i = 0; i < fields.length; i++) { | |||||
addField(fields[i]); | |||||
for (Field field : fields) { | |||||
addField(field); | |||||
} | } | ||||
} | } | ||||
public void setMethods(Method[] methods) { | public void setMethods(Method[] methods) { | ||||
methodsList.clear(); | methodsList.clear(); | ||||
for (int m = 0; m < methods.length; m++) | |||||
addMethod(methods[m]); | |||||
for (Method method : methods) addMethod(method); | |||||
} | } | ||||
public void setFields(Field[] fs) { | public void setFields(Field[] fs) { | ||||
fieldsList.clear(); | fieldsList.clear(); | ||||
for (int m = 0; m < fs.length; m++) | |||||
addField(fs[m]); | |||||
for (Field f : fs) addField(f); | |||||
} | } | ||||
public void setMethodAt(Method method, int pos) { | public void setMethodAt(Method method, int pos) { | ||||
String[] names = getInterfaceNames(); | String[] names = getInterfaceNames(); | ||||
if (names != null) { | if (names != null) { | ||||
Arrays.sort(names); | Arrays.sort(names); | ||||
for (int i = 0; i < names.length; i++) | |||||
dos.writeUTF(names[i]); | |||||
for (String name : names) dos.writeUTF(name); | |||||
} | } | ||||
// 4. ordered list of fields (ignoring private static and private transient fields): | // 4. ordered list of fields (ignoring private static and private transient fields): |
Attribute[] attrs = field.getAttributes(); | Attribute[] attrs = field.getAttributes(); | ||||
for (int i = 0; i < attrs.length; i++) { | |||||
if (attrs[i] instanceof ConstantValue) { | |||||
setValue(((ConstantValue) attrs[i]).getConstantValueIndex()); | |||||
} else if (attrs[i] instanceof RuntimeAnnos) { | |||||
RuntimeAnnos runtimeAnnotations = (RuntimeAnnos) attrs[i]; | |||||
for (Attribute attr : attrs) { | |||||
if (attr instanceof ConstantValue) { | |||||
setValue(((ConstantValue) attr).getConstantValueIndex()); | |||||
} else if (attr instanceof RuntimeAnnos) { | |||||
RuntimeAnnos runtimeAnnotations = (RuntimeAnnos) attr; | |||||
List<AnnotationGen> l = runtimeAnnotations.getAnnotations(); | List<AnnotationGen> l = runtimeAnnotations.getAnnotations(); | ||||
for (Iterator<AnnotationGen> it = l.iterator(); it.hasNext();) { | |||||
AnnotationGen element = it.next(); | |||||
for (AnnotationGen element : l) { | |||||
addAnnotation(new AnnotationGen(element, cp, false)); | addAnnotation(new AnnotationGen(element, cp, false)); | ||||
} | } | ||||
} else { | } else { | ||||
addAttribute(attrs[i]); | |||||
addAttribute(attr); | |||||
} | } | ||||
} | } | ||||
} | } |
return new InvokeInstruction(Constants.INVOKESTATIC, index); | return new InvokeInstruction(Constants.INVOKESTATIC, index); | ||||
case Constants.INVOKEINTERFACE: | case Constants.INVOKEINTERFACE: | ||||
int nargs = 0; | int nargs = 0; | ||||
for (int i = 0; i < arg_types.length; i++) { | |||||
nargs += arg_types[i].getSize(); | |||||
for (Type arg_type : arg_types) { | |||||
nargs += arg_type.getSize(); | |||||
} | } | ||||
return new INVOKEINTERFACE(index, nargs + 1, 0); | return new INVOKEINTERFACE(index, nargs + 1, 0); | ||||
default: | default: | ||||
case Constants.INVOKEINTERFACE: | case Constants.INVOKEINTERFACE: | ||||
Type[] argumentTypes = Type.getArgumentTypes(signature); | Type[] argumentTypes = Type.getArgumentTypes(signature); | ||||
int nargs = 0; | int nargs = 0; | ||||
for (int i = 0; i < argumentTypes.length; i++) {// Count size of arguments | |||||
nargs += argumentTypes[i].getSize(); | |||||
for (Type argumentType : argumentTypes) {// Count size of arguments | |||||
nargs += argumentType.getSize(); | |||||
} | } | ||||
return new INVOKEINTERFACE(index, nargs + 1, 0); | return new INVOKEINTERFACE(index, nargs + 1, 0); | ||||
default: | default: |
if (i instanceof InstructionSelect) { | if (i instanceof InstructionSelect) { | ||||
InstructionHandle[] targets = ((InstructionSelect) i).getTargets(); | InstructionHandle[] targets = ((InstructionSelect) i).getTargets(); | ||||
for (int j = 0; j < targets.length; j++) { | |||||
inst = targets[j].instruction; | |||||
for (InstructionHandle target : targets) { | |||||
inst = target.instruction; | |||||
if (!contains(inst)) { | if (!contains(inst)) { | ||||
throw new ClassGenException("Branch target of " + Constants.OPCODE_NAMES[i.opcode] + ":" + inst | throw new ClassGenException("Branch target of " + Constants.OPCODE_NAMES[i.opcode] + ":" + inst | ||||
+ " not in instruction list"); | + " not in instruction list"); | ||||
* @see MethodGen | * @see MethodGen | ||||
*/ | */ | ||||
public void redirectLocalVariables(LocalVariableGen[] lg, InstructionHandle old_target, InstructionHandle new_target) { | public void redirectLocalVariables(LocalVariableGen[] lg, InstructionHandle old_target, InstructionHandle new_target) { | ||||
for (int i = 0; i < lg.length; i++) { | |||||
InstructionHandle start = lg[i].getStart(); | |||||
InstructionHandle end = lg[i].getEnd(); | |||||
for (LocalVariableGen localVariableGen : lg) { | |||||
InstructionHandle start = localVariableGen.getStart(); | |||||
InstructionHandle end = localVariableGen.getEnd(); | |||||
if (start == old_target) { | if (start == old_target) { | ||||
lg[i].setStart(new_target); | |||||
localVariableGen.setStart(new_target); | |||||
} | } | ||||
if (end == old_target) { | if (end == old_target) { | ||||
lg[i].setEnd(new_target); | |||||
localVariableGen.setEnd(new_target); | |||||
} | } | ||||
} | } | ||||
} | } | ||||
* @see MethodGen | * @see MethodGen | ||||
*/ | */ | ||||
public void redirectExceptionHandlers(CodeExceptionGen[] exceptions, InstructionHandle old_target, InstructionHandle new_target) { | public void redirectExceptionHandlers(CodeExceptionGen[] exceptions, InstructionHandle old_target, InstructionHandle new_target) { | ||||
for (int i = 0; i < exceptions.length; i++) { | |||||
if (exceptions[i].getStartPC() == old_target) { | |||||
exceptions[i].setStartPC(new_target); | |||||
for (CodeExceptionGen exception : exceptions) { | |||||
if (exception.getStartPC() == old_target) { | |||||
exception.setStartPC(new_target); | |||||
} | } | ||||
if (exceptions[i].getEndPC() == old_target) { | |||||
exceptions[i].setEndPC(new_target); | |||||
if (exception.getEndPC() == old_target) { | |||||
exception.setEndPC(new_target); | |||||
} | } | ||||
if (exceptions[i].getHandlerPC() == old_target) { | |||||
exceptions[i].setHandlerPC(new_target); | |||||
if (exception.getHandlerPC() == old_target) { | |||||
exception.setHandlerPC(new_target); | |||||
} | } | ||||
} | } | ||||
} | } |
super(opcode, target); | super(opcode, target); | ||||
this.targets = targets; | this.targets = targets; | ||||
for (int i = 0; i < targets.length; i++) { | |||||
notifyTarget(null, targets[i], this); | |||||
for (InstructionHandle instructionHandle : targets) { | |||||
notifyTarget(null, instructionHandle, this); | |||||
} | } | ||||
this.match = match; | this.match = match; | ||||
return true; | return true; | ||||
} | } | ||||
for (int i = 0; i < targets.length; i++) { | |||||
if (targets[i] == ih) { | |||||
for (InstructionHandle target : targets) { | |||||
if (target == ih) { | |||||
return true; | return true; | ||||
} | } | ||||
} | } | ||||
void dispose() { | void dispose() { | ||||
super.dispose(); | super.dispose(); | ||||
for (int i = 0; i < targets.length; i++) { | |||||
targets[i].removeTargeter(this); | |||||
for (InstructionHandle target : targets) { | |||||
target.removeTargeter(this); | |||||
} | } | ||||
} | } | ||||
.getCode()) : null, cp); | .getCode()) : null, cp); | ||||
Attribute[] attributes = m.getAttributes(); | Attribute[] attributes = m.getAttributes(); | ||||
for (int i = 0; i < attributes.length; i++) { | |||||
Attribute a = attributes[i]; | |||||
for (Attribute attribute : attributes) { | |||||
Attribute a = attribute; | |||||
if (a instanceof Code) { | if (a instanceof Code) { | ||||
Code code = (Code) a; | Code code = (Code) a; | ||||
} | } | ||||
Attribute[] codeAttrs = code.getAttributes(); | Attribute[] codeAttrs = code.getAttributes(); | ||||
for (int j = 0; j < codeAttrs.length; j++) { | |||||
a = codeAttrs[j]; | |||||
for (Attribute codeAttr : codeAttrs) { | |||||
a = codeAttr; | |||||
if (a instanceof LineNumberTable) { | if (a instanceof LineNumberTable) { | ||||
LineNumber[] ln = ((LineNumberTable) a).getLineNumberTable(); | LineNumber[] ln = ((LineNumberTable) a).getLineNumberTable(); | ||||
if (useTags) { | if (useTags) { | ||||
// abracadabra, lets create tags rather than linenumbergens. | // abracadabra, lets create tags rather than linenumbergens. | ||||
for (int k = 0; k < ln.length; k++) { | |||||
LineNumber l = ln[k]; | |||||
for (LineNumber l : ln) { | |||||
int lnum = l.getLineNumber(); | int lnum = l.getLineNumber(); | ||||
if (lnum > highestLineNumber) { | if (lnum > highestLineNumber) { | ||||
highestLineNumber = lnum; | highestLineNumber = lnum; | ||||
il.findHandle(l.getStartPC(), arrayOfInstructions, true).addTargeter(lt); | il.findHandle(l.getStartPC(), arrayOfInstructions, true).addTargeter(lt); | ||||
} | } | ||||
} else { | } else { | ||||
for (int k = 0; k < ln.length; k++) { | |||||
LineNumber l = ln[k]; | |||||
for (LineNumber l : ln) { | |||||
addLineNumber(il.findHandle(l.getStartPC(), arrayOfInstructions, true), l.getLineNumber()); | addLineNumber(il.findHandle(l.getStartPC(), arrayOfInstructions, true), l.getLineNumber()); | ||||
} | } | ||||
} | } | ||||
if (useTags) { | if (useTags) { | ||||
LocalVariable[] lv = ((LocalVariableTable) a).getLocalVariableTable(); | LocalVariable[] lv = ((LocalVariableTable) a).getLocalVariableTable(); | ||||
for (int k = 0; k < lv.length; k++) { | |||||
LocalVariable l = lv[k]; | |||||
for (LocalVariable l : lv) { | |||||
Type t = Type.getType(l.getSignature()); | Type t = Type.getType(l.getSignature()); | ||||
LocalVariableTag lvt = new LocalVariableTag(t, l.getSignature(), l.getName(), l.getIndex(), l | LocalVariableTag lvt = new LocalVariableTag(t, l.getSignature(), l.getName(), l.getIndex(), l | ||||
.getStartPC()); | .getStartPC()); | ||||
removeLocalVariables(); | removeLocalVariables(); | ||||
for (int k = 0; k < lv.length; k++) { | |||||
LocalVariable l = lv[k]; | |||||
for (LocalVariable l : lv) { | |||||
InstructionHandle start = il.findHandle(l.getStartPC(), arrayOfInstructions); | InstructionHandle start = il.findHandle(l.getStartPC(), arrayOfInstructions); | ||||
InstructionHandle end = il.findHandle(l.getStartPC() + l.getLength(), arrayOfInstructions); | InstructionHandle end = il.findHandle(l.getStartPC() + l.getLength(), arrayOfInstructions); | ||||
// AMC, this actually gives us the first instruction AFTER the range, | // AMC, this actually gives us the first instruction AFTER the range, | ||||
} | } | ||||
} else if (a instanceof ExceptionTable) { | } else if (a instanceof ExceptionTable) { | ||||
String[] names = ((ExceptionTable) a).getExceptionNames(); | String[] names = ((ExceptionTable) a).getExceptionNames(); | ||||
for (int j = 0; j < names.length; j++) { | |||||
addException(names[j]); | |||||
for (String s : names) { | |||||
addException(s); | |||||
} | } | ||||
} else if (a instanceof RuntimeAnnos) { | } else if (a instanceof RuntimeAnnos) { | ||||
RuntimeAnnos runtimeAnnotations = (RuntimeAnnos) a; | RuntimeAnnos runtimeAnnotations = (RuntimeAnnos) a; | ||||
} | } | ||||
Attribute[] attrs = Utility.getParameterAnnotationAttributes(cp, param_annotations); | Attribute[] attrs = Utility.getParameterAnnotationAttributes(cp, param_annotations); | ||||
if (attrs != null) { | if (attrs != null) { | ||||
for (int i = 0; i < attrs.length; i++) { | |||||
addAttribute(attrs[i]); | |||||
for (Attribute attr : attrs) { | |||||
addAttribute(attr); | |||||
} | } | ||||
} | } | ||||
} | } | ||||
* Each attribute causes 6 additional header bytes | * Each attribute causes 6 additional header bytes | ||||
*/ | */ | ||||
int attrs_len = 0; | int attrs_len = 0; | ||||
for (int i = 0; i < code_attrs.length; i++) { | |||||
attrs_len += (code_attrs[i].getLength() + 6); | |||||
for (Attribute code_attr : code_attrs) { | |||||
attrs_len += (code_attr.getLength() + 6); | |||||
} | } | ||||
CodeException[] c_exc = getCodeExceptions(); | CodeException[] c_exc = getCodeExceptions(); | ||||
if ((il != null) && !isAbstract()) { | if ((il != null) && !isAbstract()) { | ||||
// Remove any stale code attribute | // Remove any stale code attribute | ||||
List<Attribute> attributes = getAttributes(); | List<Attribute> attributes = getAttributes(); | ||||
for (int i = 0; i < attributes.size(); i++) { | |||||
Attribute a = attributes.get(i); | |||||
for (Attribute a : attributes) { | |||||
if (a instanceof Code) { | if (a instanceof Code) { | ||||
removeAttribute(a); | removeAttribute(a); | ||||
} | } | ||||
int max = isStatic() ? 0 : 1; | int max = isStatic() ? 0 : 1; | ||||
if (parameterTypes != null) { | if (parameterTypes != null) { | ||||
for (int i = 0; i < parameterTypes.length; i++) { | |||||
max += parameterTypes[i].getSize(); | |||||
for (Type parameterType : parameterTypes) { | |||||
max += parameterType.getSize(); | |||||
} | } | ||||
} | } | ||||
* Initially, populate the branch stack with the exception handlers, because these aren't (necessarily) branched to | * Initially, populate the branch stack with the exception handlers, because these aren't (necessarily) branched to | ||||
* explicitly. In each case, the stack will have depth 1, containing the exception object. | * explicitly. In each case, the stack will have depth 1, containing the exception object. | ||||
*/ | */ | ||||
for (int i = 0, max = et.length; i < max; i++) { | |||||
InstructionHandle handlerPos = et[i].getHandlerPC(); | |||||
for (CodeExceptionGen codeExceptionGen : et) { | |||||
InstructionHandle handlerPos = codeExceptionGen.getHandlerPC(); | |||||
if (handlerPos != null) { | if (handlerPos != null) { | ||||
// it must be at least 1 since there is an exception handler | // it must be at least 1 since there is an exception handler | ||||
maxStackDepth = 1; | maxStackDepth = 1; | ||||
// explore all of the select's targets. the default target is handled below. | // explore all of the select's targets. the default target is handled below. | ||||
InstructionSelect select = (InstructionSelect) branch; | InstructionSelect select = (InstructionSelect) branch; | ||||
InstructionHandle[] targets = select.getTargets(); | InstructionHandle[] targets = select.getTargets(); | ||||
for (int i = 0; i < targets.length; i++) { | |||||
branchTargets.push(targets[i], stackDepth); | |||||
for (InstructionHandle target : targets) { | |||||
branchTargets.push(target, stackDepth); | |||||
} | } | ||||
// nothing to fall through to. | // nothing to fall through to. | ||||
ih = null; | ih = null; | ||||
StringBuffer buf = new StringBuffer(signature); | StringBuffer buf = new StringBuffer(signature); | ||||
if (exceptionsThrown.size() > 0) { | if (exceptionsThrown.size() > 0) { | ||||
for (Iterator<String> e = exceptionsThrown.iterator(); e.hasNext();) { | |||||
buf.append("\n\t\tthrows " + e.next()); | |||||
for (String s : exceptionsThrown) { | |||||
buf.append("\n\t\tthrows " + s); | |||||
} | } | ||||
} | } | ||||
private List /* AnnotationGen */<AnnotationGen> makeMutableVersion(AnnotationGen[] mutableArray) { | private List /* AnnotationGen */<AnnotationGen> makeMutableVersion(AnnotationGen[] mutableArray) { | ||||
List<AnnotationGen> result = new ArrayList<AnnotationGen>(); | List<AnnotationGen> result = new ArrayList<AnnotationGen>(); | ||||
for (int i = 0; i < mutableArray.length; i++) { | |||||
result.add(new AnnotationGen(mutableArray[i], getConstantPool(), false)); | |||||
for (AnnotationGen annotationGen : mutableArray) { | |||||
result.add(new AnnotationGen(annotationGen, getConstantPool(), false)); | |||||
} | } | ||||
return result; | return result; | ||||
} | } |
this_sups[0] = Repository.lookupClass(thiz.getClassName()); | this_sups[0] = Repository.lookupClass(thiz.getClassName()); | ||||
t_sups[0] = Repository.lookupClass(other.getClassName()); | t_sups[0] = Repository.lookupClass(other.getClassName()); | ||||
for (int i = 0; i < t_sups.length; i++) { | |||||
for (int j = 0; j < this_sups.length; j++) { | |||||
if (this_sups[j].equals(t_sups[i])) { | |||||
return new ObjectType(this_sups[j].getClassName()); | |||||
for (JavaClass t_sup : t_sups) { | |||||
for (JavaClass this_sup : this_sups) { | |||||
if (this_sup.equals(t_sup)) { | |||||
return new ObjectType(this_sup.getClassName()); | |||||
} | } | ||||
} | } | ||||
} | } |
StringBuffer sb = new StringBuffer("("); | StringBuffer sb = new StringBuffer("("); | ||||
Class[] params = meth.getParameterTypes(); // avoid clone | Class[] params = meth.getParameterTypes(); // avoid clone | ||||
for (int j = 0; j < params.length; j++) { | |||||
sb.append(getType(params[j]).getSignature()); | |||||
for (Class param : params) { | |||||
sb.append(getType(param).getSignature()); | |||||
} | } | ||||
sb.append(")"); | sb.append(")"); | ||||
StringBuffer sb = new StringBuffer("("); | StringBuffer sb = new StringBuffer("("); | ||||
Class<?>[] params = cons.getParameterTypes(); // avoid clone | Class<?>[] params = cons.getParameterTypes(); // avoid clone | ||||
for (int j = 0; j < params.length; j++) { | |||||
sb.append(getType(params[j]).getSignature()); | |||||
for (Class<?> param : params) { | |||||
sb.append(getType(param).getSignature()); | |||||
} | } | ||||
sb.append(")V"); | sb.append(")V"); |
public void clear() { | public void clear() { | ||||
processQueue(); | processQueue(); | ||||
Set<Object> keys = map.keySet(); | Set<Object> keys = map.keySet(); | ||||
for (Iterator<Object> iterator = keys.iterator(); iterator.hasNext();) { | |||||
Object name = iterator.next(); | |||||
for (Object name : keys) { | |||||
map.remove(name); | map.remove(name); | ||||
} | } | ||||
} | } |
protected Method getMethod(JavaClass cl, String methodname) { | protected Method getMethod(JavaClass cl, String methodname) { | ||||
Method[] methods = cl.getMethods(); | Method[] methods = cl.getMethods(); | ||||
for (int i = 0; i < methods.length; i++) { | |||||
Method m = methods[i]; | |||||
for (Method m : methods) { | |||||
if (m.getName().equals(methodname)) { | if (m.getName().equals(methodname)) { | ||||
return m; | return m; | ||||
} | } | ||||
protected Field getField(JavaClass cl, String fieldname) { | protected Field getField(JavaClass cl, String fieldname) { | ||||
Field[] fields = cl.getFields(); | Field[] fields = cl.getFields(); | ||||
for (int i = 0; i < fields.length; i++) { | |||||
Field f = fields[i]; | |||||
for (Field f : fields) { | |||||
if (f.getName().equals(fieldname)) { | if (f.getName().equals(fieldname)) { | ||||
return f; | return f; | ||||
} | } | ||||
protected Attribute[] findAttribute(String name, JavaClass clazz) { | protected Attribute[] findAttribute(String name, JavaClass clazz) { | ||||
Attribute[] all = clazz.getAttributes(); | Attribute[] all = clazz.getAttributes(); | ||||
List<Attribute> chosenAttrsList = new ArrayList<Attribute>(); | List<Attribute> chosenAttrsList = new ArrayList<Attribute>(); | ||||
for (int i = 0; i < all.length; i++) { | |||||
for (Attribute attribute : all) { | |||||
if (verbose) | if (verbose) | ||||
System.err.println("Attribute: " + all[i].getName()); | |||||
if (all[i].getName().equals(name)) | |||||
chosenAttrsList.add(all[i]); | |||||
System.err.println("Attribute: " + attribute.getName()); | |||||
if (attribute.getName().equals(name)) | |||||
chosenAttrsList.add(attribute); | |||||
} | } | ||||
return chosenAttrsList.toArray(new Attribute[] {}); | return chosenAttrsList.toArray(new Attribute[] {}); | ||||
} | } | ||||
protected Attribute findAttribute(String name, Attribute[] all) { | protected Attribute findAttribute(String name, Attribute[] all) { | ||||
List<Attribute> chosenAttrsList = new ArrayList<Attribute>(); | List<Attribute> chosenAttrsList = new ArrayList<Attribute>(); | ||||
for (int i = 0; i < all.length; i++) { | |||||
for (Attribute attribute : all) { | |||||
if (verbose) | if (verbose) | ||||
System.err.println("Attribute: " + all[i].getName()); | |||||
if (all[i].getName().equals(name)) | |||||
chosenAttrsList.add(all[i]); | |||||
System.err.println("Attribute: " + attribute.getName()); | |||||
if (attribute.getName().equals(name)) | |||||
chosenAttrsList.add(attribute); | |||||
} | } | ||||
assertTrue("Should be one match: " + chosenAttrsList.size(), chosenAttrsList.size() == 1); | assertTrue("Should be one match: " + chosenAttrsList.size(), chosenAttrsList.size() == 1); | ||||
return chosenAttrsList.get(0); | return chosenAttrsList.get(0); |
String annotationName,String annotationElementName,String annotationElementValue) { | String annotationName,String annotationElementName,String annotationElementValue) { | ||||
Field[] fields = clazz.getFields(); | Field[] fields = clazz.getFields(); | ||||
for (int i = 0; i < fields.length; i++) { | |||||
Field f = fields[i]; | |||||
for (Field f : fields) { | |||||
AnnotationGen[] fieldAnnotations = f.getAnnotations(); | AnnotationGen[] fieldAnnotations = f.getAnnotations(); | ||||
if (f.getName().equals(fieldname)) { | if (f.getName().equals(fieldname)) { | ||||
checkAnnotation(fieldAnnotations[0],annotationName,annotationElementName,annotationElementValue); | |||||
checkAnnotation(fieldAnnotations[0], annotationName, annotationElementName, annotationElementValue); | |||||
} | } | ||||
} | } | ||||
} | } | ||||
// helper methods | // helper methods | ||||
public void checkValue(AnnotationGen a,String name,String tostring) { | public void checkValue(AnnotationGen a,String name,String tostring) { | ||||
for (Iterator<NameValuePair> i = a.getValues().iterator(); i.hasNext();) { | |||||
NameValuePair element = i.next(); | |||||
for (NameValuePair element : a.getValues()) { | |||||
if (element.getNameString().equals(name)) { | if (element.getNameString().equals(name)) { | ||||
if (!element.getValue().stringifyValue().equals(tostring)) { | if (!element.getValue().stringifyValue().equals(tostring)) { | ||||
fail("Expected element "+name+" to have value "+tostring+" but it had value "+element.getValue().stringifyValue()); | |||||
fail("Expected element " + name + " to have value " + tostring + " but it had value " + element.getValue().stringifyValue()); | |||||
} | } | ||||
return; | return; | ||||
} | } |
assertTrue("Expected one annotation but found " + annotations.length, annotations.length == 1); | assertTrue("Expected one annotation but found " + annotations.length, annotations.length == 1); | ||||
List<NameValuePair> l = annotations[0].getValues(); | List<NameValuePair> l = annotations[0].getValues(); | ||||
boolean found = false; | boolean found = false; | ||||
for (Iterator<NameValuePair> iter = l.iterator(); iter.hasNext();) { | |||||
NameValuePair element = iter.next(); | |||||
for (NameValuePair element : l) { | |||||
if (element.getNameString().equals("dval")) { | if (element.getNameString().equals("dval")) { | ||||
if (((SimpleElementValue) element.getValue()).stringifyValue().equals("33.4")) | if (((SimpleElementValue) element.getValue()).stringifyValue().equals("33.4")) | ||||
found = true; | found = true; |
public Signature getSignatureAttribute(JavaClass clazz,String name) { | public Signature getSignatureAttribute(JavaClass clazz,String name) { | ||||
Method m = getMethod(clazz,name); | Method m = getMethod(clazz,name); | ||||
Attribute[] as = m.getAttributes(); | Attribute[] as = m.getAttributes(); | ||||
for (int i = 0; i < as.length; i++) { | |||||
Attribute attribute = as[i]; | |||||
for (Attribute attribute : as) { | |||||
if (attribute.getName().equals("Signature")) { | if (attribute.getName().equals("Signature")) { | ||||
return (Signature)attribute; | |||||
return (Signature) attribute; | |||||
} | } | ||||
} | } | ||||
return null; | return null; | ||||
char[] chars = brackets.toCharArray(); | char[] chars = brackets.toCharArray(); | ||||
int count = 0; | int count = 0; | ||||
boolean open = false; | boolean open = false; | ||||
for(int i=0; i<chars.length; i++) { | |||||
switch(chars[i]) { | |||||
case '[': | |||||
if (open) throw new RuntimeException("Illegally nested brackets:" + brackets); | |||||
open = true; | |||||
break; | |||||
case ']': | |||||
if (!open) throw new RuntimeException("Illegally nested brackets:" + brackets); | |||||
open = false; | |||||
count++; | |||||
break; | |||||
default: | |||||
} | |||||
} | |||||
for (char aChar : chars) { | |||||
switch (aChar) { | |||||
case '[': | |||||
if (open) throw new RuntimeException("Illegally nested brackets:" + brackets); | |||||
open = true; | |||||
break; | |||||
case ']': | |||||
if (!open) throw new RuntimeException("Illegally nested brackets:" + brackets); | |||||
open = false; | |||||
count++; | |||||
break; | |||||
default: | |||||
} | |||||
} | |||||
if (open) throw new RuntimeException("Illegally nested brackets:" + brackets); | if (open) throw new RuntimeException("Illegally nested brackets:" + brackets); | ||||
StringBuffer buf = new StringBuffer("("); | StringBuffer buf = new StringBuffer("("); | ||||
if (methodArgs != null) { | if (methodArgs != null) { | ||||
for (int i=0; i < methodArgs.length; i++) { | |||||
String str = GenericSignatureParsingTest.getSignature(methodArgs[i]); | |||||
if (str.equals("V")) // void can't be a method argument | |||||
throw new ClassFormatException("Invalid type: " + methodArgs[i]); | |||||
buf.append(str); | |||||
} | |||||
for (String methodArg : methodArgs) { | |||||
String str = GenericSignatureParsingTest.getSignature(methodArg); | |||||
if (str.equals("V")) // void can't be a method argument | |||||
throw new ClassFormatException("Invalid type: " + methodArg); | |||||
buf.append(str); | |||||
} | |||||
} | } | ||||
buf.append(")" + GenericSignatureParsingTest.getSignature(returnType)); | buf.append(")" + GenericSignatureParsingTest.getSignature(returnType)); |
public Signature getSignatureAttribute(JavaClass clazz,String name) { | public Signature getSignatureAttribute(JavaClass clazz,String name) { | ||||
Method m = getMethod(clazz,name); | Method m = getMethod(clazz,name); | ||||
Attribute[] as = m.getAttributes(); | Attribute[] as = m.getAttributes(); | ||||
for (int i = 0; i < as.length; i++) { | |||||
Attribute attribute = as[i]; | |||||
for (Attribute attribute : as) { | |||||
if (attribute.getName().equals("Signature")) { | if (attribute.getName().equals("Signature")) { | ||||
return (Signature)attribute; | |||||
return (Signature) attribute; | |||||
} | } | ||||
} | } | ||||
return null; | return null; |
boolean tc1OK = false; | boolean tc1OK = false; | ||||
boolean tc2OK = false; | boolean tc2OK = false; | ||||
String errormessage = null; | String errormessage = null; | ||||
for (int i = 0; i < lvtable.length; i++) { | |||||
String sig = Utility.signatureToString(lvtable[i].getSignature()); | |||||
if (lvtable[i].getName().equals("tc1")) { | |||||
for (LocalVariable localVariable : lvtable) { | |||||
String sig = Utility.signatureToString(localVariable.getSignature()); | |||||
if (localVariable.getName().equals("tc1")) { | |||||
if (!sig.equals("TreasureChest<String>")) { | if (!sig.equals("TreasureChest<String>")) { | ||||
errormessage="Expected signature of 'TreasureChest<String>' for tc1 but got "+sig; | |||||
errormessage = "Expected signature of 'TreasureChest<String>' for tc1 but got " + sig; | |||||
} else { | } else { | ||||
tc1OK = true; | tc1OK = true; | ||||
} | } | ||||
} | } | ||||
if (lvtable[i].getName().equals("tc2")) { | |||||
if (localVariable.getName().equals("tc2")) { | |||||
if (!sig.equals("TreasureChest<Integer>")) { | if (!sig.equals("TreasureChest<Integer>")) { | ||||
errormessage="Expected signature of 'TreasureChest<Integer>' for tc2 but got "+sig; | |||||
errormessage = "Expected signature of 'TreasureChest<Integer>' for tc2 but got " + sig; | |||||
} else { | } else { | ||||
tc2OK = true; | tc2OK = true; | ||||
} | } |
String annotationName,String annotationElementName,String annotationElementValue) { | String annotationName,String annotationElementName,String annotationElementValue) { | ||||
Method[] methods = clazz.getMethods(); | Method[] methods = clazz.getMethods(); | ||||
for (int i = 0; i < methods.length; i++) { | |||||
Method m = methods[i]; | |||||
for (Method m : methods) { | |||||
AnnotationGen[] methodAnnotations = m.getAnnotations(); | AnnotationGen[] methodAnnotations = m.getAnnotations(); | ||||
if (m.getName().equals(methodname)) { | if (m.getName().equals(methodname)) { | ||||
checkAnnotation(methodAnnotations[0],annotationName,annotationElementName,annotationElementValue); | |||||
checkAnnotation(methodAnnotations[0], annotationName, annotationElementName, annotationElementValue); | |||||
} | } | ||||
} | } | ||||
} | } | ||||
// helper methods | // helper methods | ||||
public void checkValue(AnnotationGen a,String name,String tostring) { | public void checkValue(AnnotationGen a,String name,String tostring) { | ||||
for (Iterator<NameValuePair> i = a.getValues().iterator(); i.hasNext();) { | |||||
NameValuePair element = i.next(); | |||||
for (NameValuePair element : a.getValues()) { | |||||
if (element.getNameString().equals(name)) { | if (element.getNameString().equals(name)) { | ||||
if (!element.getValue().stringifyValue().equals(tostring)) { | if (!element.getValue().stringifyValue().equals(tostring)) { | ||||
fail("Expected element "+name+" to have value "+tostring+" but it had value "+element.getValue().stringifyValue()); | |||||
fail("Expected element " + name + " to have value " + tostring + " but it had value " + element.getValue().stringifyValue()); | |||||
} | } | ||||
return; | return; | ||||
} | } |
private Method findMethod(ClassGen c,String mname) { | private Method findMethod(ClassGen c,String mname) { | ||||
Method[] ms = c.getMethods(); | Method[] ms = c.getMethods(); | ||||
for (int i = 0; i < ms.length; i++) { | |||||
if (ms[i].getName().equals(mname)) return ms[i]; | |||||
for (Method m : ms) { | |||||
if (m.getName().equals(mname)) return m; | |||||
} | } | ||||
return null; | return null; | ||||
} | } |
} | } | ||||
private void checkValue(AnnotationGen a,String name,String tostring) { | private void checkValue(AnnotationGen a,String name,String tostring) { | ||||
for (Iterator<NameValuePair> i = a.getValues().iterator(); i.hasNext();) { | |||||
NameValuePair element = i.next(); | |||||
for (NameValuePair element : a.getValues()) { | |||||
if (element.getNameString().equals(name)) { | if (element.getNameString().equals(name)) { | ||||
if (!element.getValue().stringifyValue().equals(tostring)) { | if (!element.getValue().stringifyValue().equals(tostring)) { | ||||
fail("Expected element "+name+" to have value "+tostring+" but it had value "+element.getValue().stringifyValue()); | |||||
fail("Expected element " + name + " to have value " + tostring + " but it had value " + element.getValue().stringifyValue()); | |||||
} | } | ||||
return; | return; | ||||
} | } | ||||
public static List<String> getListOfAnnotationNames(AnnotationGen a) { | public static List<String> getListOfAnnotationNames(AnnotationGen a) { | ||||
List<NameValuePair> l = a.getValues(); | List<NameValuePair> l = a.getValues(); | ||||
List<String> names = new ArrayList<String>(); | List<String> names = new ArrayList<String>(); | ||||
for (Iterator<NameValuePair> i = l.iterator(); i.hasNext();) { | |||||
NameValuePair element = i.next(); | |||||
for (NameValuePair element : l) { | |||||
names.add(element.getNameString()); | names.add(element.getNameString()); | ||||
} | } | ||||
return names; | return names; |
Attribute[] rvaAttr = findAttribute("RuntimeVisibleParameterAnnotations",clazz); | Attribute[] rvaAttr = findAttribute("RuntimeVisibleParameterAnnotations",clazz); | ||||
Method[] methods = clazz.getMethods(); | Method[] methods = clazz.getMethods(); | ||||
for (int i = 0; i < methods.length; i++) { | |||||
Method m = methods[i]; | |||||
for (Method m : methods) { | |||||
if (m.getName().equals("foo")) { | if (m.getName().equals("foo")) { | ||||
RuntimeVisParamAnnos paramAnns = | |||||
(RuntimeVisParamAnnos) findAttribute("RuntimeVisibleParameterAnnotations",m.getAttributes()); | |||||
assertTrue("foo takes two parameters, not "+paramAnns.getParameterAnnotations().size(), | |||||
paramAnns.getParameterAnnotations().size()==2); | |||||
RuntimeVisParamAnnos paramAnns = | |||||
(RuntimeVisParamAnnos) findAttribute("RuntimeVisibleParameterAnnotations", m.getAttributes()); | |||||
assertTrue("foo takes two parameters, not " + paramAnns.getParameterAnnotations().size(), | |||||
paramAnns.getParameterAnnotations().size() == 2); | |||||
AnnotationGen[] firstParamAnnotations = paramAnns.getAnnotationsOnParameter(0); | AnnotationGen[] firstParamAnnotations = paramAnns.getAnnotationsOnParameter(0); | ||||
checkAnnotation(firstParamAnnotations[0],"SimpleAnnotation","id","2"); | |||||
checkAnnotation(firstParamAnnotations[0], "SimpleAnnotation", "id", "2"); | |||||
AnnotationGen[] secondParamAnnotations = paramAnns.getAnnotationsOnParameter(1); | AnnotationGen[] secondParamAnnotations = paramAnns.getAnnotationsOnParameter(1); | ||||
checkAnnotation(secondParamAnnotations[0],"SimpleAnnotation","id","3"); | |||||
checkAnnotation(secondParamAnnotations[1],"AnnotationEnumElement","enumval","LSimpleEnum;Red"); | |||||
checkAnnotation(secondParamAnnotations[0], "SimpleAnnotation", "id", "3"); | |||||
checkAnnotation(secondParamAnnotations[1], "AnnotationEnumElement", "enumval", "LSimpleEnum;Red"); | |||||
} | } | ||||
if (m.getName().equals("main")) { | if (m.getName().equals("main")) { | ||||
RuntimeVisParamAnnos paramAnns = | |||||
(RuntimeVisParamAnnos) findAttribute("RuntimeVisibleParameterAnnotations",m.getAttributes()); | |||||
assertTrue("main takes one parameter, not "+paramAnns.getParameterAnnotations().size(), | |||||
paramAnns.getParameterAnnotations().size()==1); | |||||
RuntimeVisParamAnnos paramAnns = | |||||
(RuntimeVisParamAnnos) findAttribute("RuntimeVisibleParameterAnnotations", m.getAttributes()); | |||||
assertTrue("main takes one parameter, not " + paramAnns.getParameterAnnotations().size(), | |||||
paramAnns.getParameterAnnotations().size() == 1); | |||||
AnnotationGen[] firstParamAnnotations = paramAnns.getAnnotationsOnParameter(0); | AnnotationGen[] firstParamAnnotations = paramAnns.getAnnotationsOnParameter(0); | ||||
checkAnnotation(firstParamAnnotations[0],"SimpleAnnotation","id","1"); | |||||
checkAnnotation(firstParamAnnotations[0], "SimpleAnnotation", "id", "1"); | |||||
} | } | ||||
} | } | ||||
} | } | ||||
public void checkFooMethod(JavaClass clazz) { | public void checkFooMethod(JavaClass clazz) { | ||||
Method[] methods = clazz.getMethods(); | Method[] methods = clazz.getMethods(); | ||||
for (int i = 0; i < methods.length; i++) { | |||||
Method m = methods[i]; | |||||
for (Method m : methods) { | |||||
if (m.getName().equals("foo")) { | if (m.getName().equals("foo")) { | ||||
AnnotationGen[] firstParamAnnotations = m.getAnnotationsOnParameter(0); | AnnotationGen[] firstParamAnnotations = m.getAnnotationsOnParameter(0); | ||||
checkAnnotation(firstParamAnnotations[0],"SimpleAnnotation","id","2"); | |||||
checkAnnotation(firstParamAnnotations[0], "SimpleAnnotation", "id", "2"); | |||||
AnnotationGen[] secondParamAnnotations = m.getAnnotationsOnParameter(1); | AnnotationGen[] secondParamAnnotations = m.getAnnotationsOnParameter(1); | ||||
checkAnnotation(secondParamAnnotations[0],"SimpleAnnotation","id","3"); | |||||
checkAnnotation(secondParamAnnotations[1],"AnnotationEnumElement","enumval","LSimpleEnum;Red"); | |||||
checkAnnotation(secondParamAnnotations[0], "SimpleAnnotation", "id", "3"); | |||||
checkAnnotation(secondParamAnnotations[1], "AnnotationEnumElement", "enumval", "LSimpleEnum;Red"); | |||||
} | } | ||||
} | } | ||||
} | } | ||||
// helper methods | // helper methods | ||||
public void checkValue(AnnotationGen a,String name,String tostring) { | public void checkValue(AnnotationGen a,String name,String tostring) { | ||||
for (Iterator<NameValuePair> i = a.getValues().iterator(); i.hasNext();) { | |||||
NameValuePair element = i.next(); | |||||
for (NameValuePair element : a.getValues()) { | |||||
if (element.getNameString().equals(name)) { | if (element.getNameString().equals(name)) { | ||||
if (!element.getValue().stringifyValue().equals(tostring)) { | if (!element.getValue().stringifyValue().equals(tostring)) { | ||||
fail("Expected element "+name+" to have value "+tostring+" but it had value "+element.getValue().stringifyValue()); | |||||
fail("Expected element " + name + " to have value " + tostring + " but it had value " + element.getValue().stringifyValue()); | |||||
} | } | ||||
return; | return; | ||||
} | } |
public void checkMarkedVarargs(JavaClass clazz,String methodname,boolean shouldBeMarked) { | public void checkMarkedVarargs(JavaClass clazz,String methodname,boolean shouldBeMarked) { | ||||
Method[] methods = clazz.getMethods(); | Method[] methods = clazz.getMethods(); | ||||
for (int i = 0; i < methods.length; i++) { | |||||
Method m = methods[i]; | |||||
for (Method m : methods) { | |||||
if (m.getName().equals(methodname)) { | if (m.getName().equals(methodname)) { | ||||
assertTrue("Method '"+methodname+"' should answer varargs="+shouldBeMarked, | |||||
m.isVarargs()==shouldBeMarked); | |||||
assertTrue("Method '" + methodname + "' should answer varargs=" + shouldBeMarked, | |||||
m.isVarargs() == shouldBeMarked); | |||||
} | } | ||||
} | } | ||||
} | } | ||||
// helper methods | // helper methods | ||||
public void checkValue(AnnotationGen a,String name,String tostring) { | public void checkValue(AnnotationGen a,String name,String tostring) { | ||||
for (Iterator<NameValuePair> i = a.getValues().iterator(); i.hasNext();) { | |||||
NameValuePair element = i.next(); | |||||
for (NameValuePair element : a.getValues()) { | |||||
if (element.getNameString().equals(name)) { | if (element.getNameString().equals(name)) { | ||||
if (!element.getValue().stringifyValue().equals(tostring)) { | if (!element.getValue().stringifyValue().equals(tostring)) { | ||||
fail("Expected element "+name+" to have value "+tostring+" but it had value "+element.getValue().stringifyValue()); | |||||
fail("Expected element " + name + " to have value " + tostring + " but it had value " + element.getValue().stringifyValue()); | |||||
} | } | ||||
return; | return; | ||||
} | } |
return true; | return true; | ||||
} | } | ||||
boolean result = true; | boolean result = true; | ||||
for (int i = 0; i < sources.length; i++) { | |||||
if (!sink.handleMessage(sources[i])) { | |||||
for (IMessage source : sources) { | |||||
if (!sink.handleMessage(source)) { | |||||
if (fastFail) { | if (fastFail) { | ||||
return false; | return false; | ||||
} | } |
public void testKind_isSameOrLessThan() { | public void testKind_isSameOrLessThan() { | ||||
IMessage.Kind last; | IMessage.Kind last; | ||||
IMessage.Kind next = null; | IMessage.Kind next = null; | ||||
for (Iterator<IMessage.Kind> iter = IMessage.KINDS.iterator(); iter.hasNext();) { | |||||
last = next; | |||||
next = iter.next(); | |||||
if (null == last) { | |||||
continue; | |||||
} | |||||
String label = "last: " + last + " next: " + next; | |||||
assertTrue(label, !next.isSameOrLessThan(null)); | |||||
assertTrue(label, !next.isSameOrLessThan(last)); | |||||
assertTrue(label, last.isSameOrLessThan(next)); | |||||
assertTrue(label, next.isSameOrLessThan(next)); | |||||
} | |||||
for (IMessage.Kind kind : IMessage.KINDS) { | |||||
last = next; | |||||
next = kind; | |||||
if (null == last) { | |||||
continue; | |||||
} | |||||
String label = "last: " + last + " next: " + next; | |||||
assertTrue(label, !next.isSameOrLessThan(null)); | |||||
assertTrue(label, !next.isSameOrLessThan(last)); | |||||
assertTrue(label, last.isSameOrLessThan(next)); | |||||
assertTrue(label, next.isSameOrLessThan(next)); | |||||
} | |||||
} | } | ||||
public void testMessageHandler() { | public void testMessageHandler() { |
public boolean isTextFile(File file) { | public boolean isTextFile(File file) { | ||||
String name = file.getName(); | String name = file.getName(); | ||||
for (int i = 0; i < TEXT_EXTENSIONS.length; i++) { | |||||
if (name.endsWith(TEXT_EXTENSIONS[i])) { | |||||
for (String textExtension : TEXT_EXTENSIONS) { | |||||
if (name.endsWith(textExtension)) { | |||||
return true; | return true; | ||||
} | } | ||||
} | } | ||||
paths = unixPaths; | paths = unixPaths; | ||||
} | } | ||||
for (int suffixIndex = 0; suffixIndex < suffixes.length; suffixIndex++) { | |||||
String suffix = suffixes[suffixIndex]; | |||||
for (int prefixIndex = 0; prefixIndex < paths.length; prefixIndex++) { | |||||
String prefix = paths[prefixIndex]; | |||||
for (String suffix : suffixes) { | |||||
for (String path : paths) { | |||||
String prefix = path; | |||||
prefix = applyProperties(prefix); | prefix = applyProperties(prefix); | ||||
File test = new File(prefix + suffix); | File test = new File(prefix + suffix); | ||||
if (isLegalJavaHome(test)) { | if (isLegalJavaHome(test)) { |
StringBuffer buf = new StringBuffer(); | StringBuffer buf = new StringBuffer(); | ||||
buf.append(contentsBytes); | buf.append(contentsBytes); | ||||
buf.append(NEWLINE); | buf.append(NEWLINE); | ||||
for (Iterator<String> i = contentsNames.iterator(); i.hasNext(); ) { | |||||
String name = i.next(); | |||||
buf.append(name); | |||||
buf.append(NEWLINE); | |||||
} | |||||
for (String name : contentsNames) { | |||||
buf.append(name); | |||||
buf.append(NEWLINE); | |||||
} | |||||
zipFile(new StringBufferInputStream(buf.toString()), zOut, CONTENTS_FILE, System.currentTimeMillis()); | zipFile(new StringBufferInputStream(buf.toString()), zOut, CONTENTS_FILE, System.currentTimeMillis()); | ||||
} | } | ||||
} | } | ||||
protected void writeDirs(ZipOutputStream zOut, String[] dirs) throws IOException { | protected void writeDirs(ZipOutputStream zOut, String[] dirs) throws IOException { | ||||
for (int i = 0; i < dirs.length; i++) { | |||||
File f = new File(baseDir,dirs[i]); | |||||
String name = dirs[i].replace(File.separatorChar,'/')+"/"; | |||||
zipDir(f, zOut, name); | |||||
} | |||||
for (String dir : dirs) { | |||||
File f = new File(baseDir, dir); | |||||
String name = dir.replace(File.separatorChar, '/') + "/"; | |||||
zipDir(f, zOut, name); | |||||
} | |||||
} | } | ||||
protected void writeFiles(ZipOutputStream zOut, String[] files) throws IOException { | protected void writeFiles(ZipOutputStream zOut, String[] files) throws IOException { | ||||
for (int i = 0; i < files.length; i++) { | |||||
File f = new File(baseDir,files[i]); | |||||
String name = files[i].replace(File.separatorChar,'/'); | |||||
zipFile(f, zOut, name); | |||||
} | |||||
for (String file : files) { | |||||
File f = new File(baseDir, file); | |||||
String name = file.replace(File.separatorChar, '/'); | |||||
zipFile(f, zOut, name); | |||||
} | |||||
} | } | ||||
} | } |
Result[] reqs = result.getRequired(); | Result[] reqs = result.getRequired(); | ||||
StringBuffer depends = new StringBuffer(); | StringBuffer depends = new StringBuffer(); | ||||
boolean first = true; | boolean first = true; | ||||
for (int i = 0; i < reqs.length; i++) { | |||||
Result reqResult = reqs[i]; | |||||
for (Result reqResult : reqs) { | |||||
if (!first) { | if (!first) { | ||||
depends.append(","); | depends.append(","); | ||||
} else { | } else { | ||||
targets.put(resultTargetName, target); | targets.put(resultTargetName, target); | ||||
// then recursively add any required results | // then recursively add any required results | ||||
for (int i = 0; i < reqs.length; i++) { | |||||
Result reqResult = reqs[i]; | |||||
for (Result reqResult : reqs) { | |||||
makeTargetsForResult(reqResult, targets); | makeTargetsForResult(reqResult, targets); | ||||
} | } | ||||
} | } | ||||
public boolean setupClasspath(Result result, Path classpath) { // XXX fix test access | public boolean setupClasspath(Result result, Path classpath) { // XXX fix test access | ||||
boolean hasLibraries = false; | boolean hasLibraries = false; | ||||
// required libraries | // required libraries | ||||
for (Iterator<File> iter = result.getLibJars().iterator(); iter.hasNext();) { | |||||
File file = iter.next(); | |||||
for (File file : result.getLibJars()) { | |||||
classpath.createPathElement().setLocation(file); | classpath.createPathElement().setLocation(file); | ||||
if (!hasLibraries) { | if (!hasLibraries) { | ||||
hasLibraries = true; | hasLibraries = true; | ||||
// Westodo Kind kind = result.getKind(); | // Westodo Kind kind = result.getKind(); | ||||
Result[] reqs = result.getRequired(); | Result[] reqs = result.getRequired(); | ||||
// required modules and their exported libraries | // required modules and their exported libraries | ||||
for (int i = 0; i < reqs.length; i++) { | |||||
Result requiredResult = reqs[i]; | |||||
for (Result requiredResult : reqs) { | |||||
classpath.createPathElement().setLocation(requiredResult.getOutputFile()); | classpath.createPathElement().setLocation(requiredResult.getOutputFile()); | ||||
if (!hasLibraries) { | if (!hasLibraries) { | ||||
hasLibraries = true; | hasLibraries = true; | ||||
} | } | ||||
// also put on classpath libraries exported from required module | // also put on classpath libraries exported from required module | ||||
// XXX exported modules not supported | // XXX exported modules not supported | ||||
for (Iterator<File> iterator = requiredResult.getExportedLibJars().iterator(); iterator.hasNext();) { | |||||
classpath.createPathElement().setLocation(iterator.next()); | |||||
for (File file : requiredResult.getExportedLibJars()) { | |||||
classpath.createPathElement().setLocation(file); | |||||
} | } | ||||
} | } | ||||
return hasLibraries; | return hasLibraries; | ||||
return new Result[0]; | return new Result[0]; | ||||
} | } | ||||
ArrayList<String> toReturn = new ArrayList<String>(); | ArrayList<String> toReturn = new ArrayList<String>(); | ||||
for (Iterator<Target> iter = result.iterator(); iter.hasNext();) { | |||||
Target target = iter.next(); | |||||
for (Target target : result) { | |||||
String name = target.getName(); | String name = target.getName(); | ||||
if (null == name) { | if (null == name) { | ||||
throw new Error("null name?"); | throw new Error("null name?"); |
return isOneOf(prop, trues) || isOneOf(prop, complement(falses)); | return isOneOf(prop, trues) || isOneOf(prop, complement(falses)); | ||||
} | } | ||||
private boolean isOneOf(String prop, String[] strings) { | private boolean isOneOf(String prop, String[] strings) { | ||||
for (int i = 0; i < strings.length; i++) { | |||||
if (strings[i].equals(prop)) { | |||||
return true; | |||||
} | |||||
} | |||||
for (String string : strings) { | |||||
if (string.equals(prop)) { | |||||
return true; | |||||
} | |||||
} | |||||
return false; | return false; | ||||
} | } | ||||
private String[] complement(String[] strings) { | private String[] complement(String[] strings) { |
log("stripping " + files.length + " files"); | log("stripping " + files.length + " files"); | ||||
int stripped = 0; | int stripped = 0; | ||||
for (int i = 0, len = files.length; i < len; i++) { | |||||
if (processFile(files[i])) { | |||||
stripped++; | |||||
} else { | |||||
log(files[i] + " not stripped"); | |||||
} | |||||
} | |||||
for (String file : files) { | |||||
if (processFile(file)) { | |||||
stripped++; | |||||
} else { | |||||
log(file + " not stripped"); | |||||
} | |||||
} | |||||
log(stripped + " files successfully stripped"); | log(stripped + " files successfully stripped"); | ||||
} | } | ||||
} finally { | } finally { | ||||
if (0 < errors.size()) { | if (0 < errors.size()) { | ||||
String label = "error building " + buildSpec + ": "; | String label = "error building " + buildSpec + ": "; | ||||
for (Iterator<String> iter = errors.iterator(); iter.hasNext();) { | |||||
String m = label + iter.next(); | |||||
handler.error(m); | |||||
} | |||||
for (String error : errors) { | |||||
String m = label + error; | |||||
handler.error(m); | |||||
} | |||||
} | } | ||||
} | } | ||||
} | } | ||||
*/ | */ | ||||
public boolean cleanup() { | public boolean cleanup() { | ||||
boolean noErr = true; | boolean noErr = true; | ||||
for (ListIterator iter = tempFiles.listIterator(); iter.hasNext();) { | |||||
File file = (File) iter.next(); | |||||
if (!Util.deleteContents(file) || !file.delete()) { | |||||
if (noErr) { | |||||
noErr = false; | |||||
} | |||||
handler.log("unable to clean up " + file); | |||||
} | |||||
} | |||||
for (Object tempFile : tempFiles) { | |||||
File file = (File) tempFile; | |||||
if (!Util.deleteContents(file) || !file.delete()) { | |||||
if (noErr) { | |||||
noErr = false; | |||||
} | |||||
handler.log("unable to clean up " + file); | |||||
} | |||||
} | |||||
return noErr; | return noErr; | ||||
} | } | ||||
if (isLogging()) { | if (isLogging()) { | ||||
handler.log("modules to build: " + Arrays.asList(buildList)); | handler.log("modules to build: " + Arrays.asList(buildList)); | ||||
} | } | ||||
for (int i = 0; i < buildList.length; i++) { | |||||
Result required = buildList[i]; | |||||
if (!buildingEnabled) { | |||||
return false; | |||||
} | |||||
String requiredName = required.getName(); | |||||
if (!doneList.contains(requiredName)) { | |||||
doneList.add(requiredName); | |||||
if (!buildOnly(required, errors)) { | |||||
return false; | |||||
} | |||||
} | |||||
} | |||||
for (Result required : buildList) { | |||||
if (!buildingEnabled) { | |||||
return false; | |||||
} | |||||
String requiredName = required.getName(); | |||||
if (!doneList.contains(requiredName)) { | |||||
doneList.add(requiredName); | |||||
if (!buildOnly(required, errors)) { | |||||
return false; | |||||
} | |||||
} | |||||
} | |||||
} | } | ||||
return true; | return true; | ||||
} | } | ||||
handler); | handler); | ||||
ProductModule[] productModules = discoverModules(buildSpec.productDir, | ProductModule[] productModules = discoverModules(buildSpec.productDir, | ||||
modules); | modules); | ||||
for (int i = 0; i < productModules.length; i++) { | |||||
if (buildSpec.verbose) { | |||||
handler.log("building product module " + productModules[i]); | |||||
} | |||||
if (!buildProductModule(productModules[i])) { | |||||
return false; | |||||
} | |||||
} | |||||
for (ProductModule module : productModules) { | |||||
if (buildSpec.verbose) { | |||||
handler.log("building product module " + module); | |||||
} | |||||
if (!buildProductModule(module)) { | |||||
return false; | |||||
} | |||||
} | |||||
if (buildSpec.verbose) { | if (buildSpec.verbose) { | ||||
handler.log("assembling product module for " + buildSpec); | handler.log("assembling product module for " + buildSpec); | ||||
} | } | ||||
String excludes = null; | String excludes = null; | ||||
{ | { | ||||
StringBuffer buf = new StringBuffer(); | StringBuffer buf = new StringBuffer(); | ||||
for (int i = 0; i < productModules.length; i++) { | |||||
if (0 < buf.length()) { | |||||
buf.append(","); | |||||
} | |||||
buf.append(productModules[i].relativePath); | |||||
} | |||||
for (ProductModule productModule : productModules) { | |||||
if (0 < buf.length()) { | |||||
buf.append(","); | |||||
} | |||||
buf.append(productModule.relativePath); | |||||
} | |||||
if (0 < buf.length()) { | if (0 < buf.length()) { | ||||
excludes = buf.toString(); | excludes = buf.toString(); | ||||
} | } | ||||
} | } | ||||
// copy binaries associated with module flag files | // copy binaries associated with module flag files | ||||
for (int i = 0; i < productModules.length; i++) { | |||||
final ProductModule product = productModules[i]; | |||||
final Kind kind = Result.kind(Result.NORMAL, product.assembleAll); | |||||
Result result = product.module.getResult(kind); | |||||
String targPath = Util.path(targDirPath, product.relativePath); | |||||
File jarFile = result.getOutputFile(); | |||||
copyFile(jarFile, new File(targPath), FILTER_OFF); | |||||
} | |||||
for (final ProductModule product : productModules) { | |||||
final Kind kind = Result.kind(Result.NORMAL, product.assembleAll); | |||||
Result result = product.module.getResult(kind); | |||||
String targPath = Util.path(targDirPath, product.relativePath); | |||||
File jarFile = result.getOutputFile(); | |||||
copyFile(jarFile, new File(targPath), FILTER_OFF); | |||||
} | |||||
handler.log("created product in " + targDir); | handler.log("created product in " + targDir); | ||||
// ---- create installer | // ---- create installer | ||||
Result result = module.module.getResult(productKind); | Result result = module.module.getResult(productKind); | ||||
return buildAll(result, errors); | return buildAll(result, errors); | ||||
} finally { | } finally { | ||||
for (Iterator<String> iter = errors.iterator(); iter.hasNext();) { | |||||
handler.error("error building " + module + ": " + iter.next()); | |||||
} | |||||
for (String error : errors) { | |||||
handler.error("error building " + module + ": " + error); | |||||
} | |||||
} | } | ||||
} | } | ||||
File library = liter.next(); | File library = liter.next(); | ||||
final String fname = library.getName(); | final String fname = library.getName(); | ||||
if (null != fname) { | if (null != fname) { | ||||
for (Iterator<String> iter = SKIP_LIBRARIES.iterator(); iter.hasNext();) { | |||||
String name = iter.next(); | |||||
if (fname.equals(name)) { | |||||
liter.remove(); | |||||
break; | |||||
} | |||||
} | |||||
for (String name : SKIP_LIBRARIES) { | |||||
if (fname.equals(name)) { | |||||
liter.remove(); | |||||
break; | |||||
} | |||||
} | |||||
} | } | ||||
} | } | ||||
} | } |
return; | return; | ||||
} | } | ||||
File[] files = srcDir.listFiles(); | File[] files = srcDir.listFiles(); | ||||
for (int i = 0; i < files.length; i++) { | |||||
if (files[i].isDirectory()) { | |||||
sourceFiles(files[i], result); | |||||
} else if (isSourceFile(files[i])) { | |||||
result.add(files[i]); | |||||
} | |||||
} | |||||
for (File file : files) { | |||||
if (file.isDirectory()) { | |||||
sourceFiles(file, result); | |||||
} else if (isSourceFile(file)) { | |||||
result.add(file); | |||||
} | |||||
} | |||||
} | } | ||||
private static void addIfNew(List<File> source, List<File> sink) { | private static void addIfNew(List<File> source, List<File> sink) { | ||||
addIfNew(result.getLibJars(), known); | addIfNew(result.getLibJars(), known); | ||||
addIfNew(result.getExportedLibJars(), known); | addIfNew(result.getExportedLibJars(), known); | ||||
Result[] reqs = result.getRequired(); | Result[] reqs = result.getRequired(); | ||||
for (int i = 0; i < reqs.length; i++) { | |||||
Result requiredResult = reqs[i]; | |||||
File requiredJar = requiredResult.getOutputFile(); | |||||
if (!known.contains(requiredJar)) { | |||||
known.add(requiredJar); | |||||
doFindJarRequirements(requiredResult, known); | |||||
} | |||||
} | |||||
for (Result requiredResult : reqs) { | |||||
File requiredJar = requiredResult.getOutputFile(); | |||||
if (!known.contains(requiredJar)) { | |||||
known.add(requiredJar); | |||||
doFindJarRequirements(requiredResult, known); | |||||
} | |||||
} | |||||
} | } | ||||
/** @return true if this is a source file */ | /** @return true if this is a source file */ | ||||
} | } | ||||
final long time = outputFile.lastModified(); | final long time = outputFile.lastModified(); | ||||
File file; | File file; | ||||
for (Iterator<File> iter = result.getSrcDirs().iterator(); iter.hasNext();) { | |||||
File srcDir = iter.next(); | |||||
for (Iterator<File> srcFiles = sourceFiles(srcDir); srcFiles.hasNext();) { | |||||
file = srcFiles.next(); | |||||
if (outOfDate(time, file)) { | |||||
return true; | |||||
} | |||||
} | |||||
} | |||||
for (File srcDir : result.getSrcDirs()) { | |||||
for (Iterator<File> srcFiles = sourceFiles(srcDir); srcFiles.hasNext(); ) { | |||||
file = srcFiles.next(); | |||||
if (outOfDate(time, file)) { | |||||
return true; | |||||
} | |||||
} | |||||
} | |||||
// required modules | // required modules | ||||
Result[] reqs = result.getRequired(); | Result[] reqs = result.getRequired(); | ||||
for (int i = 0; i < reqs.length; i++) { | |||||
Result requiredResult = reqs[i]; | |||||
file = requiredResult.getOutputFile(); | |||||
if (outOfDate(time, file)) { | |||||
return true; | |||||
} | |||||
} | |||||
for (Result requiredResult : reqs) { | |||||
file = requiredResult.getOutputFile(); | |||||
if (outOfDate(time, file)) { | |||||
return true; | |||||
} | |||||
} | |||||
// libraries | // libraries | ||||
for (Iterator<File> iter = result.getLibJars().iterator(); iter.hasNext();) { | |||||
file = iter.next(); | |||||
if (outOfDate(time, file)) { | |||||
return true; | |||||
} | |||||
} | |||||
for (File value : result.getLibJars()) { | |||||
file = value; | |||||
if (outOfDate(time, file)) { | |||||
return true; | |||||
} | |||||
} | |||||
return false; | return false; | ||||
} | } | ||||
Util.closeSilently(fin); | Util.closeSilently(fin); | ||||
} | } | ||||
RequiredBundle[] bundles = bundle.getRequiredBundles(); | RequiredBundle[] bundles = bundle.getRequiredBundles(); | ||||
for (int i = 0; i < bundles.length; i++) { | |||||
RequiredBundle required = bundles[i]; | |||||
update("src", "/" + required.name, required.text, false); | |||||
} | |||||
for (RequiredBundle required : bundles) { | |||||
update("src", "/" + required.name, required.text, false); | |||||
} | |||||
String[] libs = bundle.getClasspath(); | String[] libs = bundle.getClasspath(); | ||||
for (int i = 0; i < libs.length; i++) { | |||||
update("lib", libs[i], libs[i], false); | |||||
} | |||||
for (String lib : libs) { | |||||
update("lib", lib, lib, false); | |||||
} | |||||
return true; | return true; | ||||
} | } | ||||
private void warnVariable(String path, String toString) { | private void warnVariable(String path, String toString) { | ||||
String[] known = { "JRE_LIB", "ASPECTJRT_LIB", "JRE15_LIB" }; | String[] known = { "JRE_LIB", "ASPECTJRT_LIB", "JRE15_LIB" }; | ||||
for (int i = 0; i < known.length; i++) { | |||||
if (known[i].equals(path)) { | |||||
return; | |||||
} | |||||
} | |||||
for (String s : known) { | |||||
if (s.equals(path)) { | |||||
return; | |||||
} | |||||
} | |||||
messager.log("Module cannot handle var yet: " + toString); | messager.log("Module cannot handle var yet: " + toString); | ||||
} | } | ||||
public void acceptLine(String line) { | public void acceptLine(String line) { | ||||
String[] tokens = tokenize(line); | String[] tokens = tokenize(line); | ||||
for (int i = 0; i < tokens.length; i++) { | |||||
next(tokens[i]); | |||||
} | |||||
for (String token : tokens) { | |||||
next(token); | |||||
} | |||||
} | } | ||||
private Properties attributesToProperties() { | private Properties attributesToProperties() { |
return; | return; | ||||
} | } | ||||
Samples result = new Samples(); | Samples result = new Samples(); | ||||
for (int i = 0; i < args.length; i++) { | |||||
result = gather(new File(args[i]), result); | |||||
} | |||||
for (String arg : args) { | |||||
result = gather(new File(arg), result); | |||||
} | |||||
StringBuffer sb = HTMLSamplesRenderer.ME.render(result, null); | StringBuffer sb = HTMLSamplesRenderer.ME.render(result, null); | ||||
} | } | ||||
} else if (source.isDirectory() && source.canRead()) { | } else if (source.isDirectory() && source.canRead()) { | ||||
File[] files = source.listFiles(); | File[] files = source.listFiles(); | ||||
for (int i = 0; i < files.length; i++) { | |||||
doGather(files[i], sink); | |||||
} | |||||
for (File file : files) { | |||||
doGather(file, sink); | |||||
} | |||||
} | } | ||||
} | } | ||||
} | } | ||||
String path = file.getName().toLowerCase(); | String path = file.getName().toLowerCase(); | ||||
String[] suffixes = Sample.Kind.SOURCE_SUFFIXES; | String[] suffixes = Sample.Kind.SOURCE_SUFFIXES; | ||||
for (int i = 0; i < suffixes.length; i++) { | |||||
if (path.endsWith(suffixes[i])) { | |||||
return true; | |||||
} | |||||
} | |||||
for (String suffix : suffixes) { | |||||
if (path.endsWith(suffix)) { | |||||
return true; | |||||
} | |||||
} | |||||
return false; | return false; | ||||
} | } | ||||
public static final String COPYRIGHT = | public static final String COPYRIGHT = | ||||
"<p><small>Copyright 2003 Contributors. All Rights Reserved. " | "<p><small>Copyright 2003 Contributors. All Rights Reserved. " | ||||
+ "This sample code is made available under the Common Public " + "License version 1.0 available at " | |||||
+ "This sample code is made available under the Common Public " | |||||
+ "License version 1.0 available at " | |||||
+ "<a href=\"http://www.eclipse.org/legal/epl-v10.html\">" | + "<a href=\"http://www.eclipse.org/legal/epl-v10.html\">" | ||||
+ "http://www.eclipse.org/legal/epl-v10.html</a>." | + "http://www.eclipse.org/legal/epl-v10.html</a>." | ||||
+ "Contributors are listed in this document as authors. " | + "Contributors are listed in this document as authors. " | ||||
startList(samples, sink); | startList(samples, sink); | ||||
List<Sample> list = samples.getSortedSamples(); | List<Sample> list = samples.getSortedSamples(); | ||||
String anchorName = null; | String anchorName = null; | ||||
for (ListIterator<Sample> iter = list.listIterator(); | |||||
iter.hasNext();) { | |||||
Sample sample = iter.next(); | |||||
String newAnchorName = sample.anchorName; | |||||
if ((null == anchorName) | |||||
|| (!anchorName.equals(newAnchorName))) { | |||||
endAnchorName(anchorName, sink); | |||||
startAnchorName(newAnchorName, sample.anchorTitle, sink); | |||||
anchorName = newAnchorName; | |||||
} | |||||
render(sample, sink); | |||||
} | |||||
for (Sample sample : list) { | |||||
String newAnchorName = sample.anchorName; | |||||
if ((null == anchorName) | |||||
|| (!anchorName.equals(newAnchorName))) { | |||||
endAnchorName(anchorName, sink); | |||||
startAnchorName(newAnchorName, sample.anchorTitle, sink); | |||||
anchorName = newAnchorName; | |||||
} | |||||
render(sample, sink); | |||||
} | |||||
endAnchorName(anchorName, sink); | endAnchorName(anchorName, sink); | ||||
endList(samples, sink); | endList(samples, sink); | ||||
return sink; | return sink; | ||||
sampleSection.append(EOL); | sampleSection.append(EOL); | ||||
if (doFlags) { | if (doFlags) { | ||||
boolean flagHeaderDone = false; | boolean flagHeaderDone = false; | ||||
for (Iterator iter = sample.flags.iterator(); iter.hasNext();) { | |||||
String flag = (String) iter.next(); | |||||
if (!flagHeaderDone) { | |||||
sampleSection.append("<p>Comments flagged:<ul>"); | |||||
sampleSection.append(EOL); | |||||
flagHeaderDone = true; | |||||
} | |||||
sampleSection.append("<li>"); | |||||
sampleSection.append(flag); | |||||
sampleSection.append("</li>"); | |||||
} | |||||
for (String flag : sample.flags) { | |||||
if (!flagHeaderDone) { | |||||
sampleSection.append("<p>Comments flagged:<ul>"); | |||||
sampleSection.append(EOL); | |||||
flagHeaderDone = true; | |||||
} | |||||
sampleSection.append("<li>"); | |||||
sampleSection.append(flag); | |||||
sampleSection.append("</li>"); | |||||
} | |||||
if (flagHeaderDone) { | if (flagHeaderDone) { | ||||
sampleSection.append("</ul>"); | sampleSection.append("</ul>"); | ||||
sampleSection.append(EOL); | sampleSection.append(EOL); | ||||
sink.append("<h2><a name=\"authorIndex\"></a>Author Index</h2>"); | sink.append("<h2><a name=\"authorIndex\"></a>Author Index</h2>"); | ||||
List<Sample> list = samples.getSortedSamples(Sample.AUTHOR_NAME_SOURCE_COMPARER); | List<Sample> list = samples.getSortedSamples(Sample.AUTHOR_NAME_SOURCE_COMPARER); | ||||
String lastAuthor = null; | String lastAuthor = null; | ||||
for (ListIterator<Sample> iter = list.listIterator(); iter.hasNext();) { | |||||
Sample sample = iter.next(); | |||||
String author = sample.author; | |||||
if (!author.equals(lastAuthor)) { | |||||
if (null != lastAuthor) { | |||||
sink.append("</li></ul>"); | |||||
} | |||||
sink.append("<li>"); | |||||
sink.append(author); | |||||
sink.append(EOL); | |||||
sink.append("<ul>"); | |||||
sink.append(EOL); | |||||
lastAuthor = author; | |||||
} | |||||
sink.append(" <li><a href=\"#"); | |||||
sink.append(sample.anchorName); | |||||
sink.append("\">"); | |||||
if (null == sample.anchorTitle) { | |||||
sink.append(sample.anchorName); | |||||
} else { | |||||
sink.append(sample.anchorTitle); | |||||
} | |||||
sink.append("</a></li>"); | |||||
} | |||||
for (Sample sample : list) { | |||||
String author = sample.author; | |||||
if (!author.equals(lastAuthor)) { | |||||
if (null != lastAuthor) { | |||||
sink.append("</li></ul>"); | |||||
} | |||||
sink.append("<li>"); | |||||
sink.append(author); | |||||
sink.append(EOL); | |||||
sink.append("<ul>"); | |||||
sink.append(EOL); | |||||
lastAuthor = author; | |||||
} | |||||
sink.append(" <li><a href=\"#"); | |||||
sink.append(sample.anchorName); | |||||
sink.append("\">"); | |||||
if (null == sample.anchorTitle) { | |||||
sink.append(sample.anchorName); | |||||
} else { | |||||
sink.append(sample.anchorTitle); | |||||
} | |||||
sink.append("</a></li>"); | |||||
} | |||||
} | } | ||||
} | } | ||||
public static void simpleRender(Samples result, StringBuffer sink) { | public static void simpleRender(Samples result, StringBuffer sink) { | ||||
List sortedSamples = result.getSortedSamples(); | List sortedSamples = result.getSortedSamples(); | ||||
int i = 0; | int i = 0; | ||||
for (ListIterator iter = sortedSamples.listIterator(); | |||||
iter.hasNext();) { | |||||
Sample sample = (Sample) iter.next(); | |||||
sink.append(i++ + ": " + sample); | |||||
} | |||||
for (Object sortedSample : sortedSamples) { | |||||
Sample sample = (Sample) sortedSample; | |||||
sink.append(i++ + ": " + sample); | |||||
} | |||||
} | } | ||||
/** result struct for getPackagePath */ | /** result struct for getPackagePath */ |
return false; | return false; | ||||
} else if (dir.isDirectory()) { | } else if (dir.isDirectory()) { | ||||
File[] files = dir.listFiles(); | File[] files = dir.listFiles(); | ||||
for (int i = 0; i < files.length; i++) { | |||||
if (!deleteContents(files[i]) || !files[i].delete()) { | |||||
return false; | |||||
} | |||||
for (File file : files) { | |||||
if (!deleteContents(file) || !file.delete()) { | |||||
return false; | |||||
} | |||||
} | } | ||||
} | } | ||||
return true; | return true; | ||||
if ((hits != expected.length) || (hits != actual.length)) { | if ((hits != expected.length) || (hits != actual.length)) { | ||||
sb.append("unexpected ["); | sb.append("unexpected ["); | ||||
String prefix = ""; | String prefix = ""; | ||||
for (int i = 0; i < actual.length; i++) { | |||||
if (null != actual[i]) { | |||||
sb.append(prefix); | |||||
prefix = ", "; | |||||
sb.append("\""); | |||||
sb.append(actual[i]); | |||||
sb.append("\""); | |||||
} | |||||
} | |||||
for (String value : actual) { | |||||
if (null != value) { | |||||
sb.append(prefix); | |||||
prefix = ", "; | |||||
sb.append("\""); | |||||
sb.append(value); | |||||
sb.append("\""); | |||||
} | |||||
} | |||||
sb.append("] missing ["); | sb.append("] missing ["); | ||||
prefix = ""; | prefix = ""; | ||||
for (int i = 0; i < expected.length; i++) { | |||||
if (null != expected[i]) { | |||||
sb.append(prefix); | |||||
prefix = ", "; | |||||
sb.append("\""); | |||||
sb.append(expected[i]); | |||||
sb.append("\""); | |||||
} | |||||
} | |||||
for (String s : expected) { | |||||
if (null != s) { | |||||
sb.append(prefix); | |||||
prefix = ", "; | |||||
sb.append("\""); | |||||
sb.append(s); | |||||
sb.append("\""); | |||||
} | |||||
} | |||||
sb.append("]"); | sb.append("]"); | ||||
return true; | return true; | ||||
} | } |
public void testLicense_org_eclipse_jdt_core() { | public void testLicense_org_eclipse_jdt_core() { | ||||
final String mod = "org.eclipse.jdt.core"; | final String mod = "org.eclipse.jdt.core"; | ||||
final String pre = BASE_DIR + mod + File.separator; | final String pre = BASE_DIR + mod + File.separator; | ||||
for (int i = 0; i < JDT_SOURCE_DIRS.length; i++) { | |||||
checkSourceDirectory(new File(pre + JDT_SOURCE_DIRS[i]), mod); | |||||
for (String jdtSourceDir : JDT_SOURCE_DIRS) { | |||||
checkSourceDirectory(new File(pre + jdtSourceDir), mod); | |||||
} | } | ||||
} | } | ||||
void checkLicense(String module) { | void checkLicense(String module) { | ||||
File moduleDir = new File(Util.path("..", module)); | File moduleDir = new File(Util.path("..", module)); | ||||
File[] srcDirs = findSourceRoots(moduleDir); | File[] srcDirs = findSourceRoots(moduleDir); | ||||
for (int i = 0; i < srcDirs.length; i++) { | |||||
System.out.println(srcDirs[i]); | |||||
checkSourceDirectory(srcDirs[i], module); | |||||
} | |||||
for (File srcDir : srcDirs) { | |||||
System.out.println(srcDir); | |||||
checkSourceDirectory(srcDir, module); | |||||
} | |||||
} | } | ||||
void checkSourceDirectory(File srcDir, String module) { | void checkSourceDirectory(File srcDir, String module) { | ||||
} | } | ||||
void unknownFiles(File dir, ArrayList<File> results) { | void unknownFiles(File dir, ArrayList<File> results) { | ||||
File[] files = dir.listFiles(this); | File[] files = dir.listFiles(this); | ||||
for (int j = 0; j < files.length; j++) { | |||||
File file = files[j]; | |||||
if (file.isDirectory()) { | |||||
String name = file.getName(); | |||||
if (!("CVS".equals(name))) { | |||||
unknownFiles(file, results); | |||||
} | |||||
} else { | |||||
results.add(file); | |||||
} | |||||
} | |||||
for (File file : files) { | |||||
if (file.isDirectory()) { | |||||
String name = file.getName(); | |||||
if (!("CVS".equals(name))) { | |||||
unknownFiles(file, results); | |||||
} | |||||
} else { | |||||
results.add(file); | |||||
} | |||||
} | |||||
} | } | ||||
} | } |
} | } | ||||
protected void deleteTempFiles() { | protected void deleteTempFiles() { | ||||
for (Iterator iter = tempFiles.iterator(); iter.hasNext();) { | |||||
File file = (File) iter.next(); | |||||
if (!Util.delete(file)) { | |||||
File[] list = file.listFiles(); | |||||
if (!Util.isEmpty(list)) { | |||||
StringBuffer sb = new StringBuffer(); | |||||
sb.append("warning: BuildModuleTest unable to delete "); | |||||
sb.append(file.toString()); | |||||
sb.append("\n"); // XXX platform | |||||
for (int i = 0; i < list.length; i++) { | |||||
sb.append(" "); | |||||
sb.append(list[i].toString()); | |||||
sb.append("\n"); // XXX platform | |||||
} | |||||
System.err.println(sb.toString()); | |||||
} | |||||
} | |||||
} | |||||
for (File file : tempFiles) { | |||||
if (!Util.delete(file)) { | |||||
File[] list = file.listFiles(); | |||||
if (!Util.isEmpty(list)) { | |||||
StringBuffer sb = new StringBuffer(); | |||||
sb.append("warning: BuildModuleTest unable to delete "); | |||||
sb.append(file.toString()); | |||||
sb.append("\n"); // XXX platform | |||||
for (File value : list) { | |||||
sb.append(" "); | |||||
sb.append(value.toString()); | |||||
sb.append("\n"); // XXX platform | |||||
} | |||||
System.err.println(sb.toString()); | |||||
} | |||||
} | |||||
} | |||||
} | } | ||||
public void testAllJunitTests() { | public void testAllJunitTests() { | ||||
printedMessage = true; | printedMessage = true; | ||||
} | } | ||||
if (debugging()) { | if (debugging()) { | ||||
for (int i = 0; i < DEBUGS.length; i++) { | |||||
if (target.equals(DEBUGS[i])) { | |||||
return true; | |||||
} | |||||
} | |||||
for (String debug : DEBUGS) { | |||||
if (target.equals(debug)) { | |||||
return true; | |||||
} | |||||
} | |||||
return false; | return false; | ||||
} else { | } else { | ||||
for (int i = 0; i < SKIPS.length; i++) { | |||||
if (SKIPS[i].equals(target)) { | |||||
if (printInfoMessages) { | |||||
System.err.println(target + " skipped build test [" + getClass().getName() + ".shouldBuild(..)]"); | |||||
} | |||||
return false; | |||||
} | |||||
} | |||||
for (String skip : SKIPS) { | |||||
if (skip.equals(target)) { | |||||
if (printInfoMessages) { | |||||
System.err.println(target + " skipped build test [" + getClass().getName() + ".shouldBuild(..)]"); | |||||
} | |||||
return false; | |||||
} | |||||
} | |||||
} | } | ||||
return building; | return building; | ||||
} | } | ||||
java.setClasspath(cp); | java.setClasspath(cp); | ||||
java.setClassname(classname); | java.setClassname(classname); | ||||
if (null != args) { | if (null != args) { | ||||
for (int i = 0; i < args.length; i++) { | |||||
Argument arg = java.createArg(); | |||||
arg.setValue(args[i]); | |||||
} | |||||
for (String s : args) { | |||||
Argument arg = java.createArg(); | |||||
arg.setValue(s); | |||||
} | |||||
} | } | ||||
try { | try { | ||||
java.execute(); | java.execute(); |
} else { | } else { | ||||
File[] files = file.listFiles(); | File[] files = file.listFiles(); | ||||
boolean result = true; | boolean result = true; | ||||
for (int i = 0; i < files.length; i++) { | |||||
if (!ModulesTest.delete(files[i]) | |||||
&& result) { | |||||
result = false; | |||||
} | |||||
} | |||||
for (File value : files) { | |||||
if (!ModulesTest.delete(value) | |||||
&& result) { | |||||
result = false; | |||||
} | |||||
} | |||||
return (file.delete() && result); | return (file.delete() && result); | ||||
} | } | ||||
} | } | ||||
protected void tearDown() throws Exception { | protected void tearDown() throws Exception { | ||||
super.tearDown(); | super.tearDown(); | ||||
for (Iterator<File> iter = tempFiles.iterator(); iter.hasNext();) { | |||||
File file = (File) iter.next(); | |||||
if (!ModulesTest.delete(file)) { | |||||
System.err.println("warning: ModulesTest unable to delete " + file); | |||||
} | |||||
for (File file : tempFiles) { | |||||
if (!ModulesTest.delete(file)) { | |||||
System.err.println("warning: ModulesTest unable to delete " + file); | |||||
} | |||||
} | } | ||||
} | } | ||||
File libDir = new File(distDir, "tools/lib"); | File libDir = new File(distDir, "tools/lib"); | ||||
String[] jars = { "tools", "rt", "weaver", "lib"}; | String[] jars = { "tools", "rt", "weaver", "lib"}; | ||||
for (int i = 0; i < jars.length; i++) { | |||||
File jar = new File(libDir, "aspectj" + jars[i] + ".jar"); | |||||
assertTrue(jar.getPath(), jar.canRead()); | |||||
if (10 > jar.length()) { | |||||
assertTrue(jar + " too small", false); | |||||
} | |||||
} | |||||
for (String s : jars) { | |||||
File jar = new File(libDir, "aspectj" + s + ".jar"); | |||||
assertTrue(jar.getPath(), jar.canRead()); | |||||
if (10 > jar.length()) { | |||||
assertTrue(jar + " too small", false); | |||||
} | |||||
} | |||||
} | } | ||||
/** | /** | ||||
* Show messages from the task. | * Show messages from the task. |
"aspectjrt" }) { | "aspectjrt" }) { | ||||
void checkOthers(OSGIBundle osgiBundle, StringBuffer sb) { | void checkOthers(OSGIBundle osgiBundle, StringBuffer sb) { | ||||
RequiredBundle[] bundles = osgiBundle.getRequiredBundles(); | RequiredBundle[] bundles = osgiBundle.getRequiredBundles(); | ||||
for (int i = 0; i < bundles.length; i++) { | |||||
RequiredBundle bundle = bundles[i]; | |||||
if ("aspectjrt".equals(bundle.name)) { | |||||
if (!bundle.optional) { | |||||
sb | |||||
.append("expected required bundle aspectjrt to be optional"); | |||||
} | |||||
String version = "[1.5.0,1.5.5]"; | |||||
if (!(version.equals(bundle.versions))) { | |||||
sb.append("expected version " + version | |||||
+ " got " + bundle.versions | |||||
+ " for required bundle aspectjrt"); | |||||
} | |||||
} | |||||
} | |||||
for (RequiredBundle bundle : bundles) { | |||||
if ("aspectjrt".equals(bundle.name)) { | |||||
if (!bundle.optional) { | |||||
sb | |||||
.append("expected required bundle aspectjrt to be optional"); | |||||
} | |||||
String version = "[1.5.0,1.5.5]"; | |||||
if (!(version.equals(bundle.versions))) { | |||||
sb.append("expected version " + version | |||||
+ " got " + bundle.versions | |||||
+ " for required bundle aspectjrt"); | |||||
} | |||||
} | |||||
} | |||||
} | } | ||||
} }; | } }; | ||||
/** disabled pending research */ | /** disabled pending research */ | ||||
public void skip_testOSGIManifests() throws Exception { | public void skip_testOSGIManifests() throws Exception { | ||||
StringBuffer sb = new StringBuffer(); | StringBuffer sb = new StringBuffer(); | ||||
for (int i = 0; i < TESTS.length; i++) { | |||||
TESTS[i].run(sb); | |||||
} | |||||
for (ManifestTest test : TESTS) { | |||||
test.run(sb); | |||||
} | |||||
if (0 < sb.length()) { | if (0 < sb.length()) { | ||||
fail(sb.toString()); | fail(sb.toString()); | ||||
} | } |
System.err.println("Weaver adaptors before queue processing:"); | System.err.println("Weaver adaptors before queue processing:"); | ||||
Map<AdaptorKey,ExplicitlyInitializedClassLoaderWeavingAdaptor> m = WeaverContainer.weavingAdaptors; | Map<AdaptorKey,ExplicitlyInitializedClassLoaderWeavingAdaptor> m = WeaverContainer.weavingAdaptors; | ||||
Set<AdaptorKey> keys = m.keySet(); | Set<AdaptorKey> keys = m.keySet(); | ||||
for (Iterator<AdaptorKey> iterator = keys.iterator(); iterator.hasNext();) { | |||||
Object object = iterator.next(); | |||||
for (Object object : keys) { | |||||
System.err.println(object + " = " + WeaverContainer.weavingAdaptors.get(object)); | System.err.println(object + " = " + WeaverContainer.weavingAdaptors.get(object)); | ||||
} | } | ||||
} | } | ||||
System.err.println("Weaver adaptors after queue processing:"); | System.err.println("Weaver adaptors after queue processing:"); | ||||
Map<AdaptorKey,ExplicitlyInitializedClassLoaderWeavingAdaptor> m = WeaverContainer.weavingAdaptors; | Map<AdaptorKey,ExplicitlyInitializedClassLoaderWeavingAdaptor> m = WeaverContainer.weavingAdaptors; | ||||
Set<AdaptorKey> keys = m.keySet(); | Set<AdaptorKey> keys = m.keySet(); | ||||
for (Iterator<AdaptorKey> iterator = keys.iterator(); iterator.hasNext();) { | |||||
Object object = iterator.next(); | |||||
for (Object object : keys) { | |||||
System.err.println(object + " = " + WeaverContainer.weavingAdaptors.get(object)); | System.err.println(object + " = " + WeaverContainer.weavingAdaptors.get(object)); | ||||
} | } | ||||
} | } |