List of usage examples for org.eclipse.jdt.core.dom ReturnStatement getExpression
public Expression getExpression()
null
if there is none. From source file:at.bestsolution.fxide.jdt.corext.dom.ASTFlattener.java
License:Open Source License
@Override public boolean visit(ReturnStatement node) { this.fBuffer.append("return");//$NON-NLS-1$ if (node.getExpression() != null) { this.fBuffer.append(" ");//$NON-NLS-1$ node.getExpression().accept(this); }// www . ja va2s . c o m this.fBuffer.append(";");//$NON-NLS-1$ return false; }
From source file:boa.datagen.util.Java7Visitor.java
License:Apache License
@Override public boolean visit(ReturnStatement node) { boa.types.Ast.Statement.Builder b = boa.types.Ast.Statement.newBuilder(); // b.setPosition(pos.build()); List<boa.types.Ast.Statement> list = statements.peek(); b.setKind(boa.types.Ast.Statement.StatementKind.RETURN); if (node.getExpression() != null) { node.getExpression().accept(this); b.setExpression(expressions.pop()); }/*www . j av a2 s . c o m*/ list.add(b.build()); return false; }
From source file:ca.mcgill.cs.swevo.ppa.inference.ReturnInferenceStrategy.java
License:Open Source License
public void inferTypes(ASTNode node) { ReturnStatement returnStmt = (ReturnStatement) node; Expression exp = returnStmt.getExpression(); if (exp == null || !indexer.isIndexable(exp) || indexer.isSafe(exp)) { return;//from w w w. j a v a 2s. c o m } MethodDeclaration mDeclaration = (MethodDeclaration) PPAASTUtil.getSpecificParentType(returnStmt, ASTNode.METHOD_DECLARATION); if (mDeclaration != null) { IMethodBinding methodBinding = mDeclaration.resolveBinding(); if (methodBinding != null) { ITypeBinding newBinding = methodBinding.getReturnType(); ITypeBinding oldBinding = exp.resolveTypeBinding(); TypeFact typeFact = new TypeFact(indexer.getMainIndex(exp), oldBinding, TypeFact.UNKNOWN, newBinding, TypeFact.SUBTYPE, TypeFact.RETURN_STRATEGY); ppaEngine.reportTypeFact(typeFact); } } }
From source file:ca.mcgill.cs.swevo.ppa.inference.ReturnInferenceStrategy.java
License:Open Source License
public boolean isSafe(ASTNode node) { ReturnStatement returnStmt = (ReturnStatement) node; Expression exp = returnStmt.getExpression(); return exp == null || !indexer.isIndexable(exp) || indexer.isSafe(exp); }
From source file:cc.kave.eclipse.commons.analysis.transformer.BodyVisitor.java
License:Apache License
@Override public boolean visit(ReturnStatement stmt) { if (isTargetMatch(stmt, CompletionCase.EmptyCompletionBefore)) { body.add(getEmptyCompletionExpression()); }//from www . j ava2s .c om cc.kave.commons.model.ssts.impl.statements.ReturnStatement returnStmt = new cc.kave.commons.model.ssts.impl.statements.ReturnStatement(); if (stmt.getExpression() == null) { returnStmt.setIsVoid(true); body.add(returnStmt); } else { ISimpleExpression simpleExpression = exprVisitor.toSimpleExpression(stmt.getExpression(), body); if (simpleExpression == null) { returnStmt.setExpression(simpleExpression); } else { returnStmt.setExpression(new UnknownExpression()); } body.add(returnStmt); } if (isTargetMatch(stmt, CompletionCase.EmptyCompletionAfter)) { body.add(getEmptyCompletionExpression()); } return super.visit(stmt); }
From source file:ch.acanda.eclipse.pmd.java.resolution.sunsecure.MethodReturnsInternalArrayQuickFix.java
License:Open Source License
@Override protected boolean apply(final ReturnStatement node) { final Expression expression = node.getExpression(); final AST ast = expression.getAST(); final MethodInvocation replacement = create(ast, MethodInvocation.class); replacement.setExpression(copy(expression)); final SimpleName name = create(ast, SimpleName.class); name.setIdentifier("clone"); replacement.setName(name);/*from w ww.j a v a2 s. c o m*/ return replace(expression, replacement); }
From source file:chibi.gumtreediff.gen.jdt.cd.CdJdtVisitor.java
License:Open Source License
@Override public boolean visit(ReturnStatement node) { pushNode(node, node.getExpression() != null ? node.getExpression().toString() : ""); return false; }
From source file:coloredide.utils.CopiedNaiveASTFlattener.java
License:Open Source License
public boolean visit(ReturnStatement node) { printIndent();/*w w w . j av a2 s . co m*/ this.buffer.append("return");//$NON-NLS-1$ if (node.getExpression() != null) { this.buffer.append(" ");//$NON-NLS-1$ node.getExpression().accept(this); } this.buffer.append(";\n");//$NON-NLS-1$ return false; }
From source file:com.bsiag.eclipse.jdt.java.formatter.SpacePreparator.java
License:Open Source License
@Override public boolean visit(ReturnStatement node) { if (node.getExpression() != null) { int returnTokenIndex = this.tm.firstIndexIn(node, TokenNamereturn); if (!(node.getExpression() instanceof ParenthesizedExpression) || this.options.insert_space_before_parenthesized_expression_in_return) { this.tm.get(returnTokenIndex).spaceAfter(); }/*from ww w . jav a 2 s. c o m*/ } return true; }
From source file:com.google.devtools.j2cpp.gen.CppStatementGenerator.java
License:Open Source License
@Override public boolean visit(ReturnStatement node) { buffer.append("return"); Expression expr = node.getExpression(); if (expr != null) { buffer.append(' '); boolean needsCast = false; ITypeBinding expressionType = Types.getTypeBinding(expr); IBinding binding = Types.getBinding(expr); if (expr instanceof SuperMethodInvocation) { needsCast = true;//from w w w .j a va 2s.c o m } else if (expressionType.isParameterizedType()) { // Add a cast if expr is a superclass field or method, as its declared // type may be more general than expr's return type. if (binding instanceof IVariableBinding && ((IVariableBinding) binding).isField()) { IVariableBinding var = (IVariableBinding) binding; ITypeBinding remoteC = var.getDeclaringClass(); ITypeBinding localC = Types.getMethodBinding(getOwningMethod(node)).getDeclaringClass(); needsCast = !localC.isEqualTo(remoteC) && var.getVariableDeclaration().getType().isTypeVariable(); } else if (binding instanceof IMethodBinding) { IMethodBinding method = (IMethodBinding) binding; ITypeBinding remoteC = method.getDeclaringClass(); ITypeBinding localC = Types.getMethodBinding(getOwningMethod(node)).getDeclaringClass(); needsCast = !localC.isEqualTo(remoteC) && method.getMethodDeclaration().getReturnType().isTypeVariable(); } } if (needsCast) { buffer.append('('); buffer.append(NameTable.javaRefToCpp(expressionType)); buffer.append(") "); } expr.accept(this); } else if (Types.getMethodBinding(getOwningMethod(node)).isConstructor()) { // A return statement without any expression is allowed in constructors. buffer.append(" self"); } buffer.append(";\n"); return false; }