@@ -1,14 +1,14 @@ | |||
/* ******************************************************************* | |||
* Copyright (c) 1999-2001 Xerox Corporation, | |||
* Copyright (c) 1999-2001 Xerox Corporation, | |||
* 2002 Palo Alto Research Center, Incorporated (PARC). | |||
* All rights reserved. | |||
* This program and the accompanying materials are made available | |||
* under the terms of the Eclipse Public License v1.0 | |||
* which accompanies this distribution and is available at | |||
* http://www.eclipse.org/legal/epl-v10.html | |||
* | |||
* Contributors: | |||
* Xerox/PARC initial implementation | |||
* All rights reserved. | |||
* This program and the accompanying materials are made available | |||
* under the terms of the Eclipse Public License v1.0 | |||
* which accompanies this distribution and is available at | |||
* http://www.eclipse.org/legal/epl-v10.html | |||
* | |||
* Contributors: | |||
* Xerox/PARC initial implementation | |||
* ******************************************************************/ | |||
@@ -46,132 +46,132 @@ public class TreeStructureViewBuilder { | |||
* @todo get rid of instanceof tests | |||
*/ | |||
public void buildView(StructureView view, IHierarchy model) { | |||
// StructureViewProperties properties = view.getViewProperties(); | |||
// StructureViewProperties properties = view.getViewProperties(); | |||
IProgramElement modelRoot = null; | |||
// boolean noStructure = false; | |||
// boolean noStructure = false; | |||
if (isFileView(view)) { | |||
FileStructureView fileView = (FileStructureView)view; | |||
if (fileView.getSourceFile() == null) { | |||
if (fileView.getSourceFile() == null) { | |||
modelRoot = IHierarchy.NO_STRUCTURE; | |||
// noStructure = true; | |||
// noStructure = true; | |||
} else { | |||
modelRoot = model.findElementForSourceFile(fileView.getSourceFile()); | |||
} | |||
} else { | |||
modelRoot = model.getRoot(); | |||
} | |||
IStructureViewNode viewRoot = null; | |||
if (!isFileView(view)) { | |||
StructureViewProperties.Hierarchy hierarchy | |||
= ((GlobalStructureView)view).getGlobalViewProperties().getHierarchy(); | |||
if (hierarchy.equals(StructureViewProperties.Hierarchy.CROSSCUTTING) | |||
|| hierarchy.equals(StructureViewProperties.Hierarchy.INHERITANCE)) { | |||
viewRoot = buildCustomTree((GlobalStructureView)view, model); | |||
} | |||
} | |||
StructureViewProperties.Hierarchy hierarchy | |||
= ((GlobalStructureView)view).getGlobalViewProperties().getHierarchy(); | |||
if (hierarchy.equals(StructureViewProperties.Hierarchy.CROSSCUTTING) | |||
|| hierarchy.equals(StructureViewProperties.Hierarchy.INHERITANCE)) { | |||
viewRoot = buildCustomTree((GlobalStructureView)view, model); | |||
} | |||
} | |||
if (viewRoot == null) { | |||
viewRoot = createViewNode(modelRoot, view.getViewProperties());//modelRoot; | |||
} | |||
} | |||
if (view.getViewProperties().getSorting() == StructureViewProperties.Sorting.ALPHABETICAL | |||
|| (!isFileView(view) && | |||
((GlobalStructureView)view).getGlobalViewProperties().getHierarchy().equals(StructureViewProperties.Hierarchy.DECLARATION))) { | |||
|| (!isFileView(view) && | |||
((GlobalStructureView)view).getGlobalViewProperties().getHierarchy().equals(StructureViewProperties.Hierarchy.DECLARATION))) { | |||
sortView(viewRoot, ALPHABETICAL_COMPARATOR); | |||
} else { | |||
sortView(viewRoot, DECLARATIONAL_COMPARATOR); | |||
} | |||
} | |||
addPackageNode(view, viewRoot); | |||
view.setRootNode(viewRoot); | |||
} | |||
private void addPackageNode(StructureView view, IStructureViewNode viewRoot) { | |||
if (isFileView(view)) { | |||
// IProgramElement fileNode = viewRoot.getStructureNode(); | |||
// IProgramElement parentNode = fileNode.getParent(); | |||
// | |||
// if (parentNode.getKind() == IProgramElement.Kind.PACKAGE) { | |||
// String name = parentNode.getName(); | |||
// IProgramElement packageNode = new ProgramElement(name, IProgramElement.Kind.PACKAGE, null); | |||
// packageNode.setSourceLocation(fileNode.getSourceLocation()); | |||
// StructureViewNode packageViewNode = createViewNode( | |||
// packageNode, | |||
// view.getViewProperties() | |||
// ); | |||
// viewRoot.getChildren().add(0, packageViewNode); | |||
// }; | |||
// IProgramElement fileNode = viewRoot.getStructureNode(); | |||
// IProgramElement parentNode = fileNode.getParent(); | |||
// | |||
// if (parentNode.getKind() == IProgramElement.Kind.PACKAGE) { | |||
// String name = parentNode.getName(); | |||
// IProgramElement packageNode = new ProgramElement(name, IProgramElement.Kind.PACKAGE, null); | |||
// packageNode.setSourceLocation(fileNode.getSourceLocation()); | |||
// StructureViewNode packageViewNode = createViewNode( | |||
// packageNode, | |||
// view.getViewProperties() | |||
// ); | |||
// viewRoot.getChildren().add(0, packageViewNode); | |||
// }; | |||
} | |||
} | |||
private IStructureViewNode createViewNode(IProgramElement node, StructureViewProperties properties) { | |||
if (node == null) return null; | |||
List children = new ArrayList(); | |||
// IProgramElement pNode = node; | |||
// if (node.getRelations() != null) { | |||
// for (Iterator it = node.getRelations().iterator(); it.hasNext(); ) { | |||
// IProgramElement IProgramElement = (IProgramElement)it.next(); | |||
// if (acceptNode(IProgramElement, properties)) { | |||
// children.add(createViewNode(IProgramElement, properties)); | |||
// } | |||
// } | |||
// } | |||
// IProgramElement pNode = node; | |||
// if (node.getRelations() != null) { | |||
// for (Iterator it = node.getRelations().iterator(); it.hasNext(); ) { | |||
// IProgramElement IProgramElement = (IProgramElement)it.next(); | |||
// if (acceptNode(IProgramElement, properties)) { | |||
// children.add(createViewNode(IProgramElement, properties)); | |||
// } | |||
// } | |||
// } | |||
if (node.isRunnable() && node.getParent() != null) { | |||
IProgramElement parent = node.getParent(); | |||
if (parent.getKind().equals(IProgramElement.Kind.CLASS) | |||
|| parent.getKind().equals(IProgramElement.Kind.ASPECT)) { | |||
parent.setRunnable(true); | |||
|| parent.getKind().equals(IProgramElement.Kind.ASPECT)) { | |||
parent.setRunnable(true); | |||
node.setRunnable(false); | |||
} | |||
} | |||
if (node.getChildren() != null) { | |||
for (Iterator it = node.getChildren().iterator(); it.hasNext(); ) { | |||
IProgramElement IProgramElement = (IProgramElement)it.next(); | |||
for (Object element : node.getChildren()) { | |||
IProgramElement IProgramElement = (IProgramElement)element; | |||
if (acceptNode(IProgramElement, properties)) { | |||
children.add(createViewNode(IProgramElement, properties)); | |||
} | |||
} | |||
} | |||
} | |||
IStructureViewNode viewNode = nodeFactory.createNode(node, children);//new TreeViewNode(root, null, children); | |||
return viewNode; | |||
return viewNode; | |||
} | |||
/** | |||
* @todo get rid of this test, fix polymorphism | |||
*/ | |||
private boolean isFileView(StructureView view) { | |||
return view instanceof FileStructureView | |||
&& !(view instanceof GlobalStructureView); | |||
&& !(view instanceof GlobalStructureView); | |||
} | |||
private boolean acceptGranularity(IProgramElement.Kind kind, StructureViewProperties.Granularity granularity) { | |||
if (granularity == StructureViewProperties.Granularity.DECLARED_ELEMENTS) { | |||
return true; | |||
} else if (granularity == StructureViewProperties.Granularity.MEMBER && | |||
(kind != IProgramElement.Kind.CODE)) { | |||
} else if (granularity == StructureViewProperties.Granularity.MEMBER && | |||
(kind != IProgramElement.Kind.CODE)) { | |||
return true; | |||
} else if (granularity == StructureViewProperties.Granularity.TYPE | |||
&& (kind == IProgramElement.Kind.PROJECT | |||
&& (kind == IProgramElement.Kind.PROJECT | |||
|| kind == IProgramElement.Kind.PACKAGE | |||
|| kind.isSourceFile() | |||
|| kind.isType())) { | |||
return true; | |||
return true; | |||
} else if (granularity == StructureViewProperties.Granularity.FILE | |||
&& (kind == IProgramElement.Kind.PROJECT | |||
&& (kind == IProgramElement.Kind.PROJECT | |||
|| kind == IProgramElement.Kind.PACKAGE | |||
|| kind.isSourceFile())) { | |||
return true; | |||
return true; | |||
} else if (granularity == StructureViewProperties.Granularity.PACKAGE | |||
&& (kind == IProgramElement.Kind.PROJECT | |||
&& (kind == IProgramElement.Kind.PROJECT | |||
|| kind == IProgramElement.Kind.PACKAGE)) { | |||
return true; | |||
return true; | |||
} else { | |||
return false; | |||
} | |||
} | |||
private boolean acceptNode(IProgramElement node, StructureViewProperties properties) { | |||
if (node!=null) { | |||
IProgramElement pNode = node; | |||
@@ -179,250 +179,249 @@ public class TreeStructureViewBuilder { | |||
return false; | |||
} else if (pNode.getKind().isMember()) { | |||
if (properties.getFilteredMemberAccessibility().contains(pNode.getAccessibility())) { | |||
return false; | |||
return false; | |||
} | |||
if (properties.getFilteredMemberKinds().contains(pNode.getKind())) { | |||
return false; | |||
return false; | |||
} | |||
for (Iterator it = pNode.getModifiers().iterator(); it.hasNext(); ) { | |||
if (properties.getFilteredMemberModifiers().contains(it.next())) { | |||
return false; | |||
} | |||
for (Object element : pNode.getModifiers()) { | |||
if (properties.getFilteredMemberModifiers().contains(element)) { | |||
return false; | |||
} | |||
} | |||
} | |||
} | |||
return true; | |||
} | |||
private void sortView(IStructureViewNode node, Comparator comparator) { | |||
private void sortView(IStructureViewNode node, Comparator<IStructureViewNode> comparator) { | |||
if (node == null || node.getChildren() == null) return; | |||
Collections.sort(node.getChildren(), comparator); | |||
for (Iterator it = node.getChildren().iterator(); it.hasNext(); ) { | |||
IStructureViewNode nextNode = (IStructureViewNode)it.next(); | |||
if (nextNode != null) sortView(nextNode, comparator); | |||
if (nextNode != null) sortView(nextNode, comparator); | |||
} | |||
} | |||
private IStructureViewNode buildCustomTree(GlobalStructureView view, IHierarchy model) { | |||
IProgramElement rootNode = model.getRoot(); | |||
IStructureViewNode treeNode = nodeFactory.createNode(rootNode); | |||
List rootNodes = new ArrayList(); | |||
getRoots(rootNode, rootNodes, view.getGlobalViewProperties().getHierarchy()); | |||
for (Iterator it = rootNodes.iterator(); it.hasNext(); ) { | |||
if (view.getGlobalViewProperties().getHierarchy().equals(StructureViewProperties.Hierarchy.CROSSCUTTING)) { | |||
treeNode.add(getCrosscuttingChildren((IProgramElement)it.next())); | |||
} else if (view.getGlobalViewProperties().getHierarchy().equals(StructureViewProperties.Hierarchy.INHERITANCE)) { | |||
treeNode.add(getInheritanceChildren( | |||
(IProgramElement)it.next(), | |||
view.getViewProperties().getRelations()) | |||
); | |||
} | |||
} | |||
return treeNode; | |||
} | |||
private void getRoots(IProgramElement rootNode, List roots, StructureViewProperties.Hierarchy hierarchy) { | |||
// if (rootNode != null && rootNode.getChildren() != null) { | |||
// for (Iterator it = rootNode.getChildren().iterator(); it.hasNext(); ) { | |||
// IProgramElement node = (IProgramElement)it.next(); | |||
// if (node instanceof IProgramElement) { | |||
// if (acceptNodeAsRoot((IProgramElement)node, hierarchy)) { | |||
// IProgramElement pNode = (IProgramElement)node; | |||
// List relations = pNode.getRelations(); | |||
// String delimiter = ""; | |||
// if (hierarchy.equals(StructureViewProperties.Hierarchy.CROSSCUTTING)) { | |||
// delimiter = "uses pointcut"; | |||
// } else if (hierarchy.equals(StructureViewProperties.Hierarchy.INHERITANCE)) { | |||
// delimiter = "inherits"; | |||
// } | |||
// if (relations != null && relations.toString().indexOf(delimiter) == -1) { | |||
// boolean found = false; | |||
// for (Iterator it2 = roots.iterator(); it2.hasNext(); ) { | |||
// if (((IProgramElement)it2.next()).equals(pNode)) found = true; | |||
// } | |||
// if (!found) roots.add(pNode); | |||
// } | |||
// } | |||
// } | |||
// getRoots(node, roots, hierarchy); | |||
// } | |||
// } | |||
} | |||
public boolean acceptNodeAsRoot(IProgramElement node, StructureViewProperties.Hierarchy hierarchy) { | |||
if (hierarchy.equals(StructureViewProperties.Hierarchy.CROSSCUTTING)) { | |||
return node.getKind().equals(IProgramElement.Kind.ADVICE) | |||
|| node.getKind().equals(IProgramElement.Kind.POINTCUT); | |||
} else if (hierarchy.equals(StructureViewProperties.Hierarchy.INHERITANCE)) { | |||
return node.getKind().equals(IProgramElement.Kind.CLASS); | |||
} else { | |||
return false; | |||
} | |||
} | |||
private IStructureViewNode getInheritanceChildren(IProgramElement node, List associations) { | |||
// IStructureViewNode treeNode = nodeFactory.createNode(node); | |||
// //StructureViewNode treeNode = new StructureViewNodeAdapter(node); | |||
// List relations = ((IProgramElement)node).getRelations(); | |||
throw new RuntimeException("unimplemented"); | |||
// if (relations != null) { | |||
// for (Iterator it = relations.iterator(); it.hasNext(); ) { | |||
// IRelationship relation = (IRelationship)it.next(); | |||
// if (relation.getName().equals("is inherited by")) { | |||
// for (Iterator it2 = relation.getTargets().iterator(); it2.hasNext(); ) { | |||
//// IProgramElement pNode = ((LinkNode)it2.next()).getProgramElementNode(); | |||
//// StructureViewNode newNode = getInheritanceChildren(pNode, associations); | |||
// StructureViewNode typeChildren = buildTree(newNode.getStructureNode(), associations); | |||
// for (int i = 0; i < typeChildren.getChildren().size(); i++) { | |||
// newNode.add((StructureViewNode)typeChildren.getChildren().get(i)); | |||
// } | |||
// treeNode.add(newNode); | |||
// } | |||
// } | |||
// } | |||
// } | |||
// return treeNode; | |||
} | |||
private IStructureViewNode getCrosscuttingChildren(IProgramElement node) { | |||
//StructureViewNodeAdapter treeNode = new StructureViewNodeAdapter(node); | |||
// IStructureViewNode treeNode = nodeFactory.createNode(node); | |||
// List relations = ((IProgramElement)node).getRelations(); | |||
throw new RuntimeException("unimplemented"); | |||
// if (relations != null) { | |||
// for (Iterator it = relations.iterator(); it.hasNext(); ) { | |||
// IRelationship relation = (IRelationship)it.next(); | |||
// if (relation.getName().equals("pointcut used by")) { | |||
// for (Iterator it2 = relation.getTargets().iterator(); it2.hasNext(); ) { | |||
// IProgramElement pNode = ((LinkNode)it2.next()).getProgramElementNode(); | |||
// StructureViewNode newNode = getCrosscuttingChildren(pNode); | |||
// for (Iterator it3 = pNode.getRelations().iterator(); it3.hasNext(); ) { | |||
// IRelationship relationNode = (IRelation)it3.next(); | |||
// if (relationNode.getName().indexOf("pointcut") == -1) { | |||
// newNode.add(getRelations(relationNode)); | |||
// } | |||
// } | |||
// treeNode.add(newNode); | |||
// } | |||
// } else if (relations.toString().indexOf("uses pointcut") == -1) { | |||
// for (Iterator it4 = relations.iterator(); it4.hasNext(); ) { | |||
// IRelation relationNode = (IRelationship)it4.next(); | |||
// if (relationNode.getName().indexOf("pointcut") == -1) { | |||
// treeNode.add(getRelations(relationNode)); | |||
// } | |||
// } | |||
// } | |||
// } | |||
// } | |||
// return treeNode; | |||
} | |||
// private IStructureViewNode buildTree(IProgramElement node, List associations) { | |||
// //StructureViewNode treeNode = new StructureViewNodeAdapter(node); | |||
// IStructureViewNode treeNode = nodeFactory.createNode(node); | |||
//// if (node instanceof IProgramElement) { | |||
// List relations = ((IProgramElement)node).getRelations(); | |||
// if (relations != null) { | |||
// for (Iterator it = relations.iterator(); it.hasNext(); ) { | |||
// IRelationship relationNode = (IRelationship)it.next(); | |||
// if (associations.contains(relationNode.toString())) { | |||
// treeNode.add(buildTree(relationNode, associations)); | |||
// } | |||
// } | |||
// } | |||
// } | |||
// if (node != null) { | |||
// List children = null; | |||
// children = node.getChildren(); | |||
// if (children != null) { | |||
// List childList = new ArrayList(); | |||
// for (Iterator itt = children.iterator(); itt.hasNext(); ) { | |||
// IProgramElement child = (IProgramElement)itt.next(); | |||
// if (child instanceof IProgramElement) { | |||
// IProgramElement progNode = (IProgramElement)child; | |||
//// if (progNode.getKind() != IProgramElement.Kind.CODE) { | |||
// childList.add(buildTree(child, associations)); | |||
//// } | |||
// } else { | |||
// childList.add(buildTree(child, associations)); | |||
// } | |||
// } | |||
// //sortNodes(childList); | |||
// for (Iterator it = childList.iterator(); it.hasNext(); ) { | |||
// treeNode.add((IStructureViewNode)it.next()); | |||
// } | |||
// } | |||
// | |||
// } | |||
// return treeNode; | |||
// } | |||
private IStructureViewNode buildCustomTree(GlobalStructureView view, IHierarchy model) { | |||
IProgramElement rootNode = model.getRoot(); | |||
IStructureViewNode treeNode = nodeFactory.createNode(rootNode); | |||
// private IStructureViewNode getRelations(IRelationship node) { | |||
// return null; | |||
// //StructureViewNode treeNode = new StructureViewNode(node); | |||
//// IStructureViewNode treeNode = nodeFactory.c(node); | |||
//// for (Iterator it = node.getTargets().iterator(); it.hasNext(); ) { | |||
//// treeNode.add( | |||
//// nodeFactory.createNode((IProgramElement)it.next()) | |||
//// ); | |||
//// } | |||
//// return treeNode; | |||
// } | |||
// | |||
// /** | |||
// * For debugging only. | |||
// */ | |||
// private void dumpView(IStructureViewNode root, int level) { | |||
// System.out.println(root.getStructureNode()); | |||
// for (Iterator it = root.getChildren().iterator(); it.hasNext(); ) { | |||
// dumpView((IStructureViewNode)it.next(), level++); | |||
// } | |||
// for (int i = 0; i < level; i++) { | |||
// System.out.print(' '); | |||
// } | |||
// } | |||
List rootNodes = new ArrayList(); | |||
getRoots(rootNode, rootNodes, view.getGlobalViewProperties().getHierarchy()); | |||
for (Iterator it = rootNodes.iterator(); it.hasNext(); ) { | |||
if (view.getGlobalViewProperties().getHierarchy().equals(StructureViewProperties.Hierarchy.CROSSCUTTING)) { | |||
treeNode.add(getCrosscuttingChildren((IProgramElement)it.next())); | |||
} else if (view.getGlobalViewProperties().getHierarchy().equals(StructureViewProperties.Hierarchy.INHERITANCE)) { | |||
treeNode.add(getInheritanceChildren( | |||
(IProgramElement)it.next(), | |||
view.getViewProperties().getRelations()) | |||
); | |||
} | |||
} | |||
return treeNode; | |||
} | |||
private void getRoots(IProgramElement rootNode, List roots, StructureViewProperties.Hierarchy hierarchy) { | |||
// if (rootNode != null && rootNode.getChildren() != null) { | |||
// for (Iterator it = rootNode.getChildren().iterator(); it.hasNext(); ) { | |||
// IProgramElement node = (IProgramElement)it.next(); | |||
// if (node instanceof IProgramElement) { | |||
// if (acceptNodeAsRoot((IProgramElement)node, hierarchy)) { | |||
// IProgramElement pNode = (IProgramElement)node; | |||
// List relations = pNode.getRelations(); | |||
// String delimiter = ""; | |||
// if (hierarchy.equals(StructureViewProperties.Hierarchy.CROSSCUTTING)) { | |||
// delimiter = "uses pointcut"; | |||
// } else if (hierarchy.equals(StructureViewProperties.Hierarchy.INHERITANCE)) { | |||
// delimiter = "inherits"; | |||
// } | |||
// if (relations != null && relations.toString().indexOf(delimiter) == -1) { | |||
// boolean found = false; | |||
// for (Iterator it2 = roots.iterator(); it2.hasNext(); ) { | |||
// if (((IProgramElement)it2.next()).equals(pNode)) found = true; | |||
// } | |||
// if (!found) roots.add(pNode); | |||
// } | |||
// } | |||
// } | |||
// getRoots(node, roots, hierarchy); | |||
// } | |||
// } | |||
} | |||
public boolean acceptNodeAsRoot(IProgramElement node, StructureViewProperties.Hierarchy hierarchy) { | |||
if (hierarchy.equals(StructureViewProperties.Hierarchy.CROSSCUTTING)) { | |||
return node.getKind().equals(IProgramElement.Kind.ADVICE) | |||
|| node.getKind().equals(IProgramElement.Kind.POINTCUT); | |||
} else if (hierarchy.equals(StructureViewProperties.Hierarchy.INHERITANCE)) { | |||
return node.getKind().equals(IProgramElement.Kind.CLASS); | |||
} else { | |||
return false; | |||
} | |||
} | |||
private IStructureViewNode getInheritanceChildren(IProgramElement node, List associations) { | |||
// IStructureViewNode treeNode = nodeFactory.createNode(node); | |||
// //StructureViewNode treeNode = new StructureViewNodeAdapter(node); | |||
// List relations = ((IProgramElement)node).getRelations(); | |||
throw new RuntimeException("unimplemented"); | |||
// if (relations != null) { | |||
// for (Iterator it = relations.iterator(); it.hasNext(); ) { | |||
// IRelationship relation = (IRelationship)it.next(); | |||
// if (relation.getName().equals("is inherited by")) { | |||
// for (Iterator it2 = relation.getTargets().iterator(); it2.hasNext(); ) { | |||
//// IProgramElement pNode = ((LinkNode)it2.next()).getProgramElementNode(); | |||
//// StructureViewNode newNode = getInheritanceChildren(pNode, associations); | |||
// StructureViewNode typeChildren = buildTree(newNode.getStructureNode(), associations); | |||
// for (int i = 0; i < typeChildren.getChildren().size(); i++) { | |||
// newNode.add((StructureViewNode)typeChildren.getChildren().get(i)); | |||
// } | |||
// treeNode.add(newNode); | |||
// } | |||
// } | |||
// } | |||
// } | |||
// return treeNode; | |||
} | |||
private IStructureViewNode getCrosscuttingChildren(IProgramElement node) { | |||
//StructureViewNodeAdapter treeNode = new StructureViewNodeAdapter(node); | |||
// IStructureViewNode treeNode = nodeFactory.createNode(node); | |||
// List relations = ((IProgramElement)node).getRelations(); | |||
throw new RuntimeException("unimplemented"); | |||
// if (relations != null) { | |||
// for (Iterator it = relations.iterator(); it.hasNext(); ) { | |||
// IRelationship relation = (IRelationship)it.next(); | |||
// if (relation.getName().equals("pointcut used by")) { | |||
// for (Iterator it2 = relation.getTargets().iterator(); it2.hasNext(); ) { | |||
// IProgramElement pNode = ((LinkNode)it2.next()).getProgramElementNode(); | |||
// StructureViewNode newNode = getCrosscuttingChildren(pNode); | |||
// for (Iterator it3 = pNode.getRelations().iterator(); it3.hasNext(); ) { | |||
// IRelationship relationNode = (IRelation)it3.next(); | |||
// if (relationNode.getName().indexOf("pointcut") == -1) { | |||
// newNode.add(getRelations(relationNode)); | |||
// } | |||
// } | |||
// treeNode.add(newNode); | |||
// } | |||
// } else if (relations.toString().indexOf("uses pointcut") == -1) { | |||
// for (Iterator it4 = relations.iterator(); it4.hasNext(); ) { | |||
// IRelation relationNode = (IRelationship)it4.next(); | |||
// if (relationNode.getName().indexOf("pointcut") == -1) { | |||
// treeNode.add(getRelations(relationNode)); | |||
// } | |||
// } | |||
// } | |||
// } | |||
// } | |||
// return treeNode; | |||
} | |||
// private IStructureViewNode buildTree(IProgramElement node, List associations) { | |||
// //StructureViewNode treeNode = new StructureViewNodeAdapter(node); | |||
// IStructureViewNode treeNode = nodeFactory.createNode(node); | |||
//// if (node instanceof IProgramElement) { | |||
// List relations = ((IProgramElement)node).getRelations(); | |||
// if (relations != null) { | |||
// for (Iterator it = relations.iterator(); it.hasNext(); ) { | |||
// IRelationship relationNode = (IRelationship)it.next(); | |||
// if (associations.contains(relationNode.toString())) { | |||
// treeNode.add(buildTree(relationNode, associations)); | |||
// } | |||
// } | |||
// } | |||
// } | |||
// if (node != null) { | |||
// List children = null; | |||
// children = node.getChildren(); | |||
// if (children != null) { | |||
// List childList = new ArrayList(); | |||
// for (Iterator itt = children.iterator(); itt.hasNext(); ) { | |||
// IProgramElement child = (IProgramElement)itt.next(); | |||
// if (child instanceof IProgramElement) { | |||
// IProgramElement progNode = (IProgramElement)child; | |||
//// if (progNode.getKind() != IProgramElement.Kind.CODE) { | |||
// childList.add(buildTree(child, associations)); | |||
//// } | |||
// } else { | |||
// childList.add(buildTree(child, associations)); | |||
// } | |||
// } | |||
// //sortNodes(childList); | |||
// for (Iterator it = childList.iterator(); it.hasNext(); ) { | |||
// treeNode.add((IStructureViewNode)it.next()); | |||
// } | |||
// } | |||
// | |||
// } | |||
// return treeNode; | |||
// } | |||
// private IStructureViewNode getRelations(IRelationship node) { | |||
// return null; | |||
// //StructureViewNode treeNode = new StructureViewNode(node); | |||
//// IStructureViewNode treeNode = nodeFactory.c(node); | |||
//// for (Iterator it = node.getTargets().iterator(); it.hasNext(); ) { | |||
//// treeNode.add( | |||
//// nodeFactory.createNode((IProgramElement)it.next()) | |||
//// ); | |||
//// } | |||
//// return treeNode; | |||
// } | |||
// | |||
// /** | |||
// * For debugging only. | |||
// */ | |||
// private void dumpView(IStructureViewNode root, int level) { | |||
// System.out.println(root.getStructureNode()); | |||
// for (Iterator it = root.getChildren().iterator(); it.hasNext(); ) { | |||
// dumpView((IStructureViewNode)it.next(), level++); | |||
// } | |||
// for (int i = 0; i < level; i++) { | |||
// System.out.print(' '); | |||
// } | |||
// } | |||
/** | |||
* Does not sort imports alphabetically. | |||
*/ | |||
private static final Comparator ALPHABETICAL_COMPARATOR = new Comparator() { | |||
public int compare(Object o1, Object o2) { | |||
IProgramElement sv1 = ((IStructureViewNode)o1).getStructureNode(); | |||
IProgramElement sv2 = ((IStructureViewNode)o2).getStructureNode(); | |||
if (sv1!=null && sv2!=null) { | |||
private static final Comparator<IStructureViewNode> ALPHABETICAL_COMPARATOR = new Comparator<IStructureViewNode>() { | |||
@Override | |||
public int compare(IStructureViewNode o1, IStructureViewNode o2) { | |||
IProgramElement sv1 = o1.getStructureNode(); | |||
IProgramElement sv2 = o2.getStructureNode(); | |||
if (sv1!=null && sv2!=null) { | |||
if (sv2.getKind() == IProgramElement.Kind.IMPORT_REFERENCE) return 1; | |||
if (sv1.getKind() == IProgramElement.Kind.IMPORT_REFERENCE) return -1; | |||
return sv1.getName().compareTo(sv2.getName()); | |||
} else { | |||
return 0; | |||
} | |||
} | |||
}; | |||
private static final Comparator DECLARATIONAL_COMPARATOR = new Comparator() { | |||
public int compare(Object o1, Object o2) { | |||
IProgramElement sv1 = ((IStructureViewNode)o1).getStructureNode(); | |||
IProgramElement sv2 = ((IStructureViewNode)o2).getStructureNode(); | |||
if (sv1!=null && sv2!=null) { | |||
if (sv2.getKind() == IProgramElement.Kind.IMPORT_REFERENCE) return 1; | |||
} else { | |||
return 0; | |||
} | |||
} | |||
}; | |||
private static final Comparator<IStructureViewNode> DECLARATIONAL_COMPARATOR = new Comparator<IStructureViewNode>() { | |||
@Override | |||
public int compare(IStructureViewNode o1, IStructureViewNode o2) { | |||
IProgramElement sv1 = o1.getStructureNode(); | |||
IProgramElement sv2 = o2.getStructureNode(); | |||
if (sv1!=null && sv2!=null) { | |||
if (sv2.getKind() == IProgramElement.Kind.IMPORT_REFERENCE) return 1; | |||
if (sv1.getKind() == IProgramElement.Kind.IMPORT_REFERENCE) return -1; | |||
if (sv1.getSourceLocation() == null || sv2.getSourceLocation() == null) { | |||
return 0; | |||
} else if (sv1.getSourceLocation().getLine() < sv2.getSourceLocation().getLine()) { | |||
return -1; | |||
} else { | |||
return 1; | |||
} | |||
} else { | |||
return 0; | |||
} | |||
} | |||
}; | |||
if (sv1.getSourceLocation() == null || sv2.getSourceLocation() == null) { | |||
return 0; | |||
} else if (sv1.getSourceLocation().getLine() < sv2.getSourceLocation().getLine()) { | |||
return -1; | |||
} else { | |||
return 1; | |||
} | |||
} else { | |||
return 0; | |||
} | |||
} | |||
}; | |||
} | |||
// private boolean acceptNode(ProgramElementNode node) { |
@@ -1,19 +1,19 @@ | |||
/* ******************************************************************* | |||
* Copyright (c) 1999-2001 Xerox Corporation, | |||
* Copyright (c) 1999-2001 Xerox Corporation, | |||
* 2002 Palo Alto Research Center, Incorporated (PARC). | |||
* All rights reserved. | |||
* This program and the accompanying materials are made available | |||
* under the terms of the Eclipse Public License v1.0 | |||
* which accompanies this distribution and is available at | |||
* http://www.eclipse.org/legal/epl-v10.html | |||
* | |||
* Contributors: | |||
* All rights reserved. | |||
* This program and the accompanying materials are made available | |||
* under the terms of the Eclipse Public License v1.0 | |||
* which accompanies this distribution and is available at | |||
* http://www.eclipse.org/legal/epl-v10.html | |||
* | |||
* Contributors: | |||
* Xerox/PARC initial implementation | |||
* Helen Hawkins Converted to new interface (bug 148190) | |||
* Helen Hawkins Converted to new interface (bug 148190) | |||
* ******************************************************************/ | |||
package org.aspectj.ajde.ui.internal; | |||
import java.io.File; | |||
@@ -33,121 +33,129 @@ import org.aspectj.bridge.Message; | |||
import org.aspectj.util.LangUtil; | |||
public class UserPreferencesStore implements UserPreferencesAdapter { | |||
public static final String FILE_NAME = "/.ajbrowser"; | |||
private static final String VALUE_SEP = ";"; | |||
private Properties properties = new Properties(); | |||
private boolean persist = true; | |||
public static final String FILE_NAME = "/.ajbrowser"; | |||
private static final String VALUE_SEP = ";"; | |||
private Properties properties = new Properties(); | |||
private boolean persist = true; | |||
public UserPreferencesStore() { | |||
this(true); | |||
this(true); | |||
} | |||
public UserPreferencesStore(boolean loadDefault) { | |||
persist = loadDefault; | |||
if (persist) { | |||
loadProperties(getPropertiesFilePath()); | |||
} | |||
} | |||
@Override | |||
public String getProjectPreference(String name) { | |||
return properties.getProperty(name); | |||
} | |||
@Override | |||
public List<String> getProjectMultivalPreference(String name) { | |||
List<String> values = new ArrayList<>(); | |||
String valuesString = properties.getProperty(name); | |||
if (valuesString != null && !valuesString.trim().equals("")) { | |||
StringTokenizer st = new StringTokenizer(valuesString, VALUE_SEP); | |||
while (st.hasMoreTokens()) { | |||
values.add(st.nextToken()); | |||
} | |||
} | |||
return values; | |||
} | |||
@Override | |||
public void setProjectPreference(String name, String value) { | |||
properties.setProperty(name, value); | |||
saveProperties(); | |||
} | |||
@Override | |||
public void setProjectMultivalPreference(String name, List values) { | |||
String valuesString = ""; | |||
for (Iterator it = values.iterator(); it.hasNext(); ) { | |||
valuesString += (String)it.next() + ';'; | |||
} | |||
properties.setProperty(name, valuesString); | |||
saveProperties(); | |||
} | |||
public static String getPropertiesFilePath() { | |||
String path = System.getProperty("user.home"); | |||
if (path == null) { | |||
path = "."; | |||
} | |||
return path + FILE_NAME; | |||
} | |||
public UserPreferencesStore(boolean loadDefault) { | |||
persist = loadDefault; | |||
if (persist) { | |||
loadProperties(getPropertiesFilePath()); | |||
} | |||
} | |||
public String getProjectPreference(String name) { | |||
return properties.getProperty(name); | |||
} | |||
public List getProjectMultivalPreference(String name) { | |||
List values = new ArrayList(); | |||
String valuesString = properties.getProperty(name); | |||
if (valuesString != null && !valuesString.trim().equals("")) { | |||
StringTokenizer st = new StringTokenizer(valuesString, VALUE_SEP); | |||
while (st.hasMoreTokens()) { | |||
values.add(st.nextToken()); | |||
} | |||
} | |||
return values; | |||
} | |||
public void setProjectPreference(String name, String value) { | |||
properties.setProperty(name, value); | |||
saveProperties(); | |||
} | |||
public void setProjectMultivalPreference(String name, List values) { | |||
String valuesString = ""; | |||
for (Iterator it = values.iterator(); it.hasNext(); ) { | |||
valuesString += (String)it.next() + ';'; | |||
} | |||
properties.setProperty(name, valuesString); | |||
saveProperties(); | |||
} | |||
public static String getPropertiesFilePath() { | |||
String path = System.getProperty("user.home"); | |||
if (path == null) { | |||
path = "."; | |||
} | |||
return path + FILE_NAME; | |||
} | |||
@Override | |||
public String getGlobalPreference(String name) { | |||
return getProjectPreference(name); | |||
} | |||
@Override | |||
public List getGlobalMultivalPreference(String name) { | |||
return getProjectMultivalPreference(name); | |||
} | |||
@Override | |||
public void setGlobalPreference(String name, String value) { | |||
setProjectPreference(name, value); | |||
} | |||
@Override | |||
public void setGlobalMultivalPreference(String name, List values) { | |||
setProjectMultivalPreference(name, values); | |||
} | |||
private void loadProperties(String path) { | |||
if (LangUtil.isEmpty(path)) { | |||
return; | |||
} | |||
File file = new File(path); | |||
if (!file.canRead()) { | |||
return; | |||
} | |||
FileInputStream in = null; | |||
try { | |||
path = getPropertiesFilePath(); | |||
in = new FileInputStream(file); | |||
properties.load(in); | |||
} catch (IOException ioe) { | |||
Message msg = new Message("Error reading properties from " + path,IMessage.ERROR,ioe,null); | |||
Ajde.getDefault().getMessageHandler().handleMessage(msg); | |||
} finally { | |||
if (null != in) { | |||
try { | |||
in.close(); | |||
} catch (IOException e) { | |||
// ignore | |||
} | |||
} | |||
} | |||
if (LangUtil.isEmpty(path)) { | |||
return; | |||
} | |||
File file = new File(path); | |||
if (!file.canRead()) { | |||
return; | |||
} | |||
FileInputStream in = null; | |||
try { | |||
path = getPropertiesFilePath(); | |||
in = new FileInputStream(file); | |||
properties.load(in); | |||
} catch (IOException ioe) { | |||
Message msg = new Message("Error reading properties from " + path,IMessage.ERROR,ioe,null); | |||
Ajde.getDefault().getMessageHandler().handleMessage(msg); | |||
} finally { | |||
if (null != in) { | |||
try { | |||
in.close(); | |||
} catch (IOException e) { | |||
// ignore | |||
} | |||
} | |||
} | |||
} | |||
public void saveProperties() { | |||
if (!persist) return; | |||
FileOutputStream out = null; | |||
String path = null; | |||
try { | |||
path = getPropertiesFilePath(); | |||
out = new FileOutputStream(path); | |||
properties.store(out, "AJDE Settings"); | |||
} catch (IOException ioe) { | |||
Message msg = new Message("Error writing properties to " + path,IMessage.ERROR,ioe,null); | |||
Ajde.getDefault().getMessageHandler().handleMessage(msg); | |||
} finally { | |||
if (null != out) { | |||
try { | |||
out.close(); | |||
} catch (IOException e) { | |||
// ignore | |||
} | |||
} | |||
} | |||
} | |||
public void saveProperties() { | |||
if (!persist) return; | |||
FileOutputStream out = null; | |||
String path = null; | |||
try { | |||
path = getPropertiesFilePath(); | |||
out = new FileOutputStream(path); | |||
properties.store(out, "AJDE Settings"); | |||
} catch (IOException ioe) { | |||
Message msg = new Message("Error writing properties to " + path,IMessage.ERROR,ioe,null); | |||
Ajde.getDefault().getMessageHandler().handleMessage(msg); | |||
} finally { | |||
if (null != out) { | |||
try { | |||
out.close(); | |||
} catch (IOException e) { | |||
// ignore | |||
} | |||
} | |||
} | |||
} | |||
} |
@@ -1,11 +1,11 @@ | |||
/******************************************************************** | |||
* Copyright (c) 2007 Contributors. All rights reserved. | |||
* This program and the accompanying materials are made available | |||
* under the terms of the Eclipse Public License v1.0 | |||
* which accompanies this distribution and is available at | |||
* http://eclipse.org/legal/epl-v10.html | |||
* | |||
* Contributors: IBM Corporation - initial API and implementation | |||
* Copyright (c) 2007 Contributors. All rights reserved. | |||
* This program and the accompanying materials are made available | |||
* under the terms of the Eclipse Public License v1.0 | |||
* which accompanies this distribution and is available at | |||
* http://eclipse.org/legal/epl-v10.html | |||
* | |||
* Contributors: IBM Corporation - initial API and implementation | |||
* Helen Hawkins - initial version (bug 148190) | |||
*******************************************************************/ | |||
package org.aspectj.ajde.ui.javaoptions; | |||
@@ -14,9 +14,7 @@ import java.awt.BorderLayout; | |||
import java.awt.Color; | |||
import java.io.IOException; | |||
import java.util.HashMap; | |||
import java.util.Iterator; | |||
import java.util.Map; | |||
import java.util.Map.Entry; | |||
import java.util.Set; | |||
import javax.swing.BorderFactory; | |||
@@ -37,9 +35,9 @@ import org.aspectj.ajde.ui.swing.OptionsPanel; | |||
public class JavaComplianceOptionsPanel extends OptionsPanel { | |||
private final String[] complianceLevels = new String[] {JavaOptions.VERSION_13, JavaOptions.VERSION_14, JavaOptions.VERSION_15, JavaOptions.VERSION_16}; | |||
private static final long serialVersionUID = 4491319302490183151L; | |||
private JPanel parentPanel; | |||
private Border complianceEtchedBorder; | |||
@@ -47,11 +45,11 @@ public class JavaComplianceOptionsPanel extends OptionsPanel { | |||
private Border complianceCompoundBorder; | |||
private JPanel compliancePanel; | |||
private Box complianceBox = Box.createVerticalBox(); | |||
private JavaBuildOptions javaBuildOptions; | |||
private Map/*String --> JComboBox*/ complianceComboBoxes = new HashMap(); | |||
private Map<String,JComboBox<String>> complianceComboBoxes = new HashMap<>(); | |||
public JavaComplianceOptionsPanel(JavaBuildOptions javaBuildOptions) { | |||
this.javaBuildOptions = javaBuildOptions; | |||
try { | |||
@@ -62,20 +60,21 @@ public class JavaComplianceOptionsPanel extends OptionsPanel { | |||
} | |||
} | |||
@Override | |||
public void loadOptions() throws IOException { | |||
createComplianceContents(); | |||
} | |||
public void saveOptions() throws IOException { | |||
Set s = complianceComboBoxes.entrySet(); | |||
for (Iterator iterator = s.iterator(); iterator.hasNext();) { | |||
Map.Entry entry = (Entry) iterator.next(); | |||
String javaOption = (String) entry.getKey(); | |||
JComboBox combo = (JComboBox)entry.getValue(); | |||
@Override | |||
public void saveOptions() throws IOException { | |||
Set<Map.Entry<String,JComboBox<String>>> s = complianceComboBoxes.entrySet(); | |||
for (Map.Entry<String,JComboBox<String>> entry : s) { | |||
String javaOption = entry.getKey(); | |||
JComboBox<String> combo = entry.getValue(); | |||
String value = (String) combo.getSelectedItem(); | |||
javaBuildOptions.setOption(javaOption, value); | |||
} | |||
} | |||
} | |||
private void jbInit() throws Exception { | |||
this.setLayout(new BorderLayout()); | |||
@@ -95,32 +94,32 @@ public class JavaComplianceOptionsPanel extends OptionsPanel { | |||
private void createComplianceEntry(String labelText, String javaOptionToSet) { | |||
JPanel panel = new JPanel(); | |||
panel.setLayout(new BorderLayout()); | |||
JLabel label = new JLabel(); | |||
label.setFont(new java.awt.Font("Dialog", 0, 11)); | |||
label.setText(labelText); | |||
panel.add(label,BorderLayout.WEST); | |||
JComboBox levels = new JComboBox(complianceLevels); | |||
String value = (String) javaBuildOptions.getJavaBuildOptionsMap().get(javaOptionToSet); | |||
JComboBox<String> levels = new JComboBox<>(complianceLevels); | |||
String value = javaBuildOptions.getJavaBuildOptionsMap().get(javaOptionToSet); | |||
if (value == null) { | |||
// default to 1.5 | |||
levels.setSelectedIndex(2); | |||
} else if (value.equals(JavaOptions.VERSION_13)) { | |||
levels.setSelectedIndex(0); | |||
} else if (value.equals(JavaOptions.VERSION_14)){ | |||
levels.setSelectedIndex(1); | |||
levels.setSelectedIndex(1); | |||
} else if (value.equals(JavaOptions.VERSION_15)){ | |||
levels.setSelectedIndex(2); | |||
levels.setSelectedIndex(2); | |||
} else if (value.equals(JavaOptions.VERSION_16)){ | |||
levels.setSelectedIndex(3); | |||
} | |||
levels.setSelectedIndex(3); | |||
} | |||
panel.add(levels,BorderLayout.EAST); | |||
complianceBox.add(panel,null); | |||
complianceComboBoxes.put(javaOptionToSet,levels); | |||
} | |||
private void createBorders() { | |||
complianceEtchedBorder = BorderFactory.createEtchedBorder(Color.white, new Color(156, 156, 158)); | |||
complianceTitleBorder = new TitledBorder(complianceEtchedBorder, "Compliance Options"); | |||
@@ -128,11 +127,11 @@ public class JavaComplianceOptionsPanel extends OptionsPanel { | |||
BorderFactory.createEmptyBorder(5, 5, 5, 5)); | |||
complianceTitleBorder.setTitleFont(new java.awt.Font("Dialog", 0, 11)); | |||
} | |||
private void addBordersToPanel() { | |||
parentPanel = new JPanel(); | |||
parentPanel.setLayout(new BorderLayout()); | |||
compliancePanel = new JPanel(); | |||
compliancePanel.setBorder(complianceCompoundBorder); | |||
@@ -1,11 +1,11 @@ | |||
/******************************************************************** | |||
* Copyright (c) 2007 Contributors. All rights reserved. | |||
* This program and the accompanying materials are made available | |||
* under the terms of the Eclipse Public License v1.0 | |||
* which accompanies this distribution and is available at | |||
* http://eclipse.org/legal/epl-v10.html | |||
* | |||
* Contributors: IBM Corporation - initial API and implementation | |||
* Copyright (c) 2007 Contributors. All rights reserved. | |||
* This program and the accompanying materials are made available | |||
* under the terms of the Eclipse Public License v1.0 | |||
* which accompanies this distribution and is available at | |||
* http://eclipse.org/legal/epl-v10.html | |||
* | |||
* Contributors: IBM Corporation - initial API and implementation | |||
* Helen Hawkins - initial version (bug 148190) | |||
*******************************************************************/ | |||
package org.aspectj.ajde.ui.javaoptions; | |||
@@ -14,9 +14,7 @@ import java.awt.BorderLayout; | |||
import java.awt.Color; | |||
import java.io.IOException; | |||
import java.util.HashMap; | |||
import java.util.Iterator; | |||
import java.util.Map; | |||
import java.util.Map.Entry; | |||
import java.util.Set; | |||
import javax.swing.BorderFactory; | |||
@@ -38,9 +36,9 @@ public class JavaDebugOptionsPanel extends OptionsPanel { | |||
private final String[] debugOptions = new String[] {JavaOptions.GENERATE,JavaOptions.DO_NOT_GENERATE}; | |||
private final String[] preserveOptions = new String[] {JavaOptions.PRESERVE,JavaOptions.OPTIMIZE}; | |||
private static final long serialVersionUID = 4491319302490183151L; | |||
private JPanel parentPanel; | |||
private Border debugEtchedBorder; | |||
@@ -48,11 +46,11 @@ public class JavaDebugOptionsPanel extends OptionsPanel { | |||
private Border debugCompoundBorder; | |||
private JPanel debugPanel; | |||
private Box debugBox = Box.createVerticalBox(); | |||
private JavaBuildOptions javaBuildOptions; | |||
private Map/*String --> JComboBox*/ debugComboBoxes = new HashMap(); | |||
private Map<String,JComboBox<String>> debugComboBoxes = new HashMap(); | |||
public JavaDebugOptionsPanel(JavaBuildOptions javaBuildOptions) { | |||
this.javaBuildOptions = javaBuildOptions; | |||
try { | |||
@@ -63,20 +61,21 @@ public class JavaDebugOptionsPanel extends OptionsPanel { | |||
} | |||
} | |||
@Override | |||
public void loadOptions() throws IOException { | |||
createDebugContents(); | |||
} | |||
public void saveOptions() throws IOException { | |||
Set s = debugComboBoxes.entrySet(); | |||
for (Iterator iterator = s.iterator(); iterator.hasNext();) { | |||
Map.Entry entry = (Entry) iterator.next(); | |||
String javaOption = (String) entry.getKey(); | |||
JComboBox combo = (JComboBox)entry.getValue(); | |||
@Override | |||
public void saveOptions() throws IOException { | |||
Set<Map.Entry<String,JComboBox<String>>> s = debugComboBoxes.entrySet(); | |||
for (Map.Entry<String,JComboBox<String>> entry : s) { | |||
String javaOption = entry.getKey(); | |||
JComboBox<String> combo = entry.getValue(); | |||
String value = (String) combo.getSelectedItem(); | |||
javaBuildOptions.setOption(javaOption, value); | |||
} | |||
} | |||
} | |||
private void jbInit() throws Exception { | |||
this.setLayout(new BorderLayout()); | |||
@@ -88,7 +87,7 @@ public class JavaDebugOptionsPanel extends OptionsPanel { | |||
private void createDebugContents() { | |||
createDebugEntry("Add line number attributes to generated class files",JavaOptions.DEBUG_LINES); | |||
createDebugEntry("Add source file name to generated class file",JavaOptions.DEBUG_SOURCE); | |||
createDebugEntry("Add variable attributes to generated class files",JavaOptions.DEBUG_VARS); | |||
createDebugEntry("Add variable attributes to generated class files",JavaOptions.DEBUG_VARS); | |||
createDebugEntry("Preserve unused (never read) local variables",JavaOptions.PRESERVE_ALL_LOCALS); | |||
debugPanel.add(debugBox); | |||
} | |||
@@ -96,48 +95,48 @@ public class JavaDebugOptionsPanel extends OptionsPanel { | |||
private void createDebugEntry(String labelText, String javaOptionToSet) { | |||
JPanel panel = new JPanel(); | |||
panel.setLayout(new BorderLayout()); | |||
JLabel label = new JLabel(); | |||
label.setFont(new java.awt.Font("Dialog", 0, 11)); | |||
label.setText(labelText); | |||
panel.add(label,BorderLayout.WEST); | |||
JComboBox debug = null; | |||
JComboBox<String> debug = null; | |||
if (javaOptionToSet.equals(JavaOptions.PRESERVE_ALL_LOCALS)) { | |||
debug = new JComboBox(preserveOptions); | |||
String value = (String) javaBuildOptions.getJavaBuildOptionsMap().get(javaOptionToSet); | |||
debug = new JComboBox<String>(preserveOptions); | |||
String value = javaBuildOptions.getJavaBuildOptionsMap().get(javaOptionToSet); | |||
if (value.equals(JavaOptions.PRESERVE)) { | |||
debug.setSelectedIndex(0); | |||
} else { | |||
debug.setSelectedIndex(1); | |||
} | |||
debug.setSelectedIndex(1); | |||
} | |||
} else { | |||
debug = new JComboBox(debugOptions); | |||
String value = (String) javaBuildOptions.getJavaBuildOptionsMap().get(javaOptionToSet); | |||
debug = new JComboBox<String>(debugOptions); | |||
String value = javaBuildOptions.getJavaBuildOptionsMap().get(javaOptionToSet); | |||
if (value.equals(JavaOptions.GENERATE)) { | |||
debug.setSelectedIndex(0); | |||
} else { | |||
debug.setSelectedIndex(1); | |||
} | |||
} | |||
debug.setSelectedIndex(1); | |||
} | |||
} | |||
panel.add(debug,BorderLayout.EAST); | |||
debugBox.add(panel,null); | |||
debugComboBoxes.put(javaOptionToSet,debug); | |||
debugComboBoxes.put(javaOptionToSet,debug); | |||
} | |||
private void createBorders() { | |||
private void createBorders() { | |||
debugEtchedBorder = BorderFactory.createEtchedBorder(Color.white, new Color(156, 156, 158)); | |||
debugTitleBorder = new TitledBorder(debugEtchedBorder, "Debug Options"); | |||
debugCompoundBorder = BorderFactory.createCompoundBorder(debugTitleBorder, | |||
BorderFactory.createEmptyBorder(5, 5, 5, 5)); | |||
debugTitleBorder.setTitleFont(new java.awt.Font("Dialog", 0, 11)); | |||
} | |||
private void addBordersToPanel() { | |||
parentPanel = new JPanel(); | |||
parentPanel.setLayout(new BorderLayout()); | |||
debugPanel = new JPanel(); | |||
debugPanel.setBorder(debugCompoundBorder); | |||
@@ -1,12 +1,12 @@ | |||
/* ******************************************************************* | |||
* Copyright (c) 2003 Contributors | |||
* All rights reserved. | |||
* This program and the accompanying materials are made available | |||
* under the terms of the Eclipse Public License v1.0 | |||
* which accompanies this distribution and is available at | |||
* http://www.eclipse.org/legal/epl-v10.html | |||
* | |||
* Contributors: | |||
* All rights reserved. | |||
* This program and the accompanying materials are made available | |||
* under the terms of the Eclipse Public License v1.0 | |||
* which accompanies this distribution and is available at | |||
* http://www.eclipse.org/legal/epl-v10.html | |||
* | |||
* Contributors: | |||
* Wes Isberg initial implementation | |||
* ******************************************************************/ | |||
@@ -18,17 +18,13 @@ import java.util.Collections; | |||
import java.util.HashMap; | |||
import java.util.Map; | |||
import junit.framework.Test; | |||
import junit.framework.TestCase; | |||
import junit.framework.TestResult; | |||
import junit.framework.TestSuite; | |||
import org.aspectj.ajdt.internal.core.builder.AjState; | |||
import org.aspectj.bridge.IMessage; | |||
import org.aspectj.bridge.IMessageHolder; | |||
import org.aspectj.bridge.MessageHandler; | |||
import org.aspectj.bridge.MessageUtil; | |||
import org.aspectj.testing.harness.bridge.AjcTest; | |||
import org.aspectj.testing.harness.bridge.AjcTest.Spec; | |||
import org.aspectj.testing.harness.bridge.RunSpecIterator; | |||
import org.aspectj.testing.harness.bridge.Sandbox; | |||
import org.aspectj.testing.harness.bridge.Validator; | |||
@@ -36,6 +32,11 @@ import org.aspectj.testing.run.IRunIterator; | |||
import org.aspectj.testing.run.RunStatus; | |||
import org.aspectj.testing.run.Runner; | |||
import junit.framework.Test; | |||
import junit.framework.TestCase; | |||
import junit.framework.TestResult; | |||
import junit.framework.TestSuite; | |||
/* | |||
* Adapt Harness tests to JUnit driver. This renders suite files as TestSuite | |||
* and AjcTest as TestCase. When run, aborts are reported as error and fails as | |||
@@ -47,336 +48,344 @@ import org.aspectj.testing.run.Runner; | |||
* the test. | |||
*/ | |||
public class AjctestsAdapter extends TestSuite { | |||
public static final String VERBOSE_NAME = AjctestsAdapter.class.getName() | |||
+ ".VERBOSE"; | |||
private static final boolean VERBOSE = HarnessJUnitUtil | |||
.readBooleanSystemProperty(VERBOSE_NAME); | |||
/** | |||
* Factory to make and populate suite without options. | |||
* | |||
* @param suitePath | |||
* the String path to a harness suite file | |||
* @return AjctestJUnitSuite populated with tests | |||
*/ | |||
public static AjctestsAdapter make(String suitePath) { | |||
return make(suitePath, null); | |||
} | |||
/** | |||
* Factory to make and populate suite | |||
* | |||
* @param suitePath | |||
* the String path to a harness suite file | |||
* @param options | |||
* the String[] options to use when creating tests | |||
* @return AjctestJUnitSuite populated with tests | |||
*/ | |||
public static AjctestsAdapter make(String suitePath, String[] options) { | |||
AjctestsAdapter result = new AjctestsAdapter(suitePath, options); | |||
AjcTest.Spec[] tests = AjcTest.Suite.getTests(result.getSpec()); | |||
if (VERBOSE) { | |||
log("loading " + tests.length + " tests in " + suitePath); | |||
} | |||
for (int i = 0; i < tests.length; i++) { | |||
AjcTest.Spec ajcTest = tests[i]; | |||
result.addTest(new AjcTestSpecAsTest(ajcTest, result)); | |||
} | |||
return result; | |||
} | |||
private static void log(String message) { | |||
System.err.println(message); | |||
System.err.flush(); | |||
} | |||
private final String suitePath; | |||
private final String[] options; | |||
private AjcTest.Suite.Spec spec; | |||
private Runner runner; | |||
private Validator validator; | |||
private IMessageHolder holder; | |||
private Sandbox sandbox; | |||
private File suiteDir; | |||
private String name; | |||
private AjctestsAdapter(String suitePath, String[] options) { | |||
this.suitePath = suitePath; | |||
String[] opts = new String[0]; | |||
if (!HarnessJUnitUtil.isEmpty(options)) { | |||
opts = new String[options.length]; | |||
System.arraycopy(options, 0, opts, 0, opts.length); | |||
} | |||
this.options = opts; | |||
} | |||
public void addTest(Test test) { | |||
if (!(test instanceof AjcTestSpecAsTest)) { | |||
String m = "expecting AjcTestSpecAsTest, got " | |||
+ (null == test ? "null test" : test.getClass().getName() | |||
+ ": " + test); | |||
throw new IllegalArgumentException(m); | |||
} | |||
super.addTest(test); | |||
} | |||
public void addTestSuite(Class testClass) { | |||
throw new Error("unimplemented"); | |||
} | |||
public String getName() { | |||
if (null == name) { | |||
name = HarnessJUnitUtil.cleanTestName(suitePath | |||
+ Arrays.asList(options)); | |||
} | |||
return name; | |||
} | |||
/** | |||
* Callback from test to run it using suite-wide holder, etc. The caller is | |||
* responsible for calling result.startTest(test) and result.endTest(test); | |||
* | |||
* @param test | |||
* the AjcTestSpecAsTest to run | |||
* @param result | |||
* the TestResult for any result messages (may be null) | |||
*/ | |||
protected void runTest(AjcTestSpecAsTest test, TestResult result) { | |||
final Runner runner = getRunner(); | |||
final Sandbox sandbox = getSandbox(); | |||
final Validator validator = getValidator(); | |||
int numIncomplete = 0; | |||
final RunStatus status = new RunStatus(new MessageHandler(), runner); | |||
status.setIdentifier(test.toString()); | |||
try { | |||
IMessageHolder holder = getHolder(); | |||
holder.clearMessages(); | |||
IRunIterator steps = test.spec.makeRunIterator(sandbox, validator); | |||
if (0 < holder.numMessages(IMessage.ERROR, true)) { | |||
MessageUtil.handleAll(status, holder, IMessage.INFO, true, | |||
false); | |||
} else { | |||
runner.runIterator(steps, status, null); | |||
} | |||
if (steps instanceof RunSpecIterator) { | |||
numIncomplete = ((RunSpecIterator) steps).getNumIncomplete(); | |||
} | |||
} finally { | |||
try { | |||
// reportResult handles null TestResult | |||
HarnessJUnitUtil | |||
.reportResult(null, status, test, numIncomplete); | |||
} finally { | |||
validator.deleteTempFiles(true); | |||
} | |||
} | |||
} | |||
private File getSuiteDir() { | |||
if (null == suiteDir) { | |||
File file = new File(suitePath); | |||
file = file.getParentFile(); | |||
if (null == file) { | |||
file = new File("."); | |||
} | |||
suiteDir = file; | |||
} | |||
return suiteDir; | |||
} | |||
private Validator getValidator() { | |||
if (null == validator) { | |||
validator = new Validator(getHolder()); | |||
// XXX lock if keepTemp? | |||
} | |||
return validator; | |||
} | |||
private Runner getRunner() { | |||
if (null == runner) { | |||
runner = new Runner(); | |||
} | |||
return runner; | |||
} | |||
private IMessageHolder getHolder() { | |||
if (null == holder) { | |||
holder = new MessageHandler(); | |||
} | |||
return holder; | |||
} | |||
private AjcTest.Suite.Spec getSpec() { | |||
if (null == spec) { | |||
IMessageHolder holder = getHolder(); | |||
spec = HarnessJUnitUtil.getSuiteSpec(suitePath, options, | |||
getHolder()); | |||
if (VERBOSE && holder.hasAnyMessage(null, true)) { | |||
MessageUtil.print(System.err, holder, "skip ", | |||
MessageUtil.MESSAGE_MOST); | |||
} | |||
holder.clearMessages(); | |||
} | |||
return spec; | |||
} | |||
private Sandbox getSandbox() { | |||
if (null == sandbox) { | |||
sandbox = new Sandbox(spec.getSuiteDirFile(), getValidator()); | |||
} | |||
return sandbox; | |||
} | |||
/** | |||
* Wrap AjcTest.Spec for lookup by description | |||
* | |||
* @author wes | |||
*/ | |||
public static class SpecTests { | |||
private static final HashMap TESTS = new HashMap(); | |||
// private static void putSpecTestsFor(String id, SpecTests tests) { | |||
// TESTS.put(id, tests); | |||
// } | |||
private static SpecTests getSpecTestsFor(String id) { | |||
SpecTests result = (SpecTests) TESTS.get(id); | |||
if (null == result) { | |||
throw new Error("no tests found for " + id); | |||
} | |||
return result; | |||
} | |||
// ------------------------------------ | |||
final AjctestsAdapter mAjctestsAdapter; | |||
private final Map mDescriptionToAjcTestSpec; | |||
// ------------------------------------ | |||
private SpecTests(AjctestsAdapter ajctestsAdapter, AjcTest.Spec[] tests) { | |||
mAjctestsAdapter = ajctestsAdapter; | |||
Map map = new HashMap(); | |||
for (int i = 0; i < tests.length; i++) { | |||
map.put(tests[i].getDescription(), tests[i]); | |||
} | |||
mDescriptionToAjcTestSpec = Collections.unmodifiableMap(map); | |||
} | |||
/** | |||
* @param description | |||
* the String description of the test | |||
* @throws IllegalArgumentException | |||
* if testName is not found | |||
*/ | |||
protected void runTest(String description) { | |||
AjcTest.Spec spec = getSpec(description); | |||
AjctestsAdapter.AjcTestSpecAsTest ajcTestAsSpec = new AjctestsAdapter.AjcTestSpecAsTest( | |||
spec, mAjctestsAdapter); | |||
// runTest handles null TestResult | |||
mAjctestsAdapter.runTest(ajcTestAsSpec, null); | |||
} | |||
/** | |||
* @param description | |||
* the String description of the test | |||
* @throws IllegalArgumentException | |||
* if testName is not found | |||
*/ | |||
private AjcTest.Spec getSpec(String description) { | |||
AjcTest.Spec spec = (AjcTest.Spec) mDescriptionToAjcTestSpec | |||
.get(description); | |||
if (null == spec) { | |||
throw new IllegalArgumentException("no test for " + description); | |||
} | |||
return spec; | |||
} | |||
/** | |||
* makeUsingTestClass(..) extends this to create TestCase with | |||
* test_{name} for each test case. | |||
*/ | |||
public static class TestClass extends TestCase { | |||
public TestClass() { | |||
} | |||
private SpecTests mTests; | |||
/** | |||
* Called by code generated in makeUsingTestClass(..) | |||
* | |||
* @param description | |||
* the String identifier of the test stored in SpecTests | |||
* mTests. | |||
* @throws Error | |||
* on first and later uses if getTestsFor() returns | |||
* null. | |||
*/ | |||
public final void runTest(String description) { | |||
if (null == mTests) { | |||
String classname = getClass().getName(); | |||
mTests = getSpecTestsFor(classname); | |||
} | |||
mTests.runTest(description); | |||
} | |||
} | |||
} | |||
/** Wrap AjcTest.Spec as a TestCase. Run by delegation to suite */ | |||
private static class AjcTestSpecAsTest extends TestCase implements | |||
HarnessJUnitUtil.IHasAjcSpec { | |||
// this could implement Test, but Ant batchtest fails to pull name | |||
final String name; | |||
final AjcTest.Spec spec; | |||
AjctestsAdapter suite; | |||
AjcTestSpecAsTest(AjcTest.Spec spec, AjctestsAdapter suite) { | |||
super(HarnessJUnitUtil.cleanTestName(spec.getDescription())); | |||
this.name = HarnessJUnitUtil.cleanTestName(spec.getDescription()); | |||
this.suite = suite; | |||
this.spec = spec; | |||
spec.setSuiteDir(suite.getSuiteDir()); | |||
} | |||
public int countTestCases() { | |||
return 1; | |||
} | |||
public AjcTest.Spec getAjcTestSpec() { | |||
return spec; | |||
} | |||
public void run(TestResult result) { | |||
if (null == suite) { | |||
throw new Error("need to re-init"); | |||
} | |||
try { | |||
AjState.FORCE_INCREMENTAL_DURING_TESTING = true; | |||
result.startTest(this); | |||
suite.runTest(this, result); | |||
} finally { | |||
result.endTest(this); | |||
suite = null; | |||
AjState.FORCE_INCREMENTAL_DURING_TESTING = false; | |||
} | |||
} | |||
public String getName() { | |||
return name; | |||
} | |||
public String toString() { | |||
return name; | |||
} | |||
} | |||
public static final String VERBOSE_NAME = AjctestsAdapter.class.getName() | |||
+ ".VERBOSE"; | |||
private static final boolean VERBOSE = HarnessJUnitUtil | |||
.readBooleanSystemProperty(VERBOSE_NAME); | |||
/** | |||
* Factory to make and populate suite without options. | |||
* | |||
* @param suitePath | |||
* the String path to a harness suite file | |||
* @return AjctestJUnitSuite populated with tests | |||
*/ | |||
public static AjctestsAdapter make(String suitePath) { | |||
return make(suitePath, null); | |||
} | |||
/** | |||
* Factory to make and populate suite | |||
* | |||
* @param suitePath | |||
* the String path to a harness suite file | |||
* @param options | |||
* the String[] options to use when creating tests | |||
* @return AjctestJUnitSuite populated with tests | |||
*/ | |||
public static AjctestsAdapter make(String suitePath, String[] options) { | |||
AjctestsAdapter result = new AjctestsAdapter(suitePath, options); | |||
AjcTest.Spec[] tests = AjcTest.Suite.getTests(result.getSpec()); | |||
if (VERBOSE) { | |||
log("loading " + tests.length + " tests in " + suitePath); | |||
} | |||
for (Spec ajcTest : tests) { | |||
result.addTest(new AjcTestSpecAsTest(ajcTest, result)); | |||
} | |||
return result; | |||
} | |||
private static void log(String message) { | |||
System.err.println(message); | |||
System.err.flush(); | |||
} | |||
private final String suitePath; | |||
private final String[] options; | |||
private AjcTest.Suite.Spec spec; | |||
private Runner runner; | |||
private Validator validator; | |||
private IMessageHolder holder; | |||
private Sandbox sandbox; | |||
private File suiteDir; | |||
private String name; | |||
private AjctestsAdapter(String suitePath, String[] options) { | |||
this.suitePath = suitePath; | |||
String[] opts = new String[0]; | |||
if (!HarnessJUnitUtil.isEmpty(options)) { | |||
opts = new String[options.length]; | |||
System.arraycopy(options, 0, opts, 0, opts.length); | |||
} | |||
this.options = opts; | |||
} | |||
@Override | |||
public void addTest(Test test) { | |||
if (!(test instanceof AjcTestSpecAsTest)) { | |||
String m = "expecting AjcTestSpecAsTest, got " | |||
+ (null == test ? "null test" : test.getClass().getName() | |||
+ ": " + test); | |||
throw new IllegalArgumentException(m); | |||
} | |||
super.addTest(test); | |||
} | |||
@SuppressWarnings("rawtypes") | |||
@Override | |||
public void addTestSuite(Class testClass) { | |||
throw new Error("unimplemented"); | |||
} | |||
@Override | |||
public String getName() { | |||
if (null == name) { | |||
name = HarnessJUnitUtil.cleanTestName(suitePath | |||
+ Arrays.asList(options)); | |||
} | |||
return name; | |||
} | |||
/** | |||
* Callback from test to run it using suite-wide holder, etc. The caller is | |||
* responsible for calling result.startTest(test) and result.endTest(test); | |||
* | |||
* @param test | |||
* the AjcTestSpecAsTest to run | |||
* @param result | |||
* the TestResult for any result messages (may be null) | |||
*/ | |||
protected void runTest(AjcTestSpecAsTest test, TestResult result) { | |||
final Runner runner = getRunner(); | |||
final Sandbox sandbox = getSandbox(); | |||
final Validator validator = getValidator(); | |||
int numIncomplete = 0; | |||
final RunStatus status = new RunStatus(new MessageHandler(), runner); | |||
status.setIdentifier(test.toString()); | |||
try { | |||
IMessageHolder holder = getHolder(); | |||
holder.clearMessages(); | |||
IRunIterator steps = test.spec.makeRunIterator(sandbox, validator); | |||
if (0 < holder.numMessages(IMessage.ERROR, true)) { | |||
MessageUtil.handleAll(status, holder, IMessage.INFO, true, | |||
false); | |||
} else { | |||
runner.runIterator(steps, status, null); | |||
} | |||
if (steps instanceof RunSpecIterator) { | |||
numIncomplete = ((RunSpecIterator) steps).getNumIncomplete(); | |||
} | |||
} finally { | |||
try { | |||
// reportResult handles null TestResult | |||
HarnessJUnitUtil | |||
.reportResult(null, status, test, numIncomplete); | |||
} finally { | |||
validator.deleteTempFiles(true); | |||
} | |||
} | |||
} | |||
private File getSuiteDir() { | |||
if (null == suiteDir) { | |||
File file = new File(suitePath); | |||
file = file.getParentFile(); | |||
if (null == file) { | |||
file = new File("."); | |||
} | |||
suiteDir = file; | |||
} | |||
return suiteDir; | |||
} | |||
private Validator getValidator() { | |||
if (null == validator) { | |||
validator = new Validator(getHolder()); | |||
// XXX lock if keepTemp? | |||
} | |||
return validator; | |||
} | |||
private Runner getRunner() { | |||
if (null == runner) { | |||
runner = new Runner(); | |||
} | |||
return runner; | |||
} | |||
private IMessageHolder getHolder() { | |||
if (null == holder) { | |||
holder = new MessageHandler(); | |||
} | |||
return holder; | |||
} | |||
private AjcTest.Suite.Spec getSpec() { | |||
if (null == spec) { | |||
IMessageHolder holder = getHolder(); | |||
spec = HarnessJUnitUtil.getSuiteSpec(suitePath, options, | |||
getHolder()); | |||
if (VERBOSE && holder.hasAnyMessage(null, true)) { | |||
MessageUtil.print(System.err, holder, "skip ", | |||
MessageUtil.MESSAGE_MOST); | |||
} | |||
holder.clearMessages(); | |||
} | |||
return spec; | |||
} | |||
private Sandbox getSandbox() { | |||
if (null == sandbox) { | |||
sandbox = new Sandbox(spec.getSuiteDirFile(), getValidator()); | |||
} | |||
return sandbox; | |||
} | |||
/** | |||
* Wrap AjcTest.Spec for lookup by description | |||
* | |||
* @author wes | |||
*/ | |||
public static class SpecTests { | |||
private static final HashMap<String,SpecTests> TESTS = new HashMap<>(); | |||
// private static void putSpecTestsFor(String id, SpecTests tests) { | |||
// TESTS.put(id, tests); | |||
// } | |||
private static SpecTests getSpecTestsFor(String id) { | |||
SpecTests result = TESTS.get(id); | |||
if (null == result) { | |||
throw new Error("no tests found for " + id); | |||
} | |||
return result; | |||
} | |||
// ------------------------------------ | |||
final AjctestsAdapter mAjctestsAdapter; | |||
private final Map<String,AjcTest.Spec> mDescriptionToAjcTestSpec; | |||
// ------------------------------------ | |||
private SpecTests(AjctestsAdapter ajctestsAdapter, AjcTest.Spec[] tests) { | |||
mAjctestsAdapter = ajctestsAdapter; | |||
Map<String,AjcTest.Spec> map = new HashMap<>(); | |||
for (Spec test : tests) { | |||
map.put(test.getDescription(), test); | |||
} | |||
mDescriptionToAjcTestSpec = Collections.unmodifiableMap(map); | |||
} | |||
/** | |||
* @param description | |||
* the String description of the test | |||
* @throws IllegalArgumentException | |||
* if testName is not found | |||
*/ | |||
protected void runTest(String description) { | |||
AjcTest.Spec spec = getSpec(description); | |||
AjctestsAdapter.AjcTestSpecAsTest ajcTestAsSpec = new AjctestsAdapter.AjcTestSpecAsTest( | |||
spec, mAjctestsAdapter); | |||
// runTest handles null TestResult | |||
mAjctestsAdapter.runTest(ajcTestAsSpec, null); | |||
} | |||
/** | |||
* @param description | |||
* the String description of the test | |||
* @throws IllegalArgumentException | |||
* if testName is not found | |||
*/ | |||
private AjcTest.Spec getSpec(String description) { | |||
AjcTest.Spec spec = mDescriptionToAjcTestSpec | |||
.get(description); | |||
if (null == spec) { | |||
throw new IllegalArgumentException("no test for " + description); | |||
} | |||
return spec; | |||
} | |||
/** | |||
* makeUsingTestClass(..) extends this to create TestCase with | |||
* test_{name} for each test case. | |||
*/ | |||
public static class TestClass extends TestCase { | |||
public TestClass() { | |||
} | |||
private SpecTests mTests; | |||
/** | |||
* Called by code generated in makeUsingTestClass(..) | |||
* | |||
* @param description | |||
* the String identifier of the test stored in SpecTests | |||
* mTests. | |||
* @throws Error | |||
* on first and later uses if getTestsFor() returns | |||
* null. | |||
*/ | |||
public final void runTest(String description) { | |||
if (null == mTests) { | |||
String classname = getClass().getName(); | |||
mTests = getSpecTestsFor(classname); | |||
} | |||
mTests.runTest(description); | |||
} | |||
} | |||
} | |||
/** Wrap AjcTest.Spec as a TestCase. Run by delegation to suite */ | |||
private static class AjcTestSpecAsTest extends TestCase implements | |||
HarnessJUnitUtil.IHasAjcSpec { | |||
// this could implement Test, but Ant batchtest fails to pull name | |||
final String name; | |||
final AjcTest.Spec spec; | |||
AjctestsAdapter suite; | |||
AjcTestSpecAsTest(AjcTest.Spec spec, AjctestsAdapter suite) { | |||
super(HarnessJUnitUtil.cleanTestName(spec.getDescription())); | |||
this.name = HarnessJUnitUtil.cleanTestName(spec.getDescription()); | |||
this.suite = suite; | |||
this.spec = spec; | |||
spec.setSuiteDir(suite.getSuiteDir()); | |||
} | |||
@Override | |||
public int countTestCases() { | |||
return 1; | |||
} | |||
@Override | |||
public AjcTest.Spec getAjcTestSpec() { | |||
return spec; | |||
} | |||
@Override | |||
public void run(TestResult result) { | |||
if (null == suite) { | |||
throw new Error("need to re-init"); | |||
} | |||
try { | |||
AjState.FORCE_INCREMENTAL_DURING_TESTING = true; | |||
result.startTest(this); | |||
suite.runTest(this, result); | |||
} finally { | |||
result.endTest(this); | |||
suite = null; | |||
AjState.FORCE_INCREMENTAL_DURING_TESTING = false; | |||
} | |||
} | |||
@Override | |||
public String getName() { | |||
return name; | |||
} | |||
@Override | |||
public String toString() { | |||
return name; | |||
} | |||
} | |||
} |
@@ -1,14 +1,14 @@ | |||
/* ******************************************************************* | |||
* Copyright (c) 1999-2001 Xerox Corporation, | |||
* Copyright (c) 1999-2001 Xerox Corporation, | |||
* 2002 Palo Alto Research Center, Incorporated (PARC). | |||
* All rights reserved. | |||
* This program and the accompanying materials are made available | |||
* under the terms of the Eclipse Public License v1.0 | |||
* which accompanies this distribution and is available at | |||
* http://www.eclipse.org/legal/epl-v10.html | |||
* | |||
* Contributors: | |||
* Xerox/PARC initial implementation | |||
* All rights reserved. | |||
* This program and the accompanying materials are made available | |||
* under the terms of the Eclipse Public License v1.0 | |||
* which accompanies this distribution and is available at | |||
* http://www.eclipse.org/legal/epl-v10.html | |||
* | |||
* Contributors: | |||
* Xerox/PARC initial implementation | |||
* Wes Isberg 2004 updates | |||
* ******************************************************************/ | |||
@@ -62,7 +62,7 @@ import org.aspectj.util.LangUtil; | |||
* <u>Coordination with writers</u>: because this reads the contents of values written by IXmlWritable, they should ensure their | |||
* values are readable. When flattening and unflattening lists, the convention is to use the {un}flattenList(..) methods in | |||
* XMLWriter. | |||
* | |||
* | |||
* @see XMLWriter@unflattenList(String) | |||
* @see XMLWriter@flattenList(List) | |||
*/ | |||
@@ -114,7 +114,7 @@ abstract public class AbstractRunSpec implements IRunSpec { | |||
// XXXXXunused sourceLocations = new ArrayList(); | |||
keywords = new ArrayList<String>(); | |||
children = new ArrayList<IRunSpec>(); | |||
dirChanges = new ArrayList(); | |||
dirChanges = new ArrayList<>(); | |||
xmlNames = XMLNames.DEFAULT; | |||
runtime = new RT(); | |||
this.skipIfAnyChildSkipped = skipIfAnyChildSkipped; | |||
@@ -191,8 +191,8 @@ abstract public class AbstractRunSpec implements IRunSpec { | |||
public void addKeywords(String[] ra) { | |||
if (null != ra) { | |||
for (int i = 0; i < ra.length; i++) { | |||
addKeyword(ra[i]); | |||
for (String element : ra) { | |||
addKeyword(element); | |||
} | |||
} | |||
} | |||
@@ -210,7 +210,7 @@ abstract public class AbstractRunSpec implements IRunSpec { | |||
/** @return String[] of options */ | |||
public String[] getOptionsArray() { | |||
return (String[]) options.toArray(new String[0]); | |||
return options.toArray(new String[0]); | |||
} | |||
public void setOption(String option) { | |||
@@ -231,7 +231,7 @@ abstract public class AbstractRunSpec implements IRunSpec { | |||
/** | |||
* Set options, removing any existing options. | |||
* | |||
* | |||
* @param options String[] options to use - may be null or empty | |||
*/ | |||
public void setOptionsArray(String[] options) { | |||
@@ -249,8 +249,8 @@ abstract public class AbstractRunSpec implements IRunSpec { | |||
public void addOptions(String[] ra) { | |||
if (null != ra) { | |||
for (int i = 0; i < ra.length; i++) { | |||
addOption(ra[i]); | |||
for (String element : ra) { | |||
addOption(element); | |||
} | |||
} | |||
} | |||
@@ -263,7 +263,7 @@ abstract public class AbstractRunSpec implements IRunSpec { | |||
/** @return String[] of paths */ | |||
public String[] getPathsArray() { | |||
return (String[]) paths.toArray(new String[0]); | |||
return paths.toArray(new String[0]); | |||
} | |||
public void setPath(String path) { | |||
@@ -288,8 +288,8 @@ abstract public class AbstractRunSpec implements IRunSpec { | |||
public void addPaths(String[] ra) { | |||
if (null != ra) { | |||
for (int i = 0; i < ra.length; i++) { | |||
addPath(ra[i]); | |||
for (String element : ra) { | |||
addPath(element); | |||
} | |||
} | |||
} | |||
@@ -327,8 +327,8 @@ abstract public class AbstractRunSpec implements IRunSpec { | |||
public void addMessages(String items) { | |||
if (null != items) { | |||
String[] ra = XMLWriter.unflattenList(items); | |||
for (int i = 0; i < ra.length; i++) { | |||
addMessage(ra[i]); | |||
for (String element : ra) { | |||
addMessage(element); | |||
} | |||
} | |||
} | |||
@@ -395,7 +395,7 @@ abstract public class AbstractRunSpec implements IRunSpec { | |||
* or the child's adoptParentValues(..) should add one info message with the reason this is being skipped. The only reason to | |||
* override this would be to NOT invoke the same for children, or to do something similar for children which are not | |||
* AbstractRunSpec. | |||
* | |||
* | |||
* @param parentRuntime the RT values to adopt - ignored if null | |||
* @param handler the IMessageHandler for info messages when skipping | |||
* @return false if this wants to be skipped, true otherwise | |||
@@ -437,7 +437,7 @@ abstract public class AbstractRunSpec implements IRunSpec { | |||
* adds any non-null options we don't already have. setting verbose and adding to parent options. Implementors override this to | |||
* affect how parent values are adopted. Implementors should not recurse into children. This method may be called multiple | |||
* times, so implementors should not destroy any spec information. Always add an info message when returning false to skip | |||
* | |||
* | |||
* @param parentRuntime the RT values to adopt - never null | |||
* @return false if this wants to be skipped, true otherwise | |||
*/ | |||
@@ -456,7 +456,7 @@ abstract public class AbstractRunSpec implements IRunSpec { | |||
/** | |||
* Implementations call this when signalling skips to ensure consistency in message formatting | |||
* | |||
* | |||
* @param handler the IMessageHandler sink - not null | |||
* @param reason the String reason to skip - not null | |||
*/ | |||
@@ -473,7 +473,7 @@ abstract public class AbstractRunSpec implements IRunSpec { | |||
/** | |||
* Control XML output by renaming or suppressing output for attributes and subelements. Subelements are skipped by setting the | |||
* XMLNames booleans to false. Attributes are skipped by setting their name to null. | |||
* | |||
* | |||
* @param names XMLNames with new names and/or suppress flags. | |||
*/ | |||
protected void setXMLNames(XMLNames names) { | |||
@@ -504,7 +504,7 @@ abstract public class AbstractRunSpec implements IRunSpec { | |||
return ((!LangUtil.isEmpty(xmlNames.descriptionName) && !LangUtil.isEmpty(description)) | |||
|| (!LangUtil.isEmpty(xmlNames.keywordsName) && !LangUtil.isEmpty(keywords)) | |||
|| (!LangUtil.isEmpty(xmlNames.optionsName) && !LangUtil.isEmpty(options)) || (!LangUtil | |||
.isEmpty(xmlNames.pathsName) && !LangUtil.isEmpty(paths))); | |||
.isEmpty(xmlNames.pathsName) && !LangUtil.isEmpty(paths))); | |||
} | |||
/** | |||
@@ -539,11 +539,12 @@ abstract public class AbstractRunSpec implements IRunSpec { | |||
* The default implementation writes everything as attributes, then subelements for dirChanges, messages, then subelements for | |||
* children. Subclasses that override may delegate back for any of these. Subclasses may also set XMLNames to name or suppress | |||
* any attribute or subelement. | |||
* | |||
* | |||
* @see writeMessages(XMLWriter) | |||
* @see writeChildren(XMLWriter) | |||
* @see IXmlWritable#writeXml(XMLWriter) | |||
*/ | |||
@Override | |||
public void writeXml(XMLWriter out) { | |||
out.startElement(xmlElementName, false); | |||
writeAttributes(out); | |||
@@ -572,8 +573,8 @@ abstract public class AbstractRunSpec implements IRunSpec { | |||
*/ | |||
protected void writeChildren(XMLWriter out) { | |||
if (0 < children.size()) { | |||
for (Iterator<IRunSpec> iter = children.iterator(); iter.hasNext();) { | |||
IXmlWritable self = (IXmlWritable) iter.next(); | |||
for (IRunSpec iRunSpec : children) { | |||
IXmlWritable self = iRunSpec; | |||
self.writeXml(out); | |||
} | |||
} | |||
@@ -583,8 +584,8 @@ abstract public class AbstractRunSpec implements IRunSpec { | |||
public void printAll(PrintStream out, String prefix) { | |||
out.println(prefix + toString()); | |||
for (Iterator<IRunSpec> iter = children.iterator(); iter.hasNext();) { | |||
AbstractRunSpec child = (AbstractRunSpec) iter.next(); // IRunSpec | |||
for (IRunSpec iRunSpec : children) { | |||
AbstractRunSpec child = (AbstractRunSpec) iRunSpec; // IRunSpec | |||
child.printAll(out, prefix + " "); | |||
} | |||
} | |||
@@ -592,7 +593,7 @@ abstract public class AbstractRunSpec implements IRunSpec { | |||
/** | |||
* default implementation returns the description if not empty or the unqualified class name otherwise. Subclasses should not | |||
* call toString from here unless they reimplement it. | |||
* | |||
* | |||
* @return name of this thing or type | |||
*/ | |||
protected String getPrintName() { | |||
@@ -604,6 +605,7 @@ abstract public class AbstractRunSpec implements IRunSpec { | |||
} | |||
/** @return summary count of spec elements */ | |||
@Override | |||
public String toString() { | |||
return getPrintName() + "(" + containedSummary() + ")"; | |||
} | |||
@@ -646,9 +648,7 @@ abstract public class AbstractRunSpec implements IRunSpec { | |||
*/ | |||
spec.badInput = badInput; | |||
spec.children.clear(); | |||
for (Iterator<IRunSpec> iter = children.iterator(); iter.hasNext();) { | |||
// clone these... | |||
IRunSpec child = iter.next(); | |||
for (IRunSpec child : children) { | |||
// require all child classes to support clone? | |||
if (child instanceof AbstractRunSpec) { | |||
spec.addChild((AbstractRunSpec) ((AbstractRunSpec) child).clone()); | |||
@@ -728,6 +728,7 @@ abstract public class AbstractRunSpec implements IRunSpec { | |||
final boolean skipMessages; | |||
final boolean skipChildren; | |||
@Override | |||
protected Object clone() { | |||
return new XMLNames(null, descriptionName, sourceLocationName, keywordsName, optionsName, pathsName, commentName, | |||
stagingName, badInputName, skipDirChanges, skipMessages, skipChildren); | |||
@@ -767,6 +768,7 @@ abstract public class AbstractRunSpec implements IRunSpec { | |||
} | |||
/** subclasses implement this to create and set up a run */ | |||
@Override | |||
abstract public IRunIterator makeRunIterator(Sandbox sandbox, Validator validator); | |||
/** segregate runtime-only state in spec */ | |||
@@ -788,15 +790,15 @@ abstract public class AbstractRunSpec implements IRunSpec { | |||
/** | |||
* Set parent options - old options destroyed. Will result in duplicates if duplicates added. Null or empty entries are | |||
* ignored | |||
* | |||
* | |||
* @param options ignored if null or empty | |||
*/ | |||
public void setOptions(String[] options) { | |||
parentOptions.clear(); | |||
if (!LangUtil.isEmpty(options)) { | |||
for (int i = 0; i < options.length; i++) { | |||
if (!LangUtil.isEmpty(options[i])) { | |||
parentOptions.add(options[i]); | |||
for (String option : options) { | |||
if (!LangUtil.isEmpty(option)) { | |||
parentOptions.add(option); | |||
} | |||
} | |||
} | |||
@@ -804,7 +806,7 @@ abstract public class AbstractRunSpec implements IRunSpec { | |||
/** | |||
* Copy values from another RT | |||
* | |||
* | |||
* @param toCopy the RT to copy from | |||
* @throws IllegalArgumentException if toCopy is null | |||
*/ | |||
@@ -817,11 +819,11 @@ abstract public class AbstractRunSpec implements IRunSpec { | |||
/** | |||
* Return any parent option accepted by validOptions, optionally removing the parent option. | |||
* | |||
* | |||
* @param validOptions String[] of options to extract | |||
* @param remove if true, then remove any parent option matched | |||
* @return String[] containing any validOptions[i] in parentOptions | |||
* | |||
* | |||
*/ | |||
public Values extractOptions(Options validOptions, boolean remove, StringBuffer errors) { | |||
Values result = Values.EMPTY; | |||
@@ -836,7 +838,7 @@ abstract public class AbstractRunSpec implements IRunSpec { | |||
return result; | |||
} | |||
// boolean haveOption = false; | |||
String[] parents = (String[]) parentOptions.toArray(new String[0]); | |||
String[] parents = parentOptions.toArray(new String[0]); | |||
try { | |||
result = validOptions.acceptInput(parents); | |||
} catch (InvalidInputException e) { | |||
@@ -869,7 +871,7 @@ abstract public class AbstractRunSpec implements IRunSpec { | |||
/** | |||
* Return any parent option which has one of validOptions as a prefix, optionally absorbing (removing) the parent option. | |||
* | |||
* | |||
* @param validOptions String[] of options to extract | |||
* @param absorb if true, then remove any parent option matched | |||
* @return String[] containing any validOptions[i] in parentOptions (at most once) | |||
@@ -880,8 +882,7 @@ abstract public class AbstractRunSpec implements IRunSpec { | |||
} | |||
ArrayList<String> result = new ArrayList<String>(); | |||
// boolean haveOption = false; | |||
for (int i = 0; i < validOptions.length; i++) { | |||
String option = validOptions[i]; | |||
for (String option : validOptions) { | |||
if (LangUtil.isEmpty(option)) { | |||
continue; | |||
} | |||
@@ -895,7 +896,7 @@ abstract public class AbstractRunSpec implements IRunSpec { | |||
} | |||
} | |||
} | |||
return (String[]) result.toArray(new String[0]); | |||
return result.toArray(new String[0]); | |||
} | |||
/** Get ListIterator that permits removals */ | |||
@@ -905,7 +906,7 @@ abstract public class AbstractRunSpec implements IRunSpec { | |||
/** | |||
* Enable verbose logging | |||
* | |||
* | |||
* @param verbose if true, do verbose logging | |||
*/ | |||
public void setVerbose(boolean verbose) { |
@@ -1,14 +1,14 @@ | |||
/* ******************************************************************* | |||
* Copyright (c) 1999-2001 Xerox Corporation, | |||
* Copyright (c) 1999-2001 Xerox Corporation, | |||
* 2002 Palo Alto Research Center, Incorporated (PARC). | |||
* All rights reserved. | |||
* This program and the accompanying materials are made available | |||
* under the terms of the Eclipse Public License v1.0 | |||
* which accompanies this distribution and is available at | |||
* http://www.eclipse.org/legal/epl-v10.html | |||
* | |||
* Contributors: | |||
* Xerox/PARC initial implementation | |||
* All rights reserved. | |||
* This program and the accompanying materials are made available | |||
* under the terms of the Eclipse Public License v1.0 | |||
* which accompanies this distribution and is available at | |||
* http://www.eclipse.org/legal/epl-v10.html | |||
* | |||
* Contributors: | |||
* Xerox/PARC initial implementation | |||
* ******************************************************************/ | |||
package org.aspectj.testing.harness.bridge; | |||
@@ -32,310 +32,310 @@ import junit.framework.TestCase; | |||
* Primarily used by others to test AjcTest | |||
*/ | |||
public class AjcSpecTest extends TestCase { | |||
public static final String NOTSAME = " != "; | |||
public static void sameAjcSuiteSpec( | |||
AjcTest.Suite.Spec lhsSpec, | |||
AjcTest.Suite.Spec rhsSpec, | |||
Assert a) { | |||
assertNotNull(lhsSpec); | |||
assertNotNull(rhsSpec); | |||
Iterator lhs = lhsSpec.getChildren().iterator(); | |||
Iterator rhs = rhsSpec.getChildren().iterator(); | |||
while (lhs.hasNext() && rhs.hasNext()) { | |||
AjcTest.Spec lhsTest = (AjcTest.Spec) lhs.next(); | |||
AjcTest.Spec rhsTest = (AjcTest.Spec) rhs.next(); | |||
AjcSpecTest.sameAjcTestSpec(lhsTest, rhsTest, a); | |||
} | |||
assertTrue(!lhs.hasNext()); | |||
assertTrue(!rhs.hasNext()); | |||
} | |||
public static final String NOTSAME = " != "; | |||
public static void sameAjcSuiteSpec( | |||
AjcTest.Suite.Spec lhsSpec, | |||
AjcTest.Suite.Spec rhsSpec, | |||
Assert a) { | |||
assertNotNull(lhsSpec); | |||
assertNotNull(rhsSpec); | |||
Iterator lhs = lhsSpec.getChildren().iterator(); | |||
Iterator rhs = rhsSpec.getChildren().iterator(); | |||
while (lhs.hasNext() && rhs.hasNext()) { | |||
AjcTest.Spec lhsTest = (AjcTest.Spec) lhs.next(); | |||
AjcTest.Spec rhsTest = (AjcTest.Spec) rhs.next(); | |||
AjcSpecTest.sameAjcTestSpec(lhsTest, rhsTest, a); | |||
} | |||
assertTrue(!lhs.hasNext()); | |||
assertTrue(!rhs.hasNext()); | |||
} | |||
public static void sameAjcTestSpec( | |||
AjcTest.Spec lhsTest, | |||
AjcTest.Spec rhsTest, | |||
Assert a) { | |||
assertNotNull(lhsTest); | |||
assertNotNull(rhsTest); | |||
assertEquals(lhsTest.getBugId(), rhsTest.getBugId()); | |||
assertEquals(lhsTest.getTestDirOffset(), rhsTest.getTestDirOffset()); | |||
// XXX suiteDir varies by run.. | |||
// description, options, paths, comments, keywords | |||
sameAbstractRunSpec(lhsTest, rhsTest, a); | |||
AjcTest.Spec lhsTest, | |||
AjcTest.Spec rhsTest, | |||
Assert a) { | |||
assertNotNull(lhsTest); | |||
assertNotNull(rhsTest); | |||
assertEquals(lhsTest.getBugId(), rhsTest.getBugId()); | |||
assertEquals(lhsTest.getTestDirOffset(), rhsTest.getTestDirOffset()); | |||
// XXX suiteDir varies by run.. | |||
// description, options, paths, comments, keywords | |||
sameAbstractRunSpec(lhsTest, rhsTest, a); | |||
} | |||
public static void sameAbstractRunSpec( | |||
AbstractRunSpec lhs, | |||
AbstractRunSpec rhs, | |||
Assert a) { | |||
assertEquals(lhs.description, rhs.description); | |||
// XXX keywords added in .txt reading - | |||
//sameList(lhs.getKeywordsList(), rhs.getKeywordsList(), a); | |||
// XXX sameList(lhs.globalOptions, rhs.globalOptions, a); | |||
sameList(lhs.getOptionsList(), rhs.getOptionsList(), a); | |||
sameList(lhs.getPathsList(), rhs.getPathsList(), a); | |||
assertEquals(lhs.isStaging(), rhs.isStaging()); | |||
sameList(lhs.keywords, rhs.keywords, a); | |||
assertEquals(lhs.comment, rhs.comment); | |||
assertEquals(lhs.badInput, rhs.badInput); | |||
// xml adds sourceloc? | |||
//sameSourceLocation(lhs.getSourceLocation(), rhs.getSourceLocation(), a); | |||
// XXX also sourceLocations? | |||
sameMessages(lhs.getMessages(), rhs.getMessages(), a); | |||
AbstractRunSpec lhs, | |||
AbstractRunSpec rhs, | |||
Assert a) { | |||
assertEquals(lhs.description, rhs.description); | |||
// XXX keywords added in .txt reading - | |||
//sameList(lhs.getKeywordsList(), rhs.getKeywordsList(), a); | |||
// XXX sameList(lhs.globalOptions, rhs.globalOptions, a); | |||
sameList(lhs.getOptionsList(), rhs.getOptionsList(), a); | |||
sameList(lhs.getPathsList(), rhs.getPathsList(), a); | |||
assertEquals(lhs.isStaging(), rhs.isStaging()); | |||
sameList(lhs.keywords, rhs.keywords, a); | |||
assertEquals(lhs.comment, rhs.comment); | |||
assertEquals(lhs.badInput, rhs.badInput); | |||
// xml adds sourceloc? | |||
//sameSourceLocation(lhs.getSourceLocation(), rhs.getSourceLocation(), a); | |||
// XXX also sourceLocations? | |||
sameMessages(lhs.getMessages(), rhs.getMessages(), a); | |||
} | |||
/** @return normal form - null is "", "" is "", and others are {fully.qualified.class}.toString().trim() */ | |||
static String normal(Object input) { | |||
if ((null == input) || ("".equals(input))) { | |||
return ""; | |||
} else { | |||
return input.getClass().getName() + "." + input.toString().trim(); | |||
} | |||
} | |||
/** @return normal form - null is "", "" is "", and others are {fully.qualified.class}.toString().trim() */ | |||
static String normal(Object input) { | |||
if ((null == input) || ("".equals(input))) { | |||
return ""; | |||
} else { | |||
return input.getClass().getName() + "." + input.toString().trim(); | |||
} | |||
} | |||
/** @return true if these match after normalizing */ | |||
public static void same(Object lhs, Object rhs, Assert a) { | |||
lhs = normal(lhs); | |||
rhs = normal(rhs); | |||
assertTrue(lhs + NOTSAME + rhs, lhs.equals(rhs)); | |||
} | |||
/** @return true if these match after normalizing */ | |||
public static void same(Object lhs, Object rhs, Assert a) { | |||
lhs = normal(lhs); | |||
rhs = normal(rhs); | |||
assertTrue(lhs + NOTSAME + rhs, lhs.equals(rhs)); | |||
} | |||
/** @return true if both are empty (null or no entries) or if all match */ | |||
public static void sameRA(String[] lhs, String[] rhs, Assert a) { | |||
if (null == lhs) { | |||
assertTrue((null == rhs) || (0 == rhs.length)); | |||
} else if (null == rhs) { | |||
assertTrue(0 == lhs.length); | |||
} else { | |||
String l = normal(lhs); | |||
String r = normal(rhs); | |||
assertTrue(l + NOTSAME + r, l.equals(r)); | |||
} | |||
} | |||
/** @return normal form for String[] items*/ | |||
static String normal(String[] items) { | |||
return (null == items ? "[]" : normal(Arrays.asList(items))); | |||
} | |||
/** @return normal form for list items */ | |||
static String normal(List list) { | |||
StringBuffer sb = new StringBuffer(); | |||
sb.append("["); | |||
boolean first = true; | |||
for (Iterator iter = list.iterator(); iter.hasNext();) { | |||
Object o = iter.next(); | |||
if (!first) { | |||
sb.append(", "); | |||
} else { | |||
first = false; | |||
} | |||
sb.append(normal(o)); | |||
} | |||
sb.append("]"); | |||
return sb.toString(); | |||
} | |||
/** @return true if both are empty (null or no entries) or if all match after trimming */ | |||
public static void sameListSize(List lhs, List rhs) { | |||
if (null == lhs) { | |||
assertTrue((null == rhs) || (0 == rhs.size())); | |||
} else if (null == rhs) { | |||
assertTrue(0 == lhs.size()); | |||
} else { | |||
assertTrue(rhs.size() == lhs.size()); | |||
} | |||
} | |||
/** @return true if both are empty (null or no entries) or if all match */ | |||
public static void sameRA(String[] lhs, String[] rhs, Assert a) { | |||
if (null == lhs) { | |||
assertTrue((null == rhs) || (0 == rhs.length)); | |||
} else if (null == rhs) { | |||
assertTrue(0 == lhs.length); | |||
} else { | |||
String l = normal(lhs); | |||
String r = normal(rhs); | |||
assertTrue(l + NOTSAME + r, l.equals(r)); | |||
} | |||
} | |||
/** @return true if both are empty (null or no entries) or if all match after trimming */ | |||
public static void sameList(List lhs, List rhs, Assert a) { | |||
sameListSize(lhs, rhs); | |||
String l = normal(lhs); | |||
String r = normal(rhs); | |||
String label = l + NOTSAME + r; | |||
assertTrue(label, l.equals(r)); | |||
} | |||
// /** | |||
// * Normalize and compare: | |||
// * <li>bug id's are not compared since extracted during xml writing</li> | |||
// * <li>keyword compare is disabled since keywords are generated during xml reading.</li> | |||
// * <li>description compare is normalized by stripping bug ids</li> | |||
// * <li>String and arrays are equal when empty (null or 0-length)</li> | |||
// * @see Ajctest#stripBugId(String) | |||
// */ | |||
// public static void sameAjcTest(AjcTest lhs, AjcTest rhs, Assert reporter) { | |||
// Assert a = reporter; | |||
// String label = lhs + NOTSAME + rhs; | |||
// assertTrue(label, null != lhs); | |||
// assertTrue(label, null != rhs); | |||
// //assertTrue(label, lhs.ignoreWarnings == rhs.ignoreWarnings); | |||
// // XXX disabled - not in .txt | |||
// // sameStringList(lhs.keywords, rhs.keywords, a); | |||
// // sameString(lhs.bugId, rhs.bugId, a); | |||
// // argh - bugid stripped from description | |||
// //same(AjcTest.stripBugId(lhs.description), AjcTest.stripBugId(lhs.description), a); | |||
// //sameRA(lhs.globals, rhs.globals, a); | |||
// //lhs.reset(); | |||
// //rhs.reset(); | |||
// boolean gotOne = false; | |||
// IMessageHolder holder = new MessageHandler(); | |||
// assertTrue(label, !holder.hasAnyMessage(IMessage.FAIL, IMessageHolder.ORGREATER)); | |||
// while (lhs.hasNextRun() && rhs.hasNextRun()) { | |||
// sameIAjcRun((IAjcRun) lhs.nextRun(holder), (IAjcRun) rhs.nextRun(holder), reporter); | |||
// assertTrue(label, !holder.hasAnyMessage(IMessage.FAIL, IMessageHolder.ORGREATER)); | |||
// if (!gotOne) { | |||
// gotOne = true; | |||
// } | |||
// } | |||
// assertTrue(label, gotOne); | |||
// assertTrue(label, !lhs.hasNextRun()); | |||
// assertTrue(label, !rhs.hasNextRun()); | |||
// } | |||
/** @return normal form for String[] items*/ | |||
static String normal(String[] items) { | |||
return (null == items ? "[]" : normal(Arrays.asList(items))); | |||
} | |||
/** @return normal form for list items */ | |||
static String normal(List list) { | |||
StringBuffer sb = new StringBuffer(); | |||
sb.append("["); | |||
boolean first = true; | |||
for (Iterator iter = list.iterator(); iter.hasNext();) { | |||
Object o = iter.next(); | |||
if (!first) { | |||
sb.append(", "); | |||
} else { | |||
first = false; | |||
} | |||
sb.append(normal(o)); | |||
} | |||
sb.append("]"); | |||
return sb.toString(); | |||
} | |||
/** @return true if both are empty (null or no entries) or if all match after trimming */ | |||
public static void sameListSize(List lhs, List rhs) { | |||
if (null == lhs) { | |||
assertTrue((null == rhs) || (0 == rhs.size())); | |||
} else if (null == rhs) { | |||
assertTrue(0 == lhs.size()); | |||
} else { | |||
assertTrue(rhs.size() == lhs.size()); | |||
} | |||
} | |||
/** @return true if both are empty (null or no entries) or if all match after trimming */ | |||
public static void sameList(List lhs, List rhs, Assert a) { | |||
sameListSize(lhs, rhs); | |||
String l = normal(lhs); | |||
String r = normal(rhs); | |||
String label = l + NOTSAME + r; | |||
assertTrue(label, l.equals(r)); | |||
} | |||
// /** | |||
// * Normalize and compare: | |||
// * <li>bug id's are not compared since extracted during xml writing</li> | |||
// * <li>keyword compare is disabled since keywords are generated during xml reading.</li> | |||
// * <li>description compare is normalized by stripping bug ids</li> | |||
// * <li>String and arrays are equal when empty (null or 0-length)</li> | |||
// * @see Ajctest#stripBugId(String) | |||
// */ | |||
// public static void sameAjcTest(AjcTest lhs, AjcTest rhs, Assert reporter) { | |||
// Assert a = reporter; | |||
// String label = lhs + NOTSAME + rhs; | |||
// assertTrue(label, null != lhs); | |||
// assertTrue(label, null != rhs); | |||
// //assertTrue(label, lhs.ignoreWarnings == rhs.ignoreWarnings); | |||
// // XXX disabled - not in .txt | |||
// // sameStringList(lhs.keywords, rhs.keywords, a); | |||
// // sameString(lhs.bugId, rhs.bugId, a); | |||
// // argh - bugid stripped from description | |||
// //same(AjcTest.stripBugId(lhs.description), AjcTest.stripBugId(lhs.description), a); | |||
// //sameRA(lhs.globals, rhs.globals, a); | |||
// //lhs.reset(); | |||
// //rhs.reset(); | |||
// boolean gotOne = false; | |||
// IMessageHolder holder = new MessageHandler(); | |||
// assertTrue(label, !holder.hasAnyMessage(IMessage.FAIL, IMessageHolder.ORGREATER)); | |||
// while (lhs.hasNextRun() && rhs.hasNextRun()) { | |||
// sameIAjcRun((IAjcRun) lhs.nextRun(holder), (IAjcRun) rhs.nextRun(holder), reporter); | |||
// assertTrue(label, !holder.hasAnyMessage(IMessage.FAIL, IMessageHolder.ORGREATER)); | |||
// if (!gotOne) { | |||
// gotOne = true; | |||
// } | |||
// } | |||
// assertTrue(label, gotOne); | |||
// assertTrue(label, !lhs.hasNextRun()); | |||
// assertTrue(label, !rhs.hasNextRun()); | |||
// } | |||
public static void sameIAjcRun(IAjcRun lhs, IAjcRun rhs, Assert reporter) { | |||
// Assert a = reporter; | |||
assertTrue(lhs != null); | |||
assertTrue(rhs != null); | |||
Class c = lhs.getClass(); | |||
assertTrue(c == rhs.getClass()); | |||
AbstractRunSpec lhsSpec; | |||
AbstractRunSpec rhsSpec; | |||
if (c == CompilerRun.class) { | |||
CompilerRun.Spec l = ((CompilerRun) lhs).spec; | |||
CompilerRun.Spec r = ((CompilerRun) rhs).spec; | |||
lhsSpec = l; | |||
rhsSpec = r; | |||
assertEquals(l.argfiles, r.argfiles); | |||
assertEquals(l.aspectpath, r.aspectpath); | |||
assertEquals(l.testSrcDirOffset, r.testSrcDirOffset); | |||
assertEquals(l.compiler, r.compiler); | |||
assertEquals(l.includeClassesDir, r.includeClassesDir); | |||
assertEquals(l.reuseCompiler, r.reuseCompiler); | |||
assertEquals(l.sourceroots, r.sourceroots); | |||
assertEquals(l.extdirs, r.extdirs); | |||
} else if (c == JavaRun.class) { | |||
JavaRun.Spec l = ((JavaRun) lhs).spec; | |||
JavaRun.Spec r = ((JavaRun) rhs).spec; | |||
lhsSpec = l; | |||
rhsSpec = r; | |||
assertTrue(l.skipTester == r.skipTester); | |||
assertEquals(l.className, r.className); | |||
assertEquals(l.javaVersion, r.javaVersion); | |||
assertEquals(l.skipTester, r.skipTester); | |||
assertEquals(l.outStreamIsError, r.outStreamIsError); | |||
assertEquals(l.errStreamIsError, r.errStreamIsError); | |||
} else if (c == IncCompilerRun.class) { | |||
IncCompilerRun.Spec l = ((IncCompilerRun) lhs).spec; | |||
IncCompilerRun.Spec r = ((IncCompilerRun) rhs).spec; | |||
lhsSpec = l; | |||
rhsSpec = r; | |||
assertEquals(l.tag, r.tag); | |||
assertEquals(l.fresh, r.fresh); | |||
} else { | |||
assertTrue(lhs.equals(rhs)); | |||
return; | |||
} | |||
sameSpec(lhsSpec, rhsSpec, reporter); | |||
// Assert a = reporter; | |||
assertTrue(lhs != null); | |||
assertTrue(rhs != null); | |||
Class c = lhs.getClass(); | |||
assertTrue(c == rhs.getClass()); | |||
AbstractRunSpec lhsSpec; | |||
AbstractRunSpec rhsSpec; | |||
if (c == CompilerRun.class) { | |||
CompilerRun.Spec l = ((CompilerRun) lhs).spec; | |||
CompilerRun.Spec r = ((CompilerRun) rhs).spec; | |||
lhsSpec = l; | |||
rhsSpec = r; | |||
assertEquals(l.argfiles, r.argfiles); | |||
assertEquals(l.aspectpath, r.aspectpath); | |||
assertEquals(l.testSrcDirOffset, r.testSrcDirOffset); | |||
assertEquals(l.compiler, r.compiler); | |||
assertEquals(l.includeClassesDir, r.includeClassesDir); | |||
assertEquals(l.reuseCompiler, r.reuseCompiler); | |||
assertEquals(l.sourceroots, r.sourceroots); | |||
assertEquals(l.extdirs, r.extdirs); | |||
} else if (c == JavaRun.class) { | |||
JavaRun.Spec l = ((JavaRun) lhs).spec; | |||
JavaRun.Spec r = ((JavaRun) rhs).spec; | |||
lhsSpec = l; | |||
rhsSpec = r; | |||
assertTrue(l.skipTester == r.skipTester); | |||
assertEquals(l.className, r.className); | |||
assertEquals(l.javaVersion, r.javaVersion); | |||
assertEquals(l.skipTester, r.skipTester); | |||
assertEquals(l.outStreamIsError, r.outStreamIsError); | |||
assertEquals(l.errStreamIsError, r.errStreamIsError); | |||
} else if (c == IncCompilerRun.class) { | |||
IncCompilerRun.Spec l = ((IncCompilerRun) lhs).spec; | |||
IncCompilerRun.Spec r = ((IncCompilerRun) rhs).spec; | |||
lhsSpec = l; | |||
rhsSpec = r; | |||
assertEquals(l.tag, r.tag); | |||
assertEquals(l.fresh, r.fresh); | |||
} else { | |||
assertTrue(lhs.equals(rhs)); | |||
return; | |||
} | |||
sameSpec(lhsSpec, rhsSpec, reporter); | |||
} | |||
public static void sameSpec(AbstractRunSpec lhs, AbstractRunSpec rhs, Assert a) { | |||
if ((null == lhs) && (null == rhs)) { | |||
return; | |||
} | |||
assertTrue(lhs != null); | |||
assertTrue(rhs != null); | |||
assertEquals(""+lhs.getOptionsList(), ""+rhs.getOptionsList()); | |||
sameList(lhs.getPathsList(), rhs.getPathsList(), a); | |||
sameMessages(lhs.getMessages(), rhs.getMessages(), a); | |||
sameDirChangesList(lhs.dirChanges, rhs.dirChanges, a); | |||
if ((null == lhs) && (null == rhs)) { | |||
return; | |||
} | |||
assertTrue(lhs != null); | |||
assertTrue(rhs != null); | |||
assertEquals(""+lhs.getOptionsList(), ""+rhs.getOptionsList()); | |||
sameList(lhs.getPathsList(), rhs.getPathsList(), a); | |||
sameMessages(lhs.getMessages(), rhs.getMessages(), a); | |||
sameDirChangesList(lhs.dirChanges, rhs.dirChanges, a); | |||
} | |||
public static void sameDirChangesList(ArrayList<DirChanges.Spec> lhs, ArrayList<DirChanges.Spec> rhs, Assert a) { | |||
if ((null == lhs) && (null == rhs)) { | |||
return; | |||
} | |||
assertTrue(rhs != null); | |||
assertTrue(lhs != null); | |||
sameListSize(lhs, rhs); | |||
Iterator<DirChanges.Spec> lhsIter = lhs.iterator(); | |||
Iterator<DirChanges.Spec> rhsIter = rhs.iterator(); | |||
while (lhsIter.hasNext() && rhsIter.hasNext()) { | |||
sameDirChangesSpec(lhsIter.next(), rhsIter.next(), a); | |||
} | |||
} | |||
public static void sameDirChangesList(ArrayList lhs, ArrayList rhs, Assert a) { | |||
if ((null == lhs) && (null == rhs)) { | |||
return; | |||
} | |||
assertTrue(rhs != null); | |||
assertTrue(lhs != null); | |||
sameListSize(lhs, rhs); | |||
Iterator lhsIter = lhs.iterator(); | |||
Iterator rhsIter = rhs.iterator(); | |||
while (lhsIter.hasNext() && rhsIter.hasNext()) { | |||
sameDirChangesSpec((DirChanges.Spec) lhsIter.next(), (DirChanges.Spec) rhsIter.next(), a); | |||
} | |||
public static void sameDirChangesSpec(DirChanges.Spec lhs, DirChanges.Spec rhs, Assert a) { | |||
if ((null == lhs) && (null == rhs)) { | |||
return; | |||
} | |||
assertTrue(rhs != null); | |||
assertTrue(lhs != null); | |||
assertEquals(lhs.defaultSuffix, rhs.defaultSuffix); | |||
assertEquals(lhs.dirToken, rhs.dirToken); | |||
assertEquals(lhs.fastFail, rhs.fastFail); | |||
assertEquals(lhs.expDir, rhs.expDir); // XXX normalize? | |||
sameList(lhs.updated, rhs.updated, a); | |||
sameList(lhs.removed, rhs.removed, a); | |||
sameList(lhs.added, rhs.added, a); | |||
} | |||
public static void sameDirChangesSpec(DirChanges.Spec lhs, DirChanges.Spec rhs, Assert a) { | |||
if ((null == lhs) && (null == rhs)) { | |||
return; | |||
} | |||
assertTrue(rhs != null); | |||
assertTrue(lhs != null); | |||
assertEquals(lhs.defaultSuffix, rhs.defaultSuffix); | |||
assertEquals(lhs.dirToken, rhs.dirToken); | |||
assertEquals(lhs.fastFail, rhs.fastFail); | |||
assertEquals(lhs.expDir, rhs.expDir); // XXX normalize? | |||
sameList(lhs.updated, rhs.updated, a); | |||
sameList(lhs.removed, rhs.removed, a); | |||
sameList(lhs.added, rhs.added, a); | |||
} | |||
public static void sameMessages(IMessageHolder one, IMessageHolder two, Assert a) { | |||
if ((null == one) && (null == two)) { | |||
return; | |||
} | |||
// order matters here | |||
ListIterator lhs = one.getUnmodifiableListView().listIterator(); | |||
ListIterator rhs = two.getUnmodifiableListView().listIterator(); | |||
while (lhs.hasNext() && rhs.hasNext()) { | |||
sameMessage((IMessage) lhs.next(), (IMessage) rhs.next(), a); | |||
} | |||
assertTrue(!lhs.hasNext()); | |||
assertTrue(!rhs.hasNext()); | |||
} | |||
public static void sameMessages(IMessageHolder one, IMessageHolder two, Assert a) { | |||
if ((null == one) && (null == two)) { | |||
return; | |||
} | |||
// order matters here | |||
ListIterator lhs = one.getUnmodifiableListView().listIterator(); | |||
ListIterator rhs = two.getUnmodifiableListView().listIterator(); | |||
while (lhs.hasNext() && rhs.hasNext()) { | |||
sameMessage((IMessage) lhs.next(), (IMessage) rhs.next(), a); | |||
} | |||
assertTrue(!lhs.hasNext()); | |||
assertTrue(!rhs.hasNext()); | |||
} | |||
public static void sameMessage(IMessage lhs, IMessage rhs, Assert a) { | |||
if ((null == lhs) && (null == rhs)) { | |||
return; | |||
} | |||
assertTrue(lhs != null); | |||
assertTrue(rhs != null); | |||
assertTrue(lhs.getKind() == rhs.getKind()); | |||
same(lhs.getMessage(), rhs.getMessage(), a); | |||
same(lhs.getDetails(), rhs.getDetails(), a); | |||
assertEquals(lhs.getThrown(), rhs.getThrown()); | |||
sameSourceLocation(lhs.getSourceLocation(), rhs.getSourceLocation()); | |||
sameSourceLocations(lhs.getExtraSourceLocations(), rhs.getExtraSourceLocations()); | |||
} | |||
public static void sameSourceLocations(List lhs, List rhs) { | |||
sameListSize(lhs, rhs); | |||
if ((null == lhs) || (0 == lhs.size())) { | |||
return; | |||
} | |||
// ok, do order-dependent check.. | |||
ListIterator iterLeft = lhs.listIterator(); | |||
ListIterator iterRight = rhs.listIterator(); | |||
while (iterLeft.hasNext() && iterRight.hasNext()) { | |||
ISourceLocation left = (ISourceLocation) iterLeft.next(); | |||
ISourceLocation right = (ISourceLocation) iterRight.next(); | |||
sameSourceLocation(left, right); | |||
} | |||
assertTrue(!iterLeft.hasNext()); | |||
assertTrue(!iterRight.hasNext()); | |||
public static void sameMessage(IMessage lhs, IMessage rhs, Assert a) { | |||
if ((null == lhs) && (null == rhs)) { | |||
return; | |||
} | |||
assertTrue(lhs != null); | |||
assertTrue(rhs != null); | |||
assertTrue(lhs.getKind() == rhs.getKind()); | |||
same(lhs.getMessage(), rhs.getMessage(), a); | |||
same(lhs.getDetails(), rhs.getDetails(), a); | |||
assertEquals(lhs.getThrown(), rhs.getThrown()); | |||
sameSourceLocation(lhs.getSourceLocation(), rhs.getSourceLocation()); | |||
sameSourceLocations(lhs.getExtraSourceLocations(), rhs.getExtraSourceLocations()); | |||
} | |||
public static void sameSourceLocations(List lhs, List rhs) { | |||
sameListSize(lhs, rhs); | |||
if ((null == lhs) || (0 == lhs.size())) { | |||
return; | |||
} | |||
// ok, do order-dependent check.. | |||
ListIterator iterLeft = lhs.listIterator(); | |||
ListIterator iterRight = rhs.listIterator(); | |||
while (iterLeft.hasNext() && iterRight.hasNext()) { | |||
ISourceLocation left = (ISourceLocation) iterLeft.next(); | |||
ISourceLocation right = (ISourceLocation) iterRight.next(); | |||
sameSourceLocation(left, right); | |||
} | |||
assertTrue(!iterLeft.hasNext()); | |||
assertTrue(!iterRight.hasNext()); | |||
} | |||
public static void sameSourceLocation(ISourceLocation lhs, ISourceLocation rhs) { | |||
if ((null == lhs) && (null == rhs)) { | |||
return; | |||
} | |||
assertTrue(lhs != null); | |||
assertTrue(rhs != null); | |||
assertTrue(lhs.getLine() == rhs.getLine()); | |||
assertTrue(lhs.getColumn() == rhs.getColumn()); | |||
assertTrue(lhs.getOffset() == rhs.getOffset()); | |||
assertTrue(lhs.getEndLine() == rhs.getEndLine()); | |||
// XXX need to compare files, permitting null == NONE | |||
if ((null == lhs) && (null == rhs)) { | |||
return; | |||
} | |||
assertTrue(lhs != null); | |||
assertTrue(rhs != null); | |||
assertTrue(lhs.getLine() == rhs.getLine()); | |||
assertTrue(lhs.getColumn() == rhs.getColumn()); | |||
assertTrue(lhs.getOffset() == rhs.getOffset()); | |||
assertTrue(lhs.getEndLine() == rhs.getEndLine()); | |||
// XXX need to compare files, permitting null == NONE | |||
} | |||
/** | |||
@@ -345,34 +345,34 @@ public class AjcSpecTest extends TestCase { | |||
public AjcSpecTest(String name) { | |||
super(name); | |||
} | |||
public void testMinimal() { | |||
AjcTest.Spec one = new AjcTest.Spec(); | |||
AjcTest.Spec two = new AjcTest.Spec(); | |||
// empty/identity tests | |||
sameAjcTestSpec(one, two, this); | |||
one.addOption("-one"); | |||
one.addKeyword("keyword"); | |||
one.addPath("path"); | |||
IMessage m = MessageUtil.info("info message"); | |||
one.addMessage(m); | |||
DirChanges.Spec dcspec = new DirChanges.Spec(); | |||
dcspec.setDirToken("dirToken"); | |||
dcspec.setDefaultSuffix(".suffix"); | |||
one.addDirChanges(dcspec); | |||
// full/identity tests | |||
sameAjcTestSpec(one, one, this); | |||
// XXX need to clone... | |||
public void testMinimal() { | |||
AjcTest.Spec one = new AjcTest.Spec(); | |||
AjcTest.Spec two = new AjcTest.Spec(); | |||
// empty/identity tests | |||
sameAjcTestSpec(one, two, this); | |||
one.addOption("-one"); | |||
one.addKeyword("keyword"); | |||
one.addPath("path"); | |||
IMessage m = MessageUtil.info("info message"); | |||
one.addMessage(m); | |||
DirChanges.Spec dcspec = new DirChanges.Spec(); | |||
dcspec.setDirToken("dirToken"); | |||
dcspec.setDefaultSuffix(".suffix"); | |||
one.addDirChanges(dcspec); | |||
// XXX need to test that more differences are detected | |||
boolean passed = false; | |||
try { | |||
sameAjcTestSpec(one, two, this); | |||
} catch (AssertionFailedError e) { | |||
passed = true; | |||
} | |||
assertTrue("did not get expected exception", passed); | |||
} | |||
// full/identity tests | |||
sameAjcTestSpec(one, one, this); | |||
// XXX need to clone... | |||
// XXX need to test that more differences are detected | |||
boolean passed = false; | |||
try { | |||
sameAjcTestSpec(one, two, this); | |||
} catch (AssertionFailedError e) { | |||
passed = true; | |||
} | |||
assertTrue("did not get expected exception", passed); | |||
} | |||
} |