Java 类org.eclipse.jdt.core.dom.ReturnStatement 实例源码

项目:eclipse.jdt.ls    文件:NecessaryParenthesesChecker.java   
private static boolean locationNeedsParentheses(StructuralPropertyDescriptor locationInParent) {
    if (locationInParent instanceof ChildListPropertyDescriptor && locationInParent != InfixExpression.EXTENDED_OPERANDS_PROPERTY) {
        // e.g. argument lists of MethodInvocation, ClassInstanceCreation, dimensions of ArrayCreation ...
        return false;
    }
    if (locationInParent == VariableDeclarationFragment.INITIALIZER_PROPERTY
            || locationInParent == SingleVariableDeclaration.INITIALIZER_PROPERTY
            || locationInParent == ReturnStatement.EXPRESSION_PROPERTY
            || locationInParent == EnhancedForStatement.EXPRESSION_PROPERTY
            || locationInParent == ForStatement.EXPRESSION_PROPERTY
            || locationInParent == WhileStatement.EXPRESSION_PROPERTY
            || locationInParent == DoStatement.EXPRESSION_PROPERTY
            || locationInParent == AssertStatement.EXPRESSION_PROPERTY
            || locationInParent == AssertStatement.MESSAGE_PROPERTY
            || locationInParent == IfStatement.EXPRESSION_PROPERTY
            || locationInParent == SwitchStatement.EXPRESSION_PROPERTY
            || locationInParent == SwitchCase.EXPRESSION_PROPERTY
            || locationInParent == ArrayAccess.INDEX_PROPERTY
            || locationInParent == ThrowStatement.EXPRESSION_PROPERTY
            || locationInParent == SynchronizedStatement.EXPRESSION_PROPERTY
            || locationInParent == ParenthesizedExpression.EXPRESSION_PROPERTY) {
        return false;
    }
    return true;
}
项目:fb-contrib-eclipse-quick-fixes    文件:UnnecessaryStoreResolution.java   
private void findUnnecessaryStore(ReturnStatement node) {
    Block block = TraversalUtil.findClosestAncestor(node, Block.class);
    @SuppressWarnings("unchecked")
    List<Statement> blockStatements = block.statements();
    for (int i = 1; i < blockStatements.size(); i++) {
        Statement statement = blockStatements.get(i);
        if (statement == this.originalReturn) {
            for (int j = i - 1; j >= 0; j--) {
                Statement storeStatement = blockStatements.get(j);
                if (storeStatement instanceof VariableDeclarationStatement) {
                    splitStatementAndInitializer((VariableDeclarationStatement) storeStatement);
                    return;
                } else if (storeStatement instanceof ExpressionStatement) {
                    if (splitStatementAndInitializer((ExpressionStatement) storeStatement)) {
                        // we found our extra storage statement
                        return;
                    }
                }
            }
        }
    }
}
项目:SparkBuilderGenerator    文件:StagedBuilderWithMethodAdderFragment.java   
private Block createWithMethodBody(AST ast, BuilderField builderField) {
    String originalFieldName = builderField.getOriginalFieldName();
    String builderFieldName = builderField.getBuilderFieldName();

    Block newBlock = ast.newBlock();
    ReturnStatement builderReturnStatement = ast.newReturnStatement();
    builderReturnStatement.setExpression(ast.newThisExpression());

    Assignment newAssignment = ast.newAssignment();

    FieldAccess fieldAccess = ast.newFieldAccess();
    fieldAccess.setExpression(ast.newThisExpression());
    fieldAccess.setName(ast.newSimpleName(originalFieldName));
    newAssignment.setLeftHandSide(fieldAccess);
    newAssignment.setRightHandSide(ast.newSimpleName(builderFieldName));

    newBlock.statements().add(ast.newExpressionStatement(newAssignment));
    newBlock.statements().add(builderReturnStatement);
    return newBlock;
}
项目:SparkBuilderGenerator    文件:RegularBuilderWithMethodAdderFragment.java   
private Block createWithMethodBody(AST ast, String originalFieldName, String builderFieldName) {
    Block newBlock = ast.newBlock();
    ReturnStatement builderReturnStatement = ast.newReturnStatement();
    builderReturnStatement.setExpression(ast.newThisExpression());

    Assignment newAssignment = ast.newAssignment();

    FieldAccess fieldAccess = ast.newFieldAccess();
    fieldAccess.setExpression(ast.newThisExpression());
    fieldAccess.setName(ast.newSimpleName(originalFieldName));
    newAssignment.setLeftHandSide(fieldAccess);
    newAssignment.setRightHandSide(ast.newSimpleName(builderFieldName));

    newBlock.statements().add(ast.newExpressionStatement(newAssignment));
    newBlock.statements().add(builderReturnStatement);
    return newBlock;
}
项目:SparkBuilderGenerator    文件:NewBuilderAndWithMethodCallCreationFragment.java   
public Block createReturnBlock(AST ast, TypeDeclaration builderType, String withName, String parameterName) {
    Block builderMethodBlock = ast.newBlock();
    ReturnStatement returnStatement = ast.newReturnStatement();
    ClassInstanceCreation newClassInstanceCreation = ast.newClassInstanceCreation();
    newClassInstanceCreation.setType(ast.newSimpleType(ast.newName(builderType.getName().toString())));

    MethodInvocation withMethodInvocation = ast.newMethodInvocation();
    withMethodInvocation.setExpression(newClassInstanceCreation);
    withMethodInvocation.setName(ast.newSimpleName(withName));
    withMethodInvocation.arguments().add(ast.newSimpleName(parameterName));

    returnStatement.setExpression(withMethodInvocation);
    builderMethodBlock.statements().add(returnStatement);
    return builderMethodBlock;
}
项目:eclipse.jdt.ls    文件:ReturnTypeSubProcessor.java   
public ITypeBinding getTypeBinding(AST ast) {
    boolean couldBeObject= false;
    for (int i= 0; i < fResult.size(); i++) {
        ReturnStatement node= fResult.get(i);
        Expression expr= node.getExpression();
        if (expr != null) {
            ITypeBinding binding= Bindings.normalizeTypeBinding(expr.resolveTypeBinding());
            if (binding != null) {
                return binding;
            } else {
                couldBeObject= true;
            }
        } else {
            return ast.resolveWellKnownType("void"); //$NON-NLS-1$
        }
    }
    if (couldBeObject) {
        return ast.resolveWellKnownType("java.lang.Object"); //$NON-NLS-1$
    }
    return ast.resolveWellKnownType("void"); //$NON-NLS-1$
}
项目:eclipse.jdt.ls    文件:ReturnTypeSubProcessor.java   
public static void addMethodReturnsVoidProposals(IInvocationContext context, IProblemLocation problem, Collection<CUCorrectionProposal> proposals) throws JavaModelException {
    CompilationUnit astRoot= context.getASTRoot();
    ASTNode selectedNode= problem.getCoveringNode(astRoot);
    if (!(selectedNode instanceof ReturnStatement)) {
        return;
    }
    ReturnStatement returnStatement= (ReturnStatement) selectedNode;
    Expression expression= returnStatement.getExpression();
    if (expression == null) {
        return;
    }
    BodyDeclaration decl= ASTResolving.findParentBodyDeclaration(selectedNode);
    if (decl instanceof MethodDeclaration) {
        MethodDeclaration methDecl= (MethodDeclaration) decl;
        Type retType= methDecl.getReturnType2();
        if (retType == null || retType.resolveBinding() == null) {
            return;
        }
        TypeMismatchSubProcessor.addChangeSenderTypeProposals(context, expression, retType.resolveBinding(), false, IProposalRelevance.METHOD_RETURNS_VOID, proposals);
    }
}
项目:che    文件:NecessaryParenthesesChecker.java   
private static boolean locationNeedsParentheses(StructuralPropertyDescriptor locationInParent) {
  if (locationInParent instanceof ChildListPropertyDescriptor
      && locationInParent != InfixExpression.EXTENDED_OPERANDS_PROPERTY) {
    // e.g. argument lists of MethodInvocation, ClassInstanceCreation, dimensions of ArrayCreation
    // ...
    return false;
  }
  if (locationInParent == VariableDeclarationFragment.INITIALIZER_PROPERTY
      || locationInParent == SingleVariableDeclaration.INITIALIZER_PROPERTY
      || locationInParent == ReturnStatement.EXPRESSION_PROPERTY
      || locationInParent == EnhancedForStatement.EXPRESSION_PROPERTY
      || locationInParent == ForStatement.EXPRESSION_PROPERTY
      || locationInParent == WhileStatement.EXPRESSION_PROPERTY
      || locationInParent == DoStatement.EXPRESSION_PROPERTY
      || locationInParent == AssertStatement.EXPRESSION_PROPERTY
      || locationInParent == AssertStatement.MESSAGE_PROPERTY
      || locationInParent == IfStatement.EXPRESSION_PROPERTY
      || locationInParent == SwitchStatement.EXPRESSION_PROPERTY
      || locationInParent == SwitchCase.EXPRESSION_PROPERTY
      || locationInParent == ArrayAccess.INDEX_PROPERTY
      || locationInParent == ThrowStatement.EXPRESSION_PROPERTY
      || locationInParent == SynchronizedStatement.EXPRESSION_PROPERTY
      || locationInParent == ParenthesizedExpression.EXPRESSION_PROPERTY) {
    return false;
  }
  return true;
}
项目:che    文件:InferTypeArgumentsConstraintCreator.java   
@Override
public void endVisit(ReturnStatement node) {
  Expression expression = node.getExpression();
  if (expression == null) return;
  ConstraintVariable2 expressionCv = getConstraintVariable(expression);
  if (expressionCv == null) return;

  MethodDeclaration methodDeclaration =
      (MethodDeclaration) ASTNodes.getParent(node, ASTNode.METHOD_DECLARATION);
  if (methodDeclaration == null) return;
  IMethodBinding methodBinding = methodDeclaration.resolveBinding();
  if (methodBinding == null) return;
  ReturnTypeVariable2 returnTypeCv = fTCModel.makeReturnTypeVariable(methodBinding);
  if (returnTypeCv == null) return;

  fTCModel.createElementEqualsConstraints(returnTypeCv, expressionCv);
}
项目:che    文件:ReturnTypeSubProcessor.java   
public ITypeBinding getTypeBinding(AST ast) {
  boolean couldBeObject = false;
  for (int i = 0; i < fResult.size(); i++) {
    ReturnStatement node = fResult.get(i);
    Expression expr = node.getExpression();
    if (expr != null) {
      ITypeBinding binding = Bindings.normalizeTypeBinding(expr.resolveTypeBinding());
      if (binding != null) {
        return binding;
      } else {
        couldBeObject = true;
      }
    } else {
      return ast.resolveWellKnownType("void"); // $NON-NLS-1$
    }
  }
  if (couldBeObject) {
    return ast.resolveWellKnownType("java.lang.Object"); // $NON-NLS-1$
  }
  return ast.resolveWellKnownType("void"); // $NON-NLS-1$
}
项目:evosuite    文件:TestExtractingVisitor.java   
/** {@inheritDoc} */
@Override
public void endVisit(ReturnStatement returnStatement) {
    VariableReference returnValue = null;
    if (returnStatement.getExpression() == null) {
        logger.warn("Since we do not represent control structures, we ignore explicit empty return statements ('return;').");
        return;
    }
    if (returnStatement.getExpression() instanceof MethodInvocation) {
        returnValue = testCase.getLastStatement().getReturnValue();
    } else {
        returnValue = retrieveVariableReference(returnStatement.getExpression(), null);
    }
    returnValue.setOriginalCode(returnStatement.toString());
    ReturnStatementPlaceholder returnStmt = new ReturnStatementPlaceholder(
            testCase.getReference(), returnValue);
    testCase.addStatement(returnStmt);
}
项目:Convert-For-Each-Loop-to-Lambda-Expression-Eclipse-Plugin    文件:EnhancedForStatementVisitor.java   
/**
 * checking if returnStatement is boolean, not null and has only one return
 * 
 * @see org.eclipse.jdt.core.dom.ASTVisitor#visit(org.eclipse.jdt.core.dom.ReturnStatement)
 */
@Override
public boolean visit(ReturnStatement node) {
    // one more return statement encountered.
    returnCount++;

    // examine what is being returned.
    ASTNode expression = node.getExpression();

    // if there is a return statement, it must return a boolean literal.
    if (expression == null || !(expression instanceof BooleanLiteral)) {
        this.encounteredInvalidReturnStatement = true;
    }

    return super.visit(node);
}
项目:Eclipse-Postfix-Code-Completion    文件:SuperTypeConstraintsCreator.java   
@Override
public final void endVisit(final ReturnStatement node) {
    final Expression expression= node.getExpression();
    if (expression != null) {
        final ConstraintVariable2 descendant= (ConstraintVariable2) expression.getProperty(PROPERTY_CONSTRAINT_VARIABLE);
        if (descendant != null) {
            final MethodDeclaration declaration= fCurrentMethods.peek();
            if (declaration != null) {
                final IMethodBinding binding= declaration.resolveBinding();
                if (binding != null) {
                    final ConstraintVariable2 ancestor= fModel.createReturnTypeVariable(binding);
                    if (ancestor != null) {
                        node.setProperty(PROPERTY_CONSTRAINT_VARIABLE, ancestor);
                        fModel.createSubtypeConstraint(descendant, ancestor);
                    }
                }
            }
        }
    }
}
项目:Eclipse-Postfix-Code-Completion    文件:InferTypeArgumentsConstraintCreator.java   
@Override
public void endVisit(ReturnStatement node) {
    Expression expression= node.getExpression();
    if (expression == null)
        return;
    ConstraintVariable2 expressionCv= getConstraintVariable(expression);
    if (expressionCv == null)
        return;

    MethodDeclaration methodDeclaration= (MethodDeclaration) ASTNodes.getParent(node, ASTNode.METHOD_DECLARATION);
    if (methodDeclaration == null)
        return;
    IMethodBinding methodBinding= methodDeclaration.resolveBinding();
    if (methodBinding == null)
        return;
    ReturnTypeVariable2 returnTypeCv= fTCModel.makeReturnTypeVariable(methodBinding);
    if (returnTypeCv == null)
        return;

    fTCModel.createElementEqualsConstraints(returnTypeCv, expressionCv);
}
项目:Eclipse-Postfix-Code-Completion    文件:NecessaryParenthesesChecker.java   
private static boolean locationNeedsParentheses(StructuralPropertyDescriptor locationInParent) {
    if (locationInParent instanceof ChildListPropertyDescriptor && locationInParent != InfixExpression.EXTENDED_OPERANDS_PROPERTY) {
        // e.g. argument lists of MethodInvocation, ClassInstanceCreation, dimensions of ArrayCreation ...
        return false;
    }
    if (locationInParent == VariableDeclarationFragment.INITIALIZER_PROPERTY
            || locationInParent == SingleVariableDeclaration.INITIALIZER_PROPERTY
            || locationInParent == ReturnStatement.EXPRESSION_PROPERTY
            || locationInParent == EnhancedForStatement.EXPRESSION_PROPERTY
            || locationInParent == ForStatement.EXPRESSION_PROPERTY
            || locationInParent == WhileStatement.EXPRESSION_PROPERTY
            || locationInParent == DoStatement.EXPRESSION_PROPERTY
            || locationInParent == AssertStatement.EXPRESSION_PROPERTY
            || locationInParent == AssertStatement.MESSAGE_PROPERTY
            || locationInParent == IfStatement.EXPRESSION_PROPERTY
            || locationInParent == SwitchStatement.EXPRESSION_PROPERTY
            || locationInParent == SwitchCase.EXPRESSION_PROPERTY
            || locationInParent == ArrayAccess.INDEX_PROPERTY
            || locationInParent == ThrowStatement.EXPRESSION_PROPERTY
            || locationInParent == SynchronizedStatement.EXPRESSION_PROPERTY
            || locationInParent == ParenthesizedExpression.EXPRESSION_PROPERTY) {
        return false;
    }
    return true;
}
项目:Eclipse-Postfix-Code-Completion    文件:StringFormatGenerator.java   
@Override
protected void complete() throws CoreException {
    super.complete();
    ReturnStatement rStatement= fAst.newReturnStatement();
    String formatClass;
    if (getContext().is50orHigher())
        formatClass= "java.lang.String"; //$NON-NLS-1$
    else
        formatClass= "java.text.MessageFormat"; //$NON-NLS-1$
    MethodInvocation formatInvocation= createMethodInvocation(addImport(formatClass), "format", null); //$NON-NLS-1$ 
    StringLiteral literal= fAst.newStringLiteral();
    literal.setLiteralValue(buffer.toString());
    formatInvocation.arguments().add(literal);
    if (getContext().is50orHigher()) {
        formatInvocation.arguments().addAll(arguments);
    } else {
        ArrayCreation arrayCreation= fAst.newArrayCreation();
        arrayCreation.setType(fAst.newArrayType(fAst.newSimpleType(addImport("java.lang.Object")))); //$NON-NLS-1$
        ArrayInitializer initializer= fAst.newArrayInitializer();
        arrayCreation.setInitializer(initializer);
        initializer.expressions().addAll(arguments);
        formatInvocation.arguments().add(arrayCreation);
    }
    rStatement.setExpression(formatInvocation);
    toStringMethod.getBody().statements().add(rStatement);
}
项目:Eclipse-Postfix-Code-Completion    文件:GenerateHashCodeEqualsOperation.java   
private MethodDeclaration createGetOuterHelper() {
    String outerTypeName= fType.getDeclaringClass().getTypeDeclaration().getName();

    MethodDeclaration helperMethod= fAst.newMethodDeclaration();
    helperMethod.modifiers().addAll(ASTNodeFactory.newModifiers(fAst, Modifier.PRIVATE));
    helperMethod.setName(fAst.newSimpleName(METHODNAME_OUTER_TYPE));
    helperMethod.setConstructor(false);
    helperMethod.setReturnType2(fAst.newSimpleType(fAst.newSimpleName(outerTypeName)));

    Block body= fAst.newBlock();
    helperMethod.setBody(body);

    ThisExpression thisExpression= fAst.newThisExpression();
    thisExpression.setQualifier(fAst.newSimpleName(outerTypeName));

    ReturnStatement endReturn= fAst.newReturnStatement();
    endReturn.setExpression(thisExpression);
    body.statements().add(endReturn);

    return helperMethod;
}
项目:Eclipse-Postfix-Code-Completion    文件:MethodExitsFinder.java   
/**
 * @param root the AST root
 * @param node the selected node
 * @return returns a message if there is a problem
 */
public String initialize(CompilationUnit root, ASTNode node) {
    fASTRoot= root;

    if (node instanceof ReturnStatement) {
        fMethodDeclaration= ASTResolving.findParentMethodDeclaration(node);
        if (fMethodDeclaration == null)
            return SearchMessages.MethodExitsFinder_no_return_type_selected;
        return null;

    }

    Type type= ASTNodes.getTopMostType(node);
    if (type == null)
        return SearchMessages.MethodExitsFinder_no_return_type_selected;
    if (type.getLocationInParent() != MethodDeclaration.RETURN_TYPE2_PROPERTY)
        return SearchMessages.MethodExitsFinder_no_return_type_selected;
    fMethodDeclaration= (MethodDeclaration)type.getParent();

    fExitDescription= Messages.format(SearchMessages.MethodExitsFinder_occurrence_exit_description, BasicElementLabels.getJavaElementName(fMethodDeclaration.getName().toString()));
    return null;
}
项目:Eclipse-Postfix-Code-Completion    文件:ReturnTypeSubProcessor.java   
public ITypeBinding getTypeBinding(AST ast) {
    boolean couldBeObject= false;
    for (int i= 0; i < fResult.size(); i++) {
        ReturnStatement node= fResult.get(i);
        Expression expr= node.getExpression();
        if (expr != null) {
            ITypeBinding binding= Bindings.normalizeTypeBinding(expr.resolveTypeBinding());
            if (binding != null) {
                return binding;
            } else {
                couldBeObject= true;
            }
        } else {
            return ast.resolveWellKnownType("void"); //$NON-NLS-1$
        }
    }
    if (couldBeObject) {
        return ast.resolveWellKnownType("java.lang.Object"); //$NON-NLS-1$
    }
    return ast.resolveWellKnownType("void"); //$NON-NLS-1$
}
项目:Eclipse-Postfix-Code-Completion    文件:ReturnTypeSubProcessor.java   
public static void addMethodRetunsVoidProposals(IInvocationContext context, IProblemLocation problem, Collection<ICommandAccess> proposals) throws JavaModelException {
    CompilationUnit astRoot= context.getASTRoot();
    ASTNode selectedNode= problem.getCoveringNode(astRoot);
    if (!(selectedNode instanceof ReturnStatement)) {
        return;
    }
    ReturnStatement returnStatement= (ReturnStatement) selectedNode;
    Expression expression= returnStatement.getExpression();
    if (expression == null) {
        return;
    }
    BodyDeclaration decl= ASTResolving.findParentBodyDeclaration(selectedNode);
    if (decl instanceof MethodDeclaration) {
        MethodDeclaration methDecl= (MethodDeclaration) decl;
        Type retType= methDecl.getReturnType2();
        if (retType == null || retType.resolveBinding() == null) {
            return;
        }
        TypeMismatchSubProcessor.addChangeSenderTypeProposals(context, expression, retType.resolveBinding(), false, IProposalRelevance.METHOD_RETURNS_VOID, proposals);
    }
}
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:NecessaryParenthesesChecker.java   
private static boolean locationNeedsParentheses(StructuralPropertyDescriptor locationInParent) {
    if (locationInParent instanceof ChildListPropertyDescriptor && locationInParent != InfixExpression.EXTENDED_OPERANDS_PROPERTY) {
        // e.g. argument lists of MethodInvocation, ClassInstanceCreation, dimensions of ArrayCreation ...
        return false;
    }
    if (locationInParent == VariableDeclarationFragment.INITIALIZER_PROPERTY
            || locationInParent == SingleVariableDeclaration.INITIALIZER_PROPERTY
            || locationInParent == ReturnStatement.EXPRESSION_PROPERTY
            || locationInParent == EnhancedForStatement.EXPRESSION_PROPERTY
            || locationInParent == ForStatement.EXPRESSION_PROPERTY
            || locationInParent == WhileStatement.EXPRESSION_PROPERTY
            || locationInParent == DoStatement.EXPRESSION_PROPERTY
            || locationInParent == AssertStatement.EXPRESSION_PROPERTY
            || locationInParent == AssertStatement.MESSAGE_PROPERTY
            || locationInParent == IfStatement.EXPRESSION_PROPERTY
            || locationInParent == SwitchStatement.EXPRESSION_PROPERTY
            || locationInParent == SwitchCase.EXPRESSION_PROPERTY
            || locationInParent == ArrayAccess.INDEX_PROPERTY
            || locationInParent == ThrowStatement.EXPRESSION_PROPERTY
            || locationInParent == SynchronizedStatement.EXPRESSION_PROPERTY
            || locationInParent == ParenthesizedExpression.EXPRESSION_PROPERTY) {
        return false;
    }
    return true;
}
项目:codemodify    文件:LambdaConverterFix.java   
private ASTNode prepareLambdaBody(Block body, List<Statement> statements) {
    ASTNode lambdaBody = body;
    if (statements.size() == 1) {
        // use short form with just an expression body if possible
        Statement statement = statements.get(0);
        if (statement instanceof ExpressionStatement) {
            lambdaBody = ((ExpressionStatement) statement).getExpression();
        } else if (statement instanceof ReturnStatement) {
            Expression returnExpression = ((ReturnStatement) statement).getExpression();
            if (returnExpression != null) {
                lambdaBody = returnExpression;
            }
        }
    }
    return lambdaBody;
}
项目:ChangeScribe    文件:MethodAnalyzer.java   
public boolean visit(final SimpleName node) {
    final IVariableBinding field = this.getLocalField((Expression)node);
    MethodAnalyzer.this.checkNonFinalStaticFieldUse(field);
    if (field != null) {
        if (this.inAssignmentRightSide > 0 && this.assignedVariableIndex != -1) {
            MethodAnalyzer.this.variables.get(this.assignedVariableIndex).addAssignedField(field);
            return super.visit(node);
        }
        if (this.inAssignmentRightSide > 0 && this.assignedParameterIndex != -1 && !MethodAnalyzer.this.parameters.get(this.assignedParameterIndex).getVariableBinding().getType().isPrimitive()) {
            MethodAnalyzer.this.parameters.get(this.assignedParameterIndex).addAssignedField(field);
            MethodAnalyzer.this.voidAccessorFields.add(field);
            super.visit(node);
        }
        if (this.inReturn > 0 && !(node.getParent() instanceof ReturnStatement) && this.inMethodArguments == 0) {
            MethodAnalyzer.this.propertyFields.add((IVariableBinding)node.resolveBinding());
            return super.visit(node);
        }
    }
    if (node.resolveBinding() instanceof ITypeBinding) {
        final ITypeBinding typeBinding = (ITypeBinding)node.resolveBinding();
        if (!typeBinding.isPrimitive() && !typeBinding.isParameterizedType()) {
            this.addUsedType(typeBinding);
        }
    }
    return super.visit(node);
}
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:SuperTypeConstraintsCreator.java   
@Override
public final void endVisit(final ReturnStatement node) {
    final Expression expression= node.getExpression();
    if (expression != null) {
        final ConstraintVariable2 descendant= (ConstraintVariable2) expression.getProperty(PROPERTY_CONSTRAINT_VARIABLE);
        if (descendant != null) {
            final MethodDeclaration declaration= fCurrentMethods.peek();
            if (declaration != null) {
                final IMethodBinding binding= declaration.resolveBinding();
                if (binding != null) {
                    final ConstraintVariable2 ancestor= fModel.createReturnTypeVariable(binding);
                    if (ancestor != null) {
                        node.setProperty(PROPERTY_CONSTRAINT_VARIABLE, ancestor);
                        fModel.createSubtypeConstraint(descendant, ancestor);
                    }
                }
            }
        }
    }
}
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:InferTypeArgumentsConstraintCreator.java   
@Override
public void endVisit(ReturnStatement node) {
    Expression expression= node.getExpression();
    if (expression == null)
        return;
    ConstraintVariable2 expressionCv= getConstraintVariable(expression);
    if (expressionCv == null)
        return;

    MethodDeclaration methodDeclaration= (MethodDeclaration) ASTNodes.getParent(node, ASTNode.METHOD_DECLARATION);
    if (methodDeclaration == null)
        return;
    IMethodBinding methodBinding= methodDeclaration.resolveBinding();
    if (methodBinding == null)
        return;
    ReturnTypeVariable2 returnTypeCv= fTCModel.makeReturnTypeVariable(methodBinding);
    if (returnTypeCv == null)
        return;

    fTCModel.createElementEqualsConstraints(returnTypeCv, expressionCv);
}
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:ReturnTypeSubProcessor.java   
public ITypeBinding getTypeBinding(AST ast) {
    boolean couldBeObject= false;
    for (int i= 0; i < fResult.size(); i++) {
        ReturnStatement node= fResult.get(i);
        Expression expr= node.getExpression();
        if (expr != null) {
            ITypeBinding binding= Bindings.normalizeTypeBinding(expr.resolveTypeBinding());
            if (binding != null) {
                return binding;
            } else {
                couldBeObject= true;
            }
        } else {
            return ast.resolveWellKnownType("void"); //$NON-NLS-1$
        }
    }
    if (couldBeObject) {
        return ast.resolveWellKnownType("java.lang.Object"); //$NON-NLS-1$
    }
    return ast.resolveWellKnownType("void"); //$NON-NLS-1$
}
项目:fb-contrib-eclipse-quick-fixes    文件:UnnecessaryStoreResolution.java   
private ReturnStatement makeNewReturnStatement(ASTRewrite rewrite, USBRVisitor visitor) {
    AST ast = rewrite.getAST();
    ReturnStatement retVal = ast.newReturnStatement();
    Expression baseExpression = (Expression) rewrite.createCopyTarget(visitor.unnecessaryStoreExpression);

    Operator assignOperator = visitor.unnecessaryStoreOperator;

    if (assignOperator != null && assignOperator != Operator.ASSIGN) {
        InfixExpression infixExpression = ast.newInfixExpression();
        infixExpression.setLeftOperand((Expression) rewrite.createCopyTarget(visitor.storedVariable));
        infixExpression.setRightOperand(baseExpression);
        infixExpression.setOperator(convertAssignOperatorToInfixOperator(assignOperator));
        baseExpression = infixExpression;
    }

    retVal.setExpression(baseExpression);
    return retVal;
}
项目:SparkBuilderGenerator    文件:BuildMethodBodyCreatorFragment.java   
public Block createBody(AST ast, TypeDeclaration originalType) {
    ClassInstanceCreation newClassInstanceCreation = ast.newClassInstanceCreation();
    newClassInstanceCreation.setType(ast.newSimpleType(ast.newName(originalType.getName().toString())));
    newClassInstanceCreation.arguments().add(ast.newThisExpression());

    ReturnStatement statement = ast.newReturnStatement();
    statement.setExpression(newClassInstanceCreation);

    Block block = ast.newBlock();
    block.statements().add(statement);
    return block;
}
项目:SparkBuilderGenerator    文件:BlockWithNewBuilderCreationFragment.java   
public Block createReturnBlock(AST ast, TypeDeclaration builderType) {
    Block builderMethodBlock = ast.newBlock();
    ReturnStatement returnStatement = ast.newReturnStatement();
    ClassInstanceCreation newClassInstanceCreation = ast.newClassInstanceCreation();
    newClassInstanceCreation.setType(ast.newSimpleType(ast.newName(builderType.getName().toString())));
    returnStatement.setExpression(newClassInstanceCreation);
    builderMethodBlock.statements().add(returnStatement);
    return builderMethodBlock;
}
项目:eclipse.jdt.ls    文件:QuickAssistProcessor.java   
private static Block getBlockBodyForLambda(Expression bodyExpr, ITypeBinding returnTypeBinding, AST ast) {
    Statement statementInBlockBody;
    if (ast.resolveWellKnownType("void").isEqualTo(returnTypeBinding)) { //$NON-NLS-1$
        ExpressionStatement expressionStatement = ast.newExpressionStatement(bodyExpr);
        statementInBlockBody = expressionStatement;
    } else {
        ReturnStatement returnStatement = ast.newReturnStatement();
        returnStatement.setExpression(bodyExpr);
        statementInBlockBody = returnStatement;
    }
    Block blockBody = ast.newBlock();
    blockBody.statements().add(statementInBlockBody);
    return blockBody;
}
项目:eclipse.jdt.ls    文件:ReturnFlowInfo.java   
private static int getReturnFlag(ReturnStatement node) {
    Expression expression = node.getExpression();
    if (expression == null || expression.resolveTypeBinding() == node.getAST().resolveWellKnownType("void")) {
        return VOID_RETURN;
    }
    return VALUE_RETURN;
}
项目:eclipse.jdt.ls    文件:FlowAnalyzer.java   
@Override
public void endVisit(ReturnStatement node) {
    if (skipNode(node)) {
        return;
    }

    if (createReturnFlowInfo(node)) {
        ReturnFlowInfo info = createReturn(node);
        setFlowInfo(node, info);
        info.merge(getFlowInfo(node.getExpression()), fFlowContext);
    } else {
        assignFlowInfo(node, node.getExpression());
    }
}
项目:eclipse.jdt.ls    文件:ExtractMethodRefactoring.java   
private ASTNode[] createCallNodes(SnippetFinder.Match duplicate, int modifiers) {
    List<ASTNode> result = new ArrayList<>(2);

    IVariableBinding[] locals = fAnalyzer.getCallerLocals();
    for (int i = 0; i < locals.length; i++) {
        result.add(createDeclaration(locals[i], null));
    }

    MethodInvocation invocation = fAST.newMethodInvocation();
    invocation.setName(fAST.newSimpleName(fMethodName));
    ASTNode typeNode = ASTResolving.findParentType(fAnalyzer.getEnclosingBodyDeclaration());
    RefactoringStatus status = new RefactoringStatus();
    while (fDestination != typeNode) {
        fAnalyzer.checkInput(status, fMethodName, typeNode);
        if (!status.isOK()) {
            SimpleName destinationTypeName = fAST.newSimpleName(ASTNodes.getEnclosingType(fDestination).getName());
            if ((modifiers & Modifier.STATIC) == 0) {
                ThisExpression thisExpression = fAST.newThisExpression();
                thisExpression.setQualifier(destinationTypeName);
                invocation.setExpression(thisExpression);
            } else {
                invocation.setExpression(destinationTypeName);
            }
            break;
        }
        typeNode = typeNode.getParent();
    }

    List<Expression> arguments = invocation.arguments();
    for (int i = 0; i < fParameterInfos.size(); i++) {
        ParameterInfo parameter = fParameterInfos.get(i);
        arguments.add(ASTNodeFactory.newName(fAST, getMappedName(duplicate, parameter)));
    }
    if (fLinkedProposalModel != null) {
        LinkedProposalPositionGroup nameGroup = fLinkedProposalModel.getPositionGroup(KEY_NAME, true);
        nameGroup.addPosition(fRewriter.track(invocation.getName()), false);
    }

    ASTNode call;
    int returnKind = fAnalyzer.getReturnKind();
    switch (returnKind) {
        case ExtractMethodAnalyzer.ACCESS_TO_LOCAL:
            IVariableBinding binding = fAnalyzer.getReturnLocal();
            if (binding != null) {
                VariableDeclarationStatement decl = createDeclaration(getMappedBinding(duplicate, binding), invocation);
                call = decl;
            } else {
                Assignment assignment = fAST.newAssignment();
                assignment.setLeftHandSide(ASTNodeFactory.newName(fAST, getMappedBinding(duplicate, fAnalyzer.getReturnValue()).getName()));
                assignment.setRightHandSide(invocation);
                call = assignment;
            }
            break;
        case ExtractMethodAnalyzer.RETURN_STATEMENT_VALUE:
            ReturnStatement rs = fAST.newReturnStatement();
            rs.setExpression(invocation);
            call = rs;
            break;
        default:
            call = invocation;
    }

    if (call instanceof Expression && !fAnalyzer.isExpressionSelected()) {
        call = fAST.newExpressionStatement((Expression) call);
    }
    result.add(call);

    // We have a void return statement. The code looks like
    // extracted();
    // return;
    if (returnKind == ExtractMethodAnalyzer.RETURN_STATEMENT_VOID && !fAnalyzer.isLastStatementSelected()) {
        result.add(fAST.newReturnStatement());
    }
    return result.toArray(new ASTNode[result.size()]);
}
项目:code    文件:HeuristicOwnedLocalsVisitor.java   
@Override
public boolean visit(MethodDeclaration methodDecl) {

    int modifiers = methodDecl.getModifiers();
    if(Modifier.isPublic(modifiers) && !methodDecl.isConstructor() && !methodDecl.getReturnType2().isPrimitiveType()){
        Block body = methodDecl.getBody();
        if(body!=null){
            List<Statement> statements = body.statements();
            for (Statement stmnt : statements) {
                if(stmnt instanceof ReturnStatement){
                    ReturnStatement retStmnt = (ReturnStatement)stmnt;
                    Expression expression = retStmnt.getExpression();
                    if(expression instanceof SimpleName){
                        SimpleName simpleExpr = (SimpleName)expression;
                        IBinding resolveBinding = simpleExpr.resolveBinding();
                        Variable variable = context.getAllBindingKeyToVariableMap(resolveBinding.getKey());
                        if(variable!=null){
                            context.removeEncapsulatedVariable(variable);
                        }
                    }
                }
            }
        }

    }

    return super.visit(methodDecl);

}
项目:code    文件:ValueFlowTransferFunctions.java   
@Override
public OOGContext transfer(ReturnInstruction instr, OOGContext value) {
    Variable returnedVariable = instr.getReturnedVariable();
    ASTNode node = instr.getNode();
    if (node instanceof ReturnStatement) {
        ReturnStatement rs = (ReturnStatement) node;
        MethodDeclaration md = getMethodDeclaration(rs);
        addToCachedDeclaration(md.resolveBinding(), returnedVariable);
    }
    return super.transfer(instr, value);
}
项目:code    文件:HeuristicOwnedLocalsVisitor.java   
@Override
public boolean visit(MethodDeclaration methodDecl) {

    int modifiers = methodDecl.getModifiers();
    if(Modifier.isPublic(modifiers) && !methodDecl.isConstructor() && !methodDecl.getReturnType2().isPrimitiveType()){
        Block body = methodDecl.getBody();
        if(body!=null){
            List<Statement> statements = body.statements();
            for (Statement stmnt : statements) {
                if(stmnt instanceof ReturnStatement){
                    ReturnStatement retStmnt = (ReturnStatement)stmnt;
                    Expression expression = retStmnt.getExpression();
                    if(expression instanceof SimpleName){
                        SimpleName simpleExpr = (SimpleName)expression;
                        IBinding resolveBinding = simpleExpr.resolveBinding();
                        Variable variable = context.getAllBindingKeyToVariableMap(resolveBinding.getKey());
                        if(variable!=null){
                            context.removeEncapsulatedVariable(variable);
                        }
                    }
                }
            }
        }

    }

    return super.visit(methodDecl);

}
项目:che    文件:DelegateMethodCreator.java   
/**
 * Creates a new return statement for the method invocation.
 *
 * @param invocation the method invocation to create a return statement for
 * @return the corresponding statement
 */
private ReturnStatement createReturnStatement(final MethodInvocation invocation) {
  Assert.isNotNull(invocation);
  final ReturnStatement statement = invocation.getAST().newReturnStatement();
  statement.setExpression(invocation);
  return statement;
}
项目:che    文件:SourceAnalyzer.java   
@Override
public boolean visit(ReturnStatement node) {
  if (node != fLastNode) {
    fInterruptedExecutionFlow = true;
  }
  return true;
}
项目:che    文件:SourceProvider.java   
@Override
public boolean visit(ReturnStatement node) {
  Expression expression = node.getExpression();
  if (!(ASTNodes.isLiteral(expression) || expression instanceof Name)) {
    fMustEvalReturnedExpression = true;
  }
  if (Invocations.isInvocation(expression) || expression instanceof ClassInstanceCreation) {
    fReturnValueNeedsLocalVariable = false;
  }
  fReturnExpressions.add(expression);
  return false;
}
项目:che    文件:SourceProvider.java   
public boolean needsReturnedExpressionParenthesis(
    ASTNode parent, StructuralPropertyDescriptor locationInParent) {
  ASTNode last = getLastStatement();
  if (last instanceof ReturnStatement) {
    return NecessaryParenthesesChecker.needsParentheses(
        ((ReturnStatement) last).getExpression(), parent, locationInParent);
  }
  return false;
}