Package org.eclipse.jdt.core.dom

Examples of org.eclipse.jdt.core.dom.ASTNode$NodeList$Cursor


      }
    }

    private String getSource(AbstractMetricElement source)
        throws JavaModelException {
      ASTNode astNode = source.getASTNode();
      int start = astNode.getStartPosition();
      int length = astNode.getLength();
      ICompilationUnit unit = source.getCompilationUnit();
      String s = unit.getSource();
      return s.substring(start, start + length);
    }
View Full Code Here


      }
    }

    private String getSource(AbstractMetricElement source)
        throws JavaModelException {
      ASTNode astNode = source.getASTNode();
      int start = astNode.getStartPosition();
      int length = astNode.getLength();
      ICompilationUnit unit = source.getCompilationUnit();
      String s = unit.getSource();
      return s.substring(start, start + length);
    }
View Full Code Here

                match.getResource(), member);
          }
          return;
        }
        CompilationUnit cuNode = retrieveCompilationUnit(member.getCompilationUnit());
        ASTNode node = ASTNodeSearchUtil.getAstNode(match, cuNode);
        Expression expr = null;

        if (node != null) {

          if (node instanceof MethodInvocation) {
            expr = (MethodInvocation) node;
          } else if (node.getParent() instanceof MethodInvocation) {
            expr = (MethodInvocation) node.getParent();
          } else if (node instanceof ClassInstanceCreation) {
            expr = (ClassInstanceCreation) node;
          } else if (node.getParent() instanceof ClassInstanceCreation) {
            expr = (ClassInstanceCreation) node.getParent();
          } else {
            System.err.println("Unknown match type: " + node
                + " of type " + node.getClass());
            try {
              System.err
                  .println("MethodReferencesSearchRequestor: Skipping node that appears in the search: "
                      + node
                      + " of type "
                      + node.getClass()
                      + " at line "
                      + member.getCorrespondingResource()
                      + ":"
                      + cuNode.getLineNumber(node
                          .getStartPosition()));
            } catch (JavaModelException e) {
              log(e.getMessage(), e);
              return;
            }
View Full Code Here

          return;
        }

        CompilationUnit cu = retrieveCompilationUnit(member
            .getCompilationUnit());
        ASTNode node = ASTNodeSearchUtil.getAstNode(match, cu);

        MethodDeclaration md = null;

        if (node != null) {
          if (node instanceof MethodDeclaration) {
            md = (MethodDeclaration) node;
          } else if (node.getParent() instanceof MethodDeclaration) {
            md = (MethodDeclaration) node.getParent();
          } else {
            try {
              System.err
                  .println("MethodDeclarationsSearchRequestor: Skipping node that appears in the search: "
                      + node
                      + " of type "
                      + node.getClass()
                      + " at line "
                      + member.getCorrespondingResource()
                      + ":"
                      + cu.getLineNumber(node
                          .getStartPosition()));
            } catch (JavaModelException e) {
              log(e.getMessage(), e);
              return;
            }
View Full Code Here

   * </ul>
   */
  public static ASTNode perform(ASTNode root, int start, int length) {
    NodeFinder finder= new NodeFinder(start, length);
    root.accept(finder);
    ASTNode result= finder.getCoveredNode();
    if (result == null || result.getStartPosition() != start || result.getLength() != length) {
      return finder.getCoveringNode();
    }
    return result;
  }
View Full Code Here

        }
      }
    });
   
    // found the relevant ASTNode
    ASTNode covering = finder.getCoveringNode();
    updateSlice(covering, unit, resource, monitor);   
   
    // restore editor position
    // TODO:
    //fEditor.setHighlightRange(textSelection.getOffset(), textSelection.getLength(), true);
View Full Code Here

        doBackwardPropagationAction = new Action() {
            public void run() {
                LapseView lapseView = LapsePlugin.getDefault().getLapseView();
                if (lapseView != null) {
                    ViewMatch match = ((ViewMatch) ((IStructuredSelection) viewer.getSelection()).getFirstElement());
                    ASTNode astNode = match.getAST();
                    SlicingFromSinkJob job = lapseView.getSinkSlicingJob();
                    if(job != null) {
                        ASTNode arg = null;
                        if (astNode instanceof MethodInvocation) {
                            arg = (ASTNode) ((MethodInvocation) astNode).arguments().get(0);
                        } else if(astNode instanceof ClassInstanceCreation)
                        {
                          arg=(ASTNode)((ClassInstanceCreation) astNode).arguments().get(0);
View Full Code Here

      log("Requesting final status for " + name);
      return finalMap.get(name) != null;
    }
   
    public VariableDeclaration getVariableDeclaration(SimpleName name) {
      ASTNode node = name;
      do {
        node = node.getParent();
      } while ( node != null && !(node instanceof MethodDeclaration) );
     
      String key = null;
     
      if(node != null) {
        key = node.toString() + "/" + name.getFullyQualifiedName();
      }else {
        key = "GLOBAL" + name.getFullyQualifiedName()
      }
     
      logError("Trying " + key);
View Full Code Here

         
          try {
            if (invokedMethod.getElementName().equals(fromMethod.getElementName())
              && invokedMethod.getSignature().equals(fromMethod.getSignature())){

              ASTNode varDeclarationStmt = node.getParent().getParent();
              if (varDeclarationStmt instanceof VariableDeclarationStatement) {
                VariableDeclarationStatement vds = (VariableDeclarationStatement) varDeclarationStmt;
               
                // change the type
                Type returnType = JDTUtils.createQualifiedType(vds.getAST(), toClass);
                vds.setType(returnType);
              }
             
              ASTNode varDeclarationFragment = node.getParent();
              if (varDeclarationFragment instanceof VariableDeclarationFragment) {
                VariableDeclarationFragment vdf = (VariableDeclarationFragment) varDeclarationFragment;
               
                ClassInstanceCreation newClassInstanceCreation = vdf.getAST().newClassInstanceCreation();
                Type newType = JDTUtils.createQualifiedType(vdf.getAST(), toClass);
View Full Code Here

            if (invokedMethod.getElementName().equals(fromMethod.getElementName())
              && invokedMethod.getSignature().equals(fromMethod.getSignature())){

              Block newBlock = parseCode(code);
             
              ASTNode target = node.getParent();
             
              if (target instanceof VariableDeclarationFragment) {
                target = (Statement) target.getParent();
              }
             
              Block block = getBlock(target);
             
              int index = 0;
             
              for (int i = 0; i < block.statements().size(); i++) {
                if (block.statements().get(i).equals(target)) {
                  index = i;
                  break;
                }
              }
             
              List statements = ASTNode.copySubtrees(node.getAST(), newBlock.statements());
             
              for (int i = statements.size() - 1; i >= 0; i--) {
                block.statements().add(index, statements.get(i));
              }
             
              int expressionIndex = index + statements.size() - 1;
              boolean assignmentAdded = false;
             
              if (node.getParent() instanceof VariableDeclarationFragment) {
                Statement expressionStatement = (Statement) block.statements().get(expressionIndex);
               
                if (expressionStatement instanceof ExpressionStatement) {
                  VariableDeclarationFragment vdf = (VariableDeclarationFragment) node.getParent();
                  Expression expression = (Expression) ASTNode.copySubtree(node.getAST(), ((ExpressionStatement) expressionStatement).getExpression());
                  vdf.setInitializer(expression);
                  block.statements().remove(expressionIndex);
                  assignmentAdded = true;
                }
              }
             
              if (! assignmentAdded) {
                block.statements().remove(expressionIndex + 1);
              }
            }
          } catch (JavaModelException e) {
            e.printStackTrace();
          }

        return true;
      }

      @SuppressWarnings("unchecked")
      private Block getBlock(ASTNode target) {
        ASTNode parent = target.getParent();
        if (parent instanceof Block) {
          return (Block) parent;
        }
       
        Block newBlock = target.getAST().newBlock();
        newBlock.statements().add(ASTNode.copySubtree(target.getAST(), target));
        Field[] declaredFields = parent.getClass().getDeclaredFields();
        for (Field field : declaredFields) {
          if (!(field.getType().isAssignableFrom(Statement.class))) {
            continue;
          }
         
          try {
            field.setAccessible(true);
            if (field.get(parent).equals(target)) {
              String setterName = "set" + field.getName().substring(0, 1).toUpperCase() + field.getName().substring(1);
              Method setter = parent.getClass().getDeclaredMethod(setterName, field.getType());
              if (setter != null) {
                setter.invoke(parent, newBlock);
              }
            }
          } catch (Exception e) {
View Full Code Here

TOP

Related Classes of org.eclipse.jdt.core.dom.ASTNode$NodeList$Cursor

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.