Java Code Examples for org.eclipse.jdt.internal.corext.dom.ASTNodes#getExclusiveEnd()

The following examples show how to use org.eclipse.jdt.internal.corext.dom.ASTNodes#getExclusiveEnd() . 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: InvertBooleanUtility.java    From eclipse.jdt.ls with Eclipse Public License 2.0 6 votes vote down vote up
private static int isOperatorSelected(InfixExpression infixExpression, int offset, int length) {
	ASTNode left = infixExpression.getLeftOperand();
	ASTNode right = infixExpression.getRightOperand();

	if (isSelectingOperator(left, right, offset, length)) {
		return ASTNodes.getExclusiveEnd(left);
	}
	List<Expression> extended = infixExpression.extendedOperands();
	for (int i = 0; i < extended.size(); i++) {
		left = right;
		right = extended.get(i);
		if (isSelectingOperator(left, right, offset, length)) {
			return ASTNodes.getExclusiveEnd(left);
		}
	}
	return -1;
}
 
Example 2
Source File: AdvancedQuickAssistProcessor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private static int isOperatorSelected(InfixExpression infixExpression, int offset, int length) {
	ASTNode left= infixExpression.getLeftOperand();
	ASTNode right= infixExpression.getRightOperand();

	if (isSelectingOperator(left, right, offset, length)) {
		return ASTNodes.getExclusiveEnd(left);
	}
	List<Expression> extended= infixExpression.extendedOperands();
	for (int i= 0; i < extended.size(); i++) {
		left= right;
		right= extended.get(i);
		if (isSelectingOperator(left, right, offset, length)) {
			return ASTNodes.getExclusiveEnd(left);
		}
	}
	return -1;
}
 
Example 3
Source File: InvertBooleanUtility.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
private static boolean isSelectingOperator(ASTNode n1, ASTNode n2, int offset, int length) {
	// between the nodes
	if (offset + length <= n2.getStartPosition() && offset >= ASTNodes.getExclusiveEnd(n1)) {
		return true;
	}
	// or exactly select the node (but not with infix expressions)
	if (n1.getStartPosition() == offset && ASTNodes.getExclusiveEnd(n2) == offset + length) {
		if (n1 instanceof InfixExpression || n2 instanceof InfixExpression) {
			return false;
		}
		return true;
	}
	return false;
}
 
Example 4
Source File: MoveInnerToTopRefactoring.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private Expression createEnclosingInstanceCreationString(final ASTNode node, final ICompilationUnit cu) throws JavaModelException {
	Assert.isTrue((node instanceof ClassInstanceCreation) || (node instanceof SuperConstructorInvocation));
	Assert.isNotNull(cu);
	Expression expression= null;
	if (node instanceof ClassInstanceCreation)
		expression= ((ClassInstanceCreation) node).getExpression();
	else
		expression= ((SuperConstructorInvocation) node).getExpression();
	final AST ast= node.getAST();
	if (expression != null)
		return expression;
	else if (JdtFlags.isStatic(fType))
		return null;
	else if (isInsideSubclassOfDeclaringType(node))
		return ast.newThisExpression();
	else if ((node.getStartPosition() >= fType.getSourceRange().getOffset() && ASTNodes.getExclusiveEnd(node) <= fType.getSourceRange().getOffset() + fType.getSourceRange().getLength())) {
		if (fCodeGenerationSettings.useKeywordThis || fEnclosingInstanceFieldName.equals(fNameForEnclosingInstanceConstructorParameter)) {
			final FieldAccess access= ast.newFieldAccess();
			access.setExpression(ast.newThisExpression());
			access.setName(ast.newSimpleName(fEnclosingInstanceFieldName));
			return access;
		} else
			return ast.newSimpleName(fEnclosingInstanceFieldName);
	} else if (isInsideTypeNestedInDeclaringType(node)) {
		final ThisExpression qualified= ast.newThisExpression();
		qualified.setQualifier(ast.newSimpleName(fType.getDeclaringType().getElementName()));
		return qualified;
	}
	return null;
}
 
Example 5
Source File: JavaSourceHover.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private int getNextElseOffset(Statement then, ITypeRoot editorInput) {
	int thenEnd= ASTNodes.getExclusiveEnd(then);
	try {
		TokenScanner scanner= new TokenScanner(editorInput);
		return scanner.getNextStartOffset(thenEnd, true);
	} catch (CoreException e) {
		// ignore
	}
	return -1;
}
 
Example 6
Source File: AdvancedQuickAssistProcessor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private static boolean isSelectingOperator(ASTNode n1, ASTNode n2, int offset, int length) {
	// between the nodes
	if (offset + length <= n2.getStartPosition() && offset >= ASTNodes.getExclusiveEnd(n1)) {
		return true;
	}
	// or exactly select the node (but not with infix expressions)
	if (n1.getStartPosition() == offset && ASTNodes.getExclusiveEnd(n2) == offset + length) {
		if (n1 instanceof InfixExpression || n2 instanceof InfixExpression) {
			return false;
		}
		return true;
	}
	return false;
}
 
Example 7
Source File: BreakContinueTargetFinder.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
private OccurrenceLocation getLocationForClosingBrace(ASTNode targetNode) {
	/* Ideally, we'd scan backwards to find the '}' token, but it may be an overkill
	 * so I'll just assume the closing brace token has a fixed length. */
	int offset= ASTNodes.getExclusiveEnd(targetNode) - BRACE_LENGTH;
	return new OccurrenceLocation(offset, BRACE_LENGTH, 0, fDescription);
}