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);
  }
  @Override
  protected String[] processSuperClasses(TypeDeclaration type) {
    final ASTListNode superClasses = type.getSuperClasses();
    if (superClasses == null) {
      return new String[] {};
    }
    final List superClassNames = superClasses.getChilds();
    final List<String> result = new ArrayList<String>(superClassNames.size());
    final Iterator iterator = superClassNames.iterator();
    while (iterator.hasNext()) {
      final Object nameNode = iterator.next();

      String name;
      if (nameNode instanceof FullyQualifiedReference) {
        final FullyQualifiedReference fullyQualifiedName = (FullyQualifiedReference) nameNode;
        name = fullyQualifiedName.getFullyQualifiedName();
        if (fullyQualifiedName.getNamespace() != null) {
          final String namespace = fullyQualifiedName.getNamespace().getName();
          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(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();
          }
        }
        result.add(name);
      } else if (nameNode instanceof SimpleReference) {
        result.add(((SimpleReference) nameNode).getName());
      }
    }
    return result.toArray(new String[result.size()]);
  }
 public boolean visit(Statement e) throws Exception {
   if (typeDeclaration.sourceStart() < e.sourceStart()
       && typeDeclaration.sourceEnd() > e.sourceEnd()) {
     if (e instanceof PHPFieldDeclaration) {
       PHPFieldDeclaration phpFieldDecl = (PHPFieldDeclaration) e;
       if (phpFieldDecl.getDeclarationStart() == offset
           && phpFieldDecl.sourceEnd() - phpFieldDecl.getDeclarationStart() == length) {
         result = ((PHPFieldDeclaration) e).getVariableValue();
         if (result instanceof Scalar) {
           Scalar scalar = (Scalar) result;
           if (scalar.getScalarType() == Scalar.TYPE_STRING
               && scalar.getValue().toLowerCase().equals(NULL)) {
             result = null;
           }
         }
         context = contextStack.peek();
       }
     }
   }
   return visitGeneral(e);
 }
    public boolean visit(Expression e) throws Exception {
      if (typeDeclaration.sourceStart() < e.sourceStart()
          && typeDeclaration.sourceEnd() > e.sourceEnd()) {
        if (e instanceof Assignment) {
          if (e.sourceStart() == offset && e.sourceEnd() - e.sourceStart() == length) {
            result = ((Assignment) e).getValue();
            context = contextStack.peek();
          } else if (variableName != null) {
            Assignment assignment = (Assignment) e;
            Expression left = assignment.getVariable();
            Expression right = assignment.getValue();

            if (left instanceof StaticFieldAccess) {
              StaticFieldAccess fieldAccess = (StaticFieldAccess) left;
              Expression dispatcher = fieldAccess.getDispatcher();
              if (dispatcher instanceof TypeReference
                  && "self".equals(((TypeReference) dispatcher).getName())) { // $NON-NLS-1$
                Expression field = fieldAccess.getField();
                if (field instanceof VariableReference
                    && variableName.equals(((VariableReference) field).getName())) {
                  staticDeclarations.put(right, contextStack.peek());
                }
              }
            } else if (left instanceof FieldAccess) {
              FieldAccess fieldAccess = (FieldAccess) left;
              Expression dispatcher = fieldAccess.getDispatcher();
              if (dispatcher instanceof VariableReference
                  && "$this".equals(((VariableReference) dispatcher).getName())) { // $NON-NLS-1$
                Expression field = fieldAccess.getField();
                if (field instanceof SimpleReference
                    && variableName.equals('$' + ((SimpleReference) field).getName())) {
                  staticDeclarations.put(right, contextStack.peek());
                }
              }
            }
          }
        }
      }
      return visitGeneral(e);
    }
Exemplo n.º 5
0
 private void selectionOnTypeDeclaration(
     ModuleDeclaration parsedUnit, TypeDeclaration typeDeclaration) {
   // if (typeDeclaration instanceof RubyClassDeclaration) {
   // RubyClassDeclaration rcd = (RubyClassDeclaration) typeDeclaration;
   // IType[] types = getSourceTypesForClass(parsedUnit, rcd
   // .getClassName());
   // selectionElements.addAll(Arrays.asList(types));
   // }
   IModelElement elementAt = null;
   try {
     elementAt = sourceModule.getElementAt(typeDeclaration.sourceStart() + 1);
   } catch (ModelException e) {
     RubyPlugin.log(e);
   }
   if (elementAt != null) selectionElements.add(elementAt);
 }
 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()) {
     String name = processNameNode(iterator.next());
     if (name != null) {
       result.add(name);
     }
   }
   return (String[]) result.toArray(new String[result.size()]);
 }
Exemplo n.º 7
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()]);
 }
Exemplo n.º 8
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);
  }