コード例 #1
0
 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;
 }
コード例 #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);
 }
コード例 #3
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" //$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;
  }
コード例 #4
0
 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;
 }
コード例 #5
0
ファイル: TclIfProcessor.java プロジェクト: eclipse/dltk.tcl
 /**
  * @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;
 }
コード例 #6
0
 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;
 }
コード例 #7
0
  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;
  }
コード例 #8
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);
  }
コード例 #9
0
 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;
 }
コード例 #10
0
 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;
 }
コード例 #11
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);
 }
コード例 #12
0
ファイル: ASTPrintVisitor.java プロジェクト: anod/pdt
 public boolean visit(SimpleReference s) throws Exception {
   Map<String, String> parameters = createInitialParameters(s);
   parameters.put("name", s.getName());
   xmlWriter.startTag("SimpleReference", parameters);
   return true;
 }