protected GoCachedReference(@NotNull T element) { super(element, TextRange.from(0, element.getTextLength())); }
public BallerinaCachedReference(@NotNull T element) { super(element, TextRange.from(0, element.getTextLength())); IGNORED_DIRECTORIES.add("resources"); IGNORED_DIRECTORIES.add("tests"); }
public GoReference(@NotNull GoReferenceExpressionBase o) { super(o, TextRange.from(o.getIdentifier().getStartOffsetInParent(), o.getIdentifier().getTextLength())); }
public GoTypeReference(@NotNull GoTypeReferenceExpression o) { super(o, TextRange.from(o.getIdentifier().getStartOffsetInParent(), o.getIdentifier().getTextLength())); myInsideInterfaceType = myElement.getParent() instanceof GoMethodSpec; }
/** * 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); } }
@Nullable public static PsiElement getType(@NotNull BallerinaAssignmentStatement ballerinaAssignmentStatement) { return CachedValuesManager.getCachedValue(ballerinaAssignmentStatement, () -> { PsiElement result = null; BallerinaVariableReference variableReference = ballerinaAssignmentStatement.getVariableReference(); if (variableReference != null) { PsiElement type = variableReference.getType(); if (type != null) { PsiReference reference = type.findReferenceAt(type.getTextLength()); if (reference != null) { result = reference.resolve(); } else { result = type; } } } return CachedValueProvider.Result.create(result, ballerinaAssignmentStatement); }); }
@Override public void visitFunctionDeclaration(@NotNull GoFunctionDeclaration o) { if (o.isBlank()) return; GoFile file = o.getContainingFile(); String name = o.getName(); if (!canRun(name)) return; if (GoConstants.MAIN.equals(file.getPackageName()) && GoConstants.MAIN.equals(name)) return; if (GoConstants.INIT.equals(name)) return; if (GoTestFinder.isTestFile(file) && GoTestFunctionType.fromName(name) != null) return; if (ReferencesSearch.search(o, o.getUseScope()).findFirst() == null) { PsiElement id = o.getIdentifier(); TextRange range = TextRange.from(id.getStartOffsetInParent(), id.getTextLength()); holder.registerProblem(o, "Unused function <code>#ref</code> #loc", ProblemHighlightType.LIKE_UNUSED_SYMBOL, range, new GoDeleteQuickFix("Delete function", GoFunctionDeclaration.class), new GoRenameToBlankQuickFix(o)); } } };
if (e.getTextLength() > 2) { result.add(TextRange.create(e.getTextRange().getStartOffset() + 1, e.getTextRange().getEndOffset() - 1));
return CachedValueProvider.Result.create(null, ballerinaVariableDefinitionStatement); PsiReference reference = type.findReferenceAt(type.getTextLength()); if (reference != null) { PsiElement resolvedElement = reference.resolve();
return CachedValueProvider.Result.create(result, signature); PsiReference reference = typeFromTypeName.findReferenceAt(typeFromTypeName.getTextLength()); if (reference == null) { return CachedValueProvider.Result.create(null, signature);
typeDefinition = (BallerinaTypeDefinition) type.getParent(); } else { PsiReference typeReference = type.findReferenceAt(type.getTextLength()); if (typeReference == null) { return true;
/** * Try to find a valid indent value, which are spaces which we need to fill */ public static int getIndentSpaceForFile(@NotNull YAMLFile yamlFile) { List<YAMLDocument> documents = yamlFile.getDocuments(); YAMLMapping mapping = ObjectUtils.tryCast(documents.get(0).getTopLevelValue(), YAMLMapping.class); if(mapping != null) { // first first INDENT element in mapping PsiElementPattern.Capture<PsiElement> pattern = PlatformPatterns .psiElement(YAMLTokenTypes.INDENT) .with(new PsiElementPatternCondition()); for (YAMLPsiElement yamlPsiElement : mapping.getKeyValues()) { // get first value PsiElement firstChild = yamlPsiElement.getFirstChild(); if(firstChild == null) { continue; } // first valid INDENT PsiElement nextSiblingOfType = PsiElementUtils.getNextSiblingOfType(firstChild, pattern); if(nextSiblingOfType != null && nextSiblingOfType.getTextLength() > 0) { return nextSiblingOfType.getTextLength(); } } } // default value return 4; }
@Override public PsiElement handleContentChange(@NotNull final PsiElement element, final String newContent) throws IncorrectOperationException { return handleContentChange(element, TextRange.create(0, element.getTextLength()), newContent); }
@Override public void visitElement(PsiElement element) { if (PsiUtilCore.getElementType(element) == REGEX_TOKEN) { if (!hasStarted[0]) { registrar.startInjecting(Perl5RegexpLanguage.INSTANCE); hasStarted[0] = true; } registrar.addPlace(null, null, (PsiPerlPerlRegexImpl)context, TextRange.from(sourceOffset[0], element.getTextLength())); } sourceOffset[0] += element.getTextLength(); } });
private void registerProblem(final PsiElement element, final String message) { myHolder.registerProblem( element, TextRange.from(0, element.getTextLength()), message); }
@NotNull @Override public TextRange getRangeInElement(@NotNull PsiElement element) { PsiElement firstChild = element.getFirstChild(); if (firstChild instanceof BashCharSequence) { return ((BashCharSequence) firstChild).getTextContentRange().shiftRight(firstChild.getStartOffsetInParent()); } return TextRange.from(0, element.getTextLength()); } }
@NotNull @Override public TextRange getRangeInElement(@NotNull BashCommand cmd) { final PsiElement element = cmd.commandElement(); if (element == null) { return TextRange.from(0, cmd.getTextLength()); } return TextRange.from(element.getStartOffsetInParent(), element.getTextLength()); } }
@Nullable public static TextRange rangeInParent(PsiElement parent, PsiElement child) { if (!parent.getTextRange().contains(child.getTextRange())) { return null; } return TextRange.from(child.getTextOffset() - parent.getTextOffset(), child.getTextLength()); }
private void annotateString(PsiElement bashString, final AnnotationHolder holder) { final Annotation annotation = holder.createInfoAnnotation(TextRange.from(bashString.getTextOffset(), bashString.getTextLength()), null); annotation.setTextAttributes(BashSyntaxHighlighter.STRING); highlightVariables(bashString, holder); }
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; }