Package org.eclipse.dltk.ast.references

Examples of org.eclipse.dltk.ast.references.SimpleReference


        return false;
      }
      if (s instanceof RutaImportStatement) {
        // handle type system imports
        if (((RutaImportStatement) s).getType() == RutaStatementConstants.S_IMPORT_TYPESYSTEM) {
          SimpleReference sRef = (SimpleReference) ((RutaImportStatement) s).getExpression();
          String localPath = sRef.getName();
          try {
            boolean checkTypeSystemImport = RutaCheckerUtils.checkTypeSystemImport(localPath,
                    project);
            if (!checkTypeSystemImport) {
              rep.reportProblem(problemFactory.createFileNotFoundProblem(sRef, localPath));
            }
            Set<String> importedTypes = importTypeSystem(localPath);
            Set<String> importedShortTypes = getShortTypeNames(importedTypes);

            if (reportWarningOnShortNames) {
              List<String> checkDuplicateShortNames = checkDuplicateShortNames(completeTypes,
                      importedTypes);
              if (!checkDuplicateShortNames.isEmpty()) {
                rep.reportProblem(problemFactory.createDuplicateShortNameInImported(sRef,
                        localPath, checkDuplicateShortNames, ProblemSeverity.WARNING));
              }
            }
            completeTypes.addAll(importedTypes);
            shortTypes.addAll(importedShortTypes);
          } catch (IOException e) {
            rep.reportProblem(problemFactory.createFileNotFoundProblem(sRef, localPath));
          } catch (InvalidXMLException e) {
            rep.reportProblem(problemFactory.createXMLProblem(sRef, localPath));
          }
          return false;
        }
        // handle script-imports
        if (((RutaImportStatement) s).getType() == RutaStatementConstants.S_IMPORT_SCRIPT) {
          SimpleReference sRef = (SimpleReference) ((RutaImportStatement) s).getExpression();
          String localpath = sRef.getName();

          // HOTFIX Peter add also the imported types of the imported type system!
          try {
            boolean checkScriptImport = RutaCheckerUtils
                    .checkScriptImport(localpath, project);
View Full Code Here


        if (me.getElementType() == IModelElement.FIELD) {
          return me.getElementName();
        }
      }
      if (element instanceof UseStatementElement) {
        SimpleReference alias = ((UseStatementElement) element)
            .getUsePart().getAlias();
        if (alias != null) {
          return NLS.bind(
              PHPUIMessages.PHPContentOutlineConfiguration_3,
              super.getText(element), alias.getName());
        }
      }
      return super.getText(element);
    }
View Full Code Here

  }

  private StringBuffer handleLinks(List<? extends SimpleReference> fragments) {
    StringBuffer sb = new StringBuffer();
    for (int i = 0; i < fragments.size(); i++) {
      SimpleReference reference = fragments.get(i);
      sb.append(handleLink(reference));
      if (i < (fragments.size() - 1)) {
        sb.append(", ");
      }
    }
View Full Code Here

  private String getParameterInfo(PHPDocTag tag, int infoType) {
    if (tag.getTagKind() != PHPDocTag.PARAM) {
      return null;
    }
    SimpleReference typeRef = null;
    SimpleReference variableRef = null;
    String value = tag.getValue();
    if (tag.getReferences().length != 2) {
      return null;
    }
    for (SimpleReference reference : tag.getReferences()) {
      if (reference instanceof TypeReference) {
        typeRef = reference;
      } else if (reference instanceof VariableReference) {
        variableRef = reference;
      }
    }
    if (infoType == PARAMETER_DESCRIPTION_TYPE) {
      int typeRefIndex = value.indexOf(typeRef.getName());
      int variableRefIndex = value.indexOf(variableRef.getName());
      int lastRefIndex = typeRefIndex > variableRefIndex ? typeRefIndex
          + typeRef.getName().length() : variableRefIndex
          + variableRef.getName().length();
      return value.substring(lastRefIndex).trim();
    } else if (infoType == PARAMETER_TYPE_TYPE) {
      return typeRef.getName();
    } else if (infoType == PARAMETER_NAME_TYPE) {
      return variableRef.getName();
    }
    return null;
  }
View Full Code Here

    for (TraitStatement traitStatement : statement.getTsList()) {
      if (traitStatement instanceof TraitAliasStatement) {
        TraitAliasStatement new_name = (TraitAliasStatement) traitStatement;
        Expression traitMethod = new_name.getAlias().getTraitMethod();
        if (traitMethod instanceof SimpleReference) {
          SimpleReference simpleReference = (SimpleReference) traitMethod;
          TraitAliasObject ta = new TraitAliasObject();
          // ta.traitName = PHPModelUtils.getFullName(
          // simpleReference.getName(), sourceModule, offset);
          ta.traitMethodName = simpleReference.getName();
          ta.newMethodVisibility = new_name.getAlias().getModifier();
          if (new_name.getAlias().getMethodName() != null) {
            ta.newMethodName = new_name.getAlias().getMethodName()
                .getName();
          }
          useTrait.getTraitAliases().add(ta);
          List<TraitAliasObject> traitAliases = useTrait
              .getAliasMap().get(ta.traitMethodName);
          if (traitAliases == null) {
            traitAliases = new ArrayList<TraitAliasObject>();
            useTrait.getAliasMap().put(ta.traitMethodName,
                traitAliases);
          }
          traitAliases.add(ta);
          // useTrait.getAliasMap().put(ta.traitMethodName, ta);
        } else if (traitMethod instanceof FullyQualifiedTraitMethodReference) {
          FullyQualifiedTraitMethodReference simpleReference = (FullyQualifiedTraitMethodReference) traitMethod;

          TraitAliasObject ta = new TraitAliasObject();
          ta.traitName = PHPModelUtils.getFullName(simpleReference
              .getClassName().getName(), sourceModule, offset);
          ta.traitMethodName = simpleReference.getFunctionName();
          ta.newMethodVisibility = new_name.getAlias().getModifier();
          if (new_name.getAlias().getMethodName() != null) {
            ta.newMethodName = new_name.getAlias().getMethodName()
                .getName();
          }
View Full Code Here

              }
              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) {
                  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()]);
                }
              }
            }

          }
        }
        // Class name in declaration
        else if ((node instanceof TypeDeclaration || node instanceof MethodDeclaration)
            && ((Declaration) node).getNameStart() <= offset
            && ((Declaration) node).getNameEnd() >= offset) {

          IModelElement element = sourceModule.getElementAt(node
              .sourceStart());
          if (element != null) {
            return new IModelElement[] { element };
          }
        } else if (node instanceof SimpleReference) {

          SimpleReference reference = (SimpleReference) node;

          node = ASTUtils.findMinimalNode(parsedUnit, offset,
              node.end() + 1);
          if (node instanceof TraitAliasStatement) {
            node = ASTUtils.findMinimalNode(parsedUnit, offset,
                node.end() + 1);
            if (node instanceof TraitUseStatement) {
              TraitUseStatement statement = (TraitUseStatement) node;
              List<IModelElement> methods = new LinkedList<IModelElement>();
              for (TypeReference typeReference : statement
                  .getTraitList()) {
                IType[] types = PHPModelUtils.getTypes(
                    typeReference.getName(), sourceModule,
                    offset, cache, null, false);
                for (IType t : types) {
                  IModelElement[] children = t.getChildren();
                  for (IModelElement modelElement : children) {
                    String name = modelElement
                        .getElementName();
                    if (name.startsWith("$")) { //$NON-NLS-1$
                      name = name.substring(1);
                    }
                    if (name.equals(reference.getName())) {
                      methods.add(modelElement);
                    }
                  }
                }
              }
View Full Code Here

        .getPHPDoc();
    String[] parameterType = new String[args.size()];
    for (int a = 0; a < args.size(); a++) {
      Argument arg = (Argument) args.get(a);
      if (arg instanceof FormalParameter) {
        SimpleReference type = ((FormalParameter) arg)
            .getParameterType();
        if (type != null) {
          parameterType[a] = type.getName();
        } else if (docBlock != null) {
          for (PHPDocTag tag : docBlock.getTags(PHPDocTag.PARAM)) {
            SimpleReference[] refs = tag.getReferences();
            if (refs.length == 2) {
              if (refs[0].getName().equals(arg.getName())) {
View Full Code Here

            info.modifiers = Modifiers.AccPublic
                | IPHPModifiers.AccMagicProperty;
            info.name = split[1];
            info.type = split[0];

            SimpleReference var = new SimpleReference(
                docTag.sourceStart(), docTag.sourceStart() + 9,
                removeParenthesis(split));
            info.nameSourceStart = var.sourceStart();
            info.nameSourceEnd = var.sourceEnd();
            info.declarationStart = info.nameSourceStart;

            fRequestor.enterField(info);
            fRequestor.exitField(info.nameSourceEnd);

          } else if (tagKind == PHPDocTag.METHOD) {
            // http://manual.phpdoc.org/HTMLSmartyConverter/HandS/phpDocumentor/tutorial_tags.method.pkg.html
            final String[] split = WHITESPACE_SEPERATOR
                .split(docTag.getValue().trim());
            if (split.length < 2) {
              break;
            }

            ISourceElementRequestor.MethodInfo mi = new ISourceElementRequestor.MethodInfo();
            mi.parameterNames = null;
            mi.name = removeParenthesis(split);
            SimpleReference var = new SimpleReference(
                docTag.sourceStart(), docTag.sourceStart() + 6,
                removeParenthesis(split));
            mi.modifiers = Modifiers.AccPublic;
            mi.nameSourceStart = var.sourceStart();
            mi.nameSourceEnd = var.sourceEnd();
            mi.declarationStart = mi.nameSourceStart;
            mi.isConstructor = false;
            mi.returnType = split[0];

            MagicMethod magicMethod;
View Full Code Here

  public boolean visit(PHPFieldDeclaration declaration) throws Exception {
    // This is variable declaration:
    ISourceElementRequestor.FieldInfo info = new ISourceElementRequestor.FieldInfo();
    info.modifiers = declaration.getModifiers();
    info.name = declaration.getName();
    SimpleReference var = declaration.getRef();
    info.nameSourceEnd = var.sourceEnd() - 1;
    info.nameSourceStart = var.sourceStart();
    info.declarationStart = declaration.getDeclarationStart();
    info.modifiers = markAsDeprecated(info.modifiers, declaration);
    PHPDocBlock doc = declaration.getPHPDoc();
    if (doc != null) {
      for (PHPDocTag tag : doc.getTags(PHPDocTag.VAR)) {
View Full Code Here

  }

  public boolean visit(CatchClause catchClause) throws Exception {
    ISourceElementRequestor.FieldInfo info = new ISourceElementRequestor.FieldInfo();
    info.modifiers = Modifiers.AccPublic;
    SimpleReference var = catchClause.getVariable();
    info.name = var.getName();
    info.nameSourceEnd = var.sourceEnd() - 1;
    info.nameSourceStart = var.sourceStart();
    info.declarationStart = catchClause.sourceStart();

    fRequestor.enterField(info);
    return true;
  }
View Full Code Here

TOP

Related Classes of org.eclipse.dltk.ast.references.SimpleReference

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.