Tabnine Logo
JsonRpcHelpers
Code IndexAdd Tabnine to your IDE (free)

How to use
JsonRpcHelpers
in
org.eclipse.jdt.ls.core.internal.handlers

Best Java code snippets using org.eclipse.jdt.ls.core.internal.handlers.JsonRpcHelpers (Showing top 20 results out of 315)

origin: eclipse/eclipse.jdt.ls

/**
 * Convert line, column to a document offset.
 * @param buffer
 * @param line
 * @param column
 * @return
 */
public static int toOffset(IBuffer buffer, int line, int column){
  if (buffer != null) {
    return toOffset(toDocument(buffer), line, column);
  }
  return -1;
}
origin: eclipse/eclipse.jdt.ls

/**
 * Convert offset to line number and column.
 * @param buffer
 * @param line
 * @param column
 * @return
 */
public static int[] toLine(IBuffer buffer, int offset){
  return toLine(toDocument(buffer), offset);
}
origin: eclipse/eclipse.jdt.ls

private List<DocumentHighlight> computeOccurrences(ITypeRoot unit, int line, int column, IProgressMonitor monitor) {
  if (unit != null) {
    try {
      int offset = JsonRpcHelpers.toOffset(unit.getBuffer(), line, column);
      OccurrencesFinder finder = new OccurrencesFinder();
      CompilationUnit ast = CoreASTProvider.getInstance().getAST(unit, CoreASTProvider.WAIT_YES, monitor);
      if (ast != null) {
        String error = finder.initialize(ast, offset, 0);
        if (error == null){
          List<DocumentHighlight> result = new ArrayList<>();
          OccurrenceLocation[] occurrences = finder.getOccurrences();
          if (occurrences != null) {
            for (OccurrenceLocation loc : occurrences) {
              if (monitor.isCanceled()) {
                return Collections.emptyList();
              }
              result.add(convertToHighlight(unit, loc));
            }
          }
          return result;
        }
      }
    } catch (JavaModelException e) {
      JavaLanguageServerPlugin.logException("Problem with compute occurrences for" + unit.getElementName(), e);
    }
  }
  return Collections.emptyList();
}
origin: eclipse/eclipse.jdt.ls

public List<HighlightedPositionCore> calculateHighlightedPositions(ICompilationUnit unit, boolean cache) throws JavaModelException, BadPositionCategoryException {
  if (enabled.get()) {
    IDocument document = JsonRpcHelpers.toDocument(unit.getBuffer());
    ASTNode ast = getASTNode(unit);
    List<HighlightedPositionCore> positions = calculateHighlightedPositions(document, ast);
    if (cache) {
      String uri = JDTUtils.getFileURI(unit.getResource());
      this.cache.put(uri, positions);
    }
    return ImmutableList.copyOf(positions);
  }
  return emptyList();
}
origin: eclipse/eclipse.jdt.ls

protected int[] getLineAndColumn(IDocument document, HighlightedPositionCore position) {
  //@formatter:off
  int[] lineAndColumn = JsonRpcHelpers.toLine(document, position.offset);
  Assert.isNotNull(
      lineAndColumn,
      "Cannot retrieve the line and column information for document. Position was: " + position + " Document was:>" + document.get() + "<."
      );
  return lineAndColumn;
  //@formatter:off
}
origin: eclipse/eclipse.jdt.ls

/**
 * Gets the end offset for the diagnostic.
 *
 * @param unit
 * @param range
 * @return starting offset or negative value if can not be determined
 */
public static int getEndOffset(ICompilationUnit unit, Range range){
  try {
    return JsonRpcHelpers.toOffset(unit.getBuffer(), range.getEnd().getLine(), range.getEnd().getCharacter());
  } catch (JavaModelException e) {
    return -1;
  }
}
origin: eclipse/eclipse.jdt.ls

public List<Position> install(ICompilationUnit unit) throws JavaModelException, BadPositionCategoryException {
  if (enabled.get()) {
    List<HighlightedPositionCore> positions = calculateHighlightedPositions(unit, false);
    String uri = JDTUtils.getFileURI(unit.getResource());
    this.cache.put(uri, positions);
    if (!positions.isEmpty()) {
      IDocument document = JsonRpcHelpers.toDocument(unit.getBuffer());
      List<SemanticHighlightingInformation> infos = toInfos(document, positions);
      VersionedTextDocumentIdentifier textDocument = new VersionedTextDocumentIdentifier(uri, 1);
      notifyClient(textDocument, infos);
    }
    return ImmutableList.copyOf(positions);
  }
  return emptyList();
}
origin: eclipse/eclipse.jdt.ls

protected List<SemanticHighlightingInformation> toInfos(IDocument document, List<HighlightedPositionCore> positions) {
  Multimap<Integer, SemanticHighlightingTokens.Token> infos = HashMultimap.create();
  for (HighlightedPositionCore position : positions) {
    int[] lineAndColumn = JsonRpcHelpers.toLine(document, position.offset);
    if (lineAndColumn == null) {
      JavaLanguageServerPlugin.logError("Cannot locate line and column information for the semantic highlighting position: " + position + ". Skipping it.");
      continue;
    }
    int line = lineAndColumn[0];
    int character = lineAndColumn[1];
    int length = position.length;
    int scope = LOOKUP_TABLE.inverse().get(position.getHighlighting());
    infos.put(line, new SemanticHighlightingTokens.Token(character, length, scope));
  }
  //@formatter:off
  return infos.asMap().entrySet().stream()
    .map(entry -> new SemanticHighlightingInformation(entry.getKey(), SemanticHighlightingTokens.encode(entry.getValue())))
    .collect(Collectors.toList());
  //@formatter:on
}
origin: eclipse/eclipse.jdt.ls

/**
 * Gets the start offset for the diagnostic.
 *
 * @param unit
 * @param range
 * @return starting offset or negative value if can not be determined
 */
public static int getStartOffset(ICompilationUnit unit, Range range){
  try {
    return JsonRpcHelpers.toOffset(unit.getBuffer(), range.getStart().getLine(), range.getStart().getCharacter());
  } catch (JavaModelException e) {
    return -1;
  }
}
/**
origin: eclipse/eclipse.jdt.ls

int startOffset = JsonRpcHelpers.toOffset(unit.getBuffer(), range.getStart().getLine(), range.getStart().getCharacter());
  IDocument newState = JsonRpcHelpers.toDocument(unit.getBuffer());
  diffContexts.add(new HighlightedPositionDiffContext(oldState, event, oldPositions, newPositions));
} else {
  IDocument document = JsonRpcHelpers.toDocument(unit.getBuffer());
  edit.apply(document, TextEdit.NONE);
origin: eclipse/eclipse.jdt.ls

/**
 * @param completionBuffer
 * @param proposal
 */
private void appendMethodPotentialReplacement(StringBuilder completionBuffer, GetterSetterCompletionProposal proposal) {
  IDocument document;
  try {
    document = JsonRpcHelpers.toDocument(this.compilationUnit.getBuffer());
    int offset = proposal.getReplaceStart();
    String replacement = proposal.updateReplacementString(document, offset, importRewrite,
        client.isCompletionSnippetsSupported());
    completionBuffer.append(replacement);
  } catch (BadLocationException | CoreException e) {
    JavaLanguageServerPlugin.logException("Failed to compute potential replacement", e);
  }
}
origin: eclipse/eclipse.jdt.ls

/**
 * Creates a range for the given offset and length for an {@link IOpenable}
 *
 * @param openable
 * @param offset
 * @param length
 * @return
 * @throws JavaModelException
 */
public static Range toRange(IOpenable openable, int offset, int length) throws JavaModelException{
  Range range = newRange();
  if (offset > 0 || length > 0) {
    int[] loc = null;
    int[] endLoc = null;
    IBuffer buffer = openable.getBuffer();
    if (buffer != null) {
      loc = JsonRpcHelpers.toLine(buffer, offset);
      endLoc = JsonRpcHelpers.toLine(buffer, offset + length);
    }
    if (loc == null) {
      loc = new int[2];
    }
    if (endLoc == null) {
      endLoc = new int[2];
    }
    setPosition(range.getStart(), loc);
    setPosition(range.getEnd(), endLoc);
  }
  return range;
}
origin: Microsoft/java-debug

IType type = resolveType(frame);
if (type != null && type.getCompilationUnit() != null) {
  final int offset = JsonRpcHelpers.toOffset(type.getCompilationUnit().getBuffer(), frame.location().lineNumber(), 0);
  CompletionProposalRequestor collector = new CompletionProposalRequestor(type.getCompilationUnit(), offset);
origin: eclipse/eclipse.jdt.ls

/**
 * @param completionBuffer
 * @param proposal
 */
private void appendMethodOverrideReplacement(StringBuilder completionBuffer, CompletionProposal proposal) {
  IDocument document;
  try {
    document = JsonRpcHelpers.toDocument(this.compilationUnit.getBuffer());
    String signature = String.valueOf(proposal.getSignature());
    String[] types = Stream.of(Signature.getParameterTypes(signature)).map(t -> Signature.toString(t))
        .toArray(String[]::new);
    String methodName = String.valueOf(proposal.getName());
    int offset = proposal.getReplaceStart();
    String completion = new String(proposal.getCompletion());
    OverrideCompletionProposal overrider = new OverrideCompletionProposal(compilationUnit, methodName, types,
        completion);
    String replacement = overrider.updateReplacementString(document, offset, importRewrite,
        client.isCompletionSnippetsSupported());
    completionBuffer.append(replacement);
  } catch (BadLocationException | CoreException e) {
    JavaLanguageServerPlugin.logException("Failed to compute override replacement", e);
  }
}
origin: eclipse/eclipse.jdt.ls

private DocumentHighlight convertToHighlight(ITypeRoot unit, OccurrenceLocation occurrence)
    throws JavaModelException {
  DocumentHighlight h = new DocumentHighlight();
  if ((occurrence.getFlags() | IOccurrencesFinder.F_WRITE_OCCURRENCE) == IOccurrencesFinder.F_WRITE_OCCURRENCE) {
    h.setKind(DocumentHighlightKind.Write);
  } else if ((occurrence.getFlags()
      | IOccurrencesFinder.F_READ_OCCURRENCE) == IOccurrencesFinder.F_READ_OCCURRENCE) {
    h.setKind(DocumentHighlightKind.Read);
  }
  int[] loc = JsonRpcHelpers.toLine(unit.getBuffer(), occurrence.getOffset());
  int[] endLoc = JsonRpcHelpers.toLine(unit.getBuffer(), occurrence.getOffset() + occurrence.getLength());
  h.setRange(new Range(
      new Position(loc[0], loc[1]),
      new Position(endLoc[0],endLoc[1])
      ));
  return h;
}
origin: eclipse/eclipse.jdt.ls

  return null;
int offset = JsonRpcHelpers.toOffset(unit.getBuffer(), line, column);
if (offset > -1) {
  return unit.codeSelect(offset, 0);
origin: eclipse/eclipse.jdt.ls

private int getOffset(TextDocumentPositionParams param, ITypeRoot typeRoot) {
  int offset = 0;
  try {
    IDocument document = JsonRpcHelpers.toDocument(typeRoot.getBuffer());
    offset = document.getLineOffset(param.getPosition().getLine()) + param.getPosition().getCharacter();
  } catch (JavaModelException | BadLocationException e) {
    JavaLanguageServerPlugin.logException(e.getMessage(), e);
  }
  return offset;
}
origin: eclipse/eclipse.jdt.ls

final int offset = JsonRpcHelpers.toOffset(unit.getBuffer(), line, column);
CompletionProposalRequestor collector = new CompletionProposalRequestor(unit, offset);
origin: eclipse/eclipse.jdt.ls

private List<? extends org.eclipse.lsp4j.TextEdit> format(String uri, FormattingOptions options, Position position, String triggerChar, IProgressMonitor monitor) {
  if (!preferenceManager.getPreferences().isJavaFormatOnTypeEnabled()) {
    return Collections.emptyList();
  }
  ICompilationUnit cu = JDTUtils.resolveCompilationUnit(uri);
  if (cu == null) {
    return Collections.emptyList();
  }
  IRegion region = null;
  IDocument document = null;
  try {
    document = JsonRpcHelpers.toDocument(cu.getBuffer());
    if (document != null && position != null) {
      region = getRegion(cu, document, position, triggerChar);
    }
  } catch (JavaModelException e) {
    JavaLanguageServerPlugin.logException(e.getMessage(), e);
  }
  if (region == null) {
    return Collections.emptyList();
  }
  return format(cu, document, region, options, false, monitor);
}
origin: eclipse/eclipse.jdt.ls

final int offset = JsonRpcHelpers.toOffset(unit.getBuffer(), position.getPosition().getLine(), position.getPosition().getCharacter());
int[] contextInfomation = getContextInfomation(unit.getBuffer(), offset);
if (contextInfomation[0] == -1) {
org.eclipse.jdt.ls.core.internal.handlersJsonRpcHelpers

Most used methods

  • toOffset
    Convert line, column to a document offset.
  • toDocument
    Returns an IDocument for the given buffer. The implementation tries to avoid copying the buffer unle
  • toLine
    Convert the document offset to line number and column.

Popular in Java

  • Start an intent from android
  • getApplicationContext (Context)
  • onRequestPermissionsResult (Fragment)
  • getSystemService (Context)
  • VirtualMachine (com.sun.tools.attach)
    A Java virtual machine. A VirtualMachine represents a Java virtual machine to which this Java vir
  • Font (java.awt)
    The Font class represents fonts, which are used to render text in a visible way. A font provides the
  • GregorianCalendar (java.util)
    GregorianCalendar is a concrete subclass of Calendarand provides the standard calendar used by most
  • Semaphore (java.util.concurrent)
    A counting semaphore. Conceptually, a semaphore maintains a set of permits. Each #acquire blocks if
  • JTable (javax.swing)
  • Location (org.springframework.beans.factory.parsing)
    Class that models an arbitrary location in a Resource.Typically used to track the location of proble
  • Best plugins for Eclipse
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now