Package org.eclipse.php.internal.core.typeinference.evaluators

Source Code of org.eclipse.php.internal.core.typeinference.evaluators.ArrayCreationEvaluator

/*******************************************************************************
* Copyright (c) 2009 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
*     IBM Corporation - initial API and implementation
*     Zend Technologies
*******************************************************************************/
package org.eclipse.php.internal.core.typeinference.evaluators;

import java.util.LinkedList;
import java.util.List;

import org.eclipse.dltk.ti.GoalState;
import org.eclipse.dltk.ti.goals.ExpressionTypeGoal;
import org.eclipse.dltk.ti.goals.GoalEvaluator;
import org.eclipse.dltk.ti.goals.IGoal;
import org.eclipse.dltk.ti.types.IEvaluatedType;
import org.eclipse.php.internal.core.compiler.ast.nodes.ArrayCreation;
import org.eclipse.php.internal.core.compiler.ast.nodes.ArrayElement;
import org.eclipse.php.internal.core.typeinference.PHPTypeInferenceUtils;

public class ArrayCreationEvaluator extends GoalEvaluator {

  private List<IEvaluatedType> evaluated = new LinkedList<IEvaluatedType>();

  public ArrayCreationEvaluator(IGoal goal) {
    super(goal);
  }

  public IGoal[] init() {
    ExpressionTypeGoal typedGoal = (ExpressionTypeGoal) goal;
    ArrayCreation arrayCreation = (ArrayCreation) typedGoal.getExpression();

    List<IGoal> subGoals = new LinkedList<IGoal>();
    for (ArrayElement arrayElement : arrayCreation.getElements()) {
      subGoals.add(new ExpressionTypeGoal(typedGoal.getContext(),
          arrayElement.getValue()));
    }
    return subGoals.toArray(new IGoal[subGoals.size()]);
  }

  public Object produceResult() {
    return PHPTypeInferenceUtils.combineMultiType(evaluated);
  }

  public IGoal[] subGoalDone(IGoal subgoal, Object result, GoalState state) {
    if (state != GoalState.RECURSIVE) {
      evaluated.add((IEvaluatedType) result);
    }
    return IGoal.NO_GOALS;
  }
}
TOP

Related Classes of org.eclipse.php.internal.core.typeinference.evaluators.ArrayCreationEvaluator

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.