org.eclipse.lsp4j.util.Ranges Java Examples

The following examples show how to use org.eclipse.lsp4j.util.Ranges. 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: QuickfixContext.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Return the current diagnostic or null, if it cannot be determined generically.
 */
public Diagnostic getDiagnostic() {
	CodeActionContext context = options.getCodeActionParams().getContext();
	for (Diagnostic d : context.getDiagnostics()) {
		if (issueCode.equals(d.getCode())) {
			if (Ranges.containsRange(d.getRange(), options.getCodeActionParams().getRange())) {
				return d;
			}
		}
	}
	return null;
}
 
Example #2
Source File: RangesTest.java    From lsp4j with Eclipse Public License 2.0 4 votes vote down vote up
@Test
public void containsPosition_afterBelow() {
	Assert.assertFalse(Ranges.containsPosition(newRange(1, 3, 2, 2), new Position(3, 3)));
}
 
Example #3
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 #4
Source File: RangesTest.java    From lsp4j with Eclipse Public License 2.0 4 votes vote down vote up
@Test
public void containsPosition_afterSameLine() {
	Assert.assertFalse(Ranges.containsPosition(newRange(1, 1, 2, 2), new Position(2, 4)));
}
 
Example #5
Source File: RangesTest.java    From lsp4j with Eclipse Public License 2.0 4 votes vote down vote up
@Test
public void containsPosition_rightBorder() {
	Assert.assertTrue(Ranges.containsPosition(newRange(1, 3, 2, 2), new Position(2, 2)));
}
 
Example #6
Source File: RangesTest.java    From lsp4j with Eclipse Public License 2.0 4 votes vote down vote up
@Test
public void containsPosition_inside() {
	Assert.assertTrue(Ranges.containsPosition(newRange(1, 3, 2, 2), new Position(1, 4)));
}
 
Example #7
Source File: RangesTest.java    From lsp4j with Eclipse Public License 2.0 4 votes vote down vote up
@Test
public void containsPosition_leftBorder() {
	Assert.assertTrue(Ranges.containsPosition(newRange(1, 3, 2, 2), new Position(1, 3)));
}
 
Example #8
Source File: RangesTest.java    From lsp4j with Eclipse Public License 2.0 4 votes vote down vote up
@Test
public void containsPosition_beforeSameLine() {
	Assert.assertFalse(Ranges.containsPosition(newRange(1, 3, 2, 2), new Position(1, 2)));
}
 
Example #9
Source File: RangesTest.java    From lsp4j with Eclipse Public License 2.0 4 votes vote down vote up
@Test
public void containsPosition_beforeAbove() {
	Assert.assertFalse(Ranges.containsPosition(newRange(1, 1, 2, 2), new Position(0, 1)));
}
 
Example #10
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);
}
 
Example #11
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 #12
Source File: RangesTest.java    From lsp4j with Eclipse Public License 2.0 4 votes vote down vote up
@Test
public void containsRange_overlaps() {
	Assert.assertFalse(Ranges.containsRange(newRange(2, 2, 3, 3), newRange(1, 1, 5, 5)));
}
 
Example #13
Source File: RangesTest.java    From lsp4j with Eclipse Public License 2.0 4 votes vote down vote up
@Test
public void containsRange_afterIntersects() {
	Assert.assertFalse(Ranges.containsRange(newRange(2, 2, 3, 3), newRange(3, 1, 5, 5)));
}
 
Example #14
Source File: RangesTest.java    From lsp4j with Eclipse Public License 2.0 4 votes vote down vote up
@Test
public void containsRange_afterSameLine() {
	Assert.assertFalse(Ranges.containsRange(newRange(2, 2, 3, 3), newRange(3, 4, 5, 5)));
}
 
Example #15
Source File: RangesTest.java    From lsp4j with Eclipse Public License 2.0 4 votes vote down vote up
@Test
public void containsRange_afterBelow() {
	Assert.assertFalse(Ranges.containsRange(newRange(2, 2, 3, 3), newRange(4, 4, 5, 5)));
}
 
Example #16
Source File: RangesTest.java    From lsp4j with Eclipse Public License 2.0 4 votes vote down vote up
@Test
public void containsRange_inside() {
	Assert.assertTrue(Ranges.containsRange(newRange(0, 0, 3, 3), newRange(1, 1, 2, 2)));
}
 
Example #17
Source File: RangesTest.java    From lsp4j with Eclipse Public License 2.0 4 votes vote down vote up
@Test
public void containsRange_equals() {
	Range range = newRange(0, 0, 1, 3);
	Assert.assertTrue(Ranges.containsRange(range, range));
}
 
Example #18
Source File: RangesTest.java    From lsp4j with Eclipse Public License 2.0 4 votes vote down vote up
@Test
public void containsRange_same() {
	Assert.assertTrue(Ranges.containsRange(newRange(0, 0, 1, 3), newRange(0, 0, 1, 3)));
}
 
Example #19
Source File: RangesTest.java    From lsp4j with Eclipse Public License 2.0 4 votes vote down vote up
@Test
public void containsRange_beforeIntersects() {
	Assert.assertFalse(Ranges.containsRange(newRange(1, 2, 3, 3), newRange(0, 0, 1, 3)));
}
 
Example #20
Source File: RangesTest.java    From lsp4j with Eclipse Public License 2.0 4 votes vote down vote up
@Test
public void containsRange_beforeSameLine() {
	Assert.assertFalse(Ranges.containsRange(newRange(1, 2, 3, 3), newRange(0, 0, 1, 1)));
}
 
Example #21
Source File: RangesTest.java    From lsp4j with Eclipse Public License 2.0 4 votes vote down vote up
@Test
public void containsRange_beforeAbove() {
	Assert.assertFalse(Ranges.containsRange(newRange(2, 2, 3, 3), newRange(0, 0, 1, 1)));
}
 
Example #22
Source File: RangesTest.java    From lsp4j with Eclipse Public License 2.0 4 votes vote down vote up
@Test(expected = NullPointerException.class)
public void containsRange_nullSmaller() {
	Ranges.containsRange(newRange(0, 0, 1, 1), null);
}
 
Example #23
Source File: RangesTest.java    From lsp4j with Eclipse Public License 2.0 4 votes vote down vote up
@Test(expected = NullPointerException.class)
public void containsRange_nullBigger() {
	Ranges.containsRange(null, newRange(0, 0, 1, 1));
}
 
Example #24
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 #25
Source File: AbstractLanguageServerTest.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
/**
 * @since 2.16
 */
protected String _toExpectation(final DocumentSymbol it) {
  String _xblockexpression = null;
  {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("selectionRange must be contained in the range: ");
    _builder.append(it);
    Assert.assertTrue(_builder.toString(), Ranges.containsRange(it.getRange(), it.getSelectionRange()));
    StringConcatenation _builder_1 = new StringConcatenation();
    _builder_1.append("symbol \"");
    String _name = it.getName();
    _builder_1.append(_name);
    _builder_1.append("\" {");
    _builder_1.newLineIfNotEmpty();
    _builder_1.append("    ");
    _builder_1.append("kind: ");
    int _value = it.getKind().getValue();
    _builder_1.append(_value, "    ");
    _builder_1.newLineIfNotEmpty();
    _builder_1.append("    ");
    _builder_1.append("range: ");
    String _expectation = this.toExpectation(it.getRange());
    _builder_1.append(_expectation, "    ");
    _builder_1.newLineIfNotEmpty();
    _builder_1.append("    ");
    _builder_1.append("selectionRange: ");
    String _expectation_1 = this.toExpectation(it.getSelectionRange());
    _builder_1.append(_expectation_1, "    ");
    _builder_1.newLineIfNotEmpty();
    _builder_1.append("    ");
    _builder_1.append("details: ");
    String _detail = it.getDetail();
    _builder_1.append(_detail, "    ");
    _builder_1.newLineIfNotEmpty();
    _builder_1.append("    ");
    _builder_1.append("deprecated: ");
    Boolean _deprecated = it.getDeprecated();
    _builder_1.append(_deprecated, "    ");
    _builder_1.newLineIfNotEmpty();
    {
      boolean _isNullOrEmpty = IterableExtensions.isNullOrEmpty(it.getChildren());
      boolean _not = (!_isNullOrEmpty);
      if (_not) {
        _builder_1.append("    ");
        _builder_1.append("children: [");
        _builder_1.newLine();
        _builder_1.append("    ");
        _builder_1.append("\t");
        {
          List<DocumentSymbol> _children = it.getChildren();
          boolean _hasElements = false;
          for(final DocumentSymbol child : _children) {
            if (!_hasElements) {
              _hasElements = true;
            } else {
              _builder_1.appendImmediate("\n", "    \t");
            }
            String _expectation_2 = this.toExpectation(child);
            _builder_1.append(_expectation_2, "    \t");
          }
        }
        _builder_1.newLineIfNotEmpty();
        _builder_1.append("    ");
        _builder_1.append("]");
        _builder_1.newLine();
      }
    }
    _builder_1.append("}");
    _xblockexpression = _builder_1.toString();
  }
  return _xblockexpression;
}