Package org.eclipse.jdt.core.dom

Examples of org.eclipse.jdt.core.dom.VariableDeclaration


      } else if (node instanceof Type) {
        return resolveBinding(((Type) node).resolveBinding());
      } else if (node instanceof TypeParameter) {
        return resolveBinding(((TypeParameter) node).resolveBinding());
      } else if (node instanceof VariableDeclaration) {
      VariableDeclaration n = (VariableDeclaration) node;
        ISourceLocation result = resolveBinding(n.resolveBinding());
        // Have to move towards parent to make the binding unique
        if (result.getScheme() == "unresolved") {
          result = resolveBinding(n.getParent(), n);
        }
        return result;
      } else if (node instanceof ConstructorInvocation) {
        return resolveBinding(((ConstructorInvocation) node).resolveConstructorBinding());
      } else if (node instanceof SuperConstructorInvocation) {
View Full Code Here


   
    TACInstruction decl, init;
    for(int i = 0; i < 4; i++) {
      VariableDeclarationStatement s = (VariableDeclarationStatement) stmts.get(i);
      Assert.assertTrue("Statement: " + s, s.fragments().size() == 1);
      VariableDeclaration d = (VariableDeclaration) s.fragments().get(0);
      decl = tac.instruction(d);
      Assert.assertNotNull("Statement: " + s, decl);
      Assert.assertNotNull("Statement: " + s, d.getInitializer());
      if(d.getInitializer() instanceof ParenthesizedExpression)
        init = tac.instruction(((ParenthesizedExpression) d.getInitializer()).getExpression());
      else
        init = tac.instruction(d.getInitializer());
      Assert.assertNotNull("Statement: " + s, init);
     
      Assert.assertTrue("Statement: " + s, init instanceof AssignmentInstruction);
      Variable t = ((AssignmentInstruction) init).getTarget();
     
      Variable declared = null;
//      if(decl instanceof SourceVariableDeclaration) {
//        declared = ((SourceVariableDeclaration) decl).getDeclaredVariable();
//        Assert.assertEquals("Statement: " + s, declared, t);
//      }
//      else
      if(decl instanceof EclipseInstructionSequence) {
        TACInstruction[] seq = ((EclipseInstructionSequence) decl).getInstructions();
        Assert.assertTrue("Statement: " + s, seq.length == 2);
        Assert.assertTrue("Statement: " + s, seq[0] instanceof SourceVariableDeclaration);
        declared = ((SourceVariableDeclaration) seq[0]).getDeclaredVariable();
        Assert.assertTrue("Statement: " + s, seq[1] instanceof CopyInstruction);
        Assert.assertEquals("Statement: " + s, declared, ((CopyInstruction) seq[1]).getTarget());
        Assert.assertEquals("Statement: " + s, t, ((CopyInstruction) seq[1]).getOperand());
      }
      else
        Assert.fail("Statement has unexpected translation: " + s);
     
      Assert.assertEquals("Statement: " + s, tac.sourceVariable(d.resolveBinding()), declared);
    }
   
  }
View Full Code Here

          }
          if (AstNodeUtils.isVariable(argument)) {
            ASTNode lastAssignment =
                ExecutionFlowUtils.getLastAssignment(flowDescription, argument);
            if (lastAssignment instanceof VariableDeclaration) {
              VariableDeclaration variableDeclaration = (VariableDeclaration) lastAssignment;
              argument = variableDeclaration.getInitializer();
              continue;
            }
          }
          if (ensure) {
            return (ClassInstanceCreation) getEditor().replaceExpression(
View Full Code Here

            }
            return true;
        } else if (arg instanceof SimpleName) {
            SimpleName name = (SimpleName) arg;
            // System.err.println("TODO -> Name: " + name);
            VariableDeclaration varDecl = LapseView.name2decl(name, unit, resource);
            if (varDecl instanceof SingleVariableDeclaration) {
                SingleVariableDeclaration decl = (SingleVariableDeclaration) varDecl;
                if (decl.getInitializer() != null && decl.getInitializer() instanceof StringLiteral) {
                    StringLiteral l = (StringLiteral) decl.getInitializer();
                    return true;
View Full Code Here

  }

  static VariableDeclaration name2decl(SimpleName sn, CompilationUnit cu, IResource resource){
    DeclarationInfoManager.DeclarationInfo info = DeclarationInfoManager.retrieveDeclarationInfo(cu);
    //System.out.println(info);
    VariableDeclaration decl = info.getVariableDeclaration(sn);
    if(decl == null) {
      logError("decl == null for " + sn)
    }
    return decl;
  }
View Full Code Here

   
  private void processDecl(SimpleName name, CompilationUnit cu, IResource resource,
      HistoryDefinitionLocation parent, LinkedList<MethodInvocation> stack,
      IProgressMonitor monitor)
  {   
    VariableDeclaration decl = name2decl(name, cu, resource);
//    if(TRACE) System.out.print('.');
    if(monitor.isCanceled()) {
      // check if the search has been cancelled
      return;
    }
    //monitor.setTaskName("Processing " + name + " in " + resource.getName/*getFullPath*/());
    monitor.subTask("Processing " + name + " in " + resource.getName/*getFullPath*/());
       
    if(decl == null) {
      logError(
          "decl: " + decl + " on line " + (decl == null ? DefinitionLocation.INVALID_SOURCE_LINE : fRoot.getLineNumber(decl.getStartPosition())) +
          " and name: " + name + "(" + name.hashCode() + ") on line " + fRoot.getLineNumber(name.getStartPosition()));
     
      // the case of no declaration found -- add a question mark
      /*HistoryDefinitionLocation dl = */new HistoryDefinitionLocation(
          name.toString(),
          null,  // this will be ignored
          DefinitionLocation.INVALID_SOURCE_LINE,
          name, parent, HistoryDefinitionLocation.UNDEFINED);
      //System.out.println("Case 1");
    } else
    if(decl.getParent() instanceof MethodDeclaration){
      // the case of a parameter -- add the actuals and recurse
      //showMessage(decl.toString() + " is a parameter of " + parent.getClass());
      MethodDeclaration methodDecl = (MethodDeclaration) decl.getParent();
      IMethod method = new MethodFinder((IFile) resource).convertMethodDecl2IMethod(methodDecl);
      if(method == null) {
        JavaPlugin.logErrorMessage("Internal error: No method found for " + methodDecl);
        return;
      }

      HistoryDefinitionLocation paramDL = new HistoryDefinitionLocation(
          decl.toString(),
          resource,
          cu.getLineNumber(decl.getStartPosition()),
          decl, parent, HistoryDefinitionLocation.FORMAL_PARAMETER);
      if(!registerExpansion(paramDL)) {
        // recursion detected here
        return;
      }

      Expression onlyCall = (Expression) (stack.isEmpty() ? null : stack.getLast());
      log("Looking for calls from " + onlyCall);
      Collection/*<ExpressionUnitPair>*/ c = CallerFinder.getActualsForFormal(method, name, onlyCall, monitor, null);
      if(c.isEmpty()){
        logError(
            "No suitable actual arguments for formal argument " +
            name + " of " + method.getElementName() + " at " +
            resource.getName() + " found");
      } else
      for (Iterator iter = c.iterator(); iter.hasNext();) {
        Utils.ExpressionUnitPair eup = (Utils.ExpressionUnitPair) iter.next();
        Expression     e        = eup.getExpression();
        CompilationUnit nextCU     = eup.getCompilationUnit();
        IResource     nextResource = eup.getResource();
               
        processExpression(paramDL, e, nextCU, nextResource, stack, monitor, HistoryDefinitionLocation.CALL_ARG,false);
      }
      //System.out.println("Case 2");
    } else {
      /**
       * The case of a declaration -- look at the right hand side.
       * */
      Object obj = (decl.getParent() instanceof VariableDeclaration) ?
          decl.getParent() :
          decl;         
      String desc = obj.toString();
      int type = (decl.getParent() instanceof FieldDeclaration) ?
            HistoryDefinitionLocation.FIELD :
            HistoryDefinitionLocation.DECLARATION;
      // the case of a regilar declaration being found
      HistoryDefinitionLocation dl = new HistoryDefinitionLocation(
          desc,
          resource,
          cu.getLineNumber(decl.getStartPosition()),
          decl, parent, type);
      Expression e = decl.getInitializer();
     
      if(e != null) {
        // TODO: add processing of the RHS of the declaration
        processExpression(dl, e, cu, resource, stack, monitor, HistoryDefinitionLocation.COPY,false);
      }
View Full Code Here

            }
            return true;
        } else if (arg instanceof SimpleName) {
            SimpleName name = (SimpleName) arg;
            // System.err.println("TODO -> Name: " + name);
            VariableDeclaration varDecl = LapseView.name2decl(name, unit, resource);
            if (varDecl instanceof SingleVariableDeclaration) {
                SingleVariableDeclaration decl = (SingleVariableDeclaration) varDecl;
                if (decl.getInitializer() != null && decl.getInitializer() instanceof StringLiteral) {
                    StringLiteral l = (StringLiteral) decl.getInitializer();
                    return true;
View Full Code Here

      }else {
        key = "GLOBAL" + name.getFullyQualifiedName()
      }
     
      logError("Trying " + key);
      VariableDeclaration var = getVariableDeclaration(key);
      if(var == null && node != null) {
        key = "GLOBAL" + name.getFullyQualifiedName();
        log("Trying " + key);
        var = getVariableDeclaration(key);
      }
View Full Code Here

      List<VariableDeclaration> astParameters = ((MethodDeclaration) methods.get(0).getInternal()).parameters();

      method.parameters().clear();
      for (VariableDeclaration declaration : astParameters)
      {
         VariableDeclaration copy = (VariableDeclaration) ASTNode.copySubtree(method.getAST(), declaration);
         method.parameters().add(copy);
      }

      return this;
   }
View Full Code Here

      List<VariableDeclaration> astParameters = ((MethodDeclaration) methods.get(0).getInternal()).parameters();

      method.parameters().clear();
      for (VariableDeclaration declaration : astParameters)
      {
         VariableDeclaration copy = (VariableDeclaration) ASTNode.copySubtree(method.getAST(), declaration);
         method.parameters().add(copy);
      }

      return this;
   }
View Full Code Here

TOP

Related Classes of org.eclipse.jdt.core.dom.VariableDeclaration

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.