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)) {
        // do it like for
        // PHPDocumentationContentAccess#handleBlockTags(List tags):
        // variable name can be optional, but if present keep only
        // the good ones
        if (tag.getVariableReference() != null
            && !tag.getVariableReference().getName().equals(declaration.getName())) {
          continue;
        }

        if (tag.getTypeReferences().size() > 0) {
          info.type = PHPModelUtils.appendTypeReferenceNames(tag.getTypeReferences());
          break;
        }
      }
    }
    fInfoStack.push(info);
    fRequestor.enterField(info);
    return true;
  }
Exemplo n.º 2
0
 public boolean visit(Assignment assignment) throws Exception {
   Expression left = assignment.getVariable();
   if (left instanceof FieldAccess) { // class variable ($this->a = .)
     FieldAccess fieldAccess = (FieldAccess) left;
     Expression dispatcher = fieldAccess.getDispatcher();
     if (dispatcher instanceof VariableReference
         && "$this".equals(((VariableReference) dispatcher).getName())) { // $NON-NLS-1$
       Expression field = fieldAccess.getField();
       if (field instanceof SimpleReference) {
         SimpleReference var = (SimpleReference) field;
         int modifiers = Modifiers.AccPublic;
         int offset = var.sourceStart();
         int length = var.sourceEnd() - offset;
         StringBuilder metadata = new StringBuilder();
         if (fCurrentQualifier != null) {
           metadata.append(fCurrentQualifierCounts.get(fCurrentQualifier));
           metadata.append(";"); // $NON-NLS-1$
         }
         modifyDeclaration(
             assignment,
             new DeclarationInfo(
                 IModelElement.FIELD,
                 modifiers,
                 offset,
                 length,
                 offset,
                 length,
                 '$' + var.getName(),
                 metadata.length() == 0 ? null : metadata.toString(),
                 null,
                 fCurrentQualifier,
                 fCurrentParent));
       }
     }
   } else if (left instanceof VariableReference) {
     int modifiers = Modifiers.AccPublic | Modifiers.AccGlobal;
     if (!declarations.empty()
         && declarations.peek() instanceof MethodDeclaration
         && !methodGlobalVars.peek().contains(((VariableReference) left).getName())) {
       return visitGeneral(assignment);
     }
     int offset = left.sourceStart();
     int length = left.sourceEnd() - offset;
     modifyDeclaration(
         assignment,
         new DeclarationInfo(
             IModelElement.FIELD,
             modifiers,
             offset,
             length,
             offset,
             length,
             ((VariableReference) left).getName(),
             null,
             null,
             null,
             null));
   }
   return visitGeneral(assignment);
 }
  public boolean visit(Assignment assignment) throws Exception {
    Expression left = assignment.getVariable();
    if (left instanceof FieldAccess) { // class variable ($this->a = .)
      FieldAccess fieldAccess = (FieldAccess) left;
      Expression dispatcher = fieldAccess.getDispatcher();
      if (dispatcher instanceof VariableReference
          && "$this" //$NON-NLS-1$
              .equals(((VariableReference) dispatcher).getName())) {
        Expression field = fieldAccess.getField();
        if (field instanceof SimpleReference) {
          SimpleReference ref = (SimpleReference) field;
          ISourceElementRequestor.FieldInfo info = new ISourceElementRequestor.FieldInfo();
          info.modifiers = Modifiers.AccPublic;
          info.name = '$' + ref.getName();
          info.nameSourceEnd = ref.sourceEnd() - 1;
          info.nameSourceStart = ref.sourceStart();
          info.declarationStart = assignment.sourceStart();
          fInfoStack.push(info);
          fRequestor.enterField(info);
          fNodes.push(assignment);
        }
      }
    } else if (left instanceof VariableReference && !(left instanceof ArrayVariableReference)) {
      if (!declarations.empty()) {
        ASTNode parentDeclaration = declarations.peek();
        if (parentDeclaration instanceof MethodDeclaration
                && methodGlobalVars.peek().contains(((VariableReference) left).getName())
            || parentDeclaration == fLastNamespace) {
          deferredDeclarations.add(assignment);
          return false;
        }
      }
      if (!fInfoStack.isEmpty() && fInfoStack.peek() instanceof ISourceElementRequestor.FieldInfo) {
        if (!fDeferredVariables.containsKey(fInfoStack.peek())) {
          fDeferredVariables.put(fInfoStack.peek(), new LinkedList<Assignment>());
        }
        fDeferredVariables.get(fInfoStack.peek()).add(assignment);
        return false;
      }
      ISourceElementRequestor.FieldInfo info = new ISourceElementRequestor.FieldInfo();
      info.modifiers = Modifiers.AccPublic;
      info.name = ((VariableReference) left).getName();
      info.nameSourceEnd = left.sourceEnd() - 1;
      info.nameSourceStart = left.sourceStart();
      info.declarationStart = assignment.sourceStart();

      fInfoStack.push(info);
      if (assignment.getOperatorType() == Assignment.OP_EQUAL) {
        fRequestor.enterField(info);
      } else {
        ISourceElementRequestor sourceElementRequestor = (ISourceElementRequestor) fRequestor;
        sourceElementRequestor.enterFieldCheckDuplicates(info);
      }
      fNodes.push(assignment);
    }
    return true;
  }
 public boolean visit(CatchClause catchClause) throws Exception {
   final ISourceElementRequestor.FieldInfo info = new ISourceElementRequestor.FieldInfo();
   info.modifiers = Modifiers.AccPublic;
   final 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;
 }
Exemplo n.º 5
0
 /**
  * @param exprs
  * @param index
  * @param keyword
  * @return
  */
 private boolean checkKeyword(IfContext context, String keyword) {
   final ASTNode node = context.get(context.index);
   if (node instanceof SimpleReference) {
     final SimpleReference ref = (SimpleReference) node;
     if (keyword.equals(ref.getName())) {
       ++context.index;
       return true;
     }
   }
   return false;
 }
 private String processReturnType(MethodDeclaration methodDeclaration) {
   final PHPDocBlock docBlock = ((PHPMethodDeclaration) methodDeclaration).getPHPDoc();
   final String type = VOID_RETURN_TYPE;
   if (docBlock != null) {
     for (final PHPDocTag tag : docBlock.getTags(PHPDocTag.RETURN)) {
       for (final SimpleReference reference : tag.getReferences()) {
         return PHPModelUtils.extractElementName(reference.getName());
       }
     }
   }
   return type;
 }
  public boolean visit(Assignment assignment) throws Exception {
    final Expression left = assignment.getVariable();
    if (left instanceof FieldAccess) { // class variable ($this->a = .)
      final FieldAccess fieldAccess = (FieldAccess) left;
      final Expression dispatcher = fieldAccess.getDispatcher();
      if (dispatcher instanceof VariableReference
          && "$this".equals(((VariableReference) dispatcher).getName())) { // $NON-NLS-1$
        final Expression field = fieldAccess.getField();
        if (field instanceof SimpleReference) {
          final SimpleReference ref = (SimpleReference) field;
          final ISourceElementRequestor.FieldInfo info = new ISourceElementRequestor.FieldInfo();
          info.modifiers = Modifiers.AccPublic;
          info.name = '$' + ref.getName();
          info.nameSourceEnd = ref.sourceEnd() - 1;
          info.nameSourceStart = ref.sourceStart();
          info.declarationStart = assignment.sourceStart();
          fRequestor.enterField(info);
          fNodes.push(assignment);
        }
      }
    } else if (left instanceof VariableReference) {
      if (!declarations.empty()) {
        final Declaration parentDeclaration = declarations.peek();
        if (parentDeclaration instanceof MethodDeclaration
                && methodGlobalVars.peek().contains(((VariableReference) left).getName())
            || parentDeclaration == fLastNamespace) {
          deferredDeclarations.add(assignment);
          return false;
        }
      }

      final ISourceElementRequestor.FieldInfo info = new ISourceElementRequestor.FieldInfo();
      info.modifiers = Modifiers.AccPublic;
      info.name = ((VariableReference) left).getName();
      info.nameSourceEnd = left.sourceEnd() - 1;
      info.nameSourceStart = left.sourceStart();
      info.declarationStart = assignment.sourceStart();
      fRequestor.enterField(info);
      fNodes.push(assignment);
    }
    return true;
  }
 @Override
 public boolean visitGeneral(ASTNode node) throws Exception {
   if (!ACTIVE) {
     return true;
   }
   if (node instanceof RubyRegexpExpression || node instanceof RubyDRegexpExpression) {
     handleRegexp(node);
   } else if (node instanceof RubySymbolReference) {
     requestor.addPosition(node.sourceStart(), node.sourceEnd(), HL_SYMBOL);
   } else if (node instanceof VariableReference) {
     handleVariableReference((VariableReference) node);
   } else if (node instanceof RubyDVarExpression) {
     requestor.addPosition(node.sourceStart(), node.sourceEnd(), HL_LOCAL_VARIABLE);
   } else if (node instanceof RubyDAssgnExpression) {
     ASTNode var = ((RubyDAssgnExpression) node).getLeft();
     requestor.addPosition(var.sourceStart(), var.sourceEnd(), HL_LOCAL_VARIABLE);
   } else if (node instanceof StringLiteral) {
     if (isStringLiteralNeeded(node)) {
       requestor.addPosition(node.sourceStart(), node.sourceEnd(), HL_STRING);
     }
   } else if (node instanceof NumericLiteral
       || node instanceof FloatNumericLiteral
       || node instanceof BigNumericLiteral) {
     requestor.addPosition(node.sourceStart(), node.sourceEnd(), HL_NUMBER);
   } else if (node instanceof RubyEvaluatableStringExpression) {
     handleEvaluatableExpression(node);
   } else if (node instanceof CallExpression) {
     final CallExpression call = (CallExpression) node;
     if (!(RubySyntaxUtils.isRubyOperator(call.getName())
         || call.getReceiver() == null && RubyCodeScanner.isPseudoKeyword(call.getName()))) {
       final SimpleReference callName = call.getCallName();
       if (callName.sourceStart() >= 0 && callName.sourceEnd() > callName.sourceStart()) {
         requestor.addPosition(callName.sourceStart(), callName.sourceEnd(), HL_DEFAULT);
       }
     }
   } else if (node instanceof Declaration) {
     final Declaration declaration = (Declaration) node;
     requestor.addPosition(declaration.getNameStart(), declaration.getNameEnd(), HL_DEFAULT);
   } else if (node instanceof RubyConstantDeclaration) {
     final RubyConstantDeclaration declaration = (RubyConstantDeclaration) node;
     final SimpleReference name = declaration.getName();
     requestor.addPosition(name.sourceStart(), name.sourceEnd(), HL_CONST);
   }
   stack.push(node);
   return true;
 }
 public boolean visit(PHPFieldDeclaration declaration) throws Exception {
   // This is variable declaration:
   final ISourceElementRequestor.FieldInfo info = new ISourceElementRequestor.FieldInfo();
   info.modifiers = declaration.getModifiers();
   info.name = declaration.getName();
   final SimpleReference var = declaration.getRef();
   info.nameSourceEnd = var.sourceEnd() - 1;
   info.nameSourceStart = var.sourceStart();
   info.declarationStart = declaration.getDeclarationStart();
   final PHPDocBlock doc = declaration.getPHPDoc();
   if (doc != null) {
     for (final PHPDocTag tag : doc.getTags(PHPDocTag.VAR)) {
       final SimpleReference[] references = tag.getReferences();
       if (references.length > 0) {
         info.type = PHPModelUtils.extractElementName(references[0].getName());
       }
     }
   }
   fRequestor.enterField(info);
   return true;
 }
Exemplo n.º 10
0
  public boolean visit(FieldAccess access) throws Exception {
    // This is variable field access:
    if (access.getField() instanceof SimpleReference) {
      SimpleReference simpleReference = (SimpleReference) access.getField();

      String name = simpleReference.getName();
      if (!name.startsWith(DOLOR)) {
        name = DOLOR + name;
      }
      modifyReference(
          access,
          new ReferenceInfo(
              IModelElement.FIELD,
              simpleReference.sourceStart(),
              simpleReference.sourceEnd() - simpleReference.sourceStart(),
              name,
              null,
              null));
    }

    return visitGeneral(access);
  }
 private String[] processParameterTypes(MethodDeclaration methodDeclaration) {
   List<?> args = methodDeclaration.getArguments();
   PHPDocBlock docBlock = ((PHPMethodDeclaration) methodDeclaration).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)) {
           if (tag.isValidParamTag()
               && tag.getVariableReference().getName().equals(arg.getName())) {
             parameterType[a] = tag.getSingleTypeReference().getName();
             break;
           }
         }
       }
     }
   }
   return parameterType;
 }
 private String[] processParamterTypes(MethodDeclaration methodDeclaration) {
   final List args = methodDeclaration.getArguments();
   final PHPDocBlock docBlock = ((PHPMethodDeclaration) methodDeclaration).getPHPDoc();
   final String[] parameterType = new String[args.size()];
   for (int a = 0; a < args.size(); a++) {
     final Argument arg = (Argument) args.get(a);
     if (arg instanceof FormalParameter) {
       final SimpleReference type = ((FormalParameter) arg).getParameterType();
       if (type != null) {
         parameterType[a] = type.getName();
       } else if (docBlock != null) {
         for (final PHPDocTag tag : docBlock.getTags(PHPDocTag.PARAM)) {
           final SimpleReference[] refs = tag.getReferences();
           if (refs.length == 2) {
             if (refs[0].getName().equals(arg.getName())) {
               parameterType[a] = refs[1].getName();
             }
           }
         }
       }
     }
   }
   return parameterType;
 }
  /**
   * Resolve class members that were defined using the @property tag
   *
   * @param type declaration for wich we add the magic variables
   */
  private void resolveMagicMembers(TypeDeclaration type) {
    if (type instanceof IPHPDocAwareDeclaration) {
      final IPHPDocAwareDeclaration declaration = (IPHPDocAwareDeclaration) type;
      final PHPDocBlock doc = declaration.getPHPDoc();
      if (doc != null) {
        final PHPDocTag[] tags = doc.getTags();
        for (final PHPDocTag docTag : tags) {
          final int tagKind = docTag.getTagKind();
          if (tagKind == PHPDocTag.PROPERTY
              || tagKind == PHPDocTag.PROPERTY_READ
              || tagKind == PHPDocTag.PROPERTY_WRITE) {
            // http://manual.phpdoc.org/HTMLSmartyConverter/HandS/phpDocumentor/tutorial_tags.property.pkg.html
            final String[] split = WHITESPACE_SEPERATOR.split(docTag.getValue().trim());
            if (split.length < 2) {
              break;
            }
            final ISourceElementRequestor.FieldInfo info = new ISourceElementRequestor.FieldInfo();
            info.modifiers = Modifiers.AccPublic;
            info.name = split[1];
            final 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;
            }

            final ISourceElementRequestor.MethodInfo mi = new ISourceElementRequestor.MethodInfo();
            mi.parameterNames = null;
            mi.name = removeParenthesis(split);
            final 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;

            this.fRequestor.enterMethod(mi);
            this.fRequestor.exitMethod(mi.nameSourceEnd);
          }
        }
      }
    }
  }
Exemplo n.º 14
0
 /**
  * Initialize a function declaration node
  *
  * @param name reference to the expression which this function is assigned to
  * @param start start offset of function body
  * @param end end offset of function body
  */
 public FunctionDeclaration(SimpleReference name, int start, int end) {
   this(name.getName(), name.sourceStart(), name.sourceEnd(), start, end);
 }
Exemplo n.º 15
0
 public boolean visit(SimpleReference s) throws Exception {
   Map<String, String> parameters = createInitialParameters(s);
   parameters.put("name", s.getName());
   xmlWriter.startTag("SimpleReference", parameters);
   return true;
 }
  /**
   * Resolve class members that were defined using the @property tag
   *
   * @param type declaration for wich we add the magic variables
   */
  private void resolveMagicMembers(TypeDeclaration type) {
    if (type instanceof IPHPDocAwareDeclaration) {
      IPHPDocAwareDeclaration declaration = (IPHPDocAwareDeclaration) type;
      final PHPDocBlock doc = declaration.getPHPDoc();
      if (doc != null) {
        Pattern WHITESPACE_SEPERATOR = MagicMemberUtil.WHITESPACE_SEPERATOR;
        final PHPDocTag[] tags = doc.getTags();
        for (PHPDocTag docTag : tags) {
          final int tagKind = docTag.getTagKind();
          if (tagKind == PHPDocTag.PROPERTY
              || tagKind == PHPDocTag.PROPERTY_READ
              || tagKind == PHPDocTag.PROPERTY_WRITE) {
            // http://manual.phpdoc.org/HTMLSmartyConverter/HandS/phpDocumentor/tutorial_tags.property.pkg.html
            final String[] split = WHITESPACE_SEPERATOR.split(docTag.getValue().trim());
            if (split.length < 2) {
              continue;
            }
            ISourceElementRequestor.FieldInfo info = new ISourceElementRequestor.FieldInfo();
            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

            // workaround for lack of method return type
            int methodModifiers = Modifiers.AccPublic;
            String docTagValue = docTag.getValue().trim();
            int index = docTagValue.indexOf('(');
            if (index != -1) {
              String[] split = WHITESPACE_SEPERATOR.split(docTagValue.substring(0, index).trim());
              if (split.length == 1) {
                docTagValue =
                    new StringBuilder(VOID_RETURN_TYPE)
                        .append(Constants.SPACE)
                        .append(docTagValue)
                        .toString();
              } else if (split.length == 2 && Constants.STATIC.equals(split[0])) {
                StringBuilder sb = new StringBuilder(Constants.STATIC);
                sb.append(Constants.SPACE).append(VOID_RETURN_TYPE);
                sb.append(docTagValue.substring(6));
                docTagValue = sb.toString();
              }
            }
            String[] split = WHITESPACE_SEPERATOR.split(docTagValue);
            if (split.length < 2) {
              continue;
            }
            if (Constants.STATIC.equals(split[0])) {
              methodModifiers |= Modifiers.AccStatic;
              split = Arrays.copyOfRange(split, 1, split.length);
              docTagValue = docTagValue.substring(7).trim();
              if (split.length < 2) {
                continue;
              }
            }

            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 = methodModifiers;
            mi.nameSourceStart = var.sourceStart();
            mi.nameSourceEnd = var.sourceEnd();
            mi.declarationStart = mi.nameSourceStart;
            mi.isConstructor = false;
            mi.returnType = split[0];

            MagicMethod magicMethod;
            if (mi.name != null && mi.name.indexOf('(') > 0) {
              magicMethod = MagicMemberUtil.getMagicMethod2(docTagValue);
              mi.name = magicMethod.name;
            } else {
              magicMethod = MagicMemberUtil.getMagicMethod(docTagValue);
            }
            if (magicMethod != null) {
              mi.parameterNames = magicMethod.parameterNames;
              mi.parameterTypes = magicMethod.parameterTypes;
              mi.parameterInitializers = magicMethod.parameterInitializers;
            }

            this.fRequestor.enterMethod(mi);
            this.fRequestor.exitMethod(mi.nameSourceEnd);
          }
        }
      }
    }
  }
 public boolean visit(ForEachStatement foreachStatement) throws Exception {
   if (foreachStatement.getKey() instanceof VariableReference) {
     final SimpleReference var = (SimpleReference) foreachStatement.getKey();
     final ISourceElementRequestor.FieldInfo info = new ISourceElementRequestor.FieldInfo();
     info.modifiers = Modifiers.AccPublic;
     info.name = var.getName();
     info.nameSourceEnd = var.sourceEnd() - 1;
     info.nameSourceStart = var.sourceStart();
     info.declarationStart = var.sourceStart();
     fRequestor.enterField(info);
     fRequestor.exitField(var.sourceEnd() - 1);
   }
   if (foreachStatement.getValue() instanceof VariableReference) {
     final SimpleReference var = (SimpleReference) foreachStatement.getValue();
     final ISourceElementRequestor.FieldInfo info = new ISourceElementRequestor.FieldInfo();
     info.modifiers = Modifiers.AccPublic;
     info.name = var.getName();
     info.nameSourceEnd = var.sourceEnd() - 1;
     info.nameSourceStart = var.sourceStart();
     info.declarationStart = var.sourceStart();
     fRequestor.enterField(info);
     fRequestor.exitField(var.sourceEnd() - 1);
   }
   return true;
 }