You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

StructureSearchManager.java 1.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /* *******************************************************************
  2. * Copyright (c) 1999-2001 Xerox Corporation,
  3. * 2002 Palo Alto Research Center, Incorporated (PARC).
  4. * All rights reserved.
  5. * This program and the accompanying materials are made available
  6. * under the terms of the Eclipse Public License v1.0
  7. * which accompanies this distribution and is available at
  8. * http://www.eclipse.org/legal/epl-v10.html
  9. *
  10. * Contributors:
  11. * Xerox/PARC initial implementation
  12. * Helen Hawkins Converted to new interface (bug 148190)
  13. * ******************************************************************/
  14. package org.aspectj.ajde.ui;
  15. import java.util.ArrayList;
  16. import java.util.Iterator;
  17. import java.util.List;
  18. import org.aspectj.asm.AsmManager;
  19. import org.aspectj.asm.IHierarchy;
  20. import org.aspectj.asm.IProgramElement;
  21. /**
  22. * @author Mik Kersten
  23. */
  24. public class StructureSearchManager {
  25. /**
  26. * @param pattern case-sensitive substring of node name
  27. *
  28. * @return null if a corresponding node was not found
  29. */
  30. public List<IProgramElement> findMatches(String pattern, IProgramElement.Kind kind) {
  31. List<IProgramElement> matches = new ArrayList<>();
  32. IHierarchy model = AsmManager.lastActiveStructureModel.getHierarchy();
  33. if (model.getRoot().equals(IHierarchy.NO_STRUCTURE)) {
  34. return null;
  35. } else {
  36. return findMatchesHelper(model.getRoot(), pattern, kind, matches);
  37. }
  38. }
  39. private List<IProgramElement> findMatchesHelper(IProgramElement node, String pattern, IProgramElement.Kind kind, List<IProgramElement> matches) {
  40. if (node != null && node.getName().contains(pattern)) {
  41. if (kind == null || node.getKind().equals(kind)) {
  42. matches.add(node);
  43. }
  44. }
  45. if (node != null && node.getChildren() != null) {
  46. for (IProgramElement nextNode : node.getChildren()) {
  47. if (nextNode != null) {
  48. findMatchesHelper(nextNode, pattern, kind, matches);
  49. }
  50. }
  51. }
  52. return matches;
  53. }
  54. }