public void process(IProject project, String pattern) {
    // test code, right now, I used the PHPSearchEngine class cut from another project
    ///////// Note: there is an real library API org.eclipse.php.internal.core.util.PHPSearchEngine.
    // I need to check details
    System.out.println("begining a iteration for pattern " + pattern);
    String elementName = null;
    SearchMatch[] newMatches = null;
    SearchMatch[] matches =
        PHPSearchEngine.findMethodCall(pattern, PHPSearchEngine.createProjectScope(project));
    // must distinguish between method declaration and method call!!!!
    IModelElement iModelElement;
    Object obj = null;
    if (matches.length > 0) {
      for (SearchMatch match : matches) {
        obj = match.getElement();
        if (obj instanceof IModelElement) {
          iModelElement = (IModelElement) obj;
          elementName = iModelElement.getElementName();
          System.out.println(
              "iModelElement.getElementName() = "
                  + elementName
                  + " --path= "
                  + iModelElement.getPath().toString());
          if (!elementName.equals(
              pattern)) { // avoid recursive, or iterative method, temp implementation, should be
                          // modified!!!!
            pattern = elementName;
            System.out.println("begining next iteration");
            process(project, pattern);
            System.out.println("return from an iteration");
          } else { // it is recursive/iterative, we regard it as the top level method call (temp
                   // implementation!!!!!)
            System.out.println(
                "Top Level(recursive reason): "
                    + "iModelElement.getElementName() = "
                    + elementName
                    + " --path= "
                    + iModelElement.getPath().toString());
          }
        }
      }
    } else { // if there is no callers, then means it is the top level

      System.out.println("Top Level(real reason): " + "pattern = " + pattern);
    }
    System.out.println("end of an iteration");
  }
コード例 #2
0
 private IPath getPath(IModelElement element, boolean relativeToRoot) {
   switch (element.getElementType()) {
     case IModelElement.SCRIPT_MODEL:
       return Path.EMPTY;
     case IModelElement.SCRIPT_PROJECT:
       return element.getPath();
     case IModelElement.PROJECT_FRAGMENT:
       if (relativeToRoot) return Path.EMPTY;
       return element.getPath();
     case IModelElement.SCRIPT_FOLDER:
       String relativePath = element.getElementName() + '/';
       return getPath(element.getParent(), relativeToRoot).append(new Path(relativePath));
     case IModelElement.SOURCE_MODULE:
       return getPath(element.getParent(), relativeToRoot)
           .append(new Path(element.getElementName()));
     default:
       return getPath(element.getParent(), relativeToRoot);
   }
 }
コード例 #3
0
 public void provideModelChanges(IModelElement parentElement, List children) {
   IScriptProject project = parentElement.getScriptProject();
   if (!"ModelMembersq".equals(project.getElementName())) {
     return;
   }
   switch (parentElement.getElementType()) {
     case IModelElement.PROJECT_FRAGMENT:
       List addon = new ArrayList();
       for (Iterator iterator = children.iterator(); iterator.hasNext(); ) {
         IModelElement el = (IModelElement) iterator.next();
         if (el.getElementType() == IModelElement.SCRIPT_FOLDER) {
           addon.add(
               new TestFolder(
                   (ModelElement) parentElement,
                   el.getPath().removeFirstSegments(el.getParent().getPath().segmentCount())));
         }
       }
       children.addAll(addon);
       break;
     case IModelElement.SCRIPT_FOLDER:
       break;
   }
 }