com.intellij.openapi.util.text.CharFilter Java Examples

The following examples show how to use com.intellij.openapi.util.text.CharFilter. 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: PantsCompletionTestBase.java    From intellij-pants-plugin with Apache License 2.0 6 votes vote down vote up
protected void doTestVariantsInner(String fileName) throws Throwable {
  final VirtualFile virtualFile = myFixture.copyFileToProject(fileName);
  final Scanner in = new Scanner(virtualFile.getInputStream());

  final CompletionType type = CompletionType.valueOf(in.next());
  final int count = in.nextInt();
  final CheckType checkType = CheckType.valueOf(in.next());

  final List<String> variants = new ArrayList<>();
  while (in.hasNext()) {
    final String variant = StringUtil.strip(in.next(), CharFilter.NOT_WHITESPACE_FILTER);
    if (variant.length() > 0) {
      variants.add(variant);
    }
  }

  myFixture.complete(type, count);
  checkCompletion(checkType, variants);
}
 
Example #2
Source File: HaxeCompletionTestBase.java    From intellij-haxe with Apache License 2.0 6 votes vote down vote up
protected void doTestVariantsInner(String fileName) throws Throwable {
  final VirtualFile virtualFile = myFixture.copyFileToProject(fileName);
  final Scanner in = new Scanner(virtualFile.getInputStream());

  final CompletionType type = CompletionType.valueOf(in.next());
  final int count = in.nextInt();
  final CheckType checkType = CheckType.valueOf(in.next());

  final List<String> variants = new ArrayList<String>();
  while (in.hasNext()) {
    final String variant = StringUtil.strip(in.next(), CharFilter.WHITESPACE_FILTER);
    if (variant.length() > 0) {
      variants.add(variant);
    }
  }

  myFixture.complete(type, count);
  checkCompletion(checkType, variants);
}
 
Example #3
Source File: ThriftCompletionTestBase.java    From intellij-thrift with Apache License 2.0 6 votes vote down vote up
protected void doTestVariantsInner(String fileName) throws Throwable {
  final VirtualFile virtualFile = myFixture.copyFileToProject(fileName);
  final Scanner in = new Scanner(virtualFile.getInputStream());

  final CompletionType type = CompletionType.valueOf(in.next());
  final int count = in.nextInt();
  final CheckType checkType = CheckType.valueOf(in.next());

  final List<String> variants = new ArrayList<String>();
  while (in.hasNext()) {
    final String variant = StringUtil.strip(in.next(), CharFilter.NOT_WHITESPACE_FILTER);
    if (variant.length() > 0) {
      variants.add(variant);
    }
  }

  myFixture.complete(type, count);
  checkCompletion(checkType, variants);
}
 
Example #4
Source File: CSharpUsingNamespaceStatementImpl.java    From consulo-csharp with Apache License 2.0 5 votes vote down vote up
@RequiredReadAction
@Override
@Nullable
public String getReferenceText()
{
	CSharpWithStringValueStub<CSharpUsingNamespaceStatement> stub = getGreenStub();
	if(stub != null)
	{
		return stub.getReferenceText();
	}

	DotNetReferenceExpression namespaceReference = getNamespaceReference();
	return namespaceReference == null ? null : StringUtil.strip(namespaceReference.getText(), CharFilter.NOT_WHITESPACE_FILTER);
}
 
Example #5
Source File: ParagraphFillHandler.java    From consulo with Apache License 2.0 5 votes vote down vote up
private int getStartOffset(@Nonnull final PsiElement element, @Nonnull final Editor editor) {
  if (isBunchOfElement(element)) {
    final PsiElement firstElement = getFirstElement(element);
    return firstElement != null? firstElement.getTextRange().getStartOffset()
                               : element.getTextRange().getStartOffset();
  }
  final int offset = editor.getCaretModel().getOffset();
  final int elementTextOffset = element.getTextOffset();
  final Document document = editor.getDocument();
  int lineNumber = document.getLineNumber(offset);

  while (lineNumber != document.getLineNumber(elementTextOffset)) {
    final String text = document.getText(TextRange.create(document.getLineStartOffset(lineNumber),
                                                          document.getLineEndOffset(lineNumber)));
    if (StringUtil.isEmptyOrSpaces(text)) {
      lineNumber += 1;
      break;
    }
    lineNumber -= 1;
  }
  final int lineStartOffset = lineNumber == document.getLineNumber(elementTextOffset) ? elementTextOffset : document.getLineStartOffset(lineNumber);
  final String lineText = document
          .getText(TextRange.create(lineStartOffset, document.getLineEndOffset(lineNumber)));
  int shift = StringUtil.findFirst(lineText, CharFilter.NOT_WHITESPACE_FILTER);

  return lineStartOffset + shift;
}