Package org.eclipse.dltk.ti.types

Examples of org.eclipse.dltk.ti.types.IEvaluatedType


        }
        // Function call:
        if (node instanceof PHPCallExpression) {
          PHPCallExpression callExpression = (PHPCallExpression) node;
          if (callExpression.getReceiver() != null) {
            IEvaluatedType receiverType = PHPTypeInferenceUtils
                .resolveExpression(sourceModule, parsedUnit,
                    context, callExpression.getReceiver());
            // (new class1())->avc2()[1][1]->avc1()
            if ((receiverType instanceof MultiTypeType)
                && callExpression.getReceiver() instanceof PHPCallExpression) {
              PHPCallExpression receiverCallExpression = (PHPCallExpression) callExpression
                  .getReceiver();
              if (((PHPCallArgumentsList) receiverCallExpression
                  .getArgs()).getArrayDereferenceList() != null
                  && !((PHPCallArgumentsList) receiverCallExpression
                      .getArgs())
                      .getArrayDereferenceList()
                      .getChilds().isEmpty()) {
                receiverType = new AmbiguousType(
                    ((MultiTypeType) receiverType)
                        .getTypes().toArray(
                            new IEvaluatedType[0]));
              }
            }
            if (receiverType != null) {
              IModelElement[] elements = null;
              if ((receiverType instanceof PHPClassType)
                  && ((PHPClassType) receiverType).isGlobal()) {

                IDLTKSearchScope scope = SearchEngine
                    .createSearchScope(sourceModule
                        .getScriptProject());
                elements = PhpModelAccess.getDefault()
                    .findTypes(receiverType.getTypeName(),
                        MatchRule.EXACT, 0, 0, scope,
                        null);
                LinkedList<IModelElement> result = new LinkedList<IModelElement>();
                for (IModelElement element : elements) {
                  IModelElement parent = element.getParent();
                  while (parent.getParent() instanceof IType) {
                    parent = parent.getParent();
                  }
                  if ((parent instanceof IType)
                      && PHPFlags
                          .isNamespace(((IType) parent)
                              .getFlags())) {
                    // Do nothing
                  } else {
                    result.add(element);
                  }
                }
                elements = result.toArray(new IType[result
                    .size()]);
              } else {
                elements = PHPTypeInferenceUtils
                    .getModelElements(receiverType,
                        (ISourceModuleContext) context,
                        offset);
              }
              List<IModelElement> methods = new LinkedList<IModelElement>();
              if (elements != null) {
                for (IModelElement element : elements) {
                  if (element instanceof IType) {
                    IType type = (IType) element;
                    try {
                      IMethod[] method = PHPModelUtils
                          .getFirstTypeHierarchyMethod(
                              type,
                              cache.getSuperTypeHierarchy(
                                  type, null),
                              callExpression
                                  .getName(),
                              true, null);
                      methods.addAll(Arrays
                          .asList(method));
                    } catch (CoreException e) {
                      PHPCorePlugin.log(e);
                    }
                  }
                }
              }
              return methods.toArray(new IModelElement[methods
                  .size()]);
            }
          } else {
            SimpleReference callName = callExpression.getCallName();
            String methodName = callName instanceof FullyQualifiedReference ? ((FullyQualifiedReference) callName)
                .getFullyQualifiedName() : callName.getName();
            IMethod[] functions = PHPModelUtils.getFunctions(
                methodName, sourceModule, offset, cache, null);
            return functions == null ? EMPTY : functions;
          }
        }
        // Static field or constant access:
        else if (node instanceof StaticDispatch) {
          StaticDispatch dispatch = (StaticDispatch) node;
          String fieldName = null;
          if (dispatch instanceof StaticConstantAccess) {
            fieldName = ((StaticConstantAccess) dispatch)
                .getConstant().getName();
          } else if (dispatch instanceof StaticFieldAccess) {
            ASTNode field = ((StaticFieldAccess) dispatch)
                .getField();
            if (field instanceof VariableReference) {
              fieldName = ((VariableReference) field).getName();
            }
          }
          if (fieldName != null && dispatch.getDispatcher() != null) {
            IEvaluatedType dispatcherType = PHPTypeInferenceUtils
                .resolveExpression(sourceModule, parsedUnit,
                    context, dispatch.getDispatcher());
            if (dispatcherType != null) {
              IModelElement[] elements = PHPTypeInferenceUtils
                  .getModelElements(dispatcherType,
                      (ISourceModuleContext) context,
                      offset);
              List<IModelElement> fields = new LinkedList<IModelElement>();
              if (elements != null) {
                for (IModelElement element : elements) {
                  if (element instanceof IType) {
                    IType type = (IType) element;
                    try {
                      fields.addAll(Arrays.asList(PHPModelUtils.getTypeHierarchyField(
                          type,
                          cache.getSuperTypeHierarchy(
                              type,
                              new NullProgressMonitor()),
                          fieldName, true,
                          new NullProgressMonitor())));
                    } catch (Exception e) {
                      PHPCorePlugin.log(e);
                    }
                  }
                }
              }
              return fields.toArray(new IModelElement[fields
                  .size()]);
            }
          }
        }
        // Dynamic field access:
        else if (node instanceof FieldAccess) {
          FieldAccess fieldAccess = (FieldAccess) node;
          ASTNode field = fieldAccess.getField();
          String fieldName = null;
          if (field instanceof SimpleReference) {
            fieldName = ((SimpleReference) field).getName();
          }
          if (fieldName != null
              && fieldAccess.getDispatcher() != null) {
            IEvaluatedType dispatcherType = PHPTypeInferenceUtils
                .resolveExpression(sourceModule, parsedUnit,
                    context, fieldAccess.getDispatcher());
            if (dispatcherType != null) {
              IModelElement[] elements = PHPTypeInferenceUtils
                  .getModelElements(dispatcherType,
                      (ISourceModuleContext) context,
                      offset);
              List<IModelElement> fields = new LinkedList<IModelElement>();
              if (elements != null) {
                for (IModelElement element : elements) {
                  if (element instanceof IType) {
                    IType type = (IType) element;
                    try {
                      fields.addAll(Arrays
                          .asList(PHPModelUtils
                              .getTypeField(type,
                                  fieldName,
                                  true)));
                    } catch (ModelException e) {
                      PHPCorePlugin.log(e);
                    }
                  }
                }
              }
              return fields.toArray(new IModelElement[fields
                  .size()]);
            }
          }
        } else if (node instanceof NamespaceReference) {
          String name = ((NamespaceReference) node).getName();
          IType[] namespace = PHPModelUtils.getNamespaceOf(name
              + NamespaceReference.NAMESPACE_SEPARATOR,
              sourceModule, offset, cache, null);
          return namespace == null ? EMPTY : namespace;
        }
        // Class/Interface reference:
        else if (node instanceof TypeReference) {
          IEvaluatedType evaluatedType = PHPTypeInferenceUtils
              .resolveExpression(sourceModule, node);
          if (evaluatedType == null) {
            return EMPTY;
          }
          String name = evaluatedType.getTypeName();
          IType[] types = PHPModelUtils.getTypes(name, sourceModule,
              offset, cache, null,
              !(evaluatedType instanceof PHPTraitType));
          if (types == null || types.length == 0) {
            // This can be a constant or namespace in PHP 5.3:
            if (name.charAt(0) == NamespaceReference.NAMESPACE_SEPARATOR) {
              name = name.substring(1);
            }
            IDLTKSearchScope scope = SearchEngine
                .createSearchScope(sourceModule
                    .getScriptProject());
            if (evaluatedType instanceof PHPTraitType) {
              types = PhpModelAccess.getDefault().findTraits(
                  null, name, MatchRule.EXACT,
                  Modifiers.AccNameSpace, 0, scope, null);
            } else {
              types = PhpModelAccess.getDefault().findTypes(null,
                  name, MatchRule.EXACT,
                  Modifiers.AccNameSpace, 0, scope, null);
            }

            if (types == null || types.length == 0) {
              name = NamespaceReference.NAMESPACE_SEPARATOR
                  + name;
              return PHPModelUtils.getFields(name, sourceModule,
                  offset, cache, null);
            }
          }
          return types;
        }
        // 'new' statement
        else if (node instanceof ClassInstanceCreation) {
          ClassInstanceCreation newNode = (ClassInstanceCreation) node;

          Expression className = newNode.getClassName();

          if ((className instanceof SimpleReference || className instanceof FullyQualifiedReference)) {
            IEvaluatedType evaluatedType = PHPTypeInferenceUtils
                .resolveExpression(sourceModule, node);
            return getConstructorsIfAny(extractClasses(PHPModelUtils
                .getTypes(evaluatedType.getTypeName(),
                    sourceModule, offset, cache, null)));
          } else if ((className instanceof StaticFieldAccess)) {
            StaticFieldAccess staticFieldAccess = (StaticFieldAccess) className;
            if ((offset >= staticFieldAccess.getDispatcher()
                .sourceStart())
                && (offset <= staticFieldAccess.getDispatcher()
                    .sourceEnd())) {
              className = staticFieldAccess.getDispatcher();
              IEvaluatedType evaluatedType = PHPTypeInferenceUtils
                  .resolveExpression(sourceModule, className);
              return extractClasses(PHPModelUtils.getTypes(
                  evaluatedType.getTypeName(), sourceModule,
                  offset, cache, null));
            } else if ((offset >= staticFieldAccess.getField()
                .sourceStart())
                && (offset <= staticFieldAccess.getField()
                    .sourceEnd())) {
              className = staticFieldAccess.getField();

              String fieldName = null;
              ASTNode field = staticFieldAccess.getField();
              if (field instanceof VariableReference) {
                fieldName = ((VariableReference) field)
                    .getName();
              }
              if (fieldName != null
                  && staticFieldAccess.getDispatcher() != null) {
                IEvaluatedType dispatcherType = PHPTypeInferenceUtils
                    .resolveExpression(sourceModule,
                        parsedUnit, context,
                        staticFieldAccess
                            .getDispatcher());
                if (dispatcherType != null) {
View Full Code Here


            .getModuleDeclaration(sourceModule);
        if (moduleDeclaration != null) {
          IContext context = ASTUtils.findContext(sourceModule,
              moduleDeclaration, offset);
          if (context instanceof MethodContext) {
            IEvaluatedType instanceType = ((MethodContext) context)
                .getInstanceType();
            if (instanceType instanceof PHPClassType) {
              PHPClassType classType = (PHPClassType) instanceType;
              String namespace = classType.getNamespace();
              if (namespace != null && namespace.length() > 0) {
View Full Code Here

   * @return
   */
  public static IEvaluatedType fromSimpleReference(SimpleReference name) {
    String typeName = name instanceof FullyQualifiedReference ? ((FullyQualifiedReference) name)
        .getFullyQualifiedName() : name.getName();
    IEvaluatedType simpleType = PHPSimpleTypes.fromString(typeName);
    if (simpleType != null) {
      return simpleType;
    }
    return new PHPClassType(typeName);
  }
View Full Code Here

      throw new IllegalArgumentException(
          "Can not resolve null expression"); //$NON-NLS-1$
    }
    int start = expression.getStart();
    int length = expression.getLength();
    IEvaluatedType type = getEvaluatedType(start, length);
    if (type != null) {
      IModelElement[] modelElements = getModelElements(start, length,
          false);
      return internalGetTypeBinding(type, modelElements);
    } else {
View Full Code Here

      evaluatedTypesCache.put(
          sourceRange,
          getType(sourceRange, contextFinder.getContext(),
              contextFinder.getNode()));
    }
    IEvaluatedType evaluatedType = evaluatedTypesCache.get(sourceRange);
    return PHPTypeInferenceUtils.getModelElements(evaluatedType,
        (ISourceModuleContext) contextFinder.getContext(),
        sourceRange.getOffset(), cache);
  }
View Full Code Here

    for (Expression expr : returnExpressions) {
      SourceRange sourceRange = new SourceRange(expr);
      try {
        ContextFinder contextFinder = getContext(sourceRange);
        IContext context = contextFinder.getContext();
        IEvaluatedType resolvedExpression = PHPTypeInferenceUtils
            .resolveExpression(cachedInferencer, sourceModule,
                sourceModuleDeclaration, context, expr);
        if (resolvedExpression != null) {
          evaluated.add(resolvedExpression);
        }
      } catch (ModelException e) {
        if (DLTKCore.DEBUG) {
          e.printStackTrace();
        }
        continue;
      }
    }
    if (yieldExpressions.size() > 0) {
      GeneratorClassType generator = new GeneratorClassType();
      for (Expression expr : yieldExpressions) {
        if (expr == null) {
          generator.getTypes().add(PHPSimpleTypes.NULL);
        } else {
          SourceRange sourceRange = new SourceRange(expr);
          try {
            ContextFinder contextFinder = getContext(sourceRange);
            IContext context = contextFinder.getContext();
            IEvaluatedType resolvedExpression = PHPTypeInferenceUtils
                .resolveExpression(cachedInferencer,
                    sourceModule, sourceModuleDeclaration,
                    context, expr);
            if (resolvedExpression != null) {
              generator.getTypes().add(resolvedExpression);
View Full Code Here

        if (!propertyName.startsWith(DOLLAR)) {
          propertyName = DOLLAR + propertyName;
        }
        PHPDocClassVariableGoal phpDocGoal = new PHPDocClassVariableGoal(
            typeContext, propertyName, offset);
        IEvaluatedType evaluatedType = typeInferencer
            .evaluateTypePHPDoc(phpDocGoal, 3000);

        IType[] modelElements = PHPTypeInferenceUtils.getModelElements(
            evaluatedType, fileContext, offset);
        if (modelElements != null) {
View Full Code Here

      VariableReference varReference = getVariableReference(variableName,
          position);
      ExpressionTypeGoal goal = new ExpressionTypeGoal(context,
          varReference);
      PHPTypeInferencer typeInferencer = new PHPTypeInferencer();
      IEvaluatedType evaluatedType = typeInferencer.evaluateType(goal);
      if (evaluatedType instanceof MultiTypeType
          || evaluatedType instanceof AmbiguousType) {
        return getTypes(position, context, evaluatedType);
      }
View Full Code Here

      VariableReference varReference = getVariableReference(variableName,
          position);
      ExpressionTypeGoal goal = new ExpressionTypeGoal(context,
          varReference);
      PHPTypeInferencer typeInferencer = new PHPTypeInferencer();
      IEvaluatedType evaluatedType = typeInferencer.evaluateType(goal);

      IType[] modelElements = getTypes(position, context, evaluatedType);
      // IType[] modelElements = PHPTypeInferenceUtils.getModelElements(
      // evaluatedType, (ISourceModuleContext) context, position);
      if (modelElements != null) {
View Full Code Here

    ModuleDeclaration moduleDeclaration = SourceParserUtil
        .getModuleDeclaration(sourceModule, null);
    IContext context = ASTUtils.findContext(sourceModule,
        moduleDeclaration, offset);

    IEvaluatedType evaluatedType;
    IType[] modelElements;
    boolean usePhpDoc = (mask & USE_PHPDOC) != 0;
    if (usePhpDoc) {
      PHPDocMethodReturnTypeGoal phpDocGoal = new PHPDocMethodReturnTypeGoal(
          context, types, method);
View Full Code Here

TOP

Related Classes of org.eclipse.dltk.ti.types.IEvaluatedType

Copyright © 2018 www.massapicom. 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.