Exemplo n.º 1
0
 /**
  * Creates a JavaNode under the given parent.
  *
  * @param parent the parent node
  * @param type the Java elements type. Legal values are from the range CU to METHOD of this class.
  * @param name the name of the Java element
  * @param start the starting position of the java element in the underlying document
  * @param length the number of characters of the java element in the underlying document
  */
 public JavaNode(JavaNode parent, int type, String name, int start, int length) {
   super(
       parent,
       type,
       JavaCompareUtilities.buildID(type, name),
       parent.getDocument(),
       start,
       length);
   parent.addChild(this);
 }
 public boolean visit(ImportDeclaration node) {
   int s = node.getStartPosition();
   int l = node.getLength();
   int declarationEnd = s + l;
   if (fImportContainer == null)
     fImportContainer = new JavaNode(getCurrentContainer(), JavaNode.IMPORT_CONTAINER, null, s, l);
   String nm = node.getName().toString();
   if (node.isOnDemand()) nm += ".*"; // $NON-NLS-1$
   new JavaNode(fImportContainer, JavaNode.IMPORT, nm, s, l);
   fImportContainer.setLength(declarationEnd - fImportContainer.getRange().getOffset() + 1);
   fImportContainer.setAppendPosition(declarationEnd + 2); // FIXME
   return false;
 }
  /** Adds a new JavaNode with the given type and name to the current container. */
  private void push(int type, String name, int declarationStart, int length) {

    while (declarationStart > 0) {
      char c = fBuffer[declarationStart - 1];
      if (c != ' ' && c != '\t') break;
      declarationStart--;
      length++;
    }

    JavaNode node = new JavaNode(getCurrentContainer(), type, name, declarationStart, length);
    if (type == JavaNode.CU) node.setAppendPosition(declarationStart + length + 1);
    else node.setAppendPosition(declarationStart + length);

    fStack.push(node);
  }