use of org.eclipse.jdt.core.dom.BreakStatement in project AutoRefactor by JnRouvignac.
the class CFGBuilder method buildCFG.
/**
* Builds a CFG for the provided node.
*
* @param node the node for which to build a CFG.
* @param state the blocks liveness state before current node
* @return the blocks liveness state after current node
*/
public LivenessState buildCFG(final BreakStatement node, final LivenessState state) {
CFGBasicBlock basicBlock = getCFGBasicBlock(node, state);
Statement targetStatement;
if (node.getLabel() != null) {
targetStatement = findLabeledParentStatement(node);
} else {
targetStatement = findBreakableParentStatement(node);
}
addEdgeToBuild(targetStatement, new CFGEdgeBuilder(basicBlock), true);
return state.copyLiveBasicBlock();
}
use of org.eclipse.jdt.core.dom.BreakStatement in project eclipse.jdt.ls by eclipse.
the class NavigateToDefinitionHandler method computeBreakContinue.
private Location computeBreakContinue(ITypeRoot typeRoot, int line, int column) throws CoreException {
int offset = JsonRpcHelpers.toOffset(typeRoot.getBuffer(), line, column);
if (offset >= 0) {
CompilationUnit unit = SharedASTProviderCore.getAST(typeRoot, SharedASTProviderCore.WAIT_YES, null);
if (unit == null) {
return null;
}
ASTNode selectedNode = NodeFinder.perform(unit, offset, 0);
ASTNode node = null;
SimpleName label = null;
if (selectedNode instanceof BreakStatement) {
node = selectedNode;
label = ((BreakStatement) node).getLabel();
} else if (selectedNode instanceof ContinueStatement) {
node = selectedNode;
label = ((ContinueStatement) node).getLabel();
} else if (selectedNode instanceof SimpleName && selectedNode.getParent() instanceof BreakStatement) {
node = selectedNode.getParent();
label = ((BreakStatement) node).getLabel();
} else if (selectedNode instanceof SimpleName && selectedNode.getParent() instanceof ContinueStatement) {
node = selectedNode.getParent();
label = ((ContinueStatement) node).getLabel();
}
if (node != null) {
ASTNode parent = node.getParent();
ASTNode target = null;
while (parent != null) {
if (parent instanceof MethodDeclaration || parent instanceof Initializer) {
break;
}
if (label == null) {
if (parent instanceof ForStatement || parent instanceof EnhancedForStatement || parent instanceof WhileStatement || parent instanceof DoStatement) {
target = parent;
break;
}
if (node instanceof BreakStatement) {
if (parent instanceof SwitchStatement || parent instanceof SwitchExpression) {
target = parent;
break;
}
}
if (node instanceof LabeledStatement) {
target = parent;
break;
}
} else if (LabeledStatement.class.isInstance(parent)) {
LabeledStatement ls = (LabeledStatement) parent;
if (ls.getLabel().getIdentifier().equals(label.getIdentifier())) {
target = ls;
break;
}
}
parent = parent.getParent();
}
if (target != null) {
int start = target.getStartPosition();
int end = new TokenScanner(unit.getTypeRoot()).getNextEndOffset(node.getStartPosition(), true) - start;
if (start >= 0 && end >= 0) {
return JDTUtils.toLocation((ICompilationUnit) typeRoot, start, end);
}
}
}
}
return null;
}
Aggregations