@Override public int getTextOffset() { PsiElement identifier = getIdentifier(); return identifier != null ? identifier.getTextOffset() : super.getTextOffset(); }
/** * Returns the offset in the file to which the caret should be placed * when performing the navigation to the element. (For classes implementing * {@link PsiNamedElement}, this should return the offset in the file of the * name identifier.) * * @return the offset of the PSI element. */ @Override public int getTextOffset() { PsiElement mirror = getMirror(); int textOffset = -1; if (mirror != null) { textOffset = mirror.getTextOffset(); } return textOffset; }
@Override public int getTextOffset() { PsiElement identifier = getIdentifier(); return identifier != null ? identifier.getTextOffset() : super.getTextOffset(); }
@Override public int getTextOffset() { PsiElement nameIdentifier = getNameIdentifier(); return nameIdentifier != null ? nameIdentifier.getTextOffset() : super.getTextOffset(); } }
private void addMarker(@NotNull Collection<LineMarkerInfo> result, @NotNull Set<Integer> lines, @NotNull PsiElement definition, @NotNull PsiElement implementation) { // Get the document manager; PsiDocumentManager documentManager = PsiDocumentManager.getInstance(definition.getProject()); // Get the document. Document document = documentManager.getDocument(implementation.getContainingFile()); if (document == null) { return; } // Get the offset of the current element. int textOffset = implementation.getTextOffset(); // Get the line number of the current element. int lineNumber = document.getLineNumber(textOffset); if (!lines.contains(lineNumber)) { // Add the number to the set. lines.add(lineNumber); // Return a new line marker. result.add(new BallerinaImplementedFunctionMarkerInfo(definition, implementation)); result.add(new BallerinaImplementingFunctionMarkerInfo(implementation, definition)); } }
/** * Handles QuickFix action invoked on {@link IgnoreSyntax}. * * @param project the {@link Project} containing the working file * @param file the {@link PsiFile} containing handled entry * @param startElement the {@link IgnoreSyntax} that will be selected and replaced * @param endElement the {@link PsiElement} which is ignored in invoked action */ @Override public void invoke(@NotNull Project project, @NotNull PsiFile file, @Nullable("is null when called from inspection") Editor editor, @NotNull PsiElement startElement, @NotNull PsiElement endElement) { if (startElement instanceof IgnoreSyntax) { PsiElement value = ((IgnoreSyntax) startElement).getValue(); if (editor != null) { editor.getSelectionModel().setSelection( value.getTextOffset(), value.getTextOffset() + value.getTextLength() ); } new CodeCompletionHandlerBase(CompletionType.BASIC).invokeCompletion(project, editor); } }
@Override public void collectSlowLineMarkers(@NotNull List<PsiElement> elements, @NotNull Collection<LineMarkerInfo> result) { Set<Integer> lines = ContainerUtil.newHashSet(); for (PsiElement element : elements) { if (element instanceof GoCallExpr) { PsiElement resolve = GoPsiImplUtil.resolveCall((GoCallExpr)element); if (resolve instanceof GoFunctionOrMethodDeclaration) { if (isRecursiveCall(element, (GoFunctionOrMethodDeclaration)resolve)) { PsiDocumentManager instance = PsiDocumentManager.getInstance(element.getProject()); Document document = instance.getDocument(element.getContainingFile()); int textOffset = element.getTextOffset(); if (document == null) continue; int lineNumber = document.getLineNumber(textOffset); if (!lines.contains(lineNumber)) { result.add(new RecursiveMethodCallMarkerInfo(element)); } lines.add(lineNumber); } } } } }
@Nullable private XSourcePosition findPosition() { XDebugSession debugSession = getSession(); if (debugSession == null) return null; XStackFrame stackFrame = debugSession.getCurrentStackFrame(); if (stackFrame == null) return null; Project project = debugSession.getProject(); XSourcePosition position = debugSession.getCurrentPosition(); Editor editor = ((FileEditorManagerImpl)FileEditorManager.getInstance(project)).getSelectedTextEditor(true); if (editor == null || position == null) return null; String name = myName.startsWith("&") ? myName.replaceFirst("\\&", "") : myName; PsiElement resolved = findTargetElement(project, position, editor, name); if (resolved == null) return null; VirtualFile virtualFile = resolved.getContainingFile().getVirtualFile(); return XDebuggerUtil.getInstance().createPositionByOffset(virtualFile, resolved.getTextOffset()); } });
/** * Returns the start offset of the code construct which owns the opening structural brace at the specified offset. * For example, if the opening brace belongs to an 'if' statement, returns the start offset of the 'if' statement. * This is used for the scope highlighting. * * @param file the file in which brace matching is performed. * @param openingBraceOffset the offset of an opening structural brace. * @return the offset of corresponding code construct, or the same offset if not defined. */ @Override public int getCodeConstructStart(PsiFile file, int openingBraceOffset) { int offset = openingBraceOffset; PsiElement element = file.findElementAt(openingBraceOffset); if (element != null) { PsiElement parent = element.getParent(); if (parent instanceof ElixirDoBlock) { PsiElement grandParent = parent.getParent(); if (grandParent instanceof Call) { offset = grandParent.getTextOffset(); } } } return offset; }
private static void addNavigationElements(@NotNull TreeElement root, @NotNull TIntArrayList navigationOffsets, boolean start) { if (root instanceof PsiTreeElementBase) { PsiElement element = ((PsiTreeElementBase)root).getValue(); int offset; if (start) { offset = element.getTextRange().getStartOffset(); if (element.getLanguage().getID().equals("JAVA")) { // HACK: for Java classes and methods, we want to jump to the opening brace int textOffset = element.getTextOffset(); int braceIndex = element.getText().indexOf('{', textOffset - offset); if (braceIndex >= 0) { offset += braceIndex; } } } else { offset = element.getTextRange().getEndOffset() - 1; } if (!navigationOffsets.contains(offset)) { navigationOffsets.add(offset); } } for (TreeElement child : root.getChildren()) { addNavigationElements(child, navigationOffsets, start); } }
@Nullable private XSourcePosition findPosition() { XDebugSession debugSession = myProcess.getSession(); if (debugSession == null) { return null; } XStackFrame stackFrame = debugSession.getCurrentStackFrame(); if (stackFrame == null) { return null; } Project project = debugSession.getProject(); XSourcePosition position = debugSession.getCurrentPosition(); Editor editor = ((FileEditorManagerImpl) FileEditorManager.getInstance(project)) .getSelectedTextEditor(true); if (editor == null || position == null) { return null; } String name = myName.startsWith("&") ? myName.replaceFirst("\\&", "") : myName; PsiElement resolved = findTargetElement(project, position, editor, name); if (resolved == null) { return null; } VirtualFile virtualFile = resolved.getContainingFile().getVirtualFile(); return XDebuggerUtil.getInstance().createPositionByOffset(virtualFile, resolved.getTextOffset()); } });
GoSignature signature = ((GoNamedSignatureOwner)parent).getSignature(); if (signature != null) { int nameStartOffset = parent.getTextOffset(); result.add(TextRange.create(nameStartOffset, signature.getParameters().getTextRange().getEndOffset())); result.add(TextRange.create(nameStartOffset, signature.getTextRange().getEndOffset()));
private boolean execute(@NotNull Call call) { for (String resolvedFunctionName : RESOLVED_FUNCTION_NAMES) { if (call.isCalling(KERNEL, resolvedFunctionName)) { if (isFirstInGroup(call, KERNEL, resolvedFunctionName)) { Call last = lastInGroup(call, KERNEL, resolvedFunctionName); PsiElement[] finalArguments = finalArguments(call); if (finalArguments != null && finalArguments.length >= 1) { TextRange textRange = new TextRange( finalArguments[0].getTextOffset(), last.getTextRange().getEndOffset() ); foldingDescriptorList.add( new NamedFoldingDescriptor( call.getParent().getNode(), textRange, null, "..." ) ); } } } } return true; }
/** * Return element range which contains TextRange(start, end) of top level elements * common parent of elements is straight parent for each element */ @Nullable private static Couple<PsiElement> getTopmostElementRange(@NotNull Couple<PsiElement> elementRange, @NotNull PsiElement commonParent) { if (elementRange.first == null || elementRange.second == null) return null; int start = elementRange.first.getTextOffset(); int end = elementRange.second.getTextRange().getEndOffset(); TextRange range = commonParent.getTextRange(); PsiElement[] children = commonParent.getChildren(); if (commonParent.isEquivalentTo(elementRange.first) || commonParent.isEquivalentTo(elementRange.second) || range.getStartOffset() == start && (children.length == 0 || children[0].getTextRange().getStartOffset() > start) || range.getEndOffset() == end && (children.length == 0 || children[children.length - 1].getTextRange().getEndOffset() < end)) { return Couple.of(commonParent, commonParent); } PsiElement startElement = elementRange.first; PsiElement endElement = elementRange.second; for (PsiElement element : children) { range = element.getTextRange(); if (range.contains(start) && !range.contains(end)) { startElement = element; } if (range.contains(end - 1) && !range.contains(start - 1)) { endElement = element; } } return startElement.getParent().isEquivalentTo(endElement.getParent()) ? Couple.of(startElement, endElement) : null; }
nextSiblingAndSkip.getTextOffset(), nextSiblingOfType.getTextOffset() + 1 );
String substring = psiFile.getText().substring(pair.getSecond().getTextRange().getEndOffset(), endBlock.getTextOffset()).trim();
int cursorOffsetClean = cursorOffset - psiElement.getTextOffset(); if(cursorOffsetClean < 1) { return;
public void assertAtTextCompletionContains(String findByText, String... lookupStrings) { final PsiElement element = myFixture.findElementByText(findByText, PsiElement.class); assert element != null : "No element found by text: " + findByText; myFixture.getEditor().getCaretModel().moveToOffset(element.getTextOffset() + 1); myFixture.completeBasic(); checkContainsCompletion(lookupStrings); }
@Override public void apply(@NotNull Editor editor, @NotNull MathematicaSmartEnter processor, @NotNull PsiElement element) throws IncorrectOperationException { Document doc = editor.getDocument(); final CaretModel caretModel = editor.getCaretModel(); if (element instanceof PsiComment && !PsiTreeUtil.hasErrorElements(element)) { int endOffset = element.getTextOffset() + element.getTextLength(); doc.insertString(endOffset, "\n(* *)"); caretModel.moveToOffset(endOffset + 4); processor.commit(editor); } } }
public static int getElementEndLineNumber(PsiElement element) { FileViewProvider fileViewProvider = element.getContainingFile().getViewProvider(); if (fileViewProvider.getDocument() != null) { return fileViewProvider.getDocument().getLineNumber(element.getTextOffset() + element.getTextLength()) + 1; } return 0; }