Java Code Examples for org.eclipse.jdt.core.dom.Statement#getStartPosition()

The following examples show how to use org.eclipse.jdt.core.dom.Statement#getStartPosition() . 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: EndStatementCodeMining.java    From jdt-codemining with Eclipse Public License 1.0 6 votes vote down vote up
private static String getLabel(Statement node, IDocument document, int minLineNumber) {
	try {
		int offset = node.getStartPosition();
		if (minLineNumber > 0) {
			int startLine = document.getLineOfOffset(offset);
			int endLine = document.getLineOfOffset(offset + node.getLength());
			if (endLine - startLine <= minLineNumber) {
				return "";
			}
		}
		IRegion first = document.getLineInformationOfOffset(offset);
		return "  // --> " + document.get(first.getOffset(), first.getLength()).trim();
	} catch (BadLocationException e1) {
		return "";
	}
}
 
Example 2
Source File: EndStatementCodeMining.java    From jdt-codemining with Eclipse Public License 1.0 5 votes vote down vote up
public EndStatementCodeMining(Statement node, ITextEditor textEditor, ITextViewer viewer, int minLineNumber,
		ICodeMiningProvider provider) {
	super(new Position(node.getStartPosition() + node.getLength(), 1), provider, e -> {
		textEditor.selectAndReveal(node.getStartPosition(), 0);
	});
	String label = getLabel(node, viewer.getDocument(), minLineNumber);
	super.setLabel(label);
}
 
Example 3
Source File: RefactorProposalUtility.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
private static int getIndex(int offset, List<Statement> statements) {
	for (int i = 0; i < statements.size(); i++) {
		Statement s = statements.get(i);
		if (offset <= s.getStartPosition()) {
			return i;
		}
		if (offset < s.getStartPosition() + s.getLength()) {
			return -1;
		}
	}
	return statements.size();
}
 
Example 4
Source File: FlowAnalyzer.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
protected SwitchData createSwitchData(SwitchStatement node) {
	SwitchData result = new SwitchData();
	List<Statement> statements = node.statements();
	if (statements.isEmpty()) {
		return result;
	}

	int start = -1, end = -1;
	GenericSequentialFlowInfo info = null;

	for (Iterator<Statement> iter = statements.iterator(); iter.hasNext();) {
		Statement statement = iter.next();
		if (statement instanceof SwitchCase) {
			SwitchCase switchCase = (SwitchCase) statement;
			if (switchCase.isDefault()) {
				result.setHasDefaultCase();
			}
			if (info == null) {
				info = createSequential();
				start = statement.getStartPosition();
			} else {
				if (info.isReturn() || info.isPartialReturn() || info.branches()) {
					result.add(new Region(start, end - start + 1), info);
					info = createSequential();
					start = statement.getStartPosition();
				}
			}
		} else {
			info.merge(getFlowInfo(statement), fFlowContext);
		}
		end = statement.getStartPosition() + statement.getLength() - 1;
	}
	result.add(new Region(start, end - start + 1), info);
	return result;
}
 
Example 5
Source File: FlowAnalyzer.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
protected SwitchData createSwitchData(SwitchStatement node) {
	SwitchData result= new SwitchData();
	List<Statement> statements= node.statements();
	if (statements.isEmpty())
		return result;

	int start= -1, end= -1;
	GenericSequentialFlowInfo info= null;

	for (Iterator<Statement> iter= statements.iterator(); iter.hasNext(); ) {
		Statement statement= iter.next();
		if (statement instanceof SwitchCase) {
			SwitchCase switchCase= (SwitchCase)statement;
			if (switchCase.isDefault()) {
				result.setHasDefaultCase();
			}
			if (info == null) {
				info= createSequential();
				start= statement.getStartPosition();
			} else {
				if (info.isReturn() || info.isPartialReturn() || info.branches()) {
					result.add(new Region(start, end - start + 1), info);
					info= createSequential();
					start= statement.getStartPosition();
				}
			}
		} else {
			info.merge(getFlowInfo(statement), fFlowContext);
		}
		end= statement.getStartPosition() + statement.getLength() - 1;
	}
	result.add(new Region(start, end - start + 1), info);
	return result;
}
 
Example 6
Source File: QuickAssistProcessor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private static int getIndex(int offset, List<Statement> statements) {
	for (int i= 0; i < statements.size(); i++) {
		Statement s= statements.get(i);
		if (offset <= s.getStartPosition()) {
			return i;
		}
		if (offset < s.getStartPosition() + s.getLength()) {
			return -1;
		}
	}
	return statements.size();
}
 
Example 7
Source File: PDGRegionSubTreeMapper.java    From JDeodorant with MIT License 5 votes vote down vote up
private boolean cloneFragmentContainsPDGNode(List<ASTNode> cloneFragmentNodes, PDGNode pdgNode) {
	Statement pdgStatement = pdgNode.getASTStatement();
	int start = pdgStatement.getStartPosition();
	int cloneFragmentStart = cloneFragmentNodes.get(0).getStartPosition();
	int cloneFragmentLastNodeStart = cloneFragmentNodes.get(cloneFragmentNodes.size()-1).getStartPosition();
	int cloneFragmentEnd = cloneFragmentLastNodeStart + cloneFragmentNodes.get(cloneFragmentNodes.size()-1).getLength();
	if (start >= cloneFragmentStart && start <= cloneFragmentEnd)
		return true;
	else 
		return false;
}
 
Example 8
Source File: ReplaceTypeCodeWithStateStrategy.java    From JDeodorant with MIT License 5 votes vote down vote up
private boolean nodeExistsInsideTypeCheckCodeFragment(ASTNode node) {
	Statement statement = typeCheckElimination.getTypeCheckCodeFragment();
	int startPosition = statement.getStartPosition();
	int endPosition = startPosition + statement.getLength();
	if(node.getStartPosition() >= startPosition && node.getStartPosition() <= endPosition)
		return true;
	else
		return false;
}