/**
   * Search for magic variables using the @property tag
   *
   * @param types
   * @param variableName
   * @param cache
   */
  private void resolveMagicClassVariableDeclaration(
      IType[] types, String variableName, IModelAccessCache cache) {
    for (IType type : types) {
      resolveMagicClassVariableDeclaration(variableName, type, cache);
      try {
        if (evaluated.isEmpty()
            && type.getSuperClasses() != null
            && type.getSuperClasses().length > 0) {

          ITypeHierarchy hierarchy = null;
          if (cache != null) {
            hierarchy = cache.getSuperTypeHierarchy(type, null);
          }
          IType[] superClasses = PHPModelUtils.getSuperClasses(type, hierarchy);

          for (int i = 0; i < superClasses.length /* && evaluated.isEmpty() */; i++) {
            IType superClass = superClasses[i];
            resolveMagicClassVariableDeclaration(variableName, superClass, cache);
          }
        }
      } catch (ModelException e) {
        e.printStackTrace();
      }
    }
  }
  protected void getGoalFromStaticDeclaration(
      String variableName, final List<IGoal> subGoals, final IType declaringType, IType realType)
      throws ModelException {
    ISourceModule sourceModule = declaringType.getSourceModule();
    ModuleDeclaration moduleDeclaration = SourceParserUtil.getModuleDeclaration(sourceModule);
    TypeDeclaration typeDeclaration =
        PHPModelUtils.getNodeByClass(moduleDeclaration, declaringType);

    // try to search declarations of type "self::$var =" or
    // "$this->var ="
    ClassDeclarationSearcher searcher;
    if (realType != null) {
      searcher =
          new ClassDeclarationSearcher(
              sourceModule, typeDeclaration, 0, 0, variableName, realType, declaringType);
    } else {
      searcher = new ClassDeclarationSearcher(sourceModule, typeDeclaration, 0, 0, variableName);
    }
    try {
      moduleDeclaration.traverse(searcher);
      Map<ASTNode, IContext> staticDeclarations = searcher.getStaticDeclarations();
      for (ASTNode node : staticDeclarations.keySet()) {
        IContext context = staticDeclarations.get(node);
        if (context instanceof MethodContext) {
          MethodContext methodContext = (MethodContext) context;
          methodContext.setCurrentType(realType);
        }
        subGoals.add(new ExpressionTypeGoal(context, node));
      }
    } catch (Exception e) {
      if (DLTKCore.DEBUG) {
        e.printStackTrace();
      }
    }
  }
 protected void resolveMagicClassVariableDeclaration(
     String variableName, IType type, IModelAccessCache cache) {
   final PHPDocBlock docBlock = PHPModelUtils.getDocBlock(type);
   if (docBlock != null) {
     for (PHPDocTag tag : docBlock.getTags()) {
       final int tagKind = tag.getTagKind();
       if (tagKind == PHPDocTag.PROPERTY
           || tagKind == PHPDocTag.PROPERTY_READ
           || tagKind == PHPDocTag.PROPERTY_WRITE) {
         final String typeName = getTypeBinding(variableName, tag);
         if (typeName != null) {
           IEvaluatedType resolved = PHPSimpleTypes.fromString(typeName);
           if (resolved == null) {
             resolved = new PHPClassType(typeName);
           }
           evaluated.add(resolved);
         }
       }
     }
   }
 }
  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()]);
  }