org.eclipse.jdt.core.dom.BreakStatement Java Examples

The following examples show how to use org.eclipse.jdt.core.dom.BreakStatement. 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: SwitchControlStructure.java    From JDeodorant with MIT License 6 votes vote down vote up
private List<AbstractControlCase> createSwitchCases(SwitchStatement switchStatement)
{
	List<AbstractControlCase> returnList  = new ArrayList<AbstractControlCase>();
	List<AbstractControlCase> tempList    = new ArrayList<AbstractControlCase>();
	List<Statement> switchGroupStatements = switchStatement.statements();
	for (Statement currentStatement : switchGroupStatements)
	{
		if (currentStatement instanceof SwitchCase)
		{
			Expression caseValue = ((SwitchCase)currentStatement).getExpression();
			SwitchControlCase newCase = new SwitchControlCase(this.variable, caseValue, new ArrayList<Statement>());
			tempList.add(newCase);
			addToAll((SwitchCase)currentStatement, tempList);
		}
		else if (currentStatement instanceof BreakStatement || currentStatement instanceof ReturnStatement || currentStatement instanceof ContinueStatement)
		{
			addToAll(currentStatement, tempList);
			returnList.addAll(tempList);
			tempList = new ArrayList<AbstractControlCase>();
		}
	}
	return returnList;
}
 
Example #2
Source File: CFG.java    From JDeodorant with MIT License 6 votes vote down vote up
private CFGNode createNonCompositeNode(StatementObject statement) {
	CFGNode currentNode;
	Statement astStatement = statement.getStatement();
	if(astStatement instanceof ReturnStatement)
		currentNode = new CFGExitNode(statement);
	else if(astStatement instanceof SwitchCase)
		currentNode = new CFGSwitchCaseNode(statement);
	else if(astStatement instanceof BreakStatement)
		currentNode = new CFGBreakNode(statement);
	else if(astStatement instanceof ContinueStatement)
		currentNode = new CFGContinueNode(statement);
	else if(astStatement instanceof ThrowStatement)
		currentNode = new CFGThrowNode(statement);
	else
		currentNode = new CFGNode(statement);
	directlyNestedNodeInBlock(currentNode);
	return currentNode;
}
 
Example #3
Source File: BreakContinueTargetFinder.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
public String initialize(CompilationUnit root, ASTNode node) {
	ASTNode controlNode= getBreakOrContinueNode(node);
	if (controlNode != null) {
		fASTRoot= root;

		try {
			if (root.getTypeRoot() == null || root.getTypeRoot().getBuffer() == null)
				return SearchMessages.BreakContinueTargetFinder_cannot_highlight;
		} catch (JavaModelException e) {
			return SearchMessages.BreakContinueTargetFinder_cannot_highlight;
		}
		fSelected= controlNode;
		fIsBreak= fSelected instanceof BreakStatement;
		fLabel= getLabel();
		fDescription= Messages.format(SearchMessages.BreakContinueTargetFinder_occurrence_description, BasicElementLabels.getJavaElementName(ASTNodes.asString(fSelected)));
		return null;
	} else {
		return SearchMessages.BreakContinueTargetFinder_no_break_or_continue_selected;
	}
}
 
Example #4
Source File: CodeSearch.java    From SimFix with GNU General Public License v2.0 5 votes vote down vote up
public boolean visit(BreakStatement node) {
	int start = _unit.getLineNumber(node.getStartPosition());
	if(start == _extendedLine){
		_extendedStatement = node;
		return false;
	}
	return true;
}
 
Example #5
Source File: StyledStringVisitor.java    From JDeodorant with MIT License 5 votes vote down vote up
public boolean visit(BreakStatement stmnt) {
	/*
	 * break [ Identifier ] ;
	 */
	styledString.append("break", new StyledStringStyler(keywordStyle));
	if (stmnt.getLabel() != null) {
		appendSpace();
		handleExpression(stmnt.getLabel());
	}
	appendSemicolon();
	return false;
}
 
Example #6
Source File: TypeCheckElimination.java    From JDeodorant with MIT License 5 votes vote down vote up
public boolean isTypeCheckMethodStateSetter() {
	InheritanceTree tree = null;
	if(existingInheritanceTree != null)
		tree = existingInheritanceTree;
	else if(inheritanceTreeMatchingWithStaticTypes != null)
		tree = inheritanceTreeMatchingWithStaticTypes;
	if(tree != null) {
		DefaultMutableTreeNode root = tree.getRootNode();
		DefaultMutableTreeNode leaf = root.getFirstLeaf();
		List<String> subclassNames = new ArrayList<String>();
		while(leaf != null) {
			subclassNames.add((String)leaf.getUserObject());
			leaf = leaf.getNextLeaf();
		}
		Block typeCheckMethodBody = typeCheckMethod.getBody();
		List<Statement> statements = typeCheckMethodBody.statements();
		if(statements.size() > 0 && statements.get(0) instanceof SwitchStatement) {
			SwitchStatement switchStatement = (SwitchStatement)statements.get(0);
			List<Statement> statements2 = switchStatement.statements();
			ExpressionExtractor expressionExtractor = new ExpressionExtractor();
			int matchCounter = 0;
			for(Statement statement2 : statements2) {
				if(!(statement2 instanceof SwitchCase) && !(statement2 instanceof BreakStatement)) {
					List<Expression> classInstanceCreations = expressionExtractor.getClassInstanceCreations(statement2);
					if(classInstanceCreations.size() == 1) {
						ClassInstanceCreation classInstanceCreation = (ClassInstanceCreation)classInstanceCreations.get(0);
						Type classInstanceCreationType = classInstanceCreation.getType();
						if(subclassNames.contains(classInstanceCreationType.resolveBinding().getQualifiedName())) {
							matchCounter++;
						}
					}
				}
			}
			if(matchCounter == subclassNames.size())
				return true;
		}
	}
	return false;
}
 
Example #7
Source File: SwitchControlCase.java    From JDeodorant with MIT License 5 votes vote down vote up
@Override
public boolean match(SwitchControlCase otherCase, ASTNodeMatcher matcher)
{
	if (this.body.size() == otherCase.body.size())
	{
		boolean caseStatementsMatch = true;
		for (int i = 0; i < this.body.size(); i++)
		{
			Statement currentThisStatement = this.body.get(i);
			Statement currentOtherStatement = otherCase.body.get(i);
			boolean switchCaseStatementMatch = false;
			if (currentThisStatement instanceof SwitchCase && currentOtherStatement instanceof SwitchCase)
			{
				SwitchCase currentThisSwitchCase = (SwitchCase)currentThisStatement;
				SwitchCase currentOtherSwitchCase = (SwitchCase)currentOtherStatement;
				if(currentThisSwitchCase.isDefault() && currentOtherSwitchCase.isDefault())
				{
					switchCaseStatementMatch = true;
				}
				else
				{
					switchCaseStatementMatch = matchCaseCondition(currentThisSwitchCase.getExpression(), currentOtherSwitchCase.getExpression());
				}
			}
			boolean endStatementMatch = ((currentThisStatement instanceof BreakStatement && currentOtherStatement instanceof BreakStatement) ||
					(currentThisStatement instanceof ContinueStatement && currentOtherStatement instanceof ContinueStatement) ||
					(currentThisStatement instanceof ReturnStatement && currentOtherStatement instanceof ReturnStatement));
			if (!switchCaseStatementMatch && !endStatementMatch)
			{
				caseStatementsMatch = false;
			}
		}
		return caseStatementsMatch;
	}
	return false;
}
 
Example #8
Source File: CFG.java    From JDeodorant with MIT License 5 votes vote down vote up
private boolean previousNodesContainBreakOrReturn(List<CFGNode> previousNodes, CompositeStatementObject composite) {
	for(CFGNode previousNode : previousNodes) {
		Statement statement = previousNode.getASTStatement();
		if((statement instanceof BreakStatement || statement instanceof ReturnStatement) &&
				directlyNestedNode(previousNode, composite))
			return true;
	}
	return false;
}
 
Example #9
Source File: AdvancedQuickAssistProcessor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private static Statement copyStatementExceptBreak(AST ast, ASTRewrite rewrite, Statement source) {
	if (source instanceof Block) {
		Block block= (Block) source;
		Block newBlock= ast.newBlock();
		for (Iterator<Statement> iter= block.statements().iterator(); iter.hasNext();) {
			Statement statement= iter.next();
			if (statement instanceof BreakStatement) {
				continue;
			}
			newBlock.statements().add(copyStatementExceptBreak(ast, rewrite, statement));
		}
		return newBlock;
	}
	return (Statement) rewrite.createMoveTarget(source);
}
 
Example #10
Source File: JavaElementHyperlinkDetector.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Finds the target for break or continue node.
 * 
 * @param input the editor input
 * @param region the region
 * @return the break or continue target location or <code>null</code> if none
 * @since 3.7
 */
public static OccurrenceLocation findBreakOrContinueTarget(ITypeRoot input, IRegion region) {
	CompilationUnit astRoot= SharedASTProvider.getAST(input, SharedASTProvider.WAIT_NO, null);
	if (astRoot == null)
		return null;

	ASTNode node= NodeFinder.perform(astRoot, region.getOffset(), region.getLength());
	ASTNode breakOrContinueNode= null;
	boolean labelSelected= false;
	if (node instanceof SimpleName) {
		SimpleName simpleName= (SimpleName) node;
		StructuralPropertyDescriptor location= simpleName.getLocationInParent();
		if (location == ContinueStatement.LABEL_PROPERTY || location == BreakStatement.LABEL_PROPERTY) {
			breakOrContinueNode= simpleName.getParent();
			labelSelected= true;
		}
	} else if (node instanceof ContinueStatement || node instanceof BreakStatement)
		breakOrContinueNode= node;

	if (breakOrContinueNode == null)
		return null;

	BreakContinueTargetFinder finder= new BreakContinueTargetFinder();
	if (finder.initialize(astRoot, breakOrContinueNode) == null) {
		OccurrenceLocation[] locations= finder.getOccurrences();
		if (locations != null) {
			if (breakOrContinueNode instanceof BreakStatement && !labelSelected)
				return locations[locations.length - 1]; // points to the end of target statement
			return locations[0]; // points to the beginning of target statement
		}
	}
	return null;
}
 
Example #11
Source File: BreakContinueTargetFinder.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private SimpleName getLabel() {
	if (fIsBreak){
		BreakStatement bs= (BreakStatement) fSelected;
		return bs.getLabel();
	} else {
		ContinueStatement cs= (ContinueStatement) fSelected;
		return cs.getLabel();
	}
}
 
Example #12
Source File: BreakContinueTargetFinder.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private ASTNode getBreakOrContinueNode(ASTNode selectedNode) {
	if (selectedNode instanceof BreakStatement)
		return selectedNode;
	if (selectedNode instanceof ContinueStatement)
		return selectedNode;
	if (selectedNode instanceof SimpleName && selectedNode.getParent() instanceof BreakStatement)
		return selectedNode.getParent();
	if (selectedNode instanceof SimpleName && selectedNode.getParent() instanceof ContinueStatement)
		return selectedNode.getParent();
	return null;
}
 
Example #13
Source File: FlowAnalyzer.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void endVisit(BreakStatement node) {
	if (skipNode(node)) {
		return;
	}
	setFlowInfo(node, createBranch(node.getLabel()));
}
 
Example #14
Source File: JavaASTFlattener.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public boolean visit(final BreakStatement node) {
  StringConcatenation _builder = new StringConcatenation();
  _builder.append("/* FIXME Unsupported BreakStatement */ break");
  this.appendToBuffer(_builder.toString());
  this.addProblem(node, "Break statement is not supported");
  SimpleName _label = node.getLabel();
  boolean _tripleNotEquals = (_label != null);
  if (_tripleNotEquals) {
    this.appendSpaceToBuffer();
    node.getLabel().accept(this);
  }
  return false;
}
 
Example #15
Source File: LinkedNodeFinder.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public boolean visit(BreakStatement node) {
	SimpleName label= node.getLabel();
	if (fDefiningLabel != null && isSameLabel(label) && ASTNodes.isParent(label, fDefiningLabel)) {
		fResult.add(label);
	}
	return false;
}
 
Example #16
Source File: StatementCollector.java    From JDeodorant with MIT License 4 votes vote down vote up
public boolean visit(BreakStatement node) {
	statementList.add(node);
	return false;
}
 
Example #17
Source File: MethodVisitor.java    From repositoryminer with Apache License 2.0 4 votes vote down vote up
@Override
public boolean visit(BreakStatement node) {
	statements.add(new AbstractStatement(NodeType.BREAK, null));
	return true;
}
 
Example #18
Source File: ReadableFlattener.java    From junion with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public boolean br(ASTNode node) {
	return node instanceof ExpressionStatement || node instanceof VariableDeclarationStatement || node instanceof BreakStatement || node instanceof ContinueStatement || node instanceof PackageDeclaration || node instanceof ImportDeclaration || node instanceof Javadoc;
}
 
Example #19
Source File: CodeBlock.java    From SimFix with GNU General Public License v2.0 4 votes vote down vote up
private BreakStmt visit(BreakStatement node) {
	int startLine = _cunit.getLineNumber(node.getStartPosition());
	int endLine = _cunit.getLineNumber(node.getStartPosition() + node.getLength());
	BreakStmt breakStmt = new BreakStmt(startLine, endLine, node);
	return breakStmt;
}
 
Example #20
Source File: NavigateToDefinitionHandler.java    From eclipse.jdt.ls with Eclipse Public License 2.0 4 votes vote down vote up
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;
}
 
Example #21
Source File: FlowAnalyzer.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public void endVisit(BreakStatement node) {
	if (skipNode(node))
		return;
	setFlowInfo(node, createBranch(node.getLabel()));
}
 
Example #22
Source File: ExtractStatementsVisitor.java    From JDeodorant with MIT License 4 votes vote down vote up
public boolean visit(BreakStatement node) {
	statementsList.add(node);
	
	return false;
}
 
Example #23
Source File: CFGBreakNode.java    From JDeodorant with MIT License 4 votes vote down vote up
public CFGBreakNode(AbstractStatement statement) {
	super(statement);
	BreakStatement breakStatement = (BreakStatement)statement.getStatement();
	if(breakStatement.getLabel() != null)
		label = breakStatement.getLabel().getIdentifier();
}
 
Example #24
Source File: InstanceOfBreakStatement.java    From JDeodorant with MIT License 4 votes vote down vote up
public boolean instanceOf(Statement statement) {
	if(statement instanceof BreakStatement)
		return true;
	else
		return false;
}
 
Example #25
Source File: InstanceOfBranchingStatement.java    From JDeodorant with MIT License 4 votes vote down vote up
public boolean instanceOf(Statement statement) {
	if(statement instanceof BreakStatement || statement instanceof ContinueStatement || statement instanceof ReturnStatement)
		return true;
	else
		return false;
}
 
Example #26
Source File: AstMatchingNodeFinder.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public boolean visit(BreakStatement node) {
	if (node.subtreeMatch(fMatcher, fNodeToMatch))
		return matches(node);
	return super.visit(node);
}
 
Example #27
Source File: ConstraintCollector.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public boolean visit(BreakStatement node) {
	add(fCreator.create(node));
	return true;
}
 
Example #28
Source File: GenericVisitor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public void endVisit(BreakStatement node) {
	endVisitNode(node);
}
 
Example #29
Source File: GenericVisitor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public boolean visit(BreakStatement node) {
	return visitNode(node);
}
 
Example #30
Source File: ConstraintCreator.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 2 votes vote down vote up
/**
 * @param node the AST node
 * @return array of type constraints, may be empty
 * @see org.eclipse.jdt.core.dom.ASTVisitor#visit(org.eclipse.jdt.core.dom.BreakStatement)
 */
public ITypeConstraint[] create(BreakStatement node) {
	return EMPTY_ARRAY;
}