Example #1
0
  public boolean endvisit(TypeDeclaration type) throws Exception {
    if (type instanceof NamespaceDeclaration) {
      NamespaceDeclaration namespaceDecl = (NamespaceDeclaration) type;
      while (deferredNamespacedDeclarations != null && !deferredNamespacedDeclarations.isEmpty()) {
        final ASTNode[] declarations =
            deferredNamespacedDeclarations.toArray(
                new ASTNode[deferredNamespacedDeclarations.size()]);
        deferredNamespacedDeclarations.clear();

        for (ASTNode deferred : declarations) {
          deferred.traverse(this);
        }
      }

      fCurrentNamespace = null; // there are no nested namespaces
      fCurrentQualifier = null;
      fLastUseParts.clear();
      if (namespaceDecl.isGlobal()) {
        return visitGeneral(type);
      }
    } else {
      fCurrentParent = null;
    }
    declarations.pop();

    // resolve more type member declarations
    resolveMagicMembers(type);

    for (PhpIndexingVisitorExtension visitor : extensions) {
      visitor.endvisit(type);
    }

    endvisitGeneral(type);
    return true;
  }
  public boolean visit(TypeDeclaration type) throws Exception {
    if (type instanceof NamespaceDeclaration) {
      NamespaceDeclaration namespaceDecl = (NamespaceDeclaration) type;
      fLastNamespace = namespaceDecl;
      fLastUseParts.clear();
      if (namespaceDecl.isGlobal()) {
        return true;
      }
    }
    type.setModifiers(markAsDeprecated(type.getModifiers(), type));

    // In case we are entering a nested element
    if (!declarations.empty() && declarations.peek() instanceof MethodDeclaration) {
      if (fLastNamespace == null) {
        deferredDeclarations.add(type);
      } else {
        deferredNamespacedDeclarations.add(type);
      }
      return false;
    }

    declarations.push(type);

    for (PHPSourceElementRequestorExtension visitor : extensions) {
      visitor.visit(type);
    }
    return super.visit(type);
  }
  public boolean endvisit(TypeDeclaration type) throws Exception {
    if (type instanceof NamespaceDeclaration) {
      NamespaceDeclaration namespaceDecl = (NamespaceDeclaration) type;
      while (deferredNamespacedDeclarations != null && !deferredNamespacedDeclarations.isEmpty()) {
        final ASTNode[] declarations =
            deferredNamespacedDeclarations.toArray(
                new ASTNode[deferredNamespacedDeclarations.size()]);
        deferredNamespacedDeclarations.clear();

        for (ASTNode deferred : declarations) {
          deferred.traverse(this);
        }
      }
      fLastNamespace = null; // there are no nested namespaces
      if (namespaceDecl.isGlobal()) {
        return true;
      }
    }

    declarations.pop();

    // resolve more type member declarations
    resolveMagicMembers(type);

    for (PHPSourceElementRequestorExtension visitor : extensions) {
      visitor.endvisit(type);
    }

    return super.endvisit(type);
  }
  private String processNameNode(ASTNode nameNode) {
    if (nameNode instanceof FullyQualifiedReference) {
      String name;
      FullyQualifiedReference fullyQualifiedName = (FullyQualifiedReference) nameNode;
      name = fullyQualifiedName.getFullyQualifiedName();
      if (fullyQualifiedName.getNamespace() != null) {
        String namespace = fullyQualifiedName.getNamespace().getName();

        String subnamespace = ""; // $NON-NLS-1$
        if (namespace.charAt(0) != NamespaceReference.NAMESPACE_SEPARATOR
            && namespace.indexOf(NamespaceReference.NAMESPACE_SEPARATOR) > 0) {
          int firstNSLocation = namespace.indexOf(NamespaceReference.NAMESPACE_SEPARATOR);
          subnamespace = namespace.substring(firstNSLocation);
          namespace = namespace.substring(0, firstNSLocation);
        }
        if (name.charAt(0) == NamespaceReference.NAMESPACE_SEPARATOR) {
          name = name.substring(1);
        } else if (fLastUseParts.containsKey(namespace)) {
          name =
              new StringBuilder(fLastUseParts.get(namespace).getNamespace().getFullyQualifiedName())
                  .append(subnamespace)
                  .append(NamespaceReference.NAMESPACE_SEPARATOR)
                  .append(fullyQualifiedName.getName())
                  .toString();
        } else if (fLastNamespace != null) {
          name =
              new StringBuilder(fLastNamespace.getName())
                  .append(NamespaceReference.NAMESPACE_SEPARATOR)
                  .append(name)
                  .toString();
        }
      } else if (fLastUseParts.containsKey(name)) {
        name = fLastUseParts.get(name).getNamespace().getFullyQualifiedName();
        if (name.charAt(0) == NamespaceReference.NAMESPACE_SEPARATOR) {
          name = name.substring(1);
        }
      } else {
        if (fLastNamespace != null) {
          name =
              new StringBuilder(fLastNamespace.getName())
                  .append(NamespaceReference.NAMESPACE_SEPARATOR)
                  .append(name)
                  .toString();
        }
      }
      return name;
    } else if (nameNode instanceof SimpleReference) {
      return ((SimpleReference) nameNode).getName();
    }
    return null;
  }
 public boolean visit(UseStatement declaration) throws Exception {
   Collection<UsePart> parts = declaration.getParts();
   for (UsePart part : parts) {
     String name = null;
     if (part.getAlias() != null) {
       name = part.getAlias().getName();
     } else {
       name = part.getNamespace().getName();
       int index = name.lastIndexOf(NamespaceReference.NAMESPACE_SEPARATOR);
       if (index >= 0) {
         name = name.substring(index + 1);
       }
     }
     ImportInfo info = new ImportInfo();
     String containerName;
     if (fLastNamespace == null) {
       containerName = GLOBAL_NAMESPACE_CONTAINER_NAME;
     } else {
       containerName = fLastNamespace.getName();
     }
     info.containerName = containerName;
     if (declaration.getNamespace() == null) {
       info.name = part.getNamespace().getFullyQualifiedName();
     } else {
       info.name =
           PHPModelUtils.concatFullyQualifiedNames(
               declaration.getNamespace().getFullyQualifiedName(),
               part.getNamespace().getFullyQualifiedName());
     }
     info.sourceStart = part.getNamespace().sourceStart();
     info.sourceEnd = part.getNamespace().sourceEnd();
     fRequestor.acceptImport(info);
     fLastUseParts.put(name, part);
   }
   return true;
 }
Example #6
0
 protected String[] processSuperClasses(TypeDeclaration type) {
   ASTListNode superClasses = type.getSuperClasses();
   if (superClasses == null) {
     return new String[] {};
   }
   List<ASTNode> superClassNames = superClasses.getChilds();
   List<String> result = new ArrayList<String>(superClassNames.size());
   Iterator<ASTNode> iterator = superClassNames.iterator();
   while (iterator.hasNext()) {
     ASTNode nameNode = iterator.next();
     String name;
     if (nameNode instanceof FullyQualifiedReference) {
       FullyQualifiedReference fullyQualifiedName = (FullyQualifiedReference) nameNode;
       name = fullyQualifiedName.getFullyQualifiedName();
       if (fullyQualifiedName.getNamespace() != null) {
         String namespace = fullyQualifiedName.getNamespace().getName();
         String subnamespace = ""; // $NON-NLS-1$
         if (namespace.charAt(0) != NamespaceReference.NAMESPACE_SEPARATOR
             && namespace.indexOf(NamespaceReference.NAMESPACE_SEPARATOR) > 0) {
           int firstNSLocation = namespace.indexOf(NamespaceReference.NAMESPACE_SEPARATOR);
           subnamespace = namespace.substring(firstNSLocation);
           namespace = namespace.substring(0, firstNSLocation);
         }
         if (name.charAt(0) == NamespaceReference.NAMESPACE_SEPARATOR) {
           name = name.substring(1);
         } else if (fLastUseParts.containsKey(namespace)) {
           name =
               new StringBuilder(
                       fLastUseParts.get(namespace).getNamespace().getFullyQualifiedName())
                   .append(subnamespace)
                   .append(NamespaceReference.NAMESPACE_SEPARATOR)
                   .append(fullyQualifiedName.getName())
                   .toString();
         } else if (fCurrentNamespace != null) {
           name =
               new StringBuilder(fCurrentNamespace.getName())
                   .append(NamespaceReference.NAMESPACE_SEPARATOR)
                   .append(name)
                   .toString();
         }
       } else if (fLastUseParts.containsKey(name)) {
         name = fLastUseParts.get(name).getNamespace().getFullyQualifiedName();
         if (name.charAt(0) == NamespaceReference.NAMESPACE_SEPARATOR) {
           name = name.substring(1);
         }
       } else {
         if (fCurrentNamespace != null) {
           name =
               new StringBuilder(fCurrentNamespace.getName())
                   .append(NamespaceReference.NAMESPACE_SEPARATOR)
                   .append(name)
                   .toString();
         }
       }
       result.add(name);
     } else if (nameNode instanceof SimpleReference) {
       result.add(((SimpleReference) nameNode).getName());
     }
   }
   return (String[]) result.toArray(new String[result.size()]);
 }
Example #7
0
  public boolean visit(TypeDeclaration type) throws Exception {
    if (type instanceof NamespaceDeclaration) {
      NamespaceDeclaration namespaceDecl = (NamespaceDeclaration) type;
      fCurrentNamespace = namespaceDecl;
      fLastUseParts.clear();
      if (namespaceDecl.isGlobal()) {
        return visitGeneral(type);
      }
      declarations.push(type);

      int modifiers = type.getModifiers() | Modifiers.AccNameSpace;
      fCurrentQualifier = type.getName();
      Integer count = fCurrentQualifierCounts.get(fCurrentQualifier);
      count = count != null ? count + 1 : 1;
      fCurrentQualifierCounts.put(fCurrentQualifier, count);

      modifiers = markAsDeprecated(modifiers, type);
      StringBuilder metadata = new StringBuilder();
      if (fCurrentQualifier != null) {
        metadata.append(fCurrentQualifierCounts.get(fCurrentQualifier));
        metadata.append(";"); // $NON-NLS-1$
      }
      modifyDeclaration(
          type,
          new DeclarationInfo(
              IModelElement.PACKAGE_DECLARATION,
              modifiers,
              type.sourceStart(),
              type.sourceEnd() - type.sourceStart(),
              type.getNameStart(),
              type.getNameEnd() - type.getNameStart(),
              type.getName(),
              metadata.length() == 0 ? null : metadata.toString(),
              encodeDocInfo(type),
              null,
              null));
    } else {
      Declaration parentDeclaration = null;
      if (!declarations.empty()) {
        parentDeclaration = declarations.peek();
      }
      declarations.push(type);

      if (!(parentDeclaration instanceof NamespaceDeclaration)) {
        type.setModifier(Modifiers.AccGlobal);
      }

      // In case we are entering a nested element
      if (parentDeclaration instanceof MethodDeclaration) {
        if (fCurrentNamespace == null) {
          deferredDeclarations.add(type);
        } else {
          deferredNamespacedDeclarations.add(type);
        }
        return visitGeneral(type);
      }

      int modifiers = type.getModifiers();
      fCurrentParent = type.getName();

      String[] superClasses = processSuperClasses(type);
      StringBuilder metadata = new StringBuilder();
      if (fCurrentQualifier != null) {
        metadata.append(fCurrentQualifierCounts.get(fCurrentQualifier));
        metadata.append(";"); // $NON-NLS-1$
      }
      for (int i = 0; i < superClasses.length; ++i) {
        metadata.append(superClasses[i]);
        if (i < superClasses.length - 1) {
          metadata.append(","); // $NON-NLS-1$
        }
      }
      modifiers = markAsDeprecated(modifiers, type);
      modifyDeclaration(
          type,
          new DeclarationInfo(
              IModelElement.TYPE,
              modifiers,
              type.sourceStart(),
              type.sourceEnd() - type.sourceStart(),
              type.getNameStart(),
              type.getNameEnd() - type.getNameStart(),
              type.getName(),
              metadata.length() == 0 ? null : metadata.toString(),
              encodeDocInfo(type),
              fCurrentQualifier,
              null));
    }

    for (PhpIndexingVisitorExtension visitor : extensions) {
      visitor.visit(type);
    }

    return visitGeneral(type);
  }