コード例 #1
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()) {
     String name = processNameNode(iterator.next());
     if (name != null) {
       result.add(name);
     }
   }
   return (String[]) result.toArray(new String[result.size()]);
 }
  public IGoal[] init() {
    ClassVariableDeclarationGoal typedGoal = (ClassVariableDeclarationGoal) goal;
    IType[] types = typedGoal.getTypes();

    if (types == null) {
      TypeContext context = (TypeContext) typedGoal.getContext();
      types = PHPTypeInferenceUtils.getModelElements(context.getInstanceType(), context);
    }
    if (types == null) {
      return null;
    }

    IContext context = typedGoal.getContext();
    IModelAccessCache cache = null;
    if (context instanceof IModelCacheContext) {
      cache = ((IModelCacheContext) context).getCache();
    }

    String variableName = typedGoal.getVariableName();

    final List<IGoal> subGoals = new LinkedList<IGoal>();
    for (final IType type : types) {
      try {
        ITypeHierarchy hierarchy = null;
        if (cache != null) {
          hierarchy = cache.getSuperTypeHierarchy(type, null);
        }
        IField[] fields =
            PHPModelUtils.getTypeHierarchyField(type, hierarchy, variableName, true, null);
        Map<IType, IType> fieldDeclaringTypeSet = new HashMap<IType, IType>();
        for (IField field : fields) {
          IType declaringType = field.getDeclaringType();
          if (declaringType != null) {
            fieldDeclaringTypeSet.put(declaringType, type);
            ISourceModule sourceModule = declaringType.getSourceModule();
            ModuleDeclaration moduleDeclaration =
                SourceParserUtil.getModuleDeclaration(sourceModule);
            TypeDeclaration typeDeclaration =
                PHPModelUtils.getNodeByClass(moduleDeclaration, declaringType);

            if (typeDeclaration != null && field instanceof SourceRefElement) {
              SourceRefElement sourceRefElement = (SourceRefElement) field;
              ISourceRange sourceRange = sourceRefElement.getSourceRange();

              ClassDeclarationSearcher searcher =
                  new ClassDeclarationSearcher(
                      sourceModule,
                      typeDeclaration,
                      sourceRange.getOffset(),
                      sourceRange.getLength(),
                      null,
                      type,
                      declaringType);
              try {
                moduleDeclaration.traverse(searcher);
                if (searcher.getResult() != null) {
                  subGoals.add(new ExpressionTypeGoal(searcher.getContext(), searcher.getResult()));
                }
              } catch (Exception e) {
                if (DLTKCore.DEBUG) {
                  e.printStackTrace();
                }
              }
            }
          }
        }

        if (subGoals.size() == 0) {
          getGoalFromStaticDeclaration(variableName, subGoals, type, null);
        }
        fieldDeclaringTypeSet.remove(type);
        if (subGoals.size() == 0 && !fieldDeclaringTypeSet.isEmpty()) {
          for (Iterator iterator = fieldDeclaringTypeSet.keySet().iterator();
              iterator.hasNext(); ) {
            IType fieldDeclaringType = (IType) iterator.next();
            getGoalFromStaticDeclaration(
                variableName,
                subGoals,
                fieldDeclaringType,
                fieldDeclaringTypeSet.get(fieldDeclaringType));
          }
        }
      } catch (CoreException e) {
        if (DLTKCore.DEBUG) {
          e.printStackTrace();
        }
      }
    }

    resolveMagicClassVariableDeclaration(types, variableName, cache);

    return subGoals.toArray(new IGoal[subGoals.size()]);
  }
コード例 #3
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()]);
 }
コード例 #4
0
  @SuppressWarnings("unchecked")
  public boolean visit(MethodDeclaration method) throws Exception {
    fNodes.push(method);
    methodGlobalVars.add(new HashSet<String>());
    int modifiers = method.getModifiers();
    PHPDocBlock doc = null;
    if (method instanceof IPHPDocAwareDeclaration) {
      IPHPDocAwareDeclaration declaration = (IPHPDocAwareDeclaration) method;
      doc = declaration.getPHPDoc();
    }
    Declaration parentDeclaration = null;
    if (!declarations.empty()) {
      parentDeclaration = declarations.peek();
    }
    declarations.push(method);

    // In case we are entering a nested element - just add to the deferred
    // list
    // and get out of the nested element visiting process
    if (parentDeclaration instanceof MethodDeclaration) {
      if (fCurrentNamespace == null) {
        deferredDeclarations.add(method);
      } else {
        deferredNamespacedDeclarations.add(method);
      }
      return visitGeneral(method);
    }

    if (parentDeclaration instanceof InterfaceDeclaration) {
      method.setModifier(Modifiers.AccAbstract);
    }

    String methodName = method.getName();

    // Determine whether this method represents constructor:
    if (methodName.equalsIgnoreCase(CONSTRUCTOR_NAME)
        || (parentDeclaration instanceof ClassDeclaration
            && methodName.equalsIgnoreCase(((ClassDeclaration) parentDeclaration).getName()))) {
      modifiers |= IPHPModifiers.Constructor;
    }

    if (parentDeclaration == null
        || (parentDeclaration instanceof TypeDeclaration
            && parentDeclaration == fCurrentNamespace)) {
      modifiers |= Modifiers.AccGlobal;
    }
    if (!Flags.isPrivate(modifiers)
        && !Flags.isProtected(modifiers)
        && !Flags.isPublic(modifiers)) {
      modifiers |= Modifiers.AccPublic;
    }

    modifiers = markAsDeprecated(modifiers, method);

    StringBuilder metadata = new StringBuilder();
    if (fCurrentQualifier != null) {
      metadata.append(fCurrentQualifierCounts.get(fCurrentQualifier));
      metadata.append(";"); // $NON-NLS-1$
    }
    List<Argument> arguments = method.getArguments();
    if (arguments != null) {
      Iterator<Argument> i = arguments.iterator();
      while (i.hasNext()) {
        Argument arg = (Argument) i.next();

        String type = NULL_VALUE;
        if (arg instanceof FormalParameter) {
          FormalParameter fp = (FormalParameter) arg;
          if (fp.getParameterType() != null) {
            if (fp.getParameterType().getName() != null) {
              type = fp.getParameterType().getName();
            }
          }
        }
        if (type == NULL_VALUE && doc != null) {
          type = getParamType(doc, arg.getName(), type);
        }

        metadata.append(type);
        metadata.append(PARAMETER_SEPERATOR);
        metadata.append(arg.getName());
        metadata.append(PARAMETER_SEPERATOR);
        String defaultValue = NULL_VALUE;
        if (arg.getInitialization() != null) {
          if (arg.getInitialization() instanceof Literal) {
            Literal scalar = (Literal) arg.getInitialization();
            defaultValue = scalar.getValue();
          } else {
            defaultValue = DEFAULT_VALUE;
          }
        }
        metadata.append(defaultValue);
        if (i.hasNext()) {
          metadata.append(","); // $NON-NLS-1$
        }
      }
    }

    // Add method declaration:
    modifyDeclaration(
        method,
        new DeclarationInfo(
            IModelElement.METHOD,
            modifiers,
            method.sourceStart(),
            method.sourceEnd() - method.sourceStart(),
            method.getNameStart(),
            method.getNameEnd() - method.getNameStart(),
            methodName,
            metadata.length() == 0 ? null : metadata.toString(),
            encodeDocInfo(method),
            fCurrentQualifier,
            fCurrentParent));

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

    return visitGeneral(method);
  }
コード例 #5
0
  public boolean visit(LambdaFunctionDeclaration lambdaMethod) throws Exception {

    fNodes.push(lambdaMethod);
    methodGlobalVars.add(new HashSet<String>());

    // Declaration parentDeclaration = null;
    // if (!declarations.empty()
    // && declarations.peek() instanceof MethodDeclaration) {
    // parentDeclaration = declarations.peek();
    // // In case we are entering a nested element - just add to the
    // // deferred list and get out of the nested element visiting process
    // deferredDeclarations.add(lambdaMethod);
    // return visitGeneral(lambdaMethod);
    // }

    Collection<FormalParameter> arguments = lambdaMethod.getArguments();
    StringBuilder metadata = new StringBuilder();
    String[] parameters;
    if (arguments != null) {
      parameters = new String[arguments.size()];
      Iterator<FormalParameter> i = arguments.iterator();
      int indx = 0;
      while (i.hasNext()) {
        Argument arg = (Argument) i.next();
        metadata.append(arg.getName());
        parameters[indx] = arg.getName();
        indx++;
        if (i.hasNext()) {
          metadata.append(","); // $NON-NLS-1$
        }
      }
    } else {
      parameters = new String[0];
    }

    // Add method declaration:
    for (PHPSourceElementRequestorExtension visitor : extensions) {
      visitor.visit(lambdaMethod);
    }

    ISourceElementRequestor.MethodInfo mi = new ISourceElementRequestor.MethodInfo();
    mi.parameterNames = parameters;
    mi.name = PHPCoreConstants.ANONYMOUS;
    mi.modifiers = Modifiers.AccPublic;
    if (lambdaMethod.isStatic()) {
      mi.modifiers |= Modifiers.AccStatic;
    }
    mi.nameSourceStart = lambdaMethod.sourceStart();
    mi.nameSourceEnd = lambdaMethod.sourceEnd();
    mi.declarationStart = mi.nameSourceStart;
    mi.isConstructor = false;

    fInfoStack.push(mi);
    this.fRequestor.enterMethod(mi);
    this.fInMethod = true;

    for (Argument arg : arguments) {
      ISourceElementRequestor.FieldInfo info = new ISourceElementRequestor.FieldInfo();
      info.name = arg.getName();
      info.modifiers = Modifiers.AccPublic;
      info.nameSourceStart = arg.getNameStart();
      info.nameSourceEnd = arg.getNameEnd() - 1;
      info.declarationStart = arg.sourceStart();
      fRequestor.enterField(info);
      fRequestor.exitField(arg.sourceEnd() - 1);
    }

    return true;
  }