/* ******************************************************************* | /* ******************************************************************* | ||||
* Copyright (c) 1999-2001 Xerox Corporation, | |||||
* Copyright (c) 1999-2001 Xerox Corporation, | |||||
* 2002 Palo Alto Research Center, Incorporated (PARC). | * 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 | |||||
* ******************************************************************/ | * ******************************************************************/ | ||||
* @todo get rid of instanceof tests | * @todo get rid of instanceof tests | ||||
*/ | */ | ||||
public void buildView(StructureView view, IHierarchy model) { | public void buildView(StructureView view, IHierarchy model) { | ||||
// StructureViewProperties properties = view.getViewProperties(); | |||||
// StructureViewProperties properties = view.getViewProperties(); | |||||
IProgramElement modelRoot = null; | IProgramElement modelRoot = null; | ||||
// boolean noStructure = false; | |||||
// boolean noStructure = false; | |||||
if (isFileView(view)) { | if (isFileView(view)) { | ||||
FileStructureView fileView = (FileStructureView)view; | FileStructureView fileView = (FileStructureView)view; | ||||
if (fileView.getSourceFile() == null) { | |||||
if (fileView.getSourceFile() == null) { | |||||
modelRoot = IHierarchy.NO_STRUCTURE; | modelRoot = IHierarchy.NO_STRUCTURE; | ||||
// noStructure = true; | |||||
// noStructure = true; | |||||
} else { | } else { | ||||
modelRoot = model.findElementForSourceFile(fileView.getSourceFile()); | modelRoot = model.findElementForSourceFile(fileView.getSourceFile()); | ||||
} | } | ||||
} else { | } else { | ||||
modelRoot = model.getRoot(); | modelRoot = model.getRoot(); | ||||
} | } | ||||
IStructureViewNode viewRoot = null; | IStructureViewNode viewRoot = null; | ||||
if (!isFileView(view)) { | 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) { | if (viewRoot == null) { | ||||
viewRoot = createViewNode(modelRoot, view.getViewProperties());//modelRoot; | viewRoot = createViewNode(modelRoot, view.getViewProperties());//modelRoot; | ||||
} | |||||
} | |||||
if (view.getViewProperties().getSorting() == StructureViewProperties.Sorting.ALPHABETICAL | 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); | sortView(viewRoot, ALPHABETICAL_COMPARATOR); | ||||
} else { | } else { | ||||
sortView(viewRoot, DECLARATIONAL_COMPARATOR); | sortView(viewRoot, DECLARATIONAL_COMPARATOR); | ||||
} | |||||
} | |||||
addPackageNode(view, viewRoot); | addPackageNode(view, viewRoot); | ||||
view.setRootNode(viewRoot); | view.setRootNode(viewRoot); | ||||
} | } | ||||
private void addPackageNode(StructureView view, IStructureViewNode viewRoot) { | private void addPackageNode(StructureView view, IStructureViewNode viewRoot) { | ||||
if (isFileView(view)) { | 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) { | private IStructureViewNode createViewNode(IProgramElement node, StructureViewProperties properties) { | ||||
if (node == null) return null; | if (node == null) return null; | ||||
List children = new ArrayList(); | 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) { | if (node.isRunnable() && node.getParent() != null) { | ||||
IProgramElement parent = node.getParent(); | IProgramElement parent = node.getParent(); | ||||
if (parent.getKind().equals(IProgramElement.Kind.CLASS) | 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); | node.setRunnable(false); | ||||
} | } | ||||
} | } | ||||
if (node.getChildren() != null) { | 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)) { | if (acceptNode(IProgramElement, properties)) { | ||||
children.add(createViewNode(IProgramElement, properties)); | children.add(createViewNode(IProgramElement, properties)); | ||||
} | } | ||||
} | |||||
} | |||||
} | } | ||||
IStructureViewNode viewNode = nodeFactory.createNode(node, children);//new TreeViewNode(root, null, children); | IStructureViewNode viewNode = nodeFactory.createNode(node, children);//new TreeViewNode(root, null, children); | ||||
return viewNode; | |||||
return viewNode; | |||||
} | } | ||||
/** | /** | ||||
* @todo get rid of this test, fix polymorphism | * @todo get rid of this test, fix polymorphism | ||||
*/ | */ | ||||
private boolean isFileView(StructureView view) { | private boolean isFileView(StructureView view) { | ||||
return view instanceof FileStructureView | return view instanceof FileStructureView | ||||
&& !(view instanceof GlobalStructureView); | |||||
&& !(view instanceof GlobalStructureView); | |||||
} | } | ||||
private boolean acceptGranularity(IProgramElement.Kind kind, StructureViewProperties.Granularity granularity) { | private boolean acceptGranularity(IProgramElement.Kind kind, StructureViewProperties.Granularity granularity) { | ||||
if (granularity == StructureViewProperties.Granularity.DECLARED_ELEMENTS) { | if (granularity == StructureViewProperties.Granularity.DECLARED_ELEMENTS) { | ||||
return true; | return true; | ||||
} else if (granularity == StructureViewProperties.Granularity.MEMBER && | |||||
(kind != IProgramElement.Kind.CODE)) { | |||||
} else if (granularity == StructureViewProperties.Granularity.MEMBER && | |||||
(kind != IProgramElement.Kind.CODE)) { | |||||
return true; | return true; | ||||
} else if (granularity == StructureViewProperties.Granularity.TYPE | } else if (granularity == StructureViewProperties.Granularity.TYPE | ||||
&& (kind == IProgramElement.Kind.PROJECT | |||||
&& (kind == IProgramElement.Kind.PROJECT | |||||
|| kind == IProgramElement.Kind.PACKAGE | || kind == IProgramElement.Kind.PACKAGE | ||||
|| kind.isSourceFile() | || kind.isSourceFile() | ||||
|| kind.isType())) { | || kind.isType())) { | ||||
return true; | |||||
return true; | |||||
} else if (granularity == StructureViewProperties.Granularity.FILE | } else if (granularity == StructureViewProperties.Granularity.FILE | ||||
&& (kind == IProgramElement.Kind.PROJECT | |||||
&& (kind == IProgramElement.Kind.PROJECT | |||||
|| kind == IProgramElement.Kind.PACKAGE | || kind == IProgramElement.Kind.PACKAGE | ||||
|| kind.isSourceFile())) { | || kind.isSourceFile())) { | ||||
return true; | |||||
return true; | |||||
} else if (granularity == StructureViewProperties.Granularity.PACKAGE | } else if (granularity == StructureViewProperties.Granularity.PACKAGE | ||||
&& (kind == IProgramElement.Kind.PROJECT | |||||
&& (kind == IProgramElement.Kind.PROJECT | |||||
|| kind == IProgramElement.Kind.PACKAGE)) { | || kind == IProgramElement.Kind.PACKAGE)) { | ||||
return true; | |||||
return true; | |||||
} else { | } else { | ||||
return false; | return false; | ||||
} | } | ||||
} | } | ||||
private boolean acceptNode(IProgramElement node, StructureViewProperties properties) { | private boolean acceptNode(IProgramElement node, StructureViewProperties properties) { | ||||
if (node!=null) { | if (node!=null) { | ||||
IProgramElement pNode = node; | IProgramElement pNode = node; | ||||
return false; | return false; | ||||
} else if (pNode.getKind().isMember()) { | } else if (pNode.getKind().isMember()) { | ||||
if (properties.getFilteredMemberAccessibility().contains(pNode.getAccessibility())) { | if (properties.getFilteredMemberAccessibility().contains(pNode.getAccessibility())) { | ||||
return false; | |||||
return false; | |||||
} | } | ||||
if (properties.getFilteredMemberKinds().contains(pNode.getKind())) { | 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; | return true; | ||||
} | } | ||||
private void sortView(IStructureViewNode node, Comparator comparator) { | |||||
private void sortView(IStructureViewNode node, Comparator<IStructureViewNode> comparator) { | |||||
if (node == null || node.getChildren() == null) return; | if (node == null || node.getChildren() == null) return; | ||||
Collections.sort(node.getChildren(), comparator); | Collections.sort(node.getChildren(), comparator); | ||||
for (Iterator it = node.getChildren().iterator(); it.hasNext(); ) { | for (Iterator it = node.getChildren().iterator(); it.hasNext(); ) { | ||||
IStructureViewNode nextNode = (IStructureViewNode)it.next(); | 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. | * 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 (sv2.getKind() == IProgramElement.Kind.IMPORT_REFERENCE) return 1; | ||||
if (sv1.getKind() == IProgramElement.Kind.IMPORT_REFERENCE) return -1; | if (sv1.getKind() == IProgramElement.Kind.IMPORT_REFERENCE) return -1; | ||||
return sv1.getName().compareTo(sv2.getName()); | 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.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) { | // private boolean acceptNode(ProgramElementNode node) { |
/* ******************************************************************* | /* ******************************************************************* | ||||
* Copyright (c) 1999-2001 Xerox Corporation, | |||||
* Copyright (c) 1999-2001 Xerox Corporation, | |||||
* 2002 Palo Alto Research Center, Incorporated (PARC). | * 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 | * 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; | package org.aspectj.ajde.ui.internal; | ||||
import java.io.File; | import java.io.File; | ||||
import org.aspectj.util.LangUtil; | import org.aspectj.util.LangUtil; | ||||
public class UserPreferencesStore implements UserPreferencesAdapter { | 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() { | 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) { | public String getGlobalPreference(String name) { | ||||
return getProjectPreference(name); | return getProjectPreference(name); | ||||
} | } | ||||
@Override | |||||
public List getGlobalMultivalPreference(String name) { | public List getGlobalMultivalPreference(String name) { | ||||
return getProjectMultivalPreference(name); | return getProjectMultivalPreference(name); | ||||
} | } | ||||
@Override | |||||
public void setGlobalPreference(String name, String value) { | public void setGlobalPreference(String name, String value) { | ||||
setProjectPreference(name, value); | setProjectPreference(name, value); | ||||
} | } | ||||
@Override | |||||
public void setGlobalMultivalPreference(String name, List values) { | public void setGlobalMultivalPreference(String name, List values) { | ||||
setProjectMultivalPreference(name, values); | setProjectMultivalPreference(name, values); | ||||
} | } | ||||
private void loadProperties(String path) { | 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 | |||||
} | |||||
} | |||||
} | |||||
} | |||||
} | } |
/******************************************************************** | /******************************************************************** | ||||
* 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) | * Helen Hawkins - initial version (bug 148190) | ||||
*******************************************************************/ | *******************************************************************/ | ||||
package org.aspectj.ajde.ui.javaoptions; | package org.aspectj.ajde.ui.javaoptions; | ||||
import java.awt.Color; | import java.awt.Color; | ||||
import java.io.IOException; | import java.io.IOException; | ||||
import java.util.HashMap; | import java.util.HashMap; | ||||
import java.util.Iterator; | |||||
import java.util.Map; | import java.util.Map; | ||||
import java.util.Map.Entry; | |||||
import java.util.Set; | import java.util.Set; | ||||
import javax.swing.BorderFactory; | import javax.swing.BorderFactory; | ||||
public class JavaComplianceOptionsPanel extends 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 final String[] complianceLevels = new String[] {JavaOptions.VERSION_13, JavaOptions.VERSION_14, JavaOptions.VERSION_15, JavaOptions.VERSION_16}; | ||||
private static final long serialVersionUID = 4491319302490183151L; | private static final long serialVersionUID = 4491319302490183151L; | ||||
private JPanel parentPanel; | private JPanel parentPanel; | ||||
private Border complianceEtchedBorder; | private Border complianceEtchedBorder; | ||||
private Border complianceCompoundBorder; | private Border complianceCompoundBorder; | ||||
private JPanel compliancePanel; | private JPanel compliancePanel; | ||||
private Box complianceBox = Box.createVerticalBox(); | private Box complianceBox = Box.createVerticalBox(); | ||||
private JavaBuildOptions javaBuildOptions; | private JavaBuildOptions javaBuildOptions; | ||||
private Map/*String --> JComboBox*/ complianceComboBoxes = new HashMap(); | |||||
private Map<String,JComboBox<String>> complianceComboBoxes = new HashMap<>(); | |||||
public JavaComplianceOptionsPanel(JavaBuildOptions javaBuildOptions) { | public JavaComplianceOptionsPanel(JavaBuildOptions javaBuildOptions) { | ||||
this.javaBuildOptions = javaBuildOptions; | this.javaBuildOptions = javaBuildOptions; | ||||
try { | try { | ||||
} | } | ||||
} | } | ||||
@Override | |||||
public void loadOptions() throws IOException { | public void loadOptions() throws IOException { | ||||
createComplianceContents(); | 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(); | String value = (String) combo.getSelectedItem(); | ||||
javaBuildOptions.setOption(javaOption, value); | javaBuildOptions.setOption(javaOption, value); | ||||
} | } | ||||
} | |||||
} | |||||
private void jbInit() throws Exception { | private void jbInit() throws Exception { | ||||
this.setLayout(new BorderLayout()); | this.setLayout(new BorderLayout()); | ||||
private void createComplianceEntry(String labelText, String javaOptionToSet) { | private void createComplianceEntry(String labelText, String javaOptionToSet) { | ||||
JPanel panel = new JPanel(); | JPanel panel = new JPanel(); | ||||
panel.setLayout(new BorderLayout()); | panel.setLayout(new BorderLayout()); | ||||
JLabel label = new JLabel(); | JLabel label = new JLabel(); | ||||
label.setFont(new java.awt.Font("Dialog", 0, 11)); | label.setFont(new java.awt.Font("Dialog", 0, 11)); | ||||
label.setText(labelText); | label.setText(labelText); | ||||
panel.add(label,BorderLayout.WEST); | 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) { | if (value == null) { | ||||
// default to 1.5 | // default to 1.5 | ||||
levels.setSelectedIndex(2); | levels.setSelectedIndex(2); | ||||
} else if (value.equals(JavaOptions.VERSION_13)) { | } else if (value.equals(JavaOptions.VERSION_13)) { | ||||
levels.setSelectedIndex(0); | levels.setSelectedIndex(0); | ||||
} else if (value.equals(JavaOptions.VERSION_14)){ | } else if (value.equals(JavaOptions.VERSION_14)){ | ||||
levels.setSelectedIndex(1); | |||||
levels.setSelectedIndex(1); | |||||
} else if (value.equals(JavaOptions.VERSION_15)){ | } else if (value.equals(JavaOptions.VERSION_15)){ | ||||
levels.setSelectedIndex(2); | |||||
levels.setSelectedIndex(2); | |||||
} else if (value.equals(JavaOptions.VERSION_16)){ | } else if (value.equals(JavaOptions.VERSION_16)){ | ||||
levels.setSelectedIndex(3); | |||||
} | |||||
levels.setSelectedIndex(3); | |||||
} | |||||
panel.add(levels,BorderLayout.EAST); | panel.add(levels,BorderLayout.EAST); | ||||
complianceBox.add(panel,null); | complianceBox.add(panel,null); | ||||
complianceComboBoxes.put(javaOptionToSet,levels); | complianceComboBoxes.put(javaOptionToSet,levels); | ||||
} | } | ||||
private void createBorders() { | private void createBorders() { | ||||
complianceEtchedBorder = BorderFactory.createEtchedBorder(Color.white, new Color(156, 156, 158)); | complianceEtchedBorder = BorderFactory.createEtchedBorder(Color.white, new Color(156, 156, 158)); | ||||
complianceTitleBorder = new TitledBorder(complianceEtchedBorder, "Compliance Options"); | complianceTitleBorder = new TitledBorder(complianceEtchedBorder, "Compliance Options"); | ||||
BorderFactory.createEmptyBorder(5, 5, 5, 5)); | BorderFactory.createEmptyBorder(5, 5, 5, 5)); | ||||
complianceTitleBorder.setTitleFont(new java.awt.Font("Dialog", 0, 11)); | complianceTitleBorder.setTitleFont(new java.awt.Font("Dialog", 0, 11)); | ||||
} | } | ||||
private void addBordersToPanel() { | private void addBordersToPanel() { | ||||
parentPanel = new JPanel(); | parentPanel = new JPanel(); | ||||
parentPanel.setLayout(new BorderLayout()); | parentPanel.setLayout(new BorderLayout()); | ||||
compliancePanel = new JPanel(); | compliancePanel = new JPanel(); | ||||
compliancePanel.setBorder(complianceCompoundBorder); | compliancePanel.setBorder(complianceCompoundBorder); | ||||
/******************************************************************** | /******************************************************************** | ||||
* 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) | * Helen Hawkins - initial version (bug 148190) | ||||
*******************************************************************/ | *******************************************************************/ | ||||
package org.aspectj.ajde.ui.javaoptions; | package org.aspectj.ajde.ui.javaoptions; | ||||
import java.awt.Color; | import java.awt.Color; | ||||
import java.io.IOException; | import java.io.IOException; | ||||
import java.util.HashMap; | import java.util.HashMap; | ||||
import java.util.Iterator; | |||||
import java.util.Map; | import java.util.Map; | ||||
import java.util.Map.Entry; | |||||
import java.util.Set; | import java.util.Set; | ||||
import javax.swing.BorderFactory; | import javax.swing.BorderFactory; | ||||
private final String[] debugOptions = new String[] {JavaOptions.GENERATE,JavaOptions.DO_NOT_GENERATE}; | private final String[] debugOptions = new String[] {JavaOptions.GENERATE,JavaOptions.DO_NOT_GENERATE}; | ||||
private final String[] preserveOptions = new String[] {JavaOptions.PRESERVE,JavaOptions.OPTIMIZE}; | private final String[] preserveOptions = new String[] {JavaOptions.PRESERVE,JavaOptions.OPTIMIZE}; | ||||
private static final long serialVersionUID = 4491319302490183151L; | private static final long serialVersionUID = 4491319302490183151L; | ||||
private JPanel parentPanel; | private JPanel parentPanel; | ||||
private Border debugEtchedBorder; | private Border debugEtchedBorder; | ||||
private Border debugCompoundBorder; | private Border debugCompoundBorder; | ||||
private JPanel debugPanel; | private JPanel debugPanel; | ||||
private Box debugBox = Box.createVerticalBox(); | private Box debugBox = Box.createVerticalBox(); | ||||
private JavaBuildOptions javaBuildOptions; | private JavaBuildOptions javaBuildOptions; | ||||
private Map/*String --> JComboBox*/ debugComboBoxes = new HashMap(); | |||||
private Map<String,JComboBox<String>> debugComboBoxes = new HashMap(); | |||||
public JavaDebugOptionsPanel(JavaBuildOptions javaBuildOptions) { | public JavaDebugOptionsPanel(JavaBuildOptions javaBuildOptions) { | ||||
this.javaBuildOptions = javaBuildOptions; | this.javaBuildOptions = javaBuildOptions; | ||||
try { | try { | ||||
} | } | ||||
} | } | ||||
@Override | |||||
public void loadOptions() throws IOException { | public void loadOptions() throws IOException { | ||||
createDebugContents(); | 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(); | String value = (String) combo.getSelectedItem(); | ||||
javaBuildOptions.setOption(javaOption, value); | javaBuildOptions.setOption(javaOption, value); | ||||
} | } | ||||
} | |||||
} | |||||
private void jbInit() throws Exception { | private void jbInit() throws Exception { | ||||
this.setLayout(new BorderLayout()); | this.setLayout(new BorderLayout()); | ||||
private void createDebugContents() { | private void createDebugContents() { | ||||
createDebugEntry("Add line number attributes to generated class files",JavaOptions.DEBUG_LINES); | 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 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); | createDebugEntry("Preserve unused (never read) local variables",JavaOptions.PRESERVE_ALL_LOCALS); | ||||
debugPanel.add(debugBox); | debugPanel.add(debugBox); | ||||
} | } | ||||
private void createDebugEntry(String labelText, String javaOptionToSet) { | private void createDebugEntry(String labelText, String javaOptionToSet) { | ||||
JPanel panel = new JPanel(); | JPanel panel = new JPanel(); | ||||
panel.setLayout(new BorderLayout()); | panel.setLayout(new BorderLayout()); | ||||
JLabel label = new JLabel(); | JLabel label = new JLabel(); | ||||
label.setFont(new java.awt.Font("Dialog", 0, 11)); | label.setFont(new java.awt.Font("Dialog", 0, 11)); | ||||
label.setText(labelText); | label.setText(labelText); | ||||
panel.add(label,BorderLayout.WEST); | panel.add(label,BorderLayout.WEST); | ||||
JComboBox debug = null; | |||||
JComboBox<String> debug = null; | |||||
if (javaOptionToSet.equals(JavaOptions.PRESERVE_ALL_LOCALS)) { | 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)) { | if (value.equals(JavaOptions.PRESERVE)) { | ||||
debug.setSelectedIndex(0); | debug.setSelectedIndex(0); | ||||
} else { | } else { | ||||
debug.setSelectedIndex(1); | |||||
} | |||||
debug.setSelectedIndex(1); | |||||
} | |||||
} else { | } 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)) { | if (value.equals(JavaOptions.GENERATE)) { | ||||
debug.setSelectedIndex(0); | debug.setSelectedIndex(0); | ||||
} else { | } else { | ||||
debug.setSelectedIndex(1); | |||||
} | |||||
} | |||||
debug.setSelectedIndex(1); | |||||
} | |||||
} | |||||
panel.add(debug,BorderLayout.EAST); | panel.add(debug,BorderLayout.EAST); | ||||
debugBox.add(panel,null); | 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)); | debugEtchedBorder = BorderFactory.createEtchedBorder(Color.white, new Color(156, 156, 158)); | ||||
debugTitleBorder = new TitledBorder(debugEtchedBorder, "Debug Options"); | debugTitleBorder = new TitledBorder(debugEtchedBorder, "Debug Options"); | ||||
debugCompoundBorder = BorderFactory.createCompoundBorder(debugTitleBorder, | debugCompoundBorder = BorderFactory.createCompoundBorder(debugTitleBorder, | ||||
BorderFactory.createEmptyBorder(5, 5, 5, 5)); | BorderFactory.createEmptyBorder(5, 5, 5, 5)); | ||||
debugTitleBorder.setTitleFont(new java.awt.Font("Dialog", 0, 11)); | debugTitleBorder.setTitleFont(new java.awt.Font("Dialog", 0, 11)); | ||||
} | } | ||||
private void addBordersToPanel() { | private void addBordersToPanel() { | ||||
parentPanel = new JPanel(); | parentPanel = new JPanel(); | ||||
parentPanel.setLayout(new BorderLayout()); | parentPanel.setLayout(new BorderLayout()); | ||||
debugPanel = new JPanel(); | debugPanel = new JPanel(); | ||||
debugPanel.setBorder(debugCompoundBorder); | debugPanel.setBorder(debugCompoundBorder); | ||||
/* ******************************************************************* | /* ******************************************************************* | ||||
* Copyright (c) 2003 Contributors | * 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 | * Wes Isberg initial implementation | ||||
* ******************************************************************/ | * ******************************************************************/ | ||||
import java.util.HashMap; | import java.util.HashMap; | ||||
import java.util.Map; | 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.ajdt.internal.core.builder.AjState; | ||||
import org.aspectj.bridge.IMessage; | import org.aspectj.bridge.IMessage; | ||||
import org.aspectj.bridge.IMessageHolder; | import org.aspectj.bridge.IMessageHolder; | ||||
import org.aspectj.bridge.MessageHandler; | import org.aspectj.bridge.MessageHandler; | ||||
import org.aspectj.bridge.MessageUtil; | import org.aspectj.bridge.MessageUtil; | ||||
import org.aspectj.testing.harness.bridge.AjcTest; | 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.RunSpecIterator; | ||||
import org.aspectj.testing.harness.bridge.Sandbox; | import org.aspectj.testing.harness.bridge.Sandbox; | ||||
import org.aspectj.testing.harness.bridge.Validator; | import org.aspectj.testing.harness.bridge.Validator; | ||||
import org.aspectj.testing.run.RunStatus; | import org.aspectj.testing.run.RunStatus; | ||||
import org.aspectj.testing.run.Runner; | 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 | * 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 | * and AjcTest as TestCase. When run, aborts are reported as error and fails as | ||||
* the test. | * the test. | ||||
*/ | */ | ||||
public class AjctestsAdapter extends TestSuite { | 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; | |||||
} | |||||
} | |||||
} | } |
/* ******************************************************************* | /* ******************************************************************* | ||||
* Copyright (c) 1999-2001 Xerox Corporation, | |||||
* Copyright (c) 1999-2001 Xerox Corporation, | |||||
* 2002 Palo Alto Research Center, Incorporated (PARC). | * 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 | * Wes Isberg 2004 updates | ||||
* ******************************************************************/ | * ******************************************************************/ | ||||
* <u>Coordination with writers</u>: because this reads the contents of values written by IXmlWritable, they should ensure their | * <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 | * values are readable. When flattening and unflattening lists, the convention is to use the {un}flattenList(..) methods in | ||||
* XMLWriter. | * XMLWriter. | ||||
* | |||||
* | |||||
* @see XMLWriter@unflattenList(String) | * @see XMLWriter@unflattenList(String) | ||||
* @see XMLWriter@flattenList(List) | * @see XMLWriter@flattenList(List) | ||||
*/ | */ | ||||
// XXXXXunused sourceLocations = new ArrayList(); | // XXXXXunused sourceLocations = new ArrayList(); | ||||
keywords = new ArrayList<String>(); | keywords = new ArrayList<String>(); | ||||
children = new ArrayList<IRunSpec>(); | children = new ArrayList<IRunSpec>(); | ||||
dirChanges = new ArrayList(); | |||||
dirChanges = new ArrayList<>(); | |||||
xmlNames = XMLNames.DEFAULT; | xmlNames = XMLNames.DEFAULT; | ||||
runtime = new RT(); | runtime = new RT(); | ||||
this.skipIfAnyChildSkipped = skipIfAnyChildSkipped; | this.skipIfAnyChildSkipped = skipIfAnyChildSkipped; | ||||
public void addKeywords(String[] ra) { | public void addKeywords(String[] ra) { | ||||
if (null != ra) { | if (null != ra) { | ||||
for (int i = 0; i < ra.length; i++) { | |||||
addKeyword(ra[i]); | |||||
for (String element : ra) { | |||||
addKeyword(element); | |||||
} | } | ||||
} | } | ||||
} | } | ||||
/** @return String[] of options */ | /** @return String[] of options */ | ||||
public String[] getOptionsArray() { | public String[] getOptionsArray() { | ||||
return (String[]) options.toArray(new String[0]); | |||||
return options.toArray(new String[0]); | |||||
} | } | ||||
public void setOption(String option) { | public void setOption(String option) { | ||||
/** | /** | ||||
* Set options, removing any existing options. | * Set options, removing any existing options. | ||||
* | |||||
* | |||||
* @param options String[] options to use - may be null or empty | * @param options String[] options to use - may be null or empty | ||||
*/ | */ | ||||
public void setOptionsArray(String[] options) { | public void setOptionsArray(String[] options) { | ||||
public void addOptions(String[] ra) { | public void addOptions(String[] ra) { | ||||
if (null != ra) { | if (null != ra) { | ||||
for (int i = 0; i < ra.length; i++) { | |||||
addOption(ra[i]); | |||||
for (String element : ra) { | |||||
addOption(element); | |||||
} | } | ||||
} | } | ||||
} | } | ||||
/** @return String[] of paths */ | /** @return String[] of paths */ | ||||
public String[] getPathsArray() { | public String[] getPathsArray() { | ||||
return (String[]) paths.toArray(new String[0]); | |||||
return paths.toArray(new String[0]); | |||||
} | } | ||||
public void setPath(String path) { | public void setPath(String path) { | ||||
public void addPaths(String[] ra) { | public void addPaths(String[] ra) { | ||||
if (null != ra) { | if (null != ra) { | ||||
for (int i = 0; i < ra.length; i++) { | |||||
addPath(ra[i]); | |||||
for (String element : ra) { | |||||
addPath(element); | |||||
} | } | ||||
} | } | ||||
} | } | ||||
public void addMessages(String items) { | public void addMessages(String items) { | ||||
if (null != items) { | if (null != items) { | ||||
String[] ra = XMLWriter.unflattenList(items); | String[] ra = XMLWriter.unflattenList(items); | ||||
for (int i = 0; i < ra.length; i++) { | |||||
addMessage(ra[i]); | |||||
for (String element : ra) { | |||||
addMessage(element); | |||||
} | } | ||||
} | } | ||||
} | } | ||||
* or the child's adoptParentValues(..) should add one info message with the reason this is being skipped. The only reason to | * 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 | * override this would be to NOT invoke the same for children, or to do something similar for children which are not | ||||
* AbstractRunSpec. | * AbstractRunSpec. | ||||
* | |||||
* | |||||
* @param parentRuntime the RT values to adopt - ignored if null | * @param parentRuntime the RT values to adopt - ignored if null | ||||
* @param handler the IMessageHandler for info messages when skipping | * @param handler the IMessageHandler for info messages when skipping | ||||
* @return false if this wants to be skipped, true otherwise | * @return false if this wants to be skipped, true otherwise | ||||
* adds any non-null options we don't already have. setting verbose and adding to parent options. Implementors override this to | * 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 | * 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 | * 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 | * @param parentRuntime the RT values to adopt - never null | ||||
* @return false if this wants to be skipped, true otherwise | * @return false if this wants to be skipped, true otherwise | ||||
*/ | */ | ||||
/** | /** | ||||
* Implementations call this when signalling skips to ensure consistency in message formatting | * Implementations call this when signalling skips to ensure consistency in message formatting | ||||
* | |||||
* | |||||
* @param handler the IMessageHandler sink - not null | * @param handler the IMessageHandler sink - not null | ||||
* @param reason the String reason to skip - not null | * @param reason the String reason to skip - not null | ||||
*/ | */ | ||||
/** | /** | ||||
* Control XML output by renaming or suppressing output for attributes and subelements. Subelements are skipped by setting the | * 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. | * XMLNames booleans to false. Attributes are skipped by setting their name to null. | ||||
* | |||||
* | |||||
* @param names XMLNames with new names and/or suppress flags. | * @param names XMLNames with new names and/or suppress flags. | ||||
*/ | */ | ||||
protected void setXMLNames(XMLNames names) { | protected void setXMLNames(XMLNames names) { | ||||
return ((!LangUtil.isEmpty(xmlNames.descriptionName) && !LangUtil.isEmpty(description)) | return ((!LangUtil.isEmpty(xmlNames.descriptionName) && !LangUtil.isEmpty(description)) | ||||
|| (!LangUtil.isEmpty(xmlNames.keywordsName) && !LangUtil.isEmpty(keywords)) | || (!LangUtil.isEmpty(xmlNames.keywordsName) && !LangUtil.isEmpty(keywords)) | ||||
|| (!LangUtil.isEmpty(xmlNames.optionsName) && !LangUtil.isEmpty(options)) || (!LangUtil | || (!LangUtil.isEmpty(xmlNames.optionsName) && !LangUtil.isEmpty(options)) || (!LangUtil | ||||
.isEmpty(xmlNames.pathsName) && !LangUtil.isEmpty(paths))); | |||||
.isEmpty(xmlNames.pathsName) && !LangUtil.isEmpty(paths))); | |||||
} | } | ||||
/** | /** | ||||
* The default implementation writes everything as attributes, then subelements for dirChanges, messages, then subelements for | * 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 | * children. Subclasses that override may delegate back for any of these. Subclasses may also set XMLNames to name or suppress | ||||
* any attribute or subelement. | * any attribute or subelement. | ||||
* | |||||
* | |||||
* @see writeMessages(XMLWriter) | * @see writeMessages(XMLWriter) | ||||
* @see writeChildren(XMLWriter) | * @see writeChildren(XMLWriter) | ||||
* @see IXmlWritable#writeXml(XMLWriter) | * @see IXmlWritable#writeXml(XMLWriter) | ||||
*/ | */ | ||||
@Override | |||||
public void writeXml(XMLWriter out) { | public void writeXml(XMLWriter out) { | ||||
out.startElement(xmlElementName, false); | out.startElement(xmlElementName, false); | ||||
writeAttributes(out); | writeAttributes(out); | ||||
*/ | */ | ||||
protected void writeChildren(XMLWriter out) { | protected void writeChildren(XMLWriter out) { | ||||
if (0 < children.size()) { | 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); | self.writeXml(out); | ||||
} | } | ||||
} | } | ||||
public void printAll(PrintStream out, String prefix) { | public void printAll(PrintStream out, String prefix) { | ||||
out.println(prefix + toString()); | 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 + " "); | child.printAll(out, prefix + " "); | ||||
} | } | ||||
} | } | ||||
/** | /** | ||||
* default implementation returns the description if not empty or the unqualified class name otherwise. Subclasses should not | * 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. | * call toString from here unless they reimplement it. | ||||
* | |||||
* | |||||
* @return name of this thing or type | * @return name of this thing or type | ||||
*/ | */ | ||||
protected String getPrintName() { | protected String getPrintName() { | ||||
} | } | ||||
/** @return summary count of spec elements */ | /** @return summary count of spec elements */ | ||||
@Override | |||||
public String toString() { | public String toString() { | ||||
return getPrintName() + "(" + containedSummary() + ")"; | return getPrintName() + "(" + containedSummary() + ")"; | ||||
} | } | ||||
*/ | */ | ||||
spec.badInput = badInput; | spec.badInput = badInput; | ||||
spec.children.clear(); | 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? | // require all child classes to support clone? | ||||
if (child instanceof AbstractRunSpec) { | if (child instanceof AbstractRunSpec) { | ||||
spec.addChild((AbstractRunSpec) ((AbstractRunSpec) child).clone()); | spec.addChild((AbstractRunSpec) ((AbstractRunSpec) child).clone()); | ||||
final boolean skipMessages; | final boolean skipMessages; | ||||
final boolean skipChildren; | final boolean skipChildren; | ||||
@Override | |||||
protected Object clone() { | protected Object clone() { | ||||
return new XMLNames(null, descriptionName, sourceLocationName, keywordsName, optionsName, pathsName, commentName, | return new XMLNames(null, descriptionName, sourceLocationName, keywordsName, optionsName, pathsName, commentName, | ||||
stagingName, badInputName, skipDirChanges, skipMessages, skipChildren); | stagingName, badInputName, skipDirChanges, skipMessages, skipChildren); | ||||
} | } | ||||
/** subclasses implement this to create and set up a run */ | /** subclasses implement this to create and set up a run */ | ||||
@Override | |||||
abstract public IRunIterator makeRunIterator(Sandbox sandbox, Validator validator); | abstract public IRunIterator makeRunIterator(Sandbox sandbox, Validator validator); | ||||
/** segregate runtime-only state in spec */ | /** segregate runtime-only state in spec */ | ||||
/** | /** | ||||
* Set parent options - old options destroyed. Will result in duplicates if duplicates added. Null or empty entries are | * Set parent options - old options destroyed. Will result in duplicates if duplicates added. Null or empty entries are | ||||
* ignored | * ignored | ||||
* | |||||
* | |||||
* @param options ignored if null or empty | * @param options ignored if null or empty | ||||
*/ | */ | ||||
public void setOptions(String[] options) { | public void setOptions(String[] options) { | ||||
parentOptions.clear(); | parentOptions.clear(); | ||||
if (!LangUtil.isEmpty(options)) { | 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); | |||||
} | } | ||||
} | } | ||||
} | } | ||||
/** | /** | ||||
* Copy values from another RT | * Copy values from another RT | ||||
* | |||||
* | |||||
* @param toCopy the RT to copy from | * @param toCopy the RT to copy from | ||||
* @throws IllegalArgumentException if toCopy is null | * @throws IllegalArgumentException if toCopy is null | ||||
*/ | */ | ||||
/** | /** | ||||
* Return any parent option accepted by validOptions, optionally removing the parent option. | * Return any parent option accepted by validOptions, optionally removing the parent option. | ||||
* | |||||
* | |||||
* @param validOptions String[] of options to extract | * @param validOptions String[] of options to extract | ||||
* @param remove if true, then remove any parent option matched | * @param remove if true, then remove any parent option matched | ||||
* @return String[] containing any validOptions[i] in parentOptions | * @return String[] containing any validOptions[i] in parentOptions | ||||
* | |||||
* | |||||
*/ | */ | ||||
public Values extractOptions(Options validOptions, boolean remove, StringBuffer errors) { | public Values extractOptions(Options validOptions, boolean remove, StringBuffer errors) { | ||||
Values result = Values.EMPTY; | Values result = Values.EMPTY; | ||||
return result; | return result; | ||||
} | } | ||||
// boolean haveOption = false; | // boolean haveOption = false; | ||||
String[] parents = (String[]) parentOptions.toArray(new String[0]); | |||||
String[] parents = parentOptions.toArray(new String[0]); | |||||
try { | try { | ||||
result = validOptions.acceptInput(parents); | result = validOptions.acceptInput(parents); | ||||
} catch (InvalidInputException e) { | } catch (InvalidInputException e) { | ||||
/** | /** | ||||
* Return any parent option which has one of validOptions as a prefix, optionally absorbing (removing) the parent option. | * 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 validOptions String[] of options to extract | ||||
* @param absorb if true, then remove any parent option matched | * @param absorb if true, then remove any parent option matched | ||||
* @return String[] containing any validOptions[i] in parentOptions (at most once) | * @return String[] containing any validOptions[i] in parentOptions (at most once) | ||||
} | } | ||||
ArrayList<String> result = new ArrayList<String>(); | ArrayList<String> result = new ArrayList<String>(); | ||||
// boolean haveOption = false; | // boolean haveOption = false; | ||||
for (int i = 0; i < validOptions.length; i++) { | |||||
String option = validOptions[i]; | |||||
for (String option : validOptions) { | |||||
if (LangUtil.isEmpty(option)) { | if (LangUtil.isEmpty(option)) { | ||||
continue; | continue; | ||||
} | } | ||||
} | } | ||||
} | } | ||||
} | } | ||||
return (String[]) result.toArray(new String[0]); | |||||
return result.toArray(new String[0]); | |||||
} | } | ||||
/** Get ListIterator that permits removals */ | /** Get ListIterator that permits removals */ | ||||
/** | /** | ||||
* Enable verbose logging | * Enable verbose logging | ||||
* | |||||
* | |||||
* @param verbose if true, do verbose logging | * @param verbose if true, do verbose logging | ||||
*/ | */ | ||||
public void setVerbose(boolean verbose) { | public void setVerbose(boolean verbose) { |
/* ******************************************************************* | /* ******************************************************************* | ||||
* Copyright (c) 1999-2001 Xerox Corporation, | |||||
* Copyright (c) 1999-2001 Xerox Corporation, | |||||
* 2002 Palo Alto Research Center, Incorporated (PARC). | * 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; | package org.aspectj.testing.harness.bridge; | ||||
* Primarily used by others to test AjcTest | * Primarily used by others to test AjcTest | ||||
*/ | */ | ||||
public class AjcSpecTest extends TestCase { | 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( | 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( | 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) { | 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) { | 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) { | 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 | |||||
} | } | ||||
/** | /** | ||||
public AjcSpecTest(String name) { | public AjcSpecTest(String name) { | ||||
super(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); | |||||
} | |||||
} | } |