Browse Source

generics

tags/V1_6_12M2
aclement 12 years ago
parent
commit
997e351ea0

+ 20
- 24
ajde/src/org/aspectj/ajde/internal/LstBuildConfigFileParser.java View File

@@ -11,7 +11,6 @@
* Xerox/PARC initial implementation
* ******************************************************************/


package org.aspectj.ajde.internal;

import java.io.File;
@@ -25,37 +24,34 @@ import org.aspectj.ajdt.ajc.ConfigParser;
*/
public class LstBuildConfigFileParser extends ConfigParser {

private List importedFiles = new ArrayList();
private List problemEntries = new ArrayList();
private List<File> importedFiles = new ArrayList<File>();
private List<String> problemEntries = new ArrayList<String>();

// private String currFilePath;
// private String currFilePath;

public LstBuildConfigFileParser(String currFilePath) {
// this.currFilePath = currFilePath;
}
// this.currFilePath = currFilePath;
}

protected void showWarning(String message) {
problemEntries.add(message);
}

protected void showWarning(String message) {
problemEntries.add(message);
}
protected void parseImportedConfigFile(String relativeFilePath) {
importedFiles.add(makeFile(relativeFilePath));
super.files.add(new File(relativeFilePath));
super.parseImportedConfigFile(relativeFilePath);
}
protected void showError(String message) {
problemEntries.add(message);
}
public List getImportedFiles() {
return importedFiles;
}
public List getProblemEntries() {
return problemEntries;
super.parseImportedConfigFile(relativeFilePath);
}
}

protected void showError(String message) {
problemEntries.add(message);
}

public List<File> getImportedFiles() {
return importedFiles;
}

public List<String> getProblemEntries() {
return problemEntries;
}
}

+ 161
- 159
ajde/src/org/aspectj/ajde/internal/LstBuildConfigFileUpdater.java View File

@@ -12,7 +12,6 @@
* Helen Hawkins Converted to new interface (bug 148190)
* ******************************************************************/


package org.aspectj.ajde.internal;

import java.io.BufferedReader;
@@ -35,181 +34,184 @@ import org.aspectj.bridge.Message;

/**
* Used for reading and writing build configuration (".lst") files.
*
*
* @author Mik Kersten
*/
class LstBuildConfigFileUpdater {

/**
* Adds an entry to a build configuration file.
*/
public void updateBuildConfigFile(String buildConfigFile, String update, boolean addToConfiguration) {
List fileContents = readConfigFile(buildConfigFile);
if (addToConfiguration) {
fileContents.add(update);
} else {
fileContents.remove(update);
}
writeConfigFile(buildConfigFile, fileContents);
}
/**
* Adds an entry to multiple build configuration files.
*/
public void updateBuildConfigFiles(List buildConfigFiles, List filesToUpdate, boolean addToConfiguration) {
for (int i = 0; i < buildConfigFiles.size(); i++) {
List fileContents = readConfigFile((String)buildConfigFiles.get(i));
if (addToConfiguration) {
for (int j = 0; j < filesToUpdate.size(); j++) {
fileContents.add(filesToUpdate.get(j));
}
} else {
for (int k =0; k < filesToUpdate.size(); k++) {
if (fileContents.contains(filesToUpdate.get(k))) {
fileContents.remove(filesToUpdate.get(k));
}
}
}
writeConfigFile((String)buildConfigFiles.get(i), fileContents);
}
}
/**
* Checks if an entry exists within a build configuration file.
*/
public boolean exists(String entry, String configFile) {
return exists(entry, configFile, "");
}
public boolean exists(String entry, String configFile, String rootPath) {
Iterator it = readConfigFile(configFile).iterator();
while (it.hasNext()) {
if ((entry).equals(rootPath + "/" + (String)it.next())) {
return true;
}
}
return false;
}
/**
* Reads the entries of a configuration file.
*/
public List readConfigFile(String filePath) {
try {
File configFile = new File(filePath);
if (!configFile.exists()) {
Message msg = new Message("Config file: " + filePath +
" does not exist. Update failed.",IMessage.WARNING,null,null);
Ajde.getDefault().getMessageHandler().handleMessage(msg);
}
List fileContents = new ArrayList();
BufferedReader reader = new BufferedReader(new FileReader(configFile));
String line = reader.readLine();
while (line != null) {
fileContents.add(line.replace('\\', '/'));
line = reader.readLine();
}
reader.close();
return fileContents;
} catch (IOException ioe) {
Message msg = new Message("Could not update build config file.",IMessage.ERROR,ioe,null);
Ajde.getDefault().getMessageHandler().handleMessage(msg);
}
return null;
}
/**
* Adds an entry to a build configuration file.
*/
public void updateBuildConfigFile(String buildConfigFile, String update, boolean addToConfiguration) {
List fileContents = readConfigFile(buildConfigFile);
if (addToConfiguration) {
fileContents.add(update);
} else {
fileContents.remove(update);
}
writeConfigFile(buildConfigFile, fileContents);
}
/**
* Adds an entry to multiple build configuration files.
*/
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));
if (addToConfiguration) {
for (int j = 0; j < filesToUpdate.size(); j++) {
fileContents.add(filesToUpdate.get(j));
}
} else {
for (int k = 0; k < filesToUpdate.size(); k++) {
if (fileContents.contains(filesToUpdate.get(k))) {
fileContents.remove(filesToUpdate.get(k));
}
}
}
writeConfigFile((String) buildConfigFiles.get(i), fileContents);
}
}
/**
* Checks if an entry exists within a build configuration file.
*/
public boolean exists(String entry, String configFile) {
return exists(entry, configFile, "");
}
public boolean exists(String entry, String configFile, String rootPath) {
Iterator it = readConfigFile(configFile).iterator();
while (it.hasNext()) {
if ((entry).equals(rootPath + "/" + (String) it.next())) {
return true;
}
}
return false;
}
/**
* Reads the entries of a configuration file.
*/
public List<String> readConfigFile(String filePath) {
try {
File configFile = new File(filePath);
if (!configFile.exists()) {
Message msg = new Message("Config file: " + filePath + " does not exist. Update failed.", IMessage.WARNING, null,
null);
Ajde.getDefault().getMessageHandler().handleMessage(msg);
}
List<String> fileContents = new ArrayList<String>();
BufferedReader reader = new BufferedReader(new FileReader(configFile));
String line = reader.readLine();
while (line != null) {
fileContents.add(line.replace('\\', '/'));
line = reader.readLine();
}
reader.close();
return fileContents;
} catch (IOException ioe) {
Message msg = new Message("Could not update build config file.", IMessage.ERROR, ioe, null);
Ajde.getDefault().getMessageHandler().handleMessage(msg);
}
return null;
}

public void writeConfigFile(String filePath, List files, List importedNodes) {
//Set contentsSet = new TreeSet(fileContents);
String fileContentsString = "";
//List filesToWrite = null;
Set includedFiles = new HashSet();
for (Iterator it = importedNodes.iterator(); it.hasNext(); ) {
BuildConfigNode node = (BuildConfigNode)it.next();
fileContentsString += '@' + node.getResourcePath() + "\n";
String parentPath = new File(filePath).getParent();
String importedFilePath = parentPath + File.separator + node.getResourcePath();
includedFiles.addAll(getIncludedFiles(importedFilePath, parentPath));
}
for (Iterator it = files.iterator(); it.hasNext(); ) {
BuildConfigNode node = (BuildConfigNode)it.next();
if (node.getName().endsWith(".lst") && !node.getResourcePath().startsWith("..")) {
fileContentsString += '@';
fileContentsString += node.getResourcePath() + "\n";
} else {
if (!includedFiles.contains(node.getResourcePath())) {
fileContentsString += node.getResourcePath() + "\n";
}
}
}
writeFile(fileContentsString, filePath);
// Set contentsSet = new TreeSet(fileContents);
String fileContentsString = "";
// List filesToWrite = null;
Set includedFiles = new HashSet();
for (Iterator it = importedNodes.iterator(); it.hasNext();) {
BuildConfigNode node = (BuildConfigNode) it.next();
fileContentsString += '@' + node.getResourcePath() + "\n";
String parentPath = new File(filePath).getParent();
String importedFilePath = parentPath + File.separator + node.getResourcePath();
includedFiles.addAll(getIncludedFiles(importedFilePath, parentPath));
}
for (Iterator it = files.iterator(); it.hasNext();) {
BuildConfigNode node = (BuildConfigNode) it.next();
if (node.getName().endsWith(".lst") && !node.getResourcePath().startsWith("..")) {
fileContentsString += '@';
fileContentsString += node.getResourcePath() + "\n";
} else {
if (!includedFiles.contains(node.getResourcePath())) {
fileContentsString += node.getResourcePath() + "\n";
}
}
}
writeFile(fileContentsString, filePath);
}

private List getIncludedFiles(String path, String rootPath) {
private List<String> getIncludedFiles(String path, String rootPath) {
try {
ConfigParser configParser = new ConfigParser();
configParser.parseConfigFile(new File(path));
List files = configParser.getFiles();
List relativeFiles = new ArrayList();
for (Iterator it = files.iterator(); it.hasNext(); ) {
relativeFiles.add(relativizePath(((File)it.next()).getPath(), rootPath));
}
return relativeFiles;
ConfigParser configParser = new ConfigParser();
configParser.parseConfigFile(new File(path));
List<File> files = configParser.getFiles();
List<String> relativeFiles = new ArrayList<String>();
for (Iterator<File> it = files.iterator(); it.hasNext();) {
relativeFiles.add(relativizePath(((File) it.next()).getPath(), rootPath));
}
return relativeFiles;
} catch (ConfigParser.ParseException pe) {
return new ArrayList();
}
return new ArrayList<String>();
}
}

// private synchronized List getUniqueFileList(List list, Set set) {
// List uniqueList = new ArrayList();
// for (Iterator it = list.iterator(); it.hasNext(); ) {
// BuildConfigNode node = (BuildConfigNode)it.next();
// String file1 = node.getResourcePath();
// if (set.contains(file1) && !uniqueList.contains(file1)) {
// uniqueList.add(file1);
// }
// }
// return uniqueList;
// }
// private synchronized List getUniqueFileList(List list, Set set) {
// List uniqueList = new ArrayList();
// for (Iterator it = list.iterator(); it.hasNext(); ) {
// BuildConfigNode node = (BuildConfigNode)it.next();
// String file1 = node.getResourcePath();
// if (set.contains(file1) && !uniqueList.contains(file1)) {
// uniqueList.add(file1);
// }
// }
// return uniqueList;
// }

public String relativizePath(String path, String rootPath) {
path = path.replace('\\', '/');
rootPath = rootPath.replace('\\', '/');
int pathIndex = path.indexOf(rootPath);
int pathIndex = path.indexOf(rootPath);
if (pathIndex > -1) {
return path.substring(pathIndex + rootPath.length() + 1);
} else {
return path;
}
}

/**
* Sorts and does not write duplicates.
*
* @param fileContents full paths representing file entries
*/
public void writeConfigFile(String filePath, List fileContents) {
Set contentsSet = new TreeSet(fileContents);
StringBuffer fileContentsSB = new StringBuffer();
Iterator it = contentsSet.iterator();
while (it.hasNext()) {
fileContentsSB.append(it.next().toString());
fileContentsSB.append("\n");
}
writeFile(fileContentsSB.toString(), filePath);
}
private void writeFile(String contents, String filePath) {
FileOutputStream fos = null;
try {
fos = new FileOutputStream(filePath, false);
fos.write(contents.getBytes());
} catch (IOException ioe) {
Message msg = new Message("Could not update build config file: " + filePath,IMessage.ERROR,ioe,null);
Ajde.getDefault().getMessageHandler().handleMessage(msg);
} finally {
if (fos!=null) try {fos.close();} catch (IOException ioe) {}
}
}
}
return path;
}
}

/**
* Sorts and does not write duplicates.
*
* @param fileContents full paths representing file entries
*/
public void writeConfigFile(String filePath, List fileContents) {
Set contentsSet = new TreeSet(fileContents);
StringBuffer fileContentsSB = new StringBuffer();
Iterator it = contentsSet.iterator();
while (it.hasNext()) {
fileContentsSB.append(it.next().toString());
fileContentsSB.append("\n");
}
writeFile(fileContentsSB.toString(), filePath);
}

private void writeFile(String contents, String filePath) {
FileOutputStream fos = null;
try {
fos = new FileOutputStream(filePath, false);
fos.write(contents.getBytes());
} catch (IOException ioe) {
Message msg = new Message("Could not update build config file: " + filePath, IMessage.ERROR, ioe, null);
Ajde.getDefault().getMessageHandler().handleMessage(msg);
} finally {
if (fos != null)
try {
fos.close();
} catch (IOException ioe) {
}
}
}
}

+ 164
- 171
ajde/src/org/aspectj/ajde/internal/LstBuildConfigManager.java View File

@@ -12,7 +12,6 @@
* Helen Hawkins Converted to new interface (bug 148190)
* ******************************************************************/

package org.aspectj.ajde.internal;

import java.io.File;
@@ -34,201 +33,195 @@ import org.aspectj.bridge.SourceLocation;
import org.aspectj.util.FileUtil;

/**
* @author Mik Kersten
* @author Mik Kersten
*/
public class LstBuildConfigManager implements BuildConfigManager {
private List allBuildConfigFiles;
private List listeners = new ArrayList();
private List<String> allBuildConfigFiles;
private List<BuildConfigListener> listeners = new ArrayList<BuildConfigListener>();
private LstBuildConfigFileUpdater fileUpdater = new LstBuildConfigFileUpdater();
protected String currConfigFilePath = null;
private static final FilenameFilter SOURCE_FILE_FILTER = new FilenameFilter() {
public boolean accept(File dir, String name) {
return FileUtil.hasSourceSuffix(name) || name.endsWith(".lst");
}
};
private static final FileFilter DIR_FILTER = new FileFilter() {
public boolean accept(File file) {
return file.isDirectory();
}
};
private static final FilenameFilter SOURCE_FILE_FILTER = new FilenameFilter() {
public boolean accept(File dir, String name) {
return FileUtil.hasSourceSuffix(name) || name.endsWith(".lst");
}
};
private static final FileFilter DIR_FILTER = new FileFilter() {
public boolean accept(File file) {
return file.isDirectory();
}
};

public BuildConfigModel buildModel(String configFilePath) {
File configFile = new File(configFilePath);
String rootPath = configFile.getParent();
String configFileName = configFile.getName();
BuildConfigModel model = new BuildConfigModel(configFilePath);
List configFiles = new ArrayList();
List importedFiles = new ArrayList();
List badEntries = null;
List<File> configFiles = new ArrayList<File>();
List<File> importedFiles = new ArrayList<File>();
List<String> badEntries = null;
try {
LstBuildConfigFileParser configParser = new LstBuildConfigFileParser(configFilePath);
configParser.parseConfigFile(new File(configFilePath));
configFiles = configParser.getFiles();
importedFiles = configParser.getImportedFiles();
badEntries = configParser.getProblemEntries();
LstBuildConfigFileParser configParser = new LstBuildConfigFileParser(configFilePath);
configParser.parseConfigFile(new File(configFilePath));
configFiles = configParser.getFiles();
importedFiles = configParser.getImportedFiles();
badEntries = configParser.getProblemEntries();
} catch (ConfigParser.ParseException pe) {
// String filePath = "<unknown>";
// if (pe.getFile() != null) filePath = pe.getFile().getAbsolutePath();
IMessage message = new Message(
pe.getMessage(),
IMessage.ERROR,
pe,
new SourceLocation(pe.getFile(), pe.getLine(), 1));
Ajde.getDefault().getMessageHandler().handleMessage(message);
}
List relativePaths = relativizeFilePaths(configFiles, rootPath);
BuildConfigNode root = new BuildConfigNode(configFileName, BuildConfigNode.Kind.FILE_LST, rootPath);
buildDirTree(root, rootPath, importedFiles, configFileName);
model.setRoot(root);
addFilesToDirTree(model, relativePaths, badEntries);
pruneEmptyDirs(root);
sortModel(model.getRoot(), ALPHABETICAL_COMPARATOR);
//addImportedFilesToDirTree(model, importedFiles);
addProblemEntries(root, badEntries);
// String filePath = "<unknown>";
// if (pe.getFile() != null) filePath = pe.getFile().getAbsolutePath();
IMessage message = new Message(pe.getMessage(), IMessage.ERROR, pe, new SourceLocation(pe.getFile(), pe.getLine(), 1));
Ajde.getDefault().getMessageHandler().handleMessage(message);
}

List<String> relativePaths = relativizeFilePaths(configFiles, rootPath);
BuildConfigNode root = new BuildConfigNode(configFileName, BuildConfigNode.Kind.FILE_LST, rootPath);
buildDirTree(root, rootPath, importedFiles, configFileName);
model.setRoot(root);
addFilesToDirTree(model, relativePaths, badEntries);

pruneEmptyDirs(root);
sortModel(model.getRoot(), ALPHABETICAL_COMPARATOR);
// addImportedFilesToDirTree(model, importedFiles);

addProblemEntries(root, badEntries);
return model;
}

private void addProblemEntries(BuildConfigNode root, List badEntries) {
for (Iterator it = badEntries.iterator(); it.hasNext(); ) {
root.addChild(new BuildConfigNode(
it.next().toString(),
BuildConfigNode.Kind.ERROR, null)
);
for (Iterator it = badEntries.iterator(); it.hasNext();) {
root.addChild(new BuildConfigNode(it.next().toString(), BuildConfigNode.Kind.ERROR, null));
}
}

public void writeModel(BuildConfigModel model) {
// final List paths = new ArrayList();
// StructureWalker walker = new StructureWalker() {
// protected void postProcess(StructureNode node) {
// BuildConfigNode configNode = (BuildConfigNode)node;
// if (configNode.isActive() && configNode.isValidResource()) {
// paths.add(configNode.getResourcePath());
// }
// }
// };
// model.getRoot().walk(walker);
// final List paths = new ArrayList();
// StructureWalker walker = new StructureWalker() {
// protected void postProcess(StructureNode node) {
// BuildConfigNode configNode = (BuildConfigNode)node;
// if (configNode.isActive() && configNode.isValidResource()) {
// paths.add(configNode.getResourcePath());
// }
// }
// };
// model.getRoot().walk(walker);
List activeSourceFiles = model.getActiveNodes(BuildConfigNode.Kind.FILE_ASPECTJ);
activeSourceFiles.addAll(model.getActiveNodes(BuildConfigNode.Kind.FILE_JAVA));
List activeImportedFiles = model.getActiveNodes(BuildConfigNode.Kind.FILE_LST);
fileUpdater.writeConfigFile(model.getSourceFile(), activeSourceFiles, activeImportedFiles);
fileUpdater.writeConfigFile(model.getSourceFile(), activeSourceFiles, activeImportedFiles);
}
public void writePaths(String configFilePath, List files) {
fileUpdater.writeConfigFile(configFilePath, files);
fileUpdater.writeConfigFile(configFilePath, files);
}
public void addFilesToConfig(String configFilePath, List paths) {
}
public void removeFilesFromConfig(String configFilePath, List files) {
}
private List relativizeFilePaths(List configFiles, String rootPath) {
List relativePathsList = new ArrayList();
for (Iterator it = configFiles.iterator(); it.hasNext(); ) {
File file = (File)it.next();

private List<String> relativizeFilePaths(List<File> configFiles, String rootPath) {
List<String> relativePathsList = new ArrayList<String>();
for (File file : configFiles) {
relativePathsList.add(fileUpdater.relativizePath(file.getPath(), rootPath));
}
return relativePathsList;
}
// private String relativizePath(String path, String rootPath) {
// path = path.replace('\\', '/');
// rootPath = rootPath.replace('\\', '/');
// int pathIndex = path.indexOf(rootPath);
// if (pathIndex > -1) {
// return path.substring(pathIndex + rootPath.length() + 1);
// } else {
// return path;
// }
// }
// private String relativizePath(String path, String rootPath) {
// path = path.replace('\\', '/');
// rootPath = rootPath.replace('\\', '/');
// int pathIndex = path.indexOf(rootPath);
// if (pathIndex > -1) {
// return path.substring(pathIndex + rootPath.length() + 1);
// } else {
// return path;
// }
// }
private void buildDirTree(BuildConfigNode node, String rootPath, List importedFiles, String configFileName) {
File[] dirs = new File(node.getResourcePath()).listFiles(DIR_FILTER);
if (dirs == null) return;
if (dirs == null)
return;
for (int i = 0; i < dirs.length; i++) {
BuildConfigNode dir = new BuildConfigNode(dirs[i].getName(), BuildConfigNode.Kind.DIRECTORY, dirs[i].getPath());
BuildConfigNode dir = new BuildConfigNode(dirs[i].getName(), BuildConfigNode.Kind.DIRECTORY, dirs[i].getPath());
File[] files = dirs[i].listFiles(SOURCE_FILE_FILTER);
for (int j = 0; j < files.length; j++) {
if (files[j] != null) {// && !files[j].getName().endsWith(".lst")) {
if (files[j] != null) {// && !files[j].getName().endsWith(".lst")) {
String filePath = fileUpdater.relativizePath(files[j].getPath(), rootPath);
BuildConfigNode.Kind kind = BuildConfigNode.Kind.FILE_JAVA;
if (!files[j].getName().endsWith(".lst")) {
//kind = BuildConfigNode.Kind.FILE_LST;
BuildConfigNode file = new BuildConfigNode(files[j].getName(), kind, filePath);
file.setActive(false);
// kind = BuildConfigNode.Kind.FILE_LST;
BuildConfigNode file = new BuildConfigNode(files[j].getName(), kind, filePath);
file.setActive(false);
dir.addChild(file);
}
}
}
}
node.addChild(dir);
// boolean foundMatch = false;
for (Iterator it = importedFiles.iterator(); it.hasNext(); ) {
File importedFile = (File)it.next();
node.addChild(dir);
// boolean foundMatch = false;
for (Iterator it = importedFiles.iterator(); it.hasNext();) {
File importedFile = (File) it.next();
if (importedFile.getParentFile().getAbsolutePath().equals(dirs[i].getAbsolutePath())) {
// foundMatch = true;
BuildConfigNode importedFileNode = new BuildConfigNode(
importedFile.getName(),
BuildConfigNode.Kind.FILE_LST,
fileUpdater.relativizePath(importedFile.getPath(), rootPath));
// foundMatch = true;
BuildConfigNode importedFileNode = new BuildConfigNode(importedFile.getName(), BuildConfigNode.Kind.FILE_LST,
fileUpdater.relativizePath(importedFile.getPath(), rootPath));
importedFileNode.setActive(true);
//dir.getChildren().clear();
// dir.getChildren().clear();
boolean found = false;
for (Iterator it2 = dir.getChildren().iterator(); it2.hasNext(); ) {
if (((BuildConfigNode)it2.next()).getName().equals(importedFile.getName())) {
found = true;
for (Iterator it2 = dir.getChildren().iterator(); it2.hasNext();) {
if (((BuildConfigNode) it2.next()).getName().equals(importedFile.getName())) {
found = true;
}
}
if (!found) dir.addChild(importedFileNode);
if (!found)
dir.addChild(importedFileNode);
}
}
//if (!foundMatch)
// if (!foundMatch)
buildDirTree(dir, rootPath, importedFiles, configFileName);
}
if (node.getName().endsWith(".lst")) {
File[] files = new File(rootPath).listFiles(SOURCE_FILE_FILTER);
if (files == null) return;
if (files == null)
return;
for (int i = 0; i < files.length; i++) {
if (files[i] != null && !files[i].getName().equals(configFileName)) {// && !files[i].getName().endsWith(".lst")) {
BuildConfigNode.Kind kind = BuildConfigNode.Kind.FILE_JAVA;
if (files[i].getName().endsWith(".lst")) {
kind = BuildConfigNode.Kind.FILE_LST;
kind = BuildConfigNode.Kind.FILE_LST;
}
BuildConfigNode file = new BuildConfigNode(files[i].getName(), kind, files[i].getName());
BuildConfigNode file = new BuildConfigNode(files[i].getName(), kind, files[i].getName());
file.setActive(false);
node.addChild(file);
}
}
}
}
private void addFilesToDirTree(BuildConfigModel model, List configFiles, List badEntries) {
for (Iterator it = configFiles.iterator(); it.hasNext(); ) {
String path = (String)it.next();
for (Iterator it = configFiles.iterator(); it.hasNext();) {
String path = (String) it.next();
if (path.startsWith("..")) {
File file = new File(path);
BuildConfigNode node = new BuildConfigNode(file.getName(), BuildConfigNode.Kind.FILE_JAVA, path);
BuildConfigNode upPath = model.getNodeForPath(file.getParentFile().getPath());
if (upPath == model.getRoot()) {
upPath = new BuildConfigNode(file.getParentFile().getPath(), BuildConfigNode.Kind.DIRECTORY, file.getParentFile().getAbsolutePath());
upPath = new BuildConfigNode(file.getParentFile().getPath(), BuildConfigNode.Kind.DIRECTORY, file
.getParentFile().getAbsolutePath());
model.getRoot().addChild(upPath);
}
}
node.setActive(true);
upPath.addChild(node);
} else if (!(new File(path).isAbsolute())) {
// String name = new File(path).getName();
// String name = new File(path).getName();
BuildConfigNode existingNode = model.getNodeForPath(path);
existingNode.setActive(true);
} else {
@@ -236,82 +229,82 @@ public class LstBuildConfigManager implements BuildConfigManager {
}
}
}
private boolean pruneEmptyDirs(BuildConfigNode node) {
List nodesToRemove = new ArrayList();
for (Iterator it = node.getChildren().iterator(); it.hasNext(); ) {
BuildConfigNode currNode = (BuildConfigNode)it.next();
for (Iterator it = node.getChildren().iterator(); it.hasNext();) {
BuildConfigNode currNode = (BuildConfigNode) it.next();
boolean hasValidChildren = pruneEmptyDirs(currNode);
if (!currNode.isValidResource() && !hasValidChildren) {
nodesToRemove.add(currNode);
}
}
}
for (Iterator it = nodesToRemove.iterator(); it.hasNext(); ) {
BuildConfigNode currNode = (BuildConfigNode)it.next();
node.removeChild(currNode);
for (Iterator it = nodesToRemove.iterator(); it.hasNext();) {
BuildConfigNode currNode = (BuildConfigNode) it.next();
node.removeChild(currNode);
}
return node.getChildren().size() > 0;
}
public String getActiveConfigFile() {
return currConfigFilePath;
return currConfigFilePath;
}
public void setActiveConfigFile(String currConfigFilePath) {
if (currConfigFilePath == null) return;
if (currConfigFilePath == null)
return;
this.currConfigFilePath = currConfigFilePath;
notifyConfigChanged();
}
public void addListener(BuildConfigListener configurationListener) {
listeners.add(configurationListener);
}
public void removeListener(BuildConfigListener configurationListener) {
listeners.remove(configurationListener);
}
private void notifyConfigChanged() {
for (Iterator it = listeners.iterator(); it.hasNext(); ) {
((BuildConfigListener)it.next()).currConfigChanged(currConfigFilePath);
}
}
// private void notifyConfigsListUpdated() {
// for (Iterator it = listeners.iterator(); it.hasNext(); ) {
// ((BuildConfigListener)it.next()).configsListUpdated(configFiles);
// }
// }
//
public void addListener(BuildConfigListener configurationListener) {
listeners.add(configurationListener);
}
public void removeListener(BuildConfigListener configurationListener) {
listeners.remove(configurationListener);
}
private void notifyConfigChanged() {
for (Iterator it = listeners.iterator(); it.hasNext();) {
((BuildConfigListener) it.next()).currConfigChanged(currConfigFilePath);
}
}
// private void notifyConfigsListUpdated() {
// for (Iterator it = listeners.iterator(); it.hasNext(); ) {
// ((BuildConfigListener)it.next()).configsListUpdated(configFiles);
// }
// }
//
private void sortModel(BuildConfigNode node, Comparator comparator) {
if (node == null || node.getChildren() == null) return;
if (node == null || node.getChildren() == null)
return;
Collections.sort(node.getChildren(), comparator);
for (Iterator it = node.getChildren().iterator(); it.hasNext(); ) {
BuildConfigNode nextNode = (BuildConfigNode)it.next();
if (nextNode != null) sortModel(nextNode, comparator);
for (Iterator it = node.getChildren().iterator(); it.hasNext();) {
BuildConfigNode nextNode = (BuildConfigNode) it.next();
if (nextNode != null)
sortModel(nextNode, comparator);
}
}
private static final Comparator ALPHABETICAL_COMPARATOR = new Comparator() {
public int compare(Object o1, Object o2) {
BuildConfigNode n1 = (BuildConfigNode)o1;
BuildConfigNode n2 = (BuildConfigNode)o2;
private static final Comparator ALPHABETICAL_COMPARATOR = new Comparator() {
public int compare(Object o1, Object o2) {
BuildConfigNode n1 = (BuildConfigNode) o1;
BuildConfigNode n2 = (BuildConfigNode) o2;
return n1.getName().compareTo(n2.getName());
}
};
}
};

public List getAllBuildConfigFiles() {
public List<String> getAllBuildConfigFiles() {
if (allBuildConfigFiles == null) {
allBuildConfigFiles = new ArrayList();
allBuildConfigFiles = new ArrayList<String>();
if (getActiveConfigFile() != null) {
allBuildConfigFiles.add(getActiveConfigFile());
}
}
}
return allBuildConfigFiles;
}
}


}

+ 48
- 56
ajde/src/org/aspectj/ajde/ui/BuildConfigModel.java View File

@@ -11,11 +11,13 @@
* Xerox/PARC initial implementation
* ******************************************************************/


package org.aspectj.ajde.ui;

import java.io.IOException;
import java.util.*;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.StringTokenizer;

/**
* TODO: we have schitzophrenia between BuildConfigNode(s) and IProgramElement(s), fix.
@@ -26,14 +28,14 @@ public class BuildConfigModel {

private BuildConfigNode root = null;

private String sourceFile;
private String sourceFile;
public BuildConfigModel(String sourceFile) {
this.sourceFile = sourceFile;
}

/**
* @param path java.io.File.separator delimited path
* @param path java.io.File.separator delimited path
* @return corresponding node if the path is found, the root otherwise
*/
public BuildConfigNode getNodeForPath(String path) {
@@ -47,9 +49,9 @@ public class BuildConfigModel {
}

private BuildConfigNode searchUpPaths(String path) {
for (Iterator it = root.getChildren().iterator(); it.hasNext(); ) {
BuildConfigNode node = (BuildConfigNode)it.next();
if (node.getName().equals(path)) return node;
for (BuildConfigNode node : root.getChildren()) {
if (node.getName().equals(path))
return node;
}
return null;
}
@@ -57,39 +59,37 @@ public class BuildConfigModel {
private BuildConfigNode getNodeForPathHelper(StringTokenizer st, BuildConfigNode node) {
BuildConfigNode parent = node;
while (st.hasMoreElements()) {
String pathItem = (String)st.nextElement();
for (Iterator it = node.getChildren().iterator(); it.hasNext(); ) {
node = (BuildConfigNode)it.next();
String pathItem = (String) st.nextElement();
for (Iterator it = node.getChildren().iterator(); it.hasNext();) {
node = (BuildConfigNode) it.next();
String childName = node.getName();
if (childName.equals(pathItem)) {
return getNodeForPathHelper(st, node);
}
}
}
}
return parent;
return parent;
}
public List getActiveNodes(BuildConfigNode.Kind kind) {
List nodes = new ArrayList();
public List<BuildConfigNode> getActiveNodes(BuildConfigNode.Kind kind) {
List<BuildConfigNode> nodes = new ArrayList<BuildConfigNode>();
getActiveNodesHelper(root, kind, nodes);
return nodes;
}

private void getActiveNodesHelper(BuildConfigNode node, BuildConfigNode.Kind kind, List nodes) {
for (Iterator it = node.getChildren().iterator(); it.hasNext(); ) {
BuildConfigNode currNode = (BuildConfigNode)it.next();
if (currNode.getBuildConfigNodeKind().equals(kind)
&& currNode.isActive()) {
private void getActiveNodesHelper(BuildConfigNode node, BuildConfigNode.Kind kind, List<BuildConfigNode> nodes) {
for (BuildConfigNode currNode : node.getChildren()) {
if (currNode.getBuildConfigNodeKind().equals(kind) && currNode.isActive()) {
nodes.add(currNode);
}
getActiveNodesHelper(currNode, kind, nodes);
}
}
}
public String getSourceFile() {
return sourceFile;
}
public void setSourceFile(String sourceFile) {
this.sourceFile = sourceFile;
}
@@ -101,53 +101,45 @@ public class BuildConfigModel {
public void setRoot(BuildConfigNode node) {
root = node;
}
public BuildConfigNode findNodeForSourceLine(String sourceFilePath, int lineNumber) {
BuildConfigNode node = findNodeForSourceLineHelper(root, sourceFilePath, lineNumber);
return node;
return node;
}
private BuildConfigNode findNodeForSourceLineHelper(BuildConfigNode node, String sourceFilePath, int lineNumber) {
if (matches(node, sourceFilePath, lineNumber)
&& !hasMoreSpecificChild(node, sourceFilePath, lineNumber)) {
return node;
}
if (matches(node, sourceFilePath, lineNumber) && !hasMoreSpecificChild(node, sourceFilePath, lineNumber)) {
return node;
}

if (node != null && node.getChildren() != null) {
for (Iterator it = node.getChildren().iterator(); it.hasNext(); ) {
BuildConfigNode foundNode = findNodeForSourceLineHelper(
(BuildConfigNode)it.next(),
sourceFilePath,
lineNumber);
if (foundNode != null) return foundNode;
for (Iterator it = node.getChildren().iterator(); it.hasNext();) {
BuildConfigNode foundNode = findNodeForSourceLineHelper((BuildConfigNode) it.next(), sourceFilePath, lineNumber);
if (foundNode != null)
return foundNode;
}
}
return null;
return null;
}

private boolean matches(BuildConfigNode node, String sourceFilePath, int lineNumber) {
try {
return node != null
&& node.getSourceLocation() != null
&& node.getSourceLocation().getSourceFile().getCanonicalPath().equals(sourceFilePath)
&& ((node.getSourceLocation().getLine() <= lineNumber
&& node.getSourceLocation().getEndLine() >= lineNumber)
||
(lineNumber <= 1)
);
} catch (IOException ioe) {
try {
return node != null
&& node.getSourceLocation() != null
&& node.getSourceLocation().getSourceFile().getCanonicalPath().equals(sourceFilePath)
&& ((node.getSourceLocation().getLine() <= lineNumber && node.getSourceLocation().getEndLine() >= lineNumber) || (lineNumber <= 1));
} catch (IOException ioe) {
return false;
}
}
}

private boolean hasMoreSpecificChild(BuildConfigNode node, String sourceFilePath, int lineNumber) {
for (Iterator it = node.getChildren().iterator(); it.hasNext(); ) {
BuildConfigNode child = (BuildConfigNode)it.next();
if (matches(child, sourceFilePath, lineNumber)) return true;
for (Iterator it = node.getChildren().iterator(); it.hasNext();) {
BuildConfigNode child = (BuildConfigNode) it.next();
if (matches(child, sourceFilePath, lineNumber))
return true;
}
return false;
}

}



+ 63
- 66
ajde/src/org/aspectj/ajde/ui/BuildConfigNode.java View File

@@ -11,56 +11,57 @@
* Xerox/PARC initial implementation
* ******************************************************************/


package org.aspectj.ajde.ui;

import java.io.*;
import java.util.*;
import java.io.ObjectStreamException;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import org.aspectj.bridge.*;
import org.aspectj.bridge.IMessage;
import org.aspectj.bridge.ISourceLocation;
import org.aspectj.util.FileUtil;

/**
* @author Mik Kersten
*
* TODO: clean-up after merging of org.aspectj.asm.StructureNode
* TODO: clean-up after merging of org.aspectj.asm.StructureNode
*/
public class BuildConfigNode {



protected BuildConfigNode parent = null;
protected String name = "";
protected Kind kind;
// children.listIterator() should support remove() operation
protected List children = new ArrayList();
protected List<BuildConfigNode> children = new ArrayList<BuildConfigNode>();
protected IMessage message = null;
protected ISourceLocation sourceLocation = null;

/**
* Used during serialization.
*/
public BuildConfigNode() { }
public BuildConfigNode() {
}

// public BuildConfigNode(String name, String kind, String resourcePath, List children) {
// this(name, kind, children);
// this.resourcePath = resourcePath;
// }
// public BuildConfigNode(String name, String kind, String resourcePath, List children) {
// this(name, kind, children);
// this.resourcePath = resourcePath;
// }

public BuildConfigNode(String name, Kind kind, String resourcePath) {
public BuildConfigNode(String name, Kind kind, String resourcePath) {
this(name, kind);
this.kind = kind;
this.resourcePath = resourcePath;
this.resourcePath = resourcePath;
}

// public BuildConfigNode(String name, Kind kind, List children) {
// this.name = name;
// this.kind = kind;
// if (children != null) {
// this.children = children;
// }
// setParents();
// }
// public BuildConfigNode(String name, Kind kind, List children) {
// this.name = name;
// this.kind = kind;
// if (children != null) {
// this.children = children;
// }
// setParents();
// }

public BuildConfigNode(String name, Kind kind) {
this.name = name;
@@ -68,32 +69,32 @@ public class BuildConfigNode {
}

public String toString() {
return name;
return name;
}

public List getChildren() {
public List<BuildConfigNode> getChildren() {
return children;
}

public void addChild(BuildConfigNode child) {
if (children == null) {
children = new ArrayList();
children = new ArrayList<BuildConfigNode>();
}
children.add(child);
child.setParent(this);
}
public void addChild(int position, BuildConfigNode child) {
if (children == null) {
children = new ArrayList();
children = new ArrayList<BuildConfigNode>();
}
children.add(position, child);
child.setParent(this);
}
public boolean removeChild(BuildConfigNode child) {
child.setParent(null);
return children.remove(child);
return children.remove(child);
}

/**
@@ -101,7 +102,7 @@ public class BuildConfigNode {
*/
public int compareTo(Object o) throws ClassCastException {
if (o instanceof BuildConfigNode) {
BuildConfigNode sn = (BuildConfigNode)o;
BuildConfigNode sn = (BuildConfigNode) o;
return this.getName().compareTo(sn.getName());
}
return -1;
@@ -135,21 +136,20 @@ public class BuildConfigNode {
this.parent = parent;
}

// private void setParents() {
// if (children == null) return;
// for (Iterator it = children.iterator(); it.hasNext(); ) {
// ((BuildConfigNode)it.next()).setParent(this);
// }
// }
// private void setParents() {
// if (children == null) return;
// for (Iterator it = children.iterator(); it.hasNext(); ) {
// ((BuildConfigNode)it.next()).setParent(this);
// }
// }

public void setName(String string) {
name = string;
}

private String resourcePath;
private boolean isActive = true;
public String getResourcePath() {
return resourcePath;
}
@@ -157,11 +157,11 @@ public class BuildConfigNode {
public void setResourcePath(String resourcePath) {
this.resourcePath = resourcePath;
}
public boolean isValidResource() {
return FileUtil.hasSourceSuffix(name) || name.endsWith(".lst");
return FileUtil.hasSourceSuffix(name) || name.endsWith(".lst");
}
public boolean isActive() {
return isActive;
}
@@ -174,54 +174,51 @@ public class BuildConfigNode {
* Uses "typesafe enum" pattern.
*/
public static class Kind implements Serializable {
private static final long serialVersionUID = 3924996793884978885L;
public static final Kind FILE_JAVA = new Kind("Java source file");
public static final Kind FILE_ASPECTJ = new Kind("AspectJ source file");
public static final Kind FILE_LST = new Kind("build configuration file");
public static final Kind ERROR = new Kind("error");
public static final Kind DIRECTORY = new Kind("directory");


public static final Kind[] ALL = { FILE_JAVA, FILE_ASPECTJ, FILE_LST, DIRECTORY };
private final String name;
private Kind(String name) {
this.name = name;
}
public String toString() {
return name;
}
// public boolean equals(Object o) {
// return (o instanceof Kind? this==o : false);
//// return o.equals(name);
// }
//
// public int hashCode() {
// return ordinal;
//// return name.hashCode();
// }
}
// public boolean equals(Object o) {
// return (o instanceof Kind? this==o : false);
// // return o.equals(name);
// }
//
// public int hashCode() {
// return ordinal;
// // return name.hashCode();
// }
public boolean isDeclareKind() {
return name.startsWith("declare");
}
return name.startsWith("declare");
}

// The 4 declarations below are necessary for serialization
private static int nextOrdinal = 0;
private final int ordinal = nextOrdinal++;

private Object readResolve() throws ObjectStreamException {
return ALL[ordinal];
}
}
public Kind getBuildConfigNodeKind() {
return kind;
}
}




+ 49
- 49
ajde/src/org/aspectj/ajde/ui/javaoptions/JavaBuildOptions.java View File

@@ -15,154 +15,154 @@ import java.util.Map;
import org.aspectj.ajde.core.JavaOptions;

/**
* Class which handles the setting of the java options and the
* java options map required by ICompilerConfiguration#getJavaOptionsMap()
* Class which handles the setting of the java options and the java options map required by
* ICompilerConfiguration#getJavaOptionsMap()
*/
public class JavaBuildOptions {

private Map javaBuildOptions;
private Map<String, String> javaBuildOptions;
public JavaBuildOptions() {
javaBuildOptions = JavaOptions.getDefaultJavaOptions();
}
public Map getJavaBuildOptionsMap() {
public Map<String, String> getJavaBuildOptionsMap() {
return javaBuildOptions;
}
public void setOption(String javaOption, String value) {
javaBuildOptions.put(javaOption,value);
javaBuildOptions.put(javaOption, value);
}
// ----------------- compliance settings ---------------
// compliance
public void setComplianceLevel(String level) {
if (JavaOptions.isValidJvmVersion(level)) {
javaBuildOptions.put(JavaOptions.COMPLIANCE_LEVEL,level);
javaBuildOptions.put(JavaOptions.COMPLIANCE_LEVEL, level);
}
}

// source
public void setSourceCompatibilityLevel(String level) {
if (JavaOptions.isValidJvmVersion(level)) {
javaBuildOptions.put(JavaOptions.SOURCE_COMPATIBILITY_LEVEL,level);
javaBuildOptions.put(JavaOptions.SOURCE_COMPATIBILITY_LEVEL, level);
}
}

// target
public void setTargetLevel(String level) {
if (JavaOptions.isValidJvmVersion(level)) {
javaBuildOptions.put(JavaOptions.TARGET_COMPATIBILITY_LEVEL,level);
javaBuildOptions.put(JavaOptions.TARGET_COMPATIBILITY_LEVEL, level);
}
}
// ---------------- compiler warning options ------------------
// warn method with constructor name
public void setWarnMethodWithConstructorName(String option) {
if (JavaOptions.isIgnoreOrWarning(option)) {
javaBuildOptions.put(
JavaOptions.WARN_METHOD_WITH_CONSTRUCTOR_NAME,option);
javaBuildOptions.put(JavaOptions.WARN_METHOD_WITH_CONSTRUCTOR_NAME, option);
}
}

// warn overriding package default method
public void setWarnOverridingPackageDefaultMethod(String option) {
if (JavaOptions.isIgnoreOrWarning(option)) {
javaBuildOptions.put(
JavaOptions.WARN_OVERRIDING_PACKAGE_DEFAULT_METHOD,option);
javaBuildOptions.put(JavaOptions.WARN_OVERRIDING_PACKAGE_DEFAULT_METHOD, option);
}
}
}

// warn deprecation
public void setWarnDeprecation(String option) {
if (JavaOptions.isIgnoreOrWarning(option)) {
javaBuildOptions.put(
JavaOptions.WARN_DEPRECATION,option);
javaBuildOptions.put(JavaOptions.WARN_DEPRECATION, option);
}
}

// warn hidden catch blocks
public void setWarnHiddenCatchBlocks(String option) {
if (JavaOptions.isIgnoreOrWarning(option)) {
javaBuildOptions.put(
JavaOptions.WARN_HIDDEN_CATCH_BLOCKS,option);
javaBuildOptions.put(JavaOptions.WARN_HIDDEN_CATCH_BLOCKS, option);
}
}
}

// warn unused locals
public void setWarnUnusedLocals(String option) {
if (JavaOptions.isIgnoreOrWarning(option)) {
javaBuildOptions.put(
JavaOptions.WARN_UNUSED_LOCALS,option);
javaBuildOptions.put(JavaOptions.WARN_UNUSED_LOCALS, option);
}
}

// warn unused parameters
public void setWarnUnusedParameters(String option) {
if (JavaOptions.isIgnoreOrWarning(option)) {
javaBuildOptions.put(
JavaOptions.WARN_UNUSED_PARAMETER,option);
javaBuildOptions.put(JavaOptions.WARN_UNUSED_PARAMETER, option);
}
}

// warn unused imports
public void setWarnUnusedImports(String option) {
if (JavaOptions.isIgnoreOrWarning(option)) {
javaBuildOptions.put(
JavaOptions.WARN_UNUSED_IMPORTS,option);
javaBuildOptions.put(JavaOptions.WARN_UNUSED_IMPORTS, option);
}
}

// warn synthetic access
public void setWarnSyntheticAccess(String option) {
if (JavaOptions.isIgnoreOrWarning(option)) {
javaBuildOptions.put(
JavaOptions.WARN_SYNTHETIC_ACCESS,option);
javaBuildOptions.put(JavaOptions.WARN_SYNTHETIC_ACCESS, option);
}
}
// warn assert identifier

// warn assert identifier
public void setWarnAssertIdentifier(String option) {
if (JavaOptions.isIgnoreOrWarning(option)) {
javaBuildOptions.put(
JavaOptions.WARN_ASSERT_IDENITIFIER,option);
javaBuildOptions.put(JavaOptions.WARN_ASSERT_IDENITIFIER, option);
}
}

// warn non nls
public void setWarnNonNLS(String option) {
if (JavaOptions.isIgnoreOrWarning(option)) {
javaBuildOptions.put(
JavaOptions.WARN_NON_NLS,option);
javaBuildOptions.put(JavaOptions.WARN_NON_NLS, option);
}
}
// --------------- debug options --------------------

// debug source
public void setDebugSource(String option) {
if (JavaOptions.isGenerateOrNot(option)) {
javaBuildOptions.put(
JavaOptions.DEBUG_SOURCE,option);
javaBuildOptions.put(JavaOptions.DEBUG_SOURCE, option);
}
}

// debug lines
public void setDebugLines(String option) {
if (JavaOptions.isGenerateOrNot(option)) {
javaBuildOptions.put(
JavaOptions.DEBUG_LINES,option);
javaBuildOptions.put(JavaOptions.DEBUG_LINES, option);
}
}

// debug vars
public void setDebugVariables(String option) {
if (JavaOptions.isGenerateOrNot(option)) {
javaBuildOptions.put(
JavaOptions.DEBUG_VARS,option);
javaBuildOptions.put(JavaOptions.DEBUG_VARS, option);
}
}

// preserve all locals
public void setPreserveAllLocals(String value) {
if (JavaOptions.isValidPreserveAllLocalsOption(value)) {
javaBuildOptions.put(JavaOptions.PRESERVE_ALL_LOCALS,value);
javaBuildOptions.put(JavaOptions.PRESERVE_ALL_LOCALS, value);
}
}
// ----------- other settings
// character encoding
public void setCharacterEncoding(String value) {
javaBuildOptions.put(JavaOptions.CHARACTER_ENCODING, value);
}

}

Loading…
Cancel
Save