diff options
author | Andy Clement <aclement@pivotal.io> | 2019-11-29 11:36:58 -0800 |
---|---|---|
committer | Andy Clement <aclement@pivotal.io> | 2019-11-29 11:36:58 -0800 |
commit | 17026e35243f229c2e3c07c292f2caaac65503a4 (patch) | |
tree | ac7d72940ca7c36e3358c8bf341a36d560741ef2 /ajde | |
parent | c3c07fdb4b93cc483317d8a314233f0b9dcf4d8b (diff) | |
download | aspectj-17026e35243f229c2e3c07c292f2caaac65503a4.tar.gz aspectj-17026e35243f229c2e3c07c292f2caaac65503a4.zip |
polish
Diffstat (limited to 'ajde')
4 files changed, 477 insertions, 472 deletions
diff --git a/ajde/src/main/java/org/aspectj/ajde/ui/internal/TreeStructureViewBuilder.java b/ajde/src/main/java/org/aspectj/ajde/ui/internal/TreeStructureViewBuilder.java index 9021cbfe7..728ed9069 100644 --- a/ajde/src/main/java/org/aspectj/ajde/ui/internal/TreeStructureViewBuilder.java +++ b/ajde/src/main/java/org/aspectj/ajde/ui/internal/TreeStructureViewBuilder.java @@ -1,14 +1,14 @@ /* ******************************************************************* - * Copyright (c) 1999-2001 Xerox Corporation, + * Copyright (c) 1999-2001 Xerox Corporation, * 2002 Palo Alto Research Center, Incorporated (PARC). - * All rights reserved. - * This program and the accompanying materials are made available - * under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Xerox/PARC initial implementation + * All rights reserved. + * This program and the accompanying materials are made available + * under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Xerox/PARC initial implementation * ******************************************************************/ @@ -46,132 +46,132 @@ public class TreeStructureViewBuilder { * @todo get rid of instanceof tests */ public void buildView(StructureView view, IHierarchy model) { -// StructureViewProperties properties = view.getViewProperties(); + // StructureViewProperties properties = view.getViewProperties(); IProgramElement modelRoot = null; -// boolean noStructure = false; + // boolean noStructure = false; if (isFileView(view)) { FileStructureView fileView = (FileStructureView)view; - if (fileView.getSourceFile() == null) { + if (fileView.getSourceFile() == null) { modelRoot = IHierarchy.NO_STRUCTURE; -// noStructure = true; + // noStructure = true; } else { modelRoot = model.findElementForSourceFile(fileView.getSourceFile()); } } else { modelRoot = model.getRoot(); } - + IStructureViewNode viewRoot = null; if (!isFileView(view)) { - StructureViewProperties.Hierarchy hierarchy - = ((GlobalStructureView)view).getGlobalViewProperties().getHierarchy(); - if (hierarchy.equals(StructureViewProperties.Hierarchy.CROSSCUTTING) - || hierarchy.equals(StructureViewProperties.Hierarchy.INHERITANCE)) { - viewRoot = buildCustomTree((GlobalStructureView)view, model); - } - } + StructureViewProperties.Hierarchy hierarchy + = ((GlobalStructureView)view).getGlobalViewProperties().getHierarchy(); + if (hierarchy.equals(StructureViewProperties.Hierarchy.CROSSCUTTING) + || hierarchy.equals(StructureViewProperties.Hierarchy.INHERITANCE)) { + viewRoot = buildCustomTree((GlobalStructureView)view, model); + } + } if (viewRoot == null) { viewRoot = createViewNode(modelRoot, view.getViewProperties());//modelRoot; - } - + } + if (view.getViewProperties().getSorting() == StructureViewProperties.Sorting.ALPHABETICAL - || (!isFileView(view) && - ((GlobalStructureView)view).getGlobalViewProperties().getHierarchy().equals(StructureViewProperties.Hierarchy.DECLARATION))) { + || (!isFileView(view) && + ((GlobalStructureView)view).getGlobalViewProperties().getHierarchy().equals(StructureViewProperties.Hierarchy.DECLARATION))) { sortView(viewRoot, ALPHABETICAL_COMPARATOR); } else { sortView(viewRoot, DECLARATIONAL_COMPARATOR); - } - + } + addPackageNode(view, viewRoot); view.setRootNode(viewRoot); } private void addPackageNode(StructureView view, IStructureViewNode viewRoot) { if (isFileView(view)) { -// IProgramElement fileNode = viewRoot.getStructureNode(); -// IProgramElement parentNode = fileNode.getParent(); -// -// if (parentNode.getKind() == IProgramElement.Kind.PACKAGE) { -// String name = parentNode.getName(); -// IProgramElement packageNode = new ProgramElement(name, IProgramElement.Kind.PACKAGE, null); -// packageNode.setSourceLocation(fileNode.getSourceLocation()); -// StructureViewNode packageViewNode = createViewNode( -// packageNode, -// view.getViewProperties() -// ); -// viewRoot.getChildren().add(0, packageViewNode); -// }; + // IProgramElement fileNode = viewRoot.getStructureNode(); + // IProgramElement parentNode = fileNode.getParent(); + // + // if (parentNode.getKind() == IProgramElement.Kind.PACKAGE) { + // String name = parentNode.getName(); + // IProgramElement packageNode = new ProgramElement(name, IProgramElement.Kind.PACKAGE, null); + // packageNode.setSourceLocation(fileNode.getSourceLocation()); + // StructureViewNode packageViewNode = createViewNode( + // packageNode, + // view.getViewProperties() + // ); + // viewRoot.getChildren().add(0, packageViewNode); + // }; } } - + private IStructureViewNode createViewNode(IProgramElement node, StructureViewProperties properties) { if (node == null) return null; List children = new ArrayList(); -// IProgramElement pNode = node; -// if (node.getRelations() != null) { -// for (Iterator it = node.getRelations().iterator(); it.hasNext(); ) { -// IProgramElement IProgramElement = (IProgramElement)it.next(); -// if (acceptNode(IProgramElement, properties)) { -// children.add(createViewNode(IProgramElement, properties)); -// } -// } -// } + // IProgramElement pNode = node; + // if (node.getRelations() != null) { + // for (Iterator it = node.getRelations().iterator(); it.hasNext(); ) { + // IProgramElement IProgramElement = (IProgramElement)it.next(); + // if (acceptNode(IProgramElement, properties)) { + // children.add(createViewNode(IProgramElement, properties)); + // } + // } + // } if (node.isRunnable() && node.getParent() != null) { IProgramElement parent = node.getParent(); if (parent.getKind().equals(IProgramElement.Kind.CLASS) - || parent.getKind().equals(IProgramElement.Kind.ASPECT)) { - parent.setRunnable(true); + || parent.getKind().equals(IProgramElement.Kind.ASPECT)) { + parent.setRunnable(true); node.setRunnable(false); } } if (node.getChildren() != null) { - for (Iterator it = node.getChildren().iterator(); it.hasNext(); ) { - IProgramElement IProgramElement = (IProgramElement)it.next(); + for (Object element : node.getChildren()) { + IProgramElement IProgramElement = (IProgramElement)element; if (acceptNode(IProgramElement, properties)) { children.add(createViewNode(IProgramElement, properties)); } - } + } } IStructureViewNode viewNode = nodeFactory.createNode(node, children);//new TreeViewNode(root, null, children); - return viewNode; + return viewNode; } - + /** * @todo get rid of this test, fix polymorphism */ private boolean isFileView(StructureView view) { return view instanceof FileStructureView - && !(view instanceof GlobalStructureView); + && !(view instanceof GlobalStructureView); } - + private boolean acceptGranularity(IProgramElement.Kind kind, StructureViewProperties.Granularity granularity) { - + if (granularity == StructureViewProperties.Granularity.DECLARED_ELEMENTS) { return true; - } else if (granularity == StructureViewProperties.Granularity.MEMBER && - (kind != IProgramElement.Kind.CODE)) { + } else if (granularity == StructureViewProperties.Granularity.MEMBER && + (kind != IProgramElement.Kind.CODE)) { return true; } else if (granularity == StructureViewProperties.Granularity.TYPE - && (kind == IProgramElement.Kind.PROJECT + && (kind == IProgramElement.Kind.PROJECT || kind == IProgramElement.Kind.PACKAGE || kind.isSourceFile() || kind.isType())) { - return true; + return true; } else if (granularity == StructureViewProperties.Granularity.FILE - && (kind == IProgramElement.Kind.PROJECT + && (kind == IProgramElement.Kind.PROJECT || kind == IProgramElement.Kind.PACKAGE || kind.isSourceFile())) { - return true; + return true; } else if (granularity == StructureViewProperties.Granularity.PACKAGE - && (kind == IProgramElement.Kind.PROJECT + && (kind == IProgramElement.Kind.PROJECT || kind == IProgramElement.Kind.PACKAGE)) { - return true; + return true; } else { return false; } } - + private boolean acceptNode(IProgramElement node, StructureViewProperties properties) { if (node!=null) { IProgramElement pNode = node; @@ -179,250 +179,249 @@ public class TreeStructureViewBuilder { return false; } else if (pNode.getKind().isMember()) { if (properties.getFilteredMemberAccessibility().contains(pNode.getAccessibility())) { - return false; + return false; } if (properties.getFilteredMemberKinds().contains(pNode.getKind())) { - return false; + return false; } - for (Iterator it = pNode.getModifiers().iterator(); it.hasNext(); ) { - if (properties.getFilteredMemberModifiers().contains(it.next())) { - return false; - } + for (Object element : pNode.getModifiers()) { + if (properties.getFilteredMemberModifiers().contains(element)) { + return false; + } } } } return true; } - private void sortView(IStructureViewNode node, Comparator comparator) { + private void sortView(IStructureViewNode node, Comparator<IStructureViewNode> comparator) { if (node == null || node.getChildren() == null) return; Collections.sort(node.getChildren(), comparator); for (Iterator it = node.getChildren().iterator(); it.hasNext(); ) { IStructureViewNode nextNode = (IStructureViewNode)it.next(); - if (nextNode != null) sortView(nextNode, comparator); + if (nextNode != null) sortView(nextNode, comparator); } } - private IStructureViewNode buildCustomTree(GlobalStructureView view, IHierarchy model) { - IProgramElement rootNode = model.getRoot(); - IStructureViewNode treeNode = nodeFactory.createNode(rootNode); - - List rootNodes = new ArrayList(); - getRoots(rootNode, rootNodes, view.getGlobalViewProperties().getHierarchy()); - - for (Iterator it = rootNodes.iterator(); it.hasNext(); ) { - if (view.getGlobalViewProperties().getHierarchy().equals(StructureViewProperties.Hierarchy.CROSSCUTTING)) { - treeNode.add(getCrosscuttingChildren((IProgramElement)it.next())); - } else if (view.getGlobalViewProperties().getHierarchy().equals(StructureViewProperties.Hierarchy.INHERITANCE)) { - treeNode.add(getInheritanceChildren( - (IProgramElement)it.next(), - view.getViewProperties().getRelations()) - ); - } - } - return treeNode; - } - - private void getRoots(IProgramElement rootNode, List roots, StructureViewProperties.Hierarchy hierarchy) { -// if (rootNode != null && rootNode.getChildren() != null) { -// for (Iterator it = rootNode.getChildren().iterator(); it.hasNext(); ) { -// IProgramElement node = (IProgramElement)it.next(); -// if (node instanceof IProgramElement) { -// if (acceptNodeAsRoot((IProgramElement)node, hierarchy)) { -// IProgramElement pNode = (IProgramElement)node; -// List relations = pNode.getRelations(); -// String delimiter = ""; -// if (hierarchy.equals(StructureViewProperties.Hierarchy.CROSSCUTTING)) { -// delimiter = "uses pointcut"; -// } else if (hierarchy.equals(StructureViewProperties.Hierarchy.INHERITANCE)) { -// delimiter = "inherits"; -// } -// if (relations != null && relations.toString().indexOf(delimiter) == -1) { -// boolean found = false; -// for (Iterator it2 = roots.iterator(); it2.hasNext(); ) { -// if (((IProgramElement)it2.next()).equals(pNode)) found = true; -// } -// if (!found) roots.add(pNode); -// } -// } -// } -// getRoots(node, roots, hierarchy); -// } -// } - } - - public boolean acceptNodeAsRoot(IProgramElement node, StructureViewProperties.Hierarchy hierarchy) { - if (hierarchy.equals(StructureViewProperties.Hierarchy.CROSSCUTTING)) { - return node.getKind().equals(IProgramElement.Kind.ADVICE) - || node.getKind().equals(IProgramElement.Kind.POINTCUT); - } else if (hierarchy.equals(StructureViewProperties.Hierarchy.INHERITANCE)) { - return node.getKind().equals(IProgramElement.Kind.CLASS); - } else { - return false; - } - } - - private IStructureViewNode getInheritanceChildren(IProgramElement node, List associations) { -// IStructureViewNode treeNode = nodeFactory.createNode(node); -// //StructureViewNode treeNode = new StructureViewNodeAdapter(node); -// List relations = ((IProgramElement)node).getRelations(); - throw new RuntimeException("unimplemented"); -// if (relations != null) { -// for (Iterator it = relations.iterator(); it.hasNext(); ) { -// IRelationship relation = (IRelationship)it.next(); -// if (relation.getName().equals("is inherited by")) { -// for (Iterator it2 = relation.getTargets().iterator(); it2.hasNext(); ) { -//// IProgramElement pNode = ((LinkNode)it2.next()).getProgramElementNode(); -//// StructureViewNode newNode = getInheritanceChildren(pNode, associations); -// StructureViewNode typeChildren = buildTree(newNode.getStructureNode(), associations); -// for (int i = 0; i < typeChildren.getChildren().size(); i++) { -// newNode.add((StructureViewNode)typeChildren.getChildren().get(i)); -// } -// treeNode.add(newNode); -// } -// } -// } -// } -// return treeNode; - } - - private IStructureViewNode getCrosscuttingChildren(IProgramElement node) { - //StructureViewNodeAdapter treeNode = new StructureViewNodeAdapter(node); -// IStructureViewNode treeNode = nodeFactory.createNode(node); -// List relations = ((IProgramElement)node).getRelations(); - throw new RuntimeException("unimplemented"); -// if (relations != null) { -// for (Iterator it = relations.iterator(); it.hasNext(); ) { -// IRelationship relation = (IRelationship)it.next(); -// if (relation.getName().equals("pointcut used by")) { -// for (Iterator it2 = relation.getTargets().iterator(); it2.hasNext(); ) { -// IProgramElement pNode = ((LinkNode)it2.next()).getProgramElementNode(); -// StructureViewNode newNode = getCrosscuttingChildren(pNode); -// for (Iterator it3 = pNode.getRelations().iterator(); it3.hasNext(); ) { -// IRelationship relationNode = (IRelation)it3.next(); -// if (relationNode.getName().indexOf("pointcut") == -1) { -// newNode.add(getRelations(relationNode)); -// } -// } -// treeNode.add(newNode); -// } -// } else if (relations.toString().indexOf("uses pointcut") == -1) { -// for (Iterator it4 = relations.iterator(); it4.hasNext(); ) { -// IRelation relationNode = (IRelationship)it4.next(); -// if (relationNode.getName().indexOf("pointcut") == -1) { -// treeNode.add(getRelations(relationNode)); -// } -// } -// } -// } -// } -// return treeNode; - } - -// private IStructureViewNode buildTree(IProgramElement node, List associations) { -// //StructureViewNode treeNode = new StructureViewNodeAdapter(node); -// IStructureViewNode treeNode = nodeFactory.createNode(node); -//// if (node instanceof IProgramElement) { -// List relations = ((IProgramElement)node).getRelations(); -// if (relations != null) { -// for (Iterator it = relations.iterator(); it.hasNext(); ) { -// IRelationship relationNode = (IRelationship)it.next(); -// if (associations.contains(relationNode.toString())) { -// treeNode.add(buildTree(relationNode, associations)); -// } -// } -// } -// } -// if (node != null) { -// List children = null; -// children = node.getChildren(); -// if (children != null) { -// List childList = new ArrayList(); -// for (Iterator itt = children.iterator(); itt.hasNext(); ) { -// IProgramElement child = (IProgramElement)itt.next(); -// if (child instanceof IProgramElement) { -// IProgramElement progNode = (IProgramElement)child; -//// if (progNode.getKind() != IProgramElement.Kind.CODE) { -// childList.add(buildTree(child, associations)); -//// } -// } else { -// childList.add(buildTree(child, associations)); -// } -// } -// //sortNodes(childList); -// for (Iterator it = childList.iterator(); it.hasNext(); ) { -// treeNode.add((IStructureViewNode)it.next()); -// } -// } -// -// } -// return treeNode; -// } + private IStructureViewNode buildCustomTree(GlobalStructureView view, IHierarchy model) { + IProgramElement rootNode = model.getRoot(); + IStructureViewNode treeNode = nodeFactory.createNode(rootNode); -// private IStructureViewNode getRelations(IRelationship node) { -// return null; -// //StructureViewNode treeNode = new StructureViewNode(node); -//// IStructureViewNode treeNode = nodeFactory.c(node); -//// for (Iterator it = node.getTargets().iterator(); it.hasNext(); ) { -//// treeNode.add( -//// nodeFactory.createNode((IProgramElement)it.next()) -//// ); -//// } -//// return treeNode; -// } -// -// /** -// * For debugging only. -// */ -// private void dumpView(IStructureViewNode root, int level) { -// System.out.println(root.getStructureNode()); -// for (Iterator it = root.getChildren().iterator(); it.hasNext(); ) { -// dumpView((IStructureViewNode)it.next(), level++); -// } -// for (int i = 0; i < level; i++) { -// System.out.print(' '); -// } -// } + List rootNodes = new ArrayList(); + getRoots(rootNode, rootNodes, view.getGlobalViewProperties().getHierarchy()); + + for (Iterator it = rootNodes.iterator(); it.hasNext(); ) { + if (view.getGlobalViewProperties().getHierarchy().equals(StructureViewProperties.Hierarchy.CROSSCUTTING)) { + treeNode.add(getCrosscuttingChildren((IProgramElement)it.next())); + } else if (view.getGlobalViewProperties().getHierarchy().equals(StructureViewProperties.Hierarchy.INHERITANCE)) { + treeNode.add(getInheritanceChildren( + (IProgramElement)it.next(), + view.getViewProperties().getRelations()) + ); + } + } + return treeNode; + } + + private void getRoots(IProgramElement rootNode, List roots, StructureViewProperties.Hierarchy hierarchy) { + // if (rootNode != null && rootNode.getChildren() != null) { + // for (Iterator it = rootNode.getChildren().iterator(); it.hasNext(); ) { + // IProgramElement node = (IProgramElement)it.next(); + // if (node instanceof IProgramElement) { + // if (acceptNodeAsRoot((IProgramElement)node, hierarchy)) { + // IProgramElement pNode = (IProgramElement)node; + // List relations = pNode.getRelations(); + // String delimiter = ""; + // if (hierarchy.equals(StructureViewProperties.Hierarchy.CROSSCUTTING)) { + // delimiter = "uses pointcut"; + // } else if (hierarchy.equals(StructureViewProperties.Hierarchy.INHERITANCE)) { + // delimiter = "inherits"; + // } + // if (relations != null && relations.toString().indexOf(delimiter) == -1) { + // boolean found = false; + // for (Iterator it2 = roots.iterator(); it2.hasNext(); ) { + // if (((IProgramElement)it2.next()).equals(pNode)) found = true; + // } + // if (!found) roots.add(pNode); + // } + // } + // } + // getRoots(node, roots, hierarchy); + // } + // } + } + + public boolean acceptNodeAsRoot(IProgramElement node, StructureViewProperties.Hierarchy hierarchy) { + if (hierarchy.equals(StructureViewProperties.Hierarchy.CROSSCUTTING)) { + return node.getKind().equals(IProgramElement.Kind.ADVICE) + || node.getKind().equals(IProgramElement.Kind.POINTCUT); + } else if (hierarchy.equals(StructureViewProperties.Hierarchy.INHERITANCE)) { + return node.getKind().equals(IProgramElement.Kind.CLASS); + } else { + return false; + } + } + + private IStructureViewNode getInheritanceChildren(IProgramElement node, List associations) { + // IStructureViewNode treeNode = nodeFactory.createNode(node); + // //StructureViewNode treeNode = new StructureViewNodeAdapter(node); + // List relations = ((IProgramElement)node).getRelations(); + throw new RuntimeException("unimplemented"); + // if (relations != null) { + // for (Iterator it = relations.iterator(); it.hasNext(); ) { + // IRelationship relation = (IRelationship)it.next(); + // if (relation.getName().equals("is inherited by")) { + // for (Iterator it2 = relation.getTargets().iterator(); it2.hasNext(); ) { + //// IProgramElement pNode = ((LinkNode)it2.next()).getProgramElementNode(); + //// StructureViewNode newNode = getInheritanceChildren(pNode, associations); + // StructureViewNode typeChildren = buildTree(newNode.getStructureNode(), associations); + // for (int i = 0; i < typeChildren.getChildren().size(); i++) { + // newNode.add((StructureViewNode)typeChildren.getChildren().get(i)); + // } + // treeNode.add(newNode); + // } + // } + // } + // } + // return treeNode; + } + + private IStructureViewNode getCrosscuttingChildren(IProgramElement node) { + //StructureViewNodeAdapter treeNode = new StructureViewNodeAdapter(node); + // IStructureViewNode treeNode = nodeFactory.createNode(node); + // List relations = ((IProgramElement)node).getRelations(); + throw new RuntimeException("unimplemented"); + // if (relations != null) { + // for (Iterator it = relations.iterator(); it.hasNext(); ) { + // IRelationship relation = (IRelationship)it.next(); + // if (relation.getName().equals("pointcut used by")) { + // for (Iterator it2 = relation.getTargets().iterator(); it2.hasNext(); ) { + // IProgramElement pNode = ((LinkNode)it2.next()).getProgramElementNode(); + // StructureViewNode newNode = getCrosscuttingChildren(pNode); + // for (Iterator it3 = pNode.getRelations().iterator(); it3.hasNext(); ) { + // IRelationship relationNode = (IRelation)it3.next(); + // if (relationNode.getName().indexOf("pointcut") == -1) { + // newNode.add(getRelations(relationNode)); + // } + // } + // treeNode.add(newNode); + // } + // } else if (relations.toString().indexOf("uses pointcut") == -1) { + // for (Iterator it4 = relations.iterator(); it4.hasNext(); ) { + // IRelation relationNode = (IRelationship)it4.next(); + // if (relationNode.getName().indexOf("pointcut") == -1) { + // treeNode.add(getRelations(relationNode)); + // } + // } + // } + // } + // } + // return treeNode; + } + + // private IStructureViewNode buildTree(IProgramElement node, List associations) { + // //StructureViewNode treeNode = new StructureViewNodeAdapter(node); + // IStructureViewNode treeNode = nodeFactory.createNode(node); + //// if (node instanceof IProgramElement) { + // List relations = ((IProgramElement)node).getRelations(); + // if (relations != null) { + // for (Iterator it = relations.iterator(); it.hasNext(); ) { + // IRelationship relationNode = (IRelationship)it.next(); + // if (associations.contains(relationNode.toString())) { + // treeNode.add(buildTree(relationNode, associations)); + // } + // } + // } + // } + // if (node != null) { + // List children = null; + // children = node.getChildren(); + // if (children != null) { + // List childList = new ArrayList(); + // for (Iterator itt = children.iterator(); itt.hasNext(); ) { + // IProgramElement child = (IProgramElement)itt.next(); + // if (child instanceof IProgramElement) { + // IProgramElement progNode = (IProgramElement)child; + //// if (progNode.getKind() != IProgramElement.Kind.CODE) { + // childList.add(buildTree(child, associations)); + //// } + // } else { + // childList.add(buildTree(child, associations)); + // } + // } + // //sortNodes(childList); + // for (Iterator it = childList.iterator(); it.hasNext(); ) { + // treeNode.add((IStructureViewNode)it.next()); + // } + // } + // + // } + // return treeNode; + // } + + // private IStructureViewNode getRelations(IRelationship node) { + // return null; + // //StructureViewNode treeNode = new StructureViewNode(node); + //// IStructureViewNode treeNode = nodeFactory.c(node); + //// for (Iterator it = node.getTargets().iterator(); it.hasNext(); ) { + //// treeNode.add( + //// nodeFactory.createNode((IProgramElement)it.next()) + //// ); + //// } + //// return treeNode; + // } + // + // /** + // * For debugging only. + // */ + // private void dumpView(IStructureViewNode root, int level) { + // System.out.println(root.getStructureNode()); + // for (Iterator it = root.getChildren().iterator(); it.hasNext(); ) { + // dumpView((IStructureViewNode)it.next(), level++); + // } + // for (int i = 0; i < level; i++) { + // System.out.print(' '); + // } + // } /** * Does not sort imports alphabetically. */ - private static final Comparator ALPHABETICAL_COMPARATOR = new Comparator() { - public int compare(Object o1, Object o2) { - IProgramElement sv1 = ((IStructureViewNode)o1).getStructureNode(); - IProgramElement sv2 = ((IStructureViewNode)o2).getStructureNode(); - - if (sv1!=null && sv2!=null) { - + private static final Comparator<IStructureViewNode> ALPHABETICAL_COMPARATOR = new Comparator<IStructureViewNode>() { + @Override + public int compare(IStructureViewNode o1, IStructureViewNode o2) { + IProgramElement sv1 = o1.getStructureNode(); + IProgramElement sv2 = o2.getStructureNode(); + if (sv1!=null && sv2!=null) { if (sv2.getKind() == IProgramElement.Kind.IMPORT_REFERENCE) return 1; if (sv1.getKind() == IProgramElement.Kind.IMPORT_REFERENCE) return -1; - return sv1.getName().compareTo(sv2.getName()); - } else { - return 0; - } - } - }; - - private static final Comparator DECLARATIONAL_COMPARATOR = new Comparator() { - public int compare(Object o1, Object o2) { - IProgramElement sv1 = ((IStructureViewNode)o1).getStructureNode(); - IProgramElement sv2 = ((IStructureViewNode)o2).getStructureNode(); - if (sv1!=null && sv2!=null) { - if (sv2.getKind() == IProgramElement.Kind.IMPORT_REFERENCE) return 1; + } else { + return 0; + } + } + }; + + private static final Comparator<IStructureViewNode> DECLARATIONAL_COMPARATOR = new Comparator<IStructureViewNode>() { + @Override + public int compare(IStructureViewNode o1, IStructureViewNode o2) { + IProgramElement sv1 = o1.getStructureNode(); + IProgramElement sv2 = o2.getStructureNode(); + if (sv1!=null && sv2!=null) { + if (sv2.getKind() == IProgramElement.Kind.IMPORT_REFERENCE) return 1; if (sv1.getKind() == IProgramElement.Kind.IMPORT_REFERENCE) return -1; - if (sv1.getSourceLocation() == null || sv2.getSourceLocation() == null) { - return 0; - } else if (sv1.getSourceLocation().getLine() < sv2.getSourceLocation().getLine()) { - return -1; - } else { - return 1; - } - } else { - return 0; - } - } - }; + if (sv1.getSourceLocation() == null || sv2.getSourceLocation() == null) { + return 0; + } else if (sv1.getSourceLocation().getLine() < sv2.getSourceLocation().getLine()) { + return -1; + } else { + return 1; + } + } else { + return 0; + } + } + }; } // private boolean acceptNode(ProgramElementNode node) { diff --git a/ajde/src/main/java/org/aspectj/ajde/ui/internal/UserPreferencesStore.java b/ajde/src/main/java/org/aspectj/ajde/ui/internal/UserPreferencesStore.java index b1120f0fb..572506aed 100644 --- a/ajde/src/main/java/org/aspectj/ajde/ui/internal/UserPreferencesStore.java +++ b/ajde/src/main/java/org/aspectj/ajde/ui/internal/UserPreferencesStore.java @@ -1,19 +1,19 @@ /* ******************************************************************* - * Copyright (c) 1999-2001 Xerox Corporation, + * Copyright (c) 1999-2001 Xerox Corporation, * 2002 Palo Alto Research Center, Incorporated (PARC). - * All rights reserved. - * This program and the accompanying materials are made available - * under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: + * All rights reserved. + * This program and the accompanying materials are made available + * under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: * Xerox/PARC initial implementation - * Helen Hawkins Converted to new interface (bug 148190) + * Helen Hawkins Converted to new interface (bug 148190) * ******************************************************************/ - - + + package org.aspectj.ajde.ui.internal; import java.io.File; @@ -33,121 +33,129 @@ import org.aspectj.bridge.Message; import org.aspectj.util.LangUtil; public class UserPreferencesStore implements UserPreferencesAdapter { - public static final String FILE_NAME = "/.ajbrowser"; - private static final String VALUE_SEP = ";"; - private Properties properties = new Properties(); - private boolean persist = true; - + public static final String FILE_NAME = "/.ajbrowser"; + private static final String VALUE_SEP = ";"; + private Properties properties = new Properties(); + private boolean persist = true; + public UserPreferencesStore() { - this(true); + this(true); + } + + public UserPreferencesStore(boolean loadDefault) { + persist = loadDefault; + if (persist) { + loadProperties(getPropertiesFilePath()); + } + } + + @Override + public String getProjectPreference(String name) { + return properties.getProperty(name); + } + + @Override + public List<String> getProjectMultivalPreference(String name) { + List<String> values = new ArrayList<>(); + String valuesString = properties.getProperty(name); + if (valuesString != null && !valuesString.trim().equals("")) { + StringTokenizer st = new StringTokenizer(valuesString, VALUE_SEP); + while (st.hasMoreTokens()) { + values.add(st.nextToken()); + } + } + return values; + } + + @Override + public void setProjectPreference(String name, String value) { + properties.setProperty(name, value); + saveProperties(); + } + + @Override + public void setProjectMultivalPreference(String name, List values) { + String valuesString = ""; + for (Iterator it = values.iterator(); it.hasNext(); ) { + valuesString += (String)it.next() + ';'; + } + properties.setProperty(name, valuesString); + saveProperties(); + } + + public static String getPropertiesFilePath() { + String path = System.getProperty("user.home"); + if (path == null) { + path = "."; + } + return path + FILE_NAME; } - public UserPreferencesStore(boolean loadDefault) { - persist = loadDefault; - if (persist) { - loadProperties(getPropertiesFilePath()); - } - } - - public String getProjectPreference(String name) { - return properties.getProperty(name); - } - - public List getProjectMultivalPreference(String name) { - List values = new ArrayList(); - String valuesString = properties.getProperty(name); - if (valuesString != null && !valuesString.trim().equals("")) { - StringTokenizer st = new StringTokenizer(valuesString, VALUE_SEP); - while (st.hasMoreTokens()) { - values.add(st.nextToken()); - } - } - return values; - } - - public void setProjectPreference(String name, String value) { - properties.setProperty(name, value); - saveProperties(); - } - - public void setProjectMultivalPreference(String name, List values) { - String valuesString = ""; - for (Iterator it = values.iterator(); it.hasNext(); ) { - valuesString += (String)it.next() + ';'; - } - properties.setProperty(name, valuesString); - saveProperties(); - } - - public static String getPropertiesFilePath() { - String path = System.getProperty("user.home"); - if (path == null) { - path = "."; - } - return path + FILE_NAME; - } - + @Override public String getGlobalPreference(String name) { return getProjectPreference(name); } - + + @Override public List getGlobalMultivalPreference(String name) { return getProjectMultivalPreference(name); } - + + @Override public void setGlobalPreference(String name, String value) { setProjectPreference(name, value); } - + + @Override public void setGlobalMultivalPreference(String name, List values) { setProjectMultivalPreference(name, values); } private void loadProperties(String path) { - if (LangUtil.isEmpty(path)) { - return; - } - File file = new File(path); - if (!file.canRead()) { - return; - } - FileInputStream in = null; - try { - path = getPropertiesFilePath(); - in = new FileInputStream(file); - properties.load(in); - } catch (IOException ioe) { - Message msg = new Message("Error reading properties from " + path,IMessage.ERROR,ioe,null); - Ajde.getDefault().getMessageHandler().handleMessage(msg); - } finally { - if (null != in) { - try { - in.close(); - } catch (IOException e) { - // ignore - } - } - } + if (LangUtil.isEmpty(path)) { + return; + } + File file = new File(path); + if (!file.canRead()) { + return; + } + FileInputStream in = null; + try { + path = getPropertiesFilePath(); + in = new FileInputStream(file); + properties.load(in); + } catch (IOException ioe) { + Message msg = new Message("Error reading properties from " + path,IMessage.ERROR,ioe,null); + Ajde.getDefault().getMessageHandler().handleMessage(msg); + } finally { + if (null != in) { + try { + in.close(); + } catch (IOException e) { + // ignore + } + } + } + } + public void saveProperties() { + if (!persist) return; + + FileOutputStream out = null; + String path = null; + try { + path = getPropertiesFilePath(); + out = new FileOutputStream(path); + properties.store(out, "AJDE Settings"); + } catch (IOException ioe) { + Message msg = new Message("Error writing properties to " + path,IMessage.ERROR,ioe,null); + Ajde.getDefault().getMessageHandler().handleMessage(msg); + } finally { + if (null != out) { + try { + out.close(); + } catch (IOException e) { + // ignore + } + } + } } - public void saveProperties() { - if (!persist) return; - - FileOutputStream out = null; - String path = null; - try { - path = getPropertiesFilePath(); - out = new FileOutputStream(path); - properties.store(out, "AJDE Settings"); - } catch (IOException ioe) { - Message msg = new Message("Error writing properties to " + path,IMessage.ERROR,ioe,null); - Ajde.getDefault().getMessageHandler().handleMessage(msg); - } finally { - if (null != out) { - try { - out.close(); - } catch (IOException e) { - // ignore - } - } - } - } } diff --git a/ajde/src/main/java/org/aspectj/ajde/ui/javaoptions/JavaComplianceOptionsPanel.java b/ajde/src/main/java/org/aspectj/ajde/ui/javaoptions/JavaComplianceOptionsPanel.java index 1d8dba958..667e673ae 100644 --- a/ajde/src/main/java/org/aspectj/ajde/ui/javaoptions/JavaComplianceOptionsPanel.java +++ b/ajde/src/main/java/org/aspectj/ajde/ui/javaoptions/JavaComplianceOptionsPanel.java @@ -1,11 +1,11 @@ /******************************************************************** - * Copyright (c) 2007 Contributors. All rights reserved. - * This program and the accompanying materials are made available - * under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution and is available at - * http://eclipse.org/legal/epl-v10.html - * - * Contributors: IBM Corporation - initial API and implementation + * Copyright (c) 2007 Contributors. All rights reserved. + * This program and the accompanying materials are made available + * under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution and is available at + * http://eclipse.org/legal/epl-v10.html + * + * Contributors: IBM Corporation - initial API and implementation * Helen Hawkins - initial version (bug 148190) *******************************************************************/ package org.aspectj.ajde.ui.javaoptions; @@ -14,9 +14,7 @@ import java.awt.BorderLayout; import java.awt.Color; import java.io.IOException; import java.util.HashMap; -import java.util.Iterator; import java.util.Map; -import java.util.Map.Entry; import java.util.Set; import javax.swing.BorderFactory; @@ -37,9 +35,9 @@ import org.aspectj.ajde.ui.swing.OptionsPanel; public class JavaComplianceOptionsPanel extends OptionsPanel { private final String[] complianceLevels = new String[] {JavaOptions.VERSION_13, JavaOptions.VERSION_14, JavaOptions.VERSION_15, JavaOptions.VERSION_16}; - + private static final long serialVersionUID = 4491319302490183151L; - + private JPanel parentPanel; private Border complianceEtchedBorder; @@ -47,11 +45,11 @@ public class JavaComplianceOptionsPanel extends OptionsPanel { private Border complianceCompoundBorder; private JPanel compliancePanel; private Box complianceBox = Box.createVerticalBox(); - + private JavaBuildOptions javaBuildOptions; - private Map/*String --> JComboBox*/ complianceComboBoxes = new HashMap(); - + private Map<String,JComboBox<String>> complianceComboBoxes = new HashMap<>(); + public JavaComplianceOptionsPanel(JavaBuildOptions javaBuildOptions) { this.javaBuildOptions = javaBuildOptions; try { @@ -62,20 +60,21 @@ public class JavaComplianceOptionsPanel extends OptionsPanel { } } + @Override public void loadOptions() throws IOException { createComplianceContents(); } - - public void saveOptions() throws IOException { - Set s = complianceComboBoxes.entrySet(); - for (Iterator iterator = s.iterator(); iterator.hasNext();) { - Map.Entry entry = (Entry) iterator.next(); - String javaOption = (String) entry.getKey(); - JComboBox combo = (JComboBox)entry.getValue(); + + @Override + public void saveOptions() throws IOException { + Set<Map.Entry<String,JComboBox<String>>> s = complianceComboBoxes.entrySet(); + for (Map.Entry<String,JComboBox<String>> entry : s) { + String javaOption = entry.getKey(); + JComboBox<String> combo = entry.getValue(); String value = (String) combo.getSelectedItem(); javaBuildOptions.setOption(javaOption, value); } - } + } private void jbInit() throws Exception { this.setLayout(new BorderLayout()); @@ -95,32 +94,32 @@ public class JavaComplianceOptionsPanel extends OptionsPanel { private void createComplianceEntry(String labelText, String javaOptionToSet) { JPanel panel = new JPanel(); panel.setLayout(new BorderLayout()); - + JLabel label = new JLabel(); label.setFont(new java.awt.Font("Dialog", 0, 11)); label.setText(labelText); panel.add(label,BorderLayout.WEST); - - JComboBox levels = new JComboBox(complianceLevels); - String value = (String) javaBuildOptions.getJavaBuildOptionsMap().get(javaOptionToSet); + + JComboBox<String> levels = new JComboBox<>(complianceLevels); + String value = javaBuildOptions.getJavaBuildOptionsMap().get(javaOptionToSet); if (value == null) { // default to 1.5 levels.setSelectedIndex(2); } else if (value.equals(JavaOptions.VERSION_13)) { levels.setSelectedIndex(0); } else if (value.equals(JavaOptions.VERSION_14)){ - levels.setSelectedIndex(1); + levels.setSelectedIndex(1); } else if (value.equals(JavaOptions.VERSION_15)){ - levels.setSelectedIndex(2); + levels.setSelectedIndex(2); } else if (value.equals(JavaOptions.VERSION_16)){ - levels.setSelectedIndex(3); - } + levels.setSelectedIndex(3); + } panel.add(levels,BorderLayout.EAST); complianceBox.add(panel,null); complianceComboBoxes.put(javaOptionToSet,levels); } - + private void createBorders() { complianceEtchedBorder = BorderFactory.createEtchedBorder(Color.white, new Color(156, 156, 158)); complianceTitleBorder = new TitledBorder(complianceEtchedBorder, "Compliance Options"); @@ -128,11 +127,11 @@ public class JavaComplianceOptionsPanel extends OptionsPanel { BorderFactory.createEmptyBorder(5, 5, 5, 5)); complianceTitleBorder.setTitleFont(new java.awt.Font("Dialog", 0, 11)); } - + private void addBordersToPanel() { parentPanel = new JPanel(); parentPanel.setLayout(new BorderLayout()); - + compliancePanel = new JPanel(); compliancePanel.setBorder(complianceCompoundBorder); diff --git a/ajde/src/main/java/org/aspectj/ajde/ui/javaoptions/JavaDebugOptionsPanel.java b/ajde/src/main/java/org/aspectj/ajde/ui/javaoptions/JavaDebugOptionsPanel.java index 9678e3a0d..86f7a5025 100644 --- a/ajde/src/main/java/org/aspectj/ajde/ui/javaoptions/JavaDebugOptionsPanel.java +++ b/ajde/src/main/java/org/aspectj/ajde/ui/javaoptions/JavaDebugOptionsPanel.java @@ -1,11 +1,11 @@ /******************************************************************** - * Copyright (c) 2007 Contributors. All rights reserved. - * This program and the accompanying materials are made available - * under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution and is available at - * http://eclipse.org/legal/epl-v10.html - * - * Contributors: IBM Corporation - initial API and implementation + * Copyright (c) 2007 Contributors. All rights reserved. + * This program and the accompanying materials are made available + * under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution and is available at + * http://eclipse.org/legal/epl-v10.html + * + * Contributors: IBM Corporation - initial API and implementation * Helen Hawkins - initial version (bug 148190) *******************************************************************/ package org.aspectj.ajde.ui.javaoptions; @@ -14,9 +14,7 @@ import java.awt.BorderLayout; import java.awt.Color; import java.io.IOException; import java.util.HashMap; -import java.util.Iterator; import java.util.Map; -import java.util.Map.Entry; import java.util.Set; import javax.swing.BorderFactory; @@ -38,9 +36,9 @@ public class JavaDebugOptionsPanel extends OptionsPanel { private final String[] debugOptions = new String[] {JavaOptions.GENERATE,JavaOptions.DO_NOT_GENERATE}; private final String[] preserveOptions = new String[] {JavaOptions.PRESERVE,JavaOptions.OPTIMIZE}; - + private static final long serialVersionUID = 4491319302490183151L; - + private JPanel parentPanel; private Border debugEtchedBorder; @@ -48,11 +46,11 @@ public class JavaDebugOptionsPanel extends OptionsPanel { private Border debugCompoundBorder; private JPanel debugPanel; private Box debugBox = Box.createVerticalBox(); - + private JavaBuildOptions javaBuildOptions; - private Map/*String --> JComboBox*/ debugComboBoxes = new HashMap(); - + private Map<String,JComboBox<String>> debugComboBoxes = new HashMap(); + public JavaDebugOptionsPanel(JavaBuildOptions javaBuildOptions) { this.javaBuildOptions = javaBuildOptions; try { @@ -63,20 +61,21 @@ public class JavaDebugOptionsPanel extends OptionsPanel { } } + @Override public void loadOptions() throws IOException { createDebugContents(); } - - public void saveOptions() throws IOException { - Set s = debugComboBoxes.entrySet(); - for (Iterator iterator = s.iterator(); iterator.hasNext();) { - Map.Entry entry = (Entry) iterator.next(); - String javaOption = (String) entry.getKey(); - JComboBox combo = (JComboBox)entry.getValue(); + + @Override + public void saveOptions() throws IOException { + Set<Map.Entry<String,JComboBox<String>>> s = debugComboBoxes.entrySet(); + for (Map.Entry<String,JComboBox<String>> entry : s) { + String javaOption = entry.getKey(); + JComboBox<String> combo = entry.getValue(); String value = (String) combo.getSelectedItem(); javaBuildOptions.setOption(javaOption, value); } - } + } private void jbInit() throws Exception { this.setLayout(new BorderLayout()); @@ -88,7 +87,7 @@ public class JavaDebugOptionsPanel extends OptionsPanel { private void createDebugContents() { createDebugEntry("Add line number attributes to generated class files",JavaOptions.DEBUG_LINES); createDebugEntry("Add source file name to generated class file",JavaOptions.DEBUG_SOURCE); - createDebugEntry("Add variable attributes to generated class files",JavaOptions.DEBUG_VARS); + createDebugEntry("Add variable attributes to generated class files",JavaOptions.DEBUG_VARS); createDebugEntry("Preserve unused (never read) local variables",JavaOptions.PRESERVE_ALL_LOCALS); debugPanel.add(debugBox); } @@ -96,48 +95,48 @@ public class JavaDebugOptionsPanel extends OptionsPanel { private void createDebugEntry(String labelText, String javaOptionToSet) { JPanel panel = new JPanel(); panel.setLayout(new BorderLayout()); - + JLabel label = new JLabel(); label.setFont(new java.awt.Font("Dialog", 0, 11)); label.setText(labelText); panel.add(label,BorderLayout.WEST); - - JComboBox debug = null; + + JComboBox<String> debug = null; if (javaOptionToSet.equals(JavaOptions.PRESERVE_ALL_LOCALS)) { - debug = new JComboBox(preserveOptions); - String value = (String) javaBuildOptions.getJavaBuildOptionsMap().get(javaOptionToSet); + debug = new JComboBox<String>(preserveOptions); + String value = javaBuildOptions.getJavaBuildOptionsMap().get(javaOptionToSet); if (value.equals(JavaOptions.PRESERVE)) { debug.setSelectedIndex(0); } else { - debug.setSelectedIndex(1); - } + debug.setSelectedIndex(1); + } } else { - debug = new JComboBox(debugOptions); - String value = (String) javaBuildOptions.getJavaBuildOptionsMap().get(javaOptionToSet); + debug = new JComboBox<String>(debugOptions); + String value = javaBuildOptions.getJavaBuildOptionsMap().get(javaOptionToSet); if (value.equals(JavaOptions.GENERATE)) { debug.setSelectedIndex(0); } else { - debug.setSelectedIndex(1); - } - } + debug.setSelectedIndex(1); + } + } panel.add(debug,BorderLayout.EAST); debugBox.add(panel,null); - debugComboBoxes.put(javaOptionToSet,debug); + debugComboBoxes.put(javaOptionToSet,debug); } - - private void createBorders() { + + private void createBorders() { debugEtchedBorder = BorderFactory.createEtchedBorder(Color.white, new Color(156, 156, 158)); debugTitleBorder = new TitledBorder(debugEtchedBorder, "Debug Options"); debugCompoundBorder = BorderFactory.createCompoundBorder(debugTitleBorder, BorderFactory.createEmptyBorder(5, 5, 5, 5)); debugTitleBorder.setTitleFont(new java.awt.Font("Dialog", 0, 11)); } - + private void addBordersToPanel() { parentPanel = new JPanel(); parentPanel.setLayout(new BorderLayout()); - + debugPanel = new JPanel(); debugPanel.setBorder(debugCompoundBorder); |