Java Code Examples for org.eclipse.lsp4j.util.Ranges#containsPosition()

The following examples show how to use org.eclipse.lsp4j.util.Ranges#containsPosition() . 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: MicroProfileConfigHoverParticipant.java    From intellij-quarkus with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public Hover collectHover(JavaHoverContext context) {
	PsiElement hoverElement = PsiTreeUtil.getParentOfType(context.getHoverElement(), PsiField.class);
	if (!(hoverElement instanceof PsiField)) {
		return null;
	}

	PsiFile typeRoot = context.getTypeRoot();
	IPsiUtils utils = context.getUtils();

	Position hoverPosition = context.getHoverPosition();
	PsiField hoverField = (PsiField) hoverElement;

	PsiAnnotation annotation = getAnnotation(hoverField, CONFIG_PROPERTY_ANNOTATION);

	if (annotation == null) {
		return null;
	}

	String annotationSource = annotation.getText();
	String propertyKey = getAnnotationMemberValue(annotation, CONFIG_PROPERTY_ANNOTATION_NAME);

	if (propertyKey == null) {
		return null;
	}

	TextRange r = annotation.getTextRange();
	int offset = annotationSource.indexOf(propertyKey);
	final Range propertyKeyRange = utils.toRange(typeRoot, r.getStartOffset() + offset, propertyKey.length());

	if (hoverPosition.equals(propertyKeyRange.getEnd())
			|| !Ranges.containsPosition(propertyKeyRange, hoverPosition)) {
		return null;
	}

	Module javaProject = context.getJavaProject();

	if (javaProject == null) {
		return null;
	}

	String propertyValue = PsiMicroProfileProjectManager.getInstance().getJDTMicroProfileProject(javaProject)
			.getProperty(propertyKey, null);
	if (propertyValue == null) {
		propertyValue = getAnnotationMemberValue(annotation, CONFIG_PROPERTY_ANNOTATION_DEFAULT_VALUE);
		if (propertyValue != null && propertyValue.length() == 0) {
			propertyValue = null;
		}
	}
	DocumentFormat documentFormat = context.getDocumentFormat();
	return new Hover(getDocumentation(propertyKey, propertyValue, documentFormat, true), propertyKeyRange);
}
 
Example 2
Source File: RenameService2.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
/**
 * If this method returns {@code false}, it is sure, that the rename operation will fail. There is no guarantee that
 * it will succeed even if it returns {@code true}.
 */
protected boolean mayPerformRename(Either<Range, PrepareRenameResult> prepareRenameResult,
		RenameParams renameParams) {
	return prepareRenameResult != null && prepareRenameResult.getLeft() != null
			&& Ranges.containsPosition(prepareRenameResult.getLeft(), renameParams.getPosition());
}
 
Example 3
Source File: RangesTest.java    From lsp4j with Eclipse Public License 2.0 4 votes vote down vote up
@Test(expected = NullPointerException.class)
public void containsPosition_nullRange() {
	Ranges.containsPosition(null, new Position(0, 0));
}
 
Example 4
Source File: RangesTest.java    From lsp4j with Eclipse Public License 2.0 4 votes vote down vote up
@Test(expected = NullPointerException.class)
public void containsPosition_nullPosition() {
	Ranges.containsPosition(newRange(0, 0, 1, 1), null);
}