类org.eclipse.jdt.core.dom.BreakStatement源码实例Demo

下面列出了怎么用org.eclipse.jdt.core.dom.BreakStatement的API类实例代码及写法,或者点击链接到github查看源代码。

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;
	}
}
 
源代码2 项目: JDeodorant   文件: CFG.java
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;
}
 
源代码3 项目: JDeodorant   文件: SwitchControlStructure.java
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;
}
 
源代码4 项目: SimFix   文件: CodeSearch.java
public boolean visit(BreakStatement node) {
	int start = _unit.getLineNumber(node.getStartPosition());
	if(start == _extendedLine){
		_extendedStatement = node;
		return false;
	}
	return true;
}
 
源代码5 项目: eclipse.jdt.ls   文件: FlowAnalyzer.java
@Override
public void endVisit(BreakStatement node) {
	if (skipNode(node)) {
		return;
	}
	setFlowInfo(node, createBranch(node.getLabel()));
}
 
源代码6 项目: xtext-xtend   文件: JavaASTFlattener.java
@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;
}
 
@Override
public boolean visit(BreakStatement node) {
	SimpleName label= node.getLabel();
	if (fDefiningLabel != null && isSameLabel(label) && ASTNodes.isParent(label, fDefiningLabel)) {
		fResult.add(label);
	}
	return false;
}
 
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;
}
 
private SimpleName getLabel() {
	if (fIsBreak){
		BreakStatement bs= (BreakStatement) fSelected;
		return bs.getLabel();
	} else {
		ContinueStatement cs= (ContinueStatement) fSelected;
		return cs.getLabel();
	}
}
 
/**
 * 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;
}
 
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);
}
 
源代码12 项目: JDeodorant   文件: CFG.java
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;
}
 
源代码13 项目: JDeodorant   文件: SwitchControlCase.java
@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;
}
 
源代码14 项目: JDeodorant   文件: TypeCheckElimination.java
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;
}
 
源代码15 项目: JDeodorant   文件: StyledStringVisitor.java
public boolean visit(BreakStatement stmnt) {
	/*
	 * break [ Identifier ] ;
	 */
	styledString.append("break", new StyledStringStyler(keywordStyle));
	if (stmnt.getLabel() != null) {
		appendSpace();
		handleExpression(stmnt.getLabel());
	}
	appendSemicolon();
	return false;
}
 
源代码16 项目: junion   文件: ReadableFlattener.java
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;
}
 
源代码17 项目: SimFix   文件: CodeBlock.java
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;
}
 
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;
}
 
@Override
public void endVisit(BreakStatement node) {
	if (skipNode(node))
		return;
	setFlowInfo(node, createBranch(node.getLabel()));
}
 
@Override
public boolean visit(BreakStatement node) {
	if (node.subtreeMatch(fMatcher, fNodeToMatch))
		return matches(node);
	return super.visit(node);
}
 
@Override
public boolean visit(BreakStatement node) {
	add(fCreator.create(node));
	return true;
}
 
@Override
public void endVisit(BreakStatement node) {
	endVisitNode(node);
}
 
@Override
public boolean visit(BreakStatement node) {
	return visitNode(node);
}
 
源代码24 项目: JDeodorant   文件: InstanceOfBranchingStatement.java
public boolean instanceOf(Statement statement) {
	if(statement instanceof BreakStatement || statement instanceof ContinueStatement || statement instanceof ReturnStatement)
		return true;
	else
		return false;
}
 
源代码25 项目: JDeodorant   文件: InstanceOfBreakStatement.java
public boolean instanceOf(Statement statement) {
	if(statement instanceof BreakStatement)
		return true;
	else
		return false;
}
 
源代码26 项目: JDeodorant   文件: CFGBreakNode.java
public CFGBreakNode(AbstractStatement statement) {
	super(statement);
	BreakStatement breakStatement = (BreakStatement)statement.getStatement();
	if(breakStatement.getLabel() != null)
		label = breakStatement.getLabel().getIdentifier();
}
 
源代码27 项目: JDeodorant   文件: StatementCollector.java
public boolean visit(BreakStatement node) {
	statementList.add(node);
	return false;
}
 
源代码28 项目: JDeodorant   文件: ExtractStatementsVisitor.java
public boolean visit(BreakStatement node) {
	statementsList.add(node);
	
	return false;
}
 
源代码29 项目: repositoryminer   文件: MethodVisitor.java
@Override
public boolean visit(BreakStatement node) {
	statements.add(new AbstractStatement(NodeType.BREAK, null));
	return true;
}
 
/**
 * @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;
}
 
 类所在包
 类方法
 同包方法