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

The following examples show how to use org.eclipse.jdt.core.dom.LabeledStatement. 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: ExtractMethodAnalyzer.java    From eclipse.jdt.ls with Eclipse Public License 2.0 6 votes vote down vote up
private Statement getParentLoopBody(ASTNode node) {
	Statement stmt = null;
	ASTNode start = node;
	while (start != null && !(start instanceof ForStatement) && !(start instanceof DoStatement) && !(start instanceof WhileStatement) && !(start instanceof EnhancedForStatement) && !(start instanceof SwitchStatement)) {
		start = start.getParent();
	}
	if (start instanceof ForStatement) {
		stmt = ((ForStatement) start).getBody();
	} else if (start instanceof DoStatement) {
		stmt = ((DoStatement) start).getBody();
	} else if (start instanceof WhileStatement) {
		stmt = ((WhileStatement) start).getBody();
	} else if (start instanceof EnhancedForStatement) {
		stmt = ((EnhancedForStatement) start).getBody();
	}
	if (start != null && start.getParent() instanceof LabeledStatement) {
		LabeledStatement labeledStatement = (LabeledStatement) start.getParent();
		fEnclosingLoopLabel = labeledStatement.getLabel();
	}
	return stmt;
}
 
Example #2
Source File: BreakContinueTargetFinder.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private boolean keepWalkingUp(ASTNode node) {
	if (node == null)
		return false;
	if (isAnyInstanceOf(STOPPERS, node))
		return false;
	if (fLabel != null && LabeledStatement.class.isInstance(node)){
		LabeledStatement ls= (LabeledStatement)node;
		return ! areEqualLabels(ls.getLabel(), fLabel);
	}
	if (fLabel == null) {
		if (isAnyInstanceOf(fIsBreak ? BREAKTARGETS : CONTINUETARGETS, node))
			return node.getParent() instanceof LabeledStatement; // for behavior consistency of break targets: see bug 339176
		if (node instanceof LabeledStatement)
			return false;
	}
	return true;
}
 
Example #3
Source File: ExtractMethodAnalyzer.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private Statement getParentLoopBody(ASTNode node) {
	Statement stmt= null;
	ASTNode start= node;
	while (start != null
			&& !(start instanceof ForStatement)
			&& !(start instanceof DoStatement)
			&& !(start instanceof WhileStatement)
			&& !(start instanceof EnhancedForStatement)
			&& !(start instanceof SwitchStatement)) {
		start= start.getParent();
	}
	if (start instanceof ForStatement) {
		stmt= ((ForStatement)start).getBody();
	} else if (start instanceof DoStatement) {
		stmt= ((DoStatement)start).getBody();
	} else if (start instanceof WhileStatement) {
		stmt= ((WhileStatement)start).getBody();
	} else if (start instanceof EnhancedForStatement) {
		stmt= ((EnhancedForStatement)start).getBody();
	}
	if (start != null && start.getParent() instanceof LabeledStatement) {
		LabeledStatement labeledStatement= (LabeledStatement)start.getParent();
		fEnclosingLoopLabel= labeledStatement.getLabel();
	}
	return stmt;
}
 
Example #4
Source File: CFGBranchNode.java    From JDeodorant with MIT License 6 votes vote down vote up
protected void processBlockStatement(Set<AbstractStatement> nestedStatements, CompositeStatementObject blockStatement) {
	for(AbstractStatement statementInsideBlock : blockStatement.getStatements()) {
		if(statementInsideBlock instanceof TryStatementObject) {
			CompositeStatementObject tryStatement = (CompositeStatementObject)statementInsideBlock;
			processTryStatement(nestedStatements, tryStatement);
		}
		else if(statementInsideBlock.getStatement() instanceof LabeledStatement || statementInsideBlock.getStatement() instanceof SynchronizedStatement) {
			CompositeStatementObject labeledStatement = (CompositeStatementObject)statementInsideBlock;
			processLabeledStatement(nestedStatements, labeledStatement);
		}
		else if(statementInsideBlock.getStatement() instanceof Block) {
			CompositeStatementObject blockStatement2 = (CompositeStatementObject)statementInsideBlock;
			processBlockStatement(nestedStatements, blockStatement2);
		}
		else
			nestedStatements.add(statementInsideBlock);
	}
}
 
Example #5
Source File: PDG.java    From JDeodorant with MIT License 6 votes vote down vote up
private PDGNode getLoopNodeUnderLabel(PDGNode node, String label) {
	for(GraphEdge edge : node.incomingEdges) {
		PDGDependence dependence = (PDGDependence)edge;
		if(dependence instanceof PDGControlDependence) {
			PDGControlDependence controlDependence = (PDGControlDependence)dependence;
			PDGNode srcPDGNode = (PDGNode)controlDependence.src;
			CFGNode srcCFGNode = srcPDGNode.getCFGNode();
			if(srcCFGNode instanceof CFGBranchLoopNode || srcCFGNode instanceof CFGBranchDoLoopNode || srcCFGNode instanceof CFGBranchSwitchNode) {
				Statement predicate = srcCFGNode.getASTStatement();
				if(predicate.getParent() instanceof LabeledStatement) {
					LabeledStatement labeled = (LabeledStatement)predicate.getParent();
					if(labeled.getLabel().getIdentifier().equals(label))
						return srcPDGNode;
				}
			}
			return getLoopNodeUnderLabel(srcPDGNode, label);
		}
	}
	return null;
}
 
Example #6
Source File: ExtractMethodFragmentRefactoring.java    From JDeodorant with MIT License 5 votes vote down vote up
public ExtractMethodFragmentRefactoring() {
	this.tryStatementsToBeRemoved = new LinkedHashSet<TryStatement>();
	this.tryStatementsToBeCopied = new LinkedHashSet<TryStatement>();
	this.tryStatementBodyRewriteMap = new LinkedHashMap<TryStatement, ListRewrite>();
	this.doLoopNodes = new ArrayList<CFGBranchDoLoopNode>();
	this.labeledStatementsToBeRemoved = new LinkedHashSet<LabeledStatement>();
}
 
Example #7
Source File: CFGBranchIfNode.java    From JDeodorant with MIT License 5 votes vote down vote up
public Set<CFGNode> getImmediatelyNestedNodesInTrueControlFlow() {
	Set<CFGNode> nestedNodes = new LinkedHashSet<CFGNode>();
	AbstractStatement abstractStatement = getStatement();
	if(abstractStatement instanceof CompositeStatementObject) {
		Set<AbstractStatement> nestedStatements = new LinkedHashSet<AbstractStatement>();
		CompositeStatementObject composite = (CompositeStatementObject)abstractStatement;
		List<AbstractStatement> statements = composite.getStatements();
		AbstractStatement trueControlFlowStatement = statements.get(0);
		if(trueControlFlowStatement.getStatement() instanceof Block) {
			CompositeStatementObject blockStatement = (CompositeStatementObject)trueControlFlowStatement;
			processBlockStatement(nestedStatements, blockStatement);
		}
		else if(trueControlFlowStatement.getStatement() instanceof LabeledStatement || trueControlFlowStatement.getStatement() instanceof SynchronizedStatement) {
			CompositeStatementObject labeledStatement = (CompositeStatementObject)trueControlFlowStatement;
			processLabeledStatement(nestedStatements, labeledStatement);
		}
		else if(trueControlFlowStatement instanceof TryStatementObject) {
			CompositeStatementObject tryStatement = (CompositeStatementObject)trueControlFlowStatement;
			processTryStatement(nestedStatements, tryStatement);
		}
		else
			nestedStatements.add(trueControlFlowStatement);
		List<BasicBlock> nestedBasicBlocks = getNestedBasicBlocks();
		nestedBasicBlocks.add(0, getBasicBlock());
		for(BasicBlock nestedBlock : nestedBasicBlocks) {
			List<CFGNode> nodes = nestedBlock.getAllNodes();
			for(CFGNode node : nodes) {
				if(nestedStatements.contains(node.getStatement())) {
					nestedNodes.add(node);
				}
			}
		}
	}
	return nestedNodes;
}
 
Example #8
Source File: CFGBranchIfNode.java    From JDeodorant with MIT License 5 votes vote down vote up
public Set<CFGNode> getImmediatelyNestedNodesInFalseControlFlow() {
	Set<CFGNode> nestedNodes = new LinkedHashSet<CFGNode>();
	AbstractStatement abstractStatement = getStatement();
	if(abstractStatement instanceof CompositeStatementObject) {
		Set<AbstractStatement> nestedStatements = new LinkedHashSet<AbstractStatement>();
		CompositeStatementObject composite = (CompositeStatementObject)abstractStatement;
		List<AbstractStatement> statements = composite.getStatements();
		if(statements.size() == 2) {
			AbstractStatement falseControlFlowStatement = statements.get(1);
			if(falseControlFlowStatement.getStatement() instanceof Block) {
				CompositeStatementObject blockStatement = (CompositeStatementObject)falseControlFlowStatement;
				processBlockStatement(nestedStatements, blockStatement);
			}
			else if(falseControlFlowStatement.getStatement() instanceof LabeledStatement || falseControlFlowStatement.getStatement() instanceof SynchronizedStatement) {
				CompositeStatementObject labeledStatement = (CompositeStatementObject)falseControlFlowStatement;
				processLabeledStatement(nestedStatements, labeledStatement);
			}
			else if(falseControlFlowStatement instanceof TryStatementObject) {
				CompositeStatementObject tryStatement = (CompositeStatementObject)falseControlFlowStatement;
				processTryStatement(nestedStatements, tryStatement);
			}
			else
				nestedStatements.add(falseControlFlowStatement);
			List<BasicBlock> nestedBasicBlocks = getNestedBasicBlocks();
			nestedBasicBlocks.add(0, getBasicBlock());
			for(BasicBlock nestedBlock : nestedBasicBlocks) {
				List<CFGNode> nodes = nestedBlock.getAllNodes();
				for(CFGNode node : nodes) {
					if(nestedStatements.contains(node.getStatement())) {
						nestedNodes.add(node);
					}
				}
			}
		}
	}
	return nestedNodes;
}
 
Example #9
Source File: CFGBranchNode.java    From JDeodorant with MIT License 5 votes vote down vote up
public Set<CFGNode> getImmediatelyNestedNodesFromAST() {
	Set<CFGNode> nestedNodes = new LinkedHashSet<CFGNode>();
	AbstractStatement abstractStatement = getStatement();
	if(abstractStatement instanceof CompositeStatementObject) {
		Set<AbstractStatement> nestedStatements = new LinkedHashSet<AbstractStatement>();
		CompositeStatementObject composite = (CompositeStatementObject)abstractStatement;
		List<AbstractStatement> statements = composite.getStatements();
		for(AbstractStatement statement : statements) {
			if(statement.getStatement() instanceof Block) {
				CompositeStatementObject blockStatement = (CompositeStatementObject)statement;
				processBlockStatement(nestedStatements, blockStatement);
			}
			else if(statement.getStatement() instanceof LabeledStatement || statement.getStatement() instanceof SynchronizedStatement) {
				CompositeStatementObject labeledStatement = (CompositeStatementObject)statement;
				processLabeledStatement(nestedStatements, labeledStatement);
			}
			else if(statement instanceof TryStatementObject) {
				CompositeStatementObject tryStatement = (CompositeStatementObject)statement;
				processTryStatement(nestedStatements, tryStatement);
			}
			else
				nestedStatements.add(statement);
		}
		List<BasicBlock> nestedBasicBlocks = getNestedBasicBlocks();
		if(this instanceof CFGBranchDoLoopNode)
			nestedBasicBlocks.add(getBasicBlock());
		else
			nestedBasicBlocks.add(0, getBasicBlock());
		for(BasicBlock nestedBlock : nestedBasicBlocks) {
			List<CFGNode> nodes = nestedBlock.getAllNodes();
			for(CFGNode node : nodes) {
				if(nestedStatements.contains(node.getStatement())) {
					nestedNodes.add(node);
				}
			}
		}
	}
	return nestedNodes;
}
 
Example #10
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(LabeledStatement node) {
	if (fDefiningLabel == null) {
		SimpleName label= node.getLabel();
		if (fLabel == label || isSameLabel(label) && ASTNodes.isParent(fLabel, node)) {
			fDefiningLabel= node;
			fResult.add(label);
		}
	}
	node.getBody().accept(this);
	return false;
}
 
Example #11
Source File: CodeSearch.java    From SimFix with GNU General Public License v2.0 5 votes vote down vote up
public boolean visit(LabeledStatement node) {
	int start = _unit.getLineNumber(node.getStartPosition());
	if(start == _extendedLine){
		_extendedStatement = node;
		return false;
	}
	return true;
}
 
Example #12
Source File: ASTNodeMatcher.java    From JDeodorant with MIT License 5 votes vote down vote up
public boolean match(LabeledStatement node, Object other) {
	if (!(other instanceof LabeledStatement)) {
		return false;
	}
	LabeledStatement o = (LabeledStatement) other;
	if(isNestedUnderAnonymousClassDeclaration(node) && isNestedUnderAnonymousClassDeclaration(o)) {
		return super.match(node, o);
	}
	return (
			safeSubtreeMatch(node.getLabel(), o.getLabel()));
}
 
Example #13
Source File: FlowAnalyzer.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void endVisit(LabeledStatement node) {
	if (skipNode(node))
		return;
	FlowInfo info= assignFlowInfo(node, node.getBody());
	if (info != null)
		info.removeLabel(node.getLabel());
}
 
Example #14
Source File: SourceProvider.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public boolean isDangligIf() {
	List<Statement> statements= fDeclaration.getBody().statements();
	if (statements.size() != 1)
		return false;

	ASTNode p= statements.get(0);

	while (true) {
		if (p instanceof IfStatement) {
			return ((IfStatement) p).getElseStatement() == null;
		} else {

			ChildPropertyDescriptor childD;
			if (p instanceof WhileStatement) {
				childD= WhileStatement.BODY_PROPERTY;
			} else if (p instanceof ForStatement) {
				childD= ForStatement.BODY_PROPERTY;
			} else if (p instanceof EnhancedForStatement) {
				childD= EnhancedForStatement.BODY_PROPERTY;
			} else if (p instanceof DoStatement) {
				childD= DoStatement.BODY_PROPERTY;
			} else if (p instanceof LabeledStatement) {
				childD= LabeledStatement.BODY_PROPERTY;
			} else {
				return false;
			}
			Statement body= (Statement) p.getStructuralProperty(childD);
			if (body instanceof Block) {
				return false;
			} else {
				p= body;
			}
		}
	}
}
 
Example #15
Source File: JavaASTFlattener.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public boolean visit(final LabeledStatement node) {
  this.addProblem(node, "LabeledStatements are not supported");
  this.appendToBuffer("/*");
  node.getLabel().accept(this);
  this.appendToBuffer(": */");
  node.getBody().accept(this);
  return false;
}
 
Example #16
Source File: ExtractMethodFragmentRefactoring.java    From JDeodorant with MIT License 5 votes vote down vote up
private LabeledStatement belongsToLabeledStatement(PDGNode pdgNode) {
	Statement statement = pdgNode.getASTStatement();
	if(statement.getParent() instanceof LabeledStatement) {
		return (LabeledStatement) statement.getParent();
	}
	return null;
}
 
Example #17
Source File: FlowAnalyzer.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void endVisit(LabeledStatement node) {
	if (skipNode(node)) {
		return;
	}
	FlowInfo info = assignFlowInfo(node, node.getBody());
	if (info != null) {
		info.removeLabel(node.getLabel());
	}
}
 
Example #18
Source File: StyledStringVisitor.java    From JDeodorant with MIT License 5 votes vote down vote up
public boolean visit(LabeledStatement stmnt){
	/*
	 * Identifier : Statement
	 */
	handleExpression(stmnt.getLabel());
	appendColon();
	return false;
}
 
Example #19
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(LabeledStatement node) {
	return visitNode(node);
}
 
Example #20
Source File: ExtractStatementsVisitor.java    From JDeodorant with MIT License 4 votes vote down vote up
public boolean visit(LabeledStatement node) {
	statementsList.add(node);
	
	return true;
}
 
Example #21
Source File: StatementCollector.java    From JDeodorant with MIT License 4 votes vote down vote up
public boolean visit(LabeledStatement node) {
	statementList.add(node);
	return true;
}
 
Example #22
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(LabeledStatement node) {
	endVisitNode(node);
}
 
Example #23
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(LabeledStatement node) {
	add(fCreator.create(node));
	return true;
}
 
Example #24
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(LabeledStatement node) {
	if (node.subtreeMatch(fMatcher, fNodeToMatch))
		return matches(node);
	return super.visit(node);
}
 
Example #25
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 #26
Source File: CodeBlock.java    From SimFix with GNU General Public License v2.0 4 votes vote down vote up
private LabeledStmt visit(LabeledStatement node) {
	int startLine = _cunit.getLineNumber(node.getStartPosition());
	int endLine = _cunit.getLineNumber(node.getStartPosition() + node.getLength());
	LabeledStmt labeledStmt = new LabeledStmt(startLine, endLine, node);
	return labeledStmt;
}
 
Example #27
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.LabeledStatement)
 */
public ITypeConstraint[] create(LabeledStatement node) {
	return EMPTY_ARRAY;
}