@Override protected void postProcess(PsiFile createdElement, String templateName, Map<String, String> customProperties) { if (createdElement instanceof GoFile) { GoPackageClause packageClause = ((GoFile)createdElement).getPackage(); if (packageClause == null) { return; } Project project = createdElement.getProject(); Editor editor = FileEditorManager.getInstance(project).getSelectedTextEditor(); if (editor == null) { return; } VirtualFile virtualFile = createdElement.getContainingFile().getVirtualFile(); if (virtualFile == null) { return; } if (FileDocumentManager.getInstance().getDocument(virtualFile) == editor.getDocument()) { editor.getCaretModel().moveToOffset(packageClause.getTextRange().getEndOffset()); } } }
private List<ArrayField> getSecurityDefinitions() { final PsiFile containingFile = completionHelper.getPsiFile().getContainingFile(); final List<? extends PsiNamedElement> securityDefinitions = new PathFinder().findNamedChildren("$.securityDefinitions", containingFile); return securityDefinitions .stream() .map(PsiNamedElement::getName) .map(ArrayField::new) .collect(Collectors.toList()); } }
private List<ArrayField> getSecurityDefinitions() { final PsiFile containingFile = completionHelper.getPsiFile().getContainingFile(); final List<? extends PsiNamedElement> securityDefinitions = new PathFinder().findNamedChildren("$.securityDefinitions", containingFile); return securityDefinitions .stream() .map(PsiNamedElement::getName) .map(ArrayField::new) .collect(Collectors.toList()); } }
private List<Value> getSecurityDefinitionByName(final String securityDefinitionName) { final PsiFile containingFile = completionHelper.getPsiFile().getContainingFile(); final List<? extends PsiNamedElement> securityDefinitions = new PathFinder().findNamedChildren("$.securityDefinitions", containingFile); return securityDefinitions .stream() .filter( e -> securityDefinitionName.equals(completionHelper.getKeyNameOfObject(e).orElse(null))) .map(completionHelper::getSecurityScopesIfOAuth2) .flatMap(Collection::stream) .map(StringValue::new) .collect(Collectors.toList()); } }
/** * Search Twig element to find use trans_default_domain and returns given string parameter */ @Nullable public static String getTransDefaultDomainOnScopeOrInjectedElement(@NotNull PsiElement position) { if(position.getContainingFile().getContainingFile() == TwigFileType.INSTANCE) { return getTransDefaultDomainOnScope(position); } PsiElement element = getElementOnTwigViewProvider(position); if(element != null) { return getTransDefaultDomainOnScope(element); } return null; }
@Override public void fill() { getSecurityDefinitions() .forEach( field -> { final PsiFile containingFile = completionHelper.getPsiFile().getContainingFile(); final List<? extends PsiNamedElement> security = new PathFinder().findNamedChildren("$.security", containingFile); final List<String> existingNames = extractNames(security); if (!existingNames.contains(field.getName())) { addUnique(field); } }); }
@NotNull public static TextRange getLineRange(@NotNull PsiFile psiFile,Integer line) { if (line == null) return TextRange.EMPTY_RANGE; Project project = psiFile.getProject(); PsiDocumentManager documentManager = PsiDocumentManager.getInstance(project); Document document = documentManager.getDocument(psiFile.getContainingFile()); if (document == null) { return TextRange.EMPTY_RANGE; } int ijLine = line > 0 ? line-1 : 0; return getTextRangeForLine(document,ijLine); }
public static TextRange getLineRange(@NotNull PsiElement psiElement) { Project project = psiElement.getProject(); PsiDocumentManager documentManager = PsiDocumentManager.getInstance(project); Document document = documentManager.getDocument(psiElement.getContainingFile().getContainingFile()); if (document == null) { return TextRange.EMPTY_RANGE; } int line = document.getLineNumber(psiElement.getTextOffset()); int lineEndOffset = document.getLineEndOffset(line); return new TextRange(psiElement.getTextOffset(),lineEndOffset); } }