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

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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 v 2.0
  7. * which accompanies this distribution and is available at
  8. * https://www.eclipse.org/org/documents/epl-2.0/EPL-2.0.txt
  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.List;
  17. import org.aspectj.asm.AsmManager;
  18. import org.aspectj.asm.IHierarchy;
  19. import org.aspectj.asm.IProgramElement;
  20. /**
  21. * @author Mik Kersten
  22. */
  23. public class StructureSearchManager {
  24. /**
  25. * @param pattern case-sensitive substring of node name
  26. *
  27. * @return null if a corresponding node was not found
  28. */
  29. public List<IProgramElement> findMatches(String pattern, IProgramElement.Kind kind) {
  30. List<IProgramElement> matches = new ArrayList<>();
  31. IHierarchy model = AsmManager.lastActiveStructureModel.getHierarchy();
  32. if (model.getRoot().equals(IHierarchy.NO_STRUCTURE)) {
  33. return null;
  34. } else {
  35. return findMatchesHelper(model.getRoot(), pattern, kind, matches);
  36. }
  37. }
  38. private List<IProgramElement> findMatchesHelper(IProgramElement node, String pattern, IProgramElement.Kind kind, List<IProgramElement> matches) {
  39. if (node != null && node.getName().contains(pattern)) {
  40. if (kind == null || node.getKind().equals(kind)) {
  41. matches.add(node);
  42. }
  43. }
  44. if (node != null && node.getChildren() != null) {
  45. for (IProgramElement nextNode : node.getChildren()) {
  46. if (nextNode != null) {
  47. findMatchesHelper(nextNode, pattern, kind, matches);
  48. }
  49. }
  50. }
  51. return matches;
  52. }
  53. }