com.sun.source.tree.IfTree Java Examples

The following examples show how to use com.sun.source.tree.IfTree. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ConvertToPatternInstanceOf.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@Override
        protected void performRewrite(JavaFix.TransformationContext ctx) {
            WorkingCopy wc = ctx.getWorkingCopy();
            TreePath main = ctx.getPath();
            IfTree it = (IfTree) main.getLeaf();
            InstanceOfTree iot = (InstanceOfTree) ((ParenthesizedTree) it.getCondition()).getExpression();
            StatementTree bt = it.getThenStatement();
//            wc.rewrite(iot.getType(), wc.getTreeMaker().BindingPattern(var.getName(), iot.getType()));
//            wc.rewrite(bt, wc.getTreeMaker().removeBlockStatement(bt, 0));
            InstanceOfTree cond = wc.getTreeMaker().InstanceOf(iot.getExpression(), wc.getTreeMaker().BindingPattern(varName, iot.getType()));
            StatementTree thenBlock = removeFirst ? wc.getTreeMaker().removeBlockStatement((BlockTree) bt, 0) : bt;
            wc.rewrite(it, wc.getTreeMaker().If(wc.getTreeMaker().Parenthesized(cond), thenBlock, it.getElseStatement()));
            replaceOccurrences.stream().map(tph -> tph.resolve(wc)).forEach(tp -> {
                if (!removeFirst && tp.getParentPath().getLeaf().getKind() == Kind.PARENTHESIZED) {
                    tp = tp.getParentPath();
                }
                wc.rewrite(tp.getLeaf(), wc.getTreeMaker().Identifier(varName));
            });
        }
 
Example #2
Source File: Ifs.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@Override
protected void performRewrite(final TransformationContext ctx) throws Exception {
    IfTree toRewrite = (IfTree) ctx.getPath().getLeaf();
    StatementTree elseStatement = toRewrite.getElseStatement();
    if (toRewrite.getCondition() == null ||
        toRewrite.getCondition().getKind() != Tree.Kind.PARENTHESIZED) {
        return;
    }
    ParenthesizedTree ptt = (ParenthesizedTree)toRewrite.getCondition();
    if (ptt.getExpression() == null) {
        return;
    }
    if (elseStatement == null) elseStatement = ctx.getWorkingCopy().getTreeMaker().Block(Collections.<StatementTree>emptyList(), false);
    
    ctx.getWorkingCopy().rewrite(toRewrite, ctx.getWorkingCopy().getTreeMaker().If(toRewrite.getCondition(), elseStatement, toRewrite.getThenStatement()));
    ExpressionTree negated = Utilities.negate(
            ctx.getWorkingCopy().getTreeMaker(), ptt.getExpression(), ptt);
    ctx.getWorkingCopy().rewrite(ptt.getExpression(), negated);
}
 
Example #3
Source File: Ifs.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@Hint(id="org.netbeans.modules.java.hints.suggestions.InvertIf", displayName = "#DN_InvertIf", description = "#DESC_InvertIf", category = "suggestions", hintKind= Hint.Kind.ACTION)
@UseOptions(SHOW_ELSE_MISSING)
@TriggerPattern(value = "if ($cond) $then; else $else$;")
@Messages({"ERR_InvertIf=Invert If",
           "FIX_InvertIf=Invert If"})
public static ErrorDescription computeWarning(HintContext ctx) {
    TreePath cond = ctx.getVariables().get("$cond");
    long conditionEnd = ctx.getInfo().getTrees().getSourcePositions().getEndPosition(cond.getCompilationUnit(), cond.getParentPath().getLeaf());
    if (ctx.getCaretLocation() > conditionEnd) return null;

    // parenthesized, then if
    TreePath ifPath = cond.getParentPath().getParentPath();
    if (ifPath.getLeaf().getKind() != Tree.Kind.IF) {
        return null;
    }
    IfTree iv = (IfTree)ifPath.getLeaf();
    if (iv.getElseStatement() == null && 
        !ctx.getPreferences().getBoolean(SHOW_ELSE_MISSING, SHOW_ELSE_MISSING_DEFAULT)) {
        return null;
    }
    return ErrorDescriptionFactory.forName(ctx, ctx.getPath(), Bundle.ERR_InvertIf(), new FixImpl(ctx.getInfo(), ctx.getPath()).toEditorFix());
}
 
Example #4
Source File: PreconditionsChecker.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private boolean isLastInControlFlow(TreePath pathToInstruction) {
    Tree currentTree = pathToInstruction.getLeaf();
    Tree parentTree = pathToInstruction.getParentPath().getLeaf();
    if (parentTree.equals(this.loop)) {
        return true;
    } else if (parentTree.getKind() == Tree.Kind.BLOCK) {
        List<? extends StatementTree> ls = ((BlockTree) parentTree).getStatements();
        if (ls.get(ls.size() - 1).equals(currentTree)) {
            return isLastInControlFlow(pathToInstruction.getParentPath());
        } else {
            return false;
        }

    } else if (parentTree.getKind() == Tree.Kind.AND.IF && ((IfTree) parentTree).getElseStatement() != null) {
        return false;
    } else {
        return this.isLastInControlFlow(pathToInstruction.getParentPath());
    }


}
 
Example #5
Source File: ProspectiveOperation.java    From netbeans with Apache License 2.0 6 votes vote down vote up
List<ExpressionTree> getArguments() {
    VariableTree var;
    ExpressionTree lambda;
    Tree lambdaBody;
    if (this.correspondingTree.getKind() == Tree.Kind.BLOCK) {
        lambdaBody = this.correspondingTree;
    } else {
        if (this.opType == OperationType.FILTER || this.opType == OperationType.ANYMATCH || this.opType == OperationType.NONEMATCH) {
            lambdaBody = ((IfTree) this.correspondingTree).getCondition();
        } else if (this.opType == OperationType.MAP) {
            lambdaBody = getLambdaForMap();
        } else if (this.opType == OperationType.FOREACH) {
            lambdaBody = blockify(castToStatementTree(this.correspondingTree));
        } else //if(this.opType== OperationType.REDUCE)
        {
            return getArgumentsForReducer();
        }
    }
    var = getLambdaArguments();
    lambda = treeMaker.LambdaExpression(Arrays.asList(var), lambdaBody);
    List<ExpressionTree> args = new ArrayList<ExpressionTree>();

    args.add(lambda);
    return args;
}
 
Example #6
Source File: EmptyStatements.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@Hint(displayName = "#LBL_Empty_IF", description = "#DSC_Empty_IF", category = "empty", hintKind = Hint.Kind.INSPECTION, severity = Severity.VERIFIER, suppressWarnings = SUPPRESS_WARNINGS_KEY, id = "EmptyStatements_IF", enabled = false)
@TriggerTreeKind(Tree.Kind.EMPTY_STATEMENT)
public static ErrorDescription forIF(HintContext ctx) {
    final TreePath treePath = ctx.getPath();

    Tree parent = treePath.getParentPath().getLeaf();        
    if (!EnumSet.of(Kind.IF).contains(parent.getKind())) {
        return null;
    }
    
    TreePath treePathForWarning = treePath;
    IfTree it = (IfTree) parent;
    if (it.getThenStatement() != null
            && it.getThenStatement().getKind() == Tree.Kind.EMPTY_STATEMENT) {
        treePathForWarning = treePath.getParentPath();
            }
    if (it.getElseStatement() != null
            && it.getElseStatement().getKind() == Tree.Kind.EMPTY_STATEMENT) {
        treePathForWarning = treePath;
            }
    
    final List<Fix> fixes = new ArrayList<>();
    fixes.add(FixFactory.createSuppressWarningsFix(ctx.getInfo(), treePathForWarning, SUPPRESS_WARNINGS_KEY));
    
    return createErrorDescription(ctx, parent, fixes, parent.getKind());
}
 
Example #7
Source File: Flow.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public Boolean visitBlock(BlockTree node, ConstructorData p) {
    List<? extends StatementTree> statements = new ArrayList<StatementTree>(node.getStatements());
    
    for (int i = 0; i < statements.size(); i++) {
        StatementTree st = statements.get(i);
        
        if (st.getKind() == Kind.IF) {
            IfTree it = (IfTree) st; 
            if (it.getElseStatement() == null && Utilities.exitsFromAllBranchers(info, new TreePath(new TreePath(getCurrentPath(), it), it.getThenStatement()))) {
                generalizedIf(it.getCondition(), it.getThenStatement(), statements.subList(i + 1, statements.size()), false);
                break;
            }
        }
        
        scan(st, null);
    }
    
    return null;
}
 
Example #8
Source File: RefasterScanner.java    From Refaster with Apache License 2.0 5 votes vote down vote up
@Override
public Void visitIf(IfTree node, Context context) {
  scan(SKIP_PARENS.visit(node.getCondition(), null), context);
  scan(node.getThenStatement(), context);
  scan(node.getElseStatement(), context);
  return null;
}
 
Example #9
Source File: NullAway.java    From NullAway with MIT License 5 votes vote down vote up
@Override
public Description matchIf(IfTree tree, VisitorState state) {
  if (!matchWithinClass) {
    return Description.NO_MATCH;
  }
  return doUnboxingCheck(state, tree.getCondition());
}
 
Example #10
Source File: UTemplater.java    From Refaster with Apache License 2.0 5 votes vote down vote up
@Override
public UIf visitIf(IfTree tree, Void v) {
  return UIf.create(
      template(tree.getCondition()), 
      template(tree.getThenStatement()),
      (tree.getElseStatement() == null) ? null : template(tree.getElseStatement()));
}
 
Example #11
Source File: TreeConverter.java    From j2objc with Apache License 2.0 5 votes vote down vote up
private TreeNode convertIf(IfTree node, TreePath parent) {
  TreePath path = getTreePath(parent, node);
  return new IfStatement()
      .setExpression(convertWithoutParens(node.getCondition(), path))
      .setThenStatement((Statement) convert(node.getThenStatement(), path))
      .setElseStatement((Statement) convert(node.getElseStatement(), path));
}
 
Example #12
Source File: CompletenessStressTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
private boolean testBlock(StringWriter writer, SourcePositions sp, String text, CompilationUnitTree cut, BlockTree blockTree) {
    boolean success = true;
    for (StatementTree st : blockTree.getStatements()) {
        if (isLegal(st)) {
            success &= testStatement(writer, sp, text, cut, st);
        }
        if (st instanceof IfTree) {
            IfTree ifTree = (IfTree) st;
            success &= testBranch(writer, sp, text, cut, ifTree.getThenStatement());
            success &= testBranch(writer, sp, text, cut, ifTree.getElseStatement());
        } else if (st instanceof WhileLoopTree) {
            WhileLoopTree whileLoopTree = (WhileLoopTree) st;
            success &= testBranch(writer, sp, text, cut, whileLoopTree.getStatement());
        } else if (st instanceof DoWhileLoopTree) {
            DoWhileLoopTree doWhileLoopTree = (DoWhileLoopTree) st;
            success &= testBranch(writer, sp, text, cut, doWhileLoopTree.getStatement());
        } else if (st instanceof ForLoopTree) {
            ForLoopTree forLoopTree = (ForLoopTree) st;
            success &= testBranch(writer, sp, text, cut, forLoopTree.getStatement());
        } else if (st instanceof LabeledStatementTree) {
            LabeledStatementTree labelTree = (LabeledStatementTree) st;
            success &= testBranch(writer, sp, text, cut, labelTree.getStatement());
        } else if (st instanceof SwitchTree) {
            SwitchTree switchTree = (SwitchTree) st;
            for (CaseTree caseTree : switchTree.getCases()) {
                for (StatementTree statementTree : caseTree.getStatements()) {
                    success &= testBranch(writer, sp, text, cut, statementTree);
                }
            }
        }
    }
    return success;
}
 
Example #13
Source File: DeclarationForInstanceOf.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public ChangeInfo implement() throws Exception {
    js.runModificationTask(new Task<WorkingCopy>() {
        public void run(WorkingCopy wc) throws Exception {
            wc.toPhase(Phase.RESOLVED);
            
            TreePath ifTP = ifHandle.resolve(wc);
            TreePath resolvedExpression = expression.resolve(wc);
            TypeMirror resolvedType = type.resolve(wc);
            
            if (ifTP == null || resolvedType == null || resolvedExpression == null) {
                return ;
            }
            
            IfTree ift = (IfTree) ifTP.getLeaf();
            StatementTree then = ift.getThenStatement();
            
            if (then.getKind() == Kind.ERRONEOUS) {
                return ; //TODO.
            }
            
            List<StatementTree> statements = new LinkedList<StatementTree>();
            
            if (then.getKind() == Kind.BLOCK) {
                statements.addAll(((BlockTree) then).getStatements());
            } else {
                statements.add(then);
            }
            
            TreeMaker make = wc.getTreeMaker();
            VariableTree decl = make.Variable(make.Modifiers(EnumSet.noneOf(Modifier.class)), name, make.Type(resolvedType), make.TypeCast(make.Type(resolvedType), (ExpressionTree) resolvedExpression.getLeaf()));
            
            statements.add(0, decl);
            
            BlockTree nue = make.Block(statements, false);
            
            wc.rewrite(then, nue);
        }
    }).commit();
    return null;
}
 
Example #14
Source File: Ifs.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private static boolean caretInsideToLevelElseKeyword(HintContext ctx) {
    IfTree it = (IfTree) ctx.getPath().getLeaf();
    SourcePositions sp = ctx.getInfo().getTrees().getSourcePositions();
    CompilationUnitTree cut = ctx.getInfo().getCompilationUnit();
    int elsePos = (int) sp.getStartPosition(cut, it.getElseStatement());
    
    
    return caretInsidePreviousToken(ctx, elsePos, JavaTokenId.ELSE);
}
 
Example #15
Source File: Ifs.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Hint(id="org.netbeans.modules.java.hints.suggestions.Tiny.mergeIfs", displayName = "#DN_org.netbeans.modules.java.hints.suggestions.Tiny.mergeIfs", description = "#DESC_org.netbeans.modules.java.hints.suggestions.Tiny.mergeIfs", category="suggestions", hintKind=org.netbeans.spi.java.hints.Hint.Kind.ACTION, severity=Severity.HINT)
@TriggerPattern(value="if ($firstCondition) if ($secondCondition) $body;")
public static ErrorDescription mergeIfs(HintContext ctx) {
    int caret = ctx.getCaretLocation();
    IfTree st = (IfTree) ctx.getPath().getLeaf();
    int conditionEnd = (int) ctx.getInfo().getTrees().getSourcePositions().getEndPosition(ctx.getPath().getCompilationUnit(), st.getCondition());
    
    if (caret > conditionEnd) return null;
    
    Fix f = JavaFixUtilities.rewriteFix(ctx, Bundle.FIX_org_netbeans_modules_java_hints_suggestions_Tiny_mergeIfs(), ctx.getPath(), "if ($firstCondition && $secondCondition) $body;");
    
    return ErrorDescriptionFactory.forName(ctx, ctx.getPath(), Bundle.ERR_org_netbeans_modules_java_hints_suggestions_Tiny_mergeIfs(), f);
}
 
Example #16
Source File: ExpectedTypeResolver.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/**
 * @return Returns boolean expression for if-conditional
 */
@Override
public List<? extends TypeMirror> visitIf(IfTree node, Object p) {
    if (theExpression == null) {
        initExpression(node.getCondition());
    }
    return booleanType();
}
 
Example #17
Source File: Refactorer.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private List<ProspectiveOperation> getBlockListRepresentation( StatementTree tree, boolean last) {
    List<ProspectiveOperation> ls = new ArrayList<ProspectiveOperation>();
    BlockTree blockTree = (BlockTree) tree;
    List<? extends StatementTree> statements = blockTree.getStatements();
    for ( int i = 0; i < statements.size(); i++) {
        StatementTree statement = statements.get(i);
        boolean l = last &&  i == statements.size() - 1;
        if (statement.getKind() == Tree.Kind.IF) {
            IfTree ifTree = (IfTree) statement;
            if (isIfWithContinue(ifTree)) {
                ifTree = refactorContinuingIf(ifTree, statements.subList(i + 1, statements.size()));
                // the if was refactored, so that all the statements are nested in it, so it became
                // the last (and single) statement within the parent
                ls.addAll(this.getListRepresentation(ifTree, last));
                break;
            } else if (l) {
                ls.addAll(this.getListRepresentation(ifTree, true));
            } else {
                if (this.isReturningIf(ifTree)) {
                    this.untrasformable = true;
                }
                ls.addAll(ProspectiveOperation.createOperator(ifTree, ProspectiveOperation.OperationType.MAP, preconditionsChecker, workingCopy));
            }
        } else {
            ls.addAll(getListRepresentation(statement, l));
        }
    }
    return ls;
}
 
Example #18
Source File: RemoveSurroundingCodeAction.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private boolean insideElse(CompilationController controller, IfTree ifTree, int caretPosition) {
    if (ifTree.getElseStatement() == null) {
        return false;
    }
    SourcePositions sp = controller.getTrees().getSourcePositions();
    int end = (int) sp.getEndPosition(controller.getCompilationUnit(), ifTree.getThenStatement());
    return end > 0 && caretPosition > end;
}
 
Example #19
Source File: ExpressionScanner.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public List<Tree> visitIf(IfTree node, ExpressionScanner.ExpressionsInfo p) {
    List<Tree> cond = null;
    Tree lastCond = null;
    if (acceptsTree(node)) {
        cond = scan(node.getCondition(), p);
        if (cond != null) {
            lastCond = cond.get(cond.size() - 1);
        }
    }
    StatementTree thent = node.getThenStatement();
    StatementTree elset = node.getElseStatement();
    List<Tree> thenr = null;
    if (isCurrentTree(thent)) {
        thenr = scan(thent, p);
        if (lastCond != null && thenr != null) {
            p.addNextExpression(lastCond, thenr.get(0));
        }
    }
    List<Tree> elser = null;
    if (isCurrentTree(elset)) {
        elser = scan(elset, p);
        if (lastCond != null && elser != null) {
            p.addNextExpression(lastCond, elser.get(0));
        }
    }
    return reduce(reduce(cond, thenr), elser);
}
 
Example #20
Source File: UIf.java    From Refaster with Apache License 2.0 5 votes vote down vote up
@Override
@Nullable
public Unifier visitIf(IfTree ifTree, @Nullable Unifier unifier) {
  unifier = getCondition().unify(ifTree.getCondition(), unifier);
  unifier = getThenStatement().unify(ifTree.getThenStatement(), unifier);
  return Unifier.unifyNullable(unifier, getElseStatement(), ifTree.getElseStatement());
}
 
Example #21
Source File: ModelBuilder.java    From vertx-codetrans with Apache License 2.0 5 votes vote down vote up
private StatementModel build(List<ConditionalBlockModel> conditionals, IfTree node, VisitContext context) {
  ExpressionModel condition = scan(node.getCondition(), context);
  StatementModel body = scan(node.getThenStatement(), context);
  conditionals.add(new ConditionalBlockModel(condition, body));
  StatementTree elseStatement = node.getElseStatement();
  if (elseStatement != null) {
    if (elseStatement instanceof IfTree) {
      IfTree next = (IfTree) elseStatement;
      return build(conditionals, next, context);
    } else {
      return scan(node.getElseStatement(), context);
    }
  }
  return null;
}
 
Example #22
Source File: TreeDiffer.java    From compile-testing with Apache License 2.0 5 votes vote down vote up
@Override
public Void visitIf(IfTree expected, Tree actual) {
  Optional<IfTree> other = checkTypeAndCast(expected, actual);
  if (!other.isPresent()) {
    addTypeMismatch(expected, actual);
    return null;
  }

  scan(expected.getCondition(), other.get().getCondition());
  scan(expected.getThenStatement(), other.get().getThenStatement());
  scan(expected.getElseStatement(), other.get().getElseStatement());
  return null;
}
 
Example #23
Source File: Ifs.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Hint(displayName="#DN_JoinElseIf", description="#DESC_JoinElseIf", category="suggestions", hintKind=Hint.Kind.ACTION)
@TriggerPattern("if ($cond1) $then1; else { if ($cond2) $then2; else $else$; }")
@Messages({"ERR_JoinElseIf=",
           "FIX_JoinElseIf=Join nested if into the enclosing if"})
public static ErrorDescription joinElseIf(HintContext ctx) {
    IfTree it = (IfTree) ctx.getPath().getLeaf();
    if (it.getElseStatement().getKind() != Kind.BLOCK) return null;
    if (!caretInsideToLevelElseKeyword(ctx)) return null;
    return ErrorDescriptionFactory.forSpan(ctx, ctx.getCaretLocation(), ctx.getCaretLocation(), Bundle.ERR_JoinElseIf(), new JoinIfFix(ctx.getInfo(), ctx.getPath()).toEditorFix());
}
 
Example #24
Source File: ProspectiveOperation.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void merge(ProspectiveOperation op) {
    if (this.opType == OperationType.FILTER) {
        this.opType = op.opType;
        IfTree ifTree = this.treeMaker.If(((IfTree) this.correspondingTree).getCondition(), (StatementTree) op.correspondingTree, null);
        this.correspondingTree = ifTree;
    } else {
        this.opType = op.opType;
        List<StatementTree> statements = new ArrayList<StatementTree>();

        if (this.correspondingTree.getKind() == Tree.Kind.BLOCK) {
            statements.addAll(((BlockTree) this.correspondingTree).getStatements());
        } else {
            statements.add(castToStatementTree(this.correspondingTree));
        }

        if (op.correspondingTree.getKind() == Tree.Kind.BLOCK) {
            statements.addAll(((BlockTree) op.correspondingTree).getStatements());
        } else {
            statements.add(castToStatementTree(op.correspondingTree));
        }
        HashSet<Name> futureAvailable = new HashSet<Name>();
        HashSet<Name> futureNeeded = new HashSet<Name>();

        futureAvailable.addAll(this.getAvailableVariables());
        futureAvailable.addAll(op.getAvailableVariables());

        futureNeeded.addAll(op.getNeededVariables());
        futureNeeded.removeAll(this.getAvailableVariables());
        futureNeeded.addAll(this.getNeededVariables());

        this.neededVariables = futureNeeded;
        this.availableVariables = futureAvailable;
        this.correspondingTree = this.treeMaker.Block(statements, false);
    }
}
 
Example #25
Source File: PreconditionsChecker.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private boolean thisIsMatcherReturn(Tree that, TreePath currentTreePath) {
    TreePath parentPath = currentTreePath.getParentPath();
    Tree parent = parentPath.getLeaf();
    if (parent.getKind() == Tree.Kind.BLOCK && ((BlockTree) parent).getStatements().size() == 1) {
        return thisIsMatcherReturn(parent, parentPath);
    } else if (parent.getKind() == Tree.Kind.IF && ((IfTree) parent).getElseStatement() == null) {
        return true;
    }
    return false;


}
 
Example #26
Source File: Refactorer.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private List<ProspectiveOperation> getIfListRepresentation( StatementTree tree, boolean last) {
    IfTree ifTree = (IfTree) tree;
    List<ProspectiveOperation> ls = new ArrayList<ProspectiveOperation>();
    if (ifTree.getElseStatement() == null) {

        StatementTree then = ifTree.getThenStatement();
        if (isOneStatementBlock(then)) {
            then = ((BlockTree) then).getStatements().get(0);
        }
        if (then.getKind() == Tree.Kind.RETURN) {
            ReturnTree returnTree = (ReturnTree) then;
            ExpressionTree returnExpression = returnTree.getExpression();
            if (returnExpression.getKind() == Tree.Kind.BOOLEAN_LITERAL && ((LiteralTree) returnExpression).getValue().equals(true)) {
                ls.addAll(ProspectiveOperation.createOperator(ifTree, ProspectiveOperation.OperationType.ANYMATCH, this.preconditionsChecker, this.workingCopy));
            } else if (returnExpression.getKind() == Tree.Kind.BOOLEAN_LITERAL && ((LiteralTree) returnExpression).getValue().equals(false)) {
                ls.addAll(ProspectiveOperation.createOperator(ifTree, ProspectiveOperation.OperationType.NONEMATCH, this.preconditionsChecker, this.workingCopy));
            }
        } else {
            ls.addAll(ProspectiveOperation.createOperator(ifTree, ProspectiveOperation.OperationType.FILTER, this.preconditionsChecker, this.workingCopy));
            ls.addAll(getListRepresentation(ifTree.getThenStatement(), last));
        }
    } else {

        ls.addAll(ProspectiveOperation.createOperator(ifTree, ProspectiveOperation.OperationType.MAP, this.preconditionsChecker, this.workingCopy));
    }
    return ls;
}
 
Example #27
Source File: TreeDuplicator.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public Tree visitIf(IfTree tree, Void p) {
    IfTree n = make.If(tree.getCondition(), tree.getThenStatement(), tree.getElseStatement());
    model.setType(n, model.getType(tree));
    comments.copyComments(tree, n);
    model.setPos(n, model.getPos(tree));
    return n;
}
 
Example #28
Source File: Refactorer.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private Boolean isIfWithContinue( IfTree ifTree) {
    StatementTree then = ifTree.getThenStatement();
    if (then.getKind() == Tree.Kind.CONTINUE) {
        return true;
    } else if (then.getKind() == Tree.Kind.BLOCK) {
        List<? extends StatementTree> statements = ((BlockTree) then).getStatements();
        if (statements.size() == 1 && statements.get(0).getKind() == Tree.Kind.CONTINUE) {
            return true;
        }

    }
    return false;
}
 
Example #29
Source File: Refactorer.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private boolean isReturningIf( IfTree ifTree) {
    StatementTree then = ifTree.getThenStatement();
    if (then.getKind() == Tree.Kind.RETURN) {
        return true;
    } else if (then.getKind() == Tree.Kind.BLOCK) {
        BlockTree block = (BlockTree) then;
        if (block.getStatements().size() == 1 && block.getStatements().get(0).getKind() == Tree.Kind.RETURN) {
            return true;
        }
    }
    return false;
}
 
Example #30
Source File: TreeNode.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public Void visitIf(IfTree tree, List<Node> d) {
    List<Node> below = new ArrayList<Node>();
    
    addCorrespondingType(below);
    addCorrespondingComments(below);
    super.visitIf(tree, below);
    
    d.add(new TreeNode(info, getCurrentPath(), below));
    return null;
}