Java Code Examples for com.intellij.util.SmartList#toArray()
The following examples show how to use
com.intellij.util.SmartList#toArray() .
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: ExtractMethodPanel.java From IntelliJDeodorant with MIT License | 6 votes |
/** * Checks that the slice can be extracted into a separate method without compilation errors. */ private boolean canBeExtracted(ASTSlice slice) { SmartList<PsiStatement> statementsToExtract = getStatementsToExtract(slice); MyExtractMethodProcessor processor = new MyExtractMethodProcessor(scope.getProject(), null, statementsToExtract.toArray(new PsiElement[0]), slice.getLocalVariableCriterion().getType(), IntelliJDeodorantBundle.message("extract.method.refactoring.name"), "", HelpID.EXTRACT_METHOD, slice.getSourceTypeDeclaration(), slice.getLocalVariableCriterion()); processor.setOutputVariable(); try { processor.setShowErrorDialogs(false); return processor.prepare(); } catch (PrepareFailedException e) { e.printStackTrace(); } return false; }
Example 2
Source File: ExtractMethodPanel.java From IntelliJDeodorant with MIT License | 5 votes |
/** * Extracts statements into new method. * * @param slice computation slice. * @return callback to run when "Refactor" button is selected. */ private Runnable doExtract(ASTSlice slice) { return () -> { Editor editor = FileEditorManager.getInstance(slice.getSourceMethodDeclaration().getProject()).getSelectedTextEditor(); SmartList<PsiStatement> statementsToExtract = getStatementsToExtract(slice); MyExtractMethodProcessor processor = new MyExtractMethodProcessor(slice.getSourceMethodDeclaration().getProject(), editor, statementsToExtract.toArray(new PsiElement[0]), slice.getLocalVariableCriterion().getType(), "", "", HelpID.EXTRACT_METHOD, slice.getSourceTypeDeclaration(), slice.getLocalVariableCriterion()); processor.setOutputVariable(); try { processor.setShowErrorDialogs(true); if (processor.prepare()) { ExtractMethodHandler.invokeOnElements(slice.getSourceMethodDeclaration().getProject(), processor, slice.getSourceMethodDeclaration().getContainingFile(), true); if (editor != null && processor.getExtractedMethod() != null) { IntelliJDeodorantCounterCollector.getInstance().extractMethodRefactoringApplied(editor.getProject(), slice, processor.getExtractedMethod()); } } } catch (PrepareFailedException e) { e.printStackTrace(); } }; }
Example 3
Source File: FilenameIndex.java From consulo with Apache License 2.0 | 5 votes |
@Nonnull public static PsiFileSystemItem[] getFilesByName(@Nonnull Project project, @Nonnull String name, @Nonnull final GlobalSearchScope scope, boolean directories) { SmartList<PsiFileSystemItem> result = new SmartList<>(); Processor<PsiFileSystemItem> processor = Processors.cancelableCollectProcessor(result); processFilesByName(name, directories, processor, scope, project, null); if (directories) { return result.toArray(new PsiFileSystemItem[0]); } //noinspection SuspiciousToArrayCall return result.toArray(PsiFile.EMPTY_ARRAY); }
Example 4
Source File: DuplicatesInspectionBase.java From consulo with Apache License 2.0 | 4 votes |
@Nullable @Override public ProblemDescriptor[] checkFile(@Nonnull final PsiFile psiFile, @Nonnull final InspectionManager manager, final boolean isOnTheFly) { final VirtualFile virtualFile = psiFile.getVirtualFile(); if (!(virtualFile instanceof VirtualFileWithId) || /*!isOnTheFly || */!DuplicatesIndex.ourEnabled) return ProblemDescriptor.EMPTY_ARRAY; final DuplicatesProfile profile = DuplicatesIndex.findDuplicatesProfile(psiFile.getFileType()); if (profile == null) return ProblemDescriptor.EMPTY_ARRAY; final FileASTNode node = psiFile.getNode(); boolean usingLightProfile = profile instanceof LightDuplicateProfile && node.getElementType() instanceof ILightStubFileElementType && DuplicatesIndex.ourEnabledLightProfiles; final Project project = psiFile.getProject(); DuplicatedCodeProcessor<?> processor; if (usingLightProfile) { processor = processLightDuplicates(node, virtualFile, (LightDuplicateProfile)profile, project); } else { processor = processPsiDuplicates(psiFile, virtualFile, profile, project); } if (processor == null) return null; final SmartList<ProblemDescriptor> descriptors = new SmartList<>(); final VirtualFile baseDir = project.getBaseDir(); for (Map.Entry<Integer, TextRange> entry : processor.reportedRanges.entrySet()) { final Integer offset = entry.getKey(); if (!usingLightProfile && processor.fragmentSize.get(offset) < MIN_FRAGMENT_SIZE) continue; final VirtualFile file = processor.reportedFiles.get(offset); String path = null; if (file.equals(virtualFile)) { path = "this file"; } else if (baseDir != null) { path = VfsUtilCore.getRelativePath(file, baseDir); } if (path == null) { path = file.getPath(); } String message = "Found duplicated code in " + path; PsiElement targetElement = processor.reportedPsi.get(offset); TextRange rangeInElement = entry.getValue(); final int offsetInOtherFile = processor.reportedOffsetInOtherFiles.get(offset); LocalQuickFix fix = isOnTheFly ? createNavigateToDupeFix(file, offsetInOtherFile) : null; long hash = processor.fragmentHash.get(offset); int hash2 = (int)(hash >> 32); LocalQuickFix viewAllDupesFix = isOnTheFly && hash != 0 ? createShowOtherDupesFix(virtualFile, offset, (int)hash, hash2) : null; boolean onlyExtractable = Registry.is("duplicates.inspection.only.extractable"); LocalQuickFix extractMethodFix = (isOnTheFly || onlyExtractable) && hash != 0 ? createExtractMethodFix(targetElement, rangeInElement, (int)hash, hash2) : null; if (onlyExtractable) { if (extractMethodFix == null) return null; if (!isOnTheFly) extractMethodFix = null; } ProblemDescriptor descriptor = manager .createProblemDescriptor(targetElement, rangeInElement, message, ProblemHighlightType.GENERIC_ERROR_OR_WARNING, isOnTheFly, fix, viewAllDupesFix, extractMethodFix); descriptors.add(descriptor); } return descriptors.isEmpty() ? null : descriptors.toArray(ProblemDescriptor.EMPTY_ARRAY); }