/** * Combines templates with the same name into a {@link CombinedPostfixTemplate} and returns the result. * * @param templates templates that may have name duplicates * @return (combined) templates */ private Set<PostfixTemplate> combineTemplatesWithSameName(Set<PostfixTemplate> templates) { // group templates by name Map<String, List<PostfixTemplate>> key2templates = templates.stream().collect( Collectors.groupingBy( PostfixTemplate::getKey, toList() ) ); // combine templates with the same name Set<PostfixTemplate> combinedTemplates = new OrderedSet<>(); for (List<PostfixTemplate> theseTemplates : key2templates.values()) { if (theseTemplates.size() == 1) { combinedTemplates.add(theseTemplates.get(0)); } else { String example = templates.stream().distinct().count() > 1 ? theseTemplates.get(0).getExample() : ""; combinedTemplates.add(new CombinedPostfixTemplate(theseTemplates.get(0).getKey(), example, theseTemplates)); } } return combinedTemplates; }
public static String[] getOutputPaths(Module[] modules) { final Set<String> outputPaths = new OrderedSet<String>(); for (Module module : modules) { final CompilerModuleExtension compilerModuleExtension = !module.isDisposed()? CompilerModuleExtension.getInstance(module) : null; if (compilerModuleExtension == null) { continue; } String outputPathUrl = compilerModuleExtension.getCompilerOutputUrl(); if (outputPathUrl != null) { outputPaths.add(VirtualFileManager.extractPath(outputPathUrl).replace('/', File.separatorChar)); } String outputPathForTestsUrl = compilerModuleExtension.getCompilerOutputUrlForTests(); if (outputPathForTestsUrl != null) { outputPaths.add(VirtualFileManager.extractPath(outputPathForTestsUrl).replace('/', File.separatorChar)); } } return ArrayUtil.toStringArray(outputPaths); }
private static String[] getCompilationClasses(final Module module, final GenerationOptionsImpl options, final boolean forRuntime, final boolean forTest, final boolean firstLevel) { final CompilerModuleExtension extension = CompilerModuleExtension.getInstance(module); if (extension == null) return ArrayUtil.EMPTY_STRING_ARRAY; if (!forRuntime) { if (forTest) { return extension.getOutputRootUrls(!firstLevel); } else { return firstLevel ? ArrayUtil.EMPTY_STRING_ARRAY : extension.getOutputRootUrls(false); } } final Set<String> jdkUrls = options.getAllJdkUrls(); final OrderedSet<String> urls = new OrderedSet<String>(); ContainerUtil.addAll(urls, extension.getOutputRootUrls(forTest)); urls.removeAll(jdkUrls); return ArrayUtil.toStringArray(urls); }
@NotNull public KeymapImpl copyTo(@NotNull final KeymapImpl otherKeymap) { otherKeymap.myParent = myParent; otherKeymap.myName = myName; otherKeymap.myCanModify = canModify(); otherKeymap.cleanShortcutsCache(); otherKeymap.myActionId2ListOfShortcuts.clear(); otherKeymap.myActionId2ListOfShortcuts.ensureCapacity(myActionId2ListOfShortcuts.size()); myActionId2ListOfShortcuts.forEachEntry(new TObjectObjectProcedure<String, OrderedSet<Shortcut>>() { @Override public boolean execute(String actionId, OrderedSet<Shortcut> shortcuts) { otherKeymap.myActionId2ListOfShortcuts.put(actionId, new OrderedSet<Shortcut>(shortcuts)); return true; } }); return otherKeymap; }
private void addShortcutSilently(String actionId, Shortcut shortcut, final boolean checkParentShortcut) { OrderedSet<Shortcut> list = myActionId2ListOfShortcuts.get(actionId); if (list == null) { list = new OrderedSet<Shortcut>(); myActionId2ListOfShortcuts.put(actionId, list); Shortcut[] boundShortcuts = getBoundShortcuts(actionId); if (boundShortcuts != null) { ContainerUtil.addAll(list, boundShortcuts); } else if (myParent != null) { ContainerUtil.addAll(list, getParentShortcuts(actionId)); } } list.add(shortcut); if (checkParentShortcut && myParent != null && areShortcutsEqual(getParentShortcuts(actionId), getShortcuts(actionId))) { myActionId2ListOfShortcuts.remove(actionId); } cleanShortcutsCache(); }
private <T extends Shortcut>void addAction2ShortcutsMap(final String actionId, final Map<T, List<String>> strokesMap, final Class<T> shortcutClass) { OrderedSet<Shortcut> listOfShortcuts = _getShortcuts(actionId); for (Shortcut shortcut : listOfShortcuts) { if (!shortcutClass.isAssignableFrom(shortcut.getClass())) { continue; } @SuppressWarnings({"unchecked"}) T t = (T)shortcut; List<String> listOfIds = strokesMap.get(t); if (listOfIds == null) { listOfIds = new ArrayList<String>(); strokesMap.put(t, listOfIds); } // action may have more that 1 shortcut with same first keystroke if (!listOfIds.contains(actionId)) { listOfIds.add(actionId); } } }
private void addKeystrokesMap(final String actionId, final Map<KeyStroke, List<String>> strokesMap) { OrderedSet<Shortcut> listOfShortcuts = _getShortcuts(actionId); for (Shortcut shortcut : listOfShortcuts) { if (!(shortcut instanceof KeyboardShortcut)) { continue; } KeyStroke firstKeyStroke = ((KeyboardShortcut)shortcut).getFirstKeyStroke(); List<String> listOfIds = strokesMap.get(firstKeyStroke); if (listOfIds == null) { listOfIds = new ArrayList<String>(); strokesMap.put(firstKeyStroke, listOfIds); } // action may have more that 1 shortcut with same first keystroke if (!listOfIds.contains(actionId)) { listOfIds.add(actionId); } } }
private OrderedSet<Shortcut> _getShortcuts(final String actionId) { KeymapManagerEx keymapManager = getKeymapManager(); OrderedSet<Shortcut> listOfShortcuts = myActionId2ListOfShortcuts.get(actionId); if (listOfShortcuts != null) { return listOfShortcuts; } else { listOfShortcuts = new OrderedSet<Shortcut>(); } final String actionBinding = keymapManager.getActionBinding(actionId); if (actionBinding != null) { listOfShortcuts.addAll(_getShortcuts(actionBinding)); } return listOfShortcuts; }
@NotNull @Override public Shortcut[] getShortcuts(String actionId) { OrderedSet<Shortcut> shortcuts = myActionId2ListOfShortcuts.get(actionId); if (shortcuts == null) { Shortcut[] boundShortcuts = getBoundShortcuts(actionId); if (boundShortcuts!= null) return boundShortcuts; } if (shortcuts == null) { if (myParent != null) { return getParentShortcuts(actionId); } else { return ourEmptyShortcutsArray; } } return shortcuts.isEmpty() ? ourEmptyShortcutsArray : shortcuts.toArray(new Shortcut[shortcuts.size()]); }
private static void addAnnotationsJar(@NotNull Module module, @NotNull OrderedSet<VirtualFile> libs) { Sdk sdk = ModuleRootManager.getInstance(module).getSdk(); if (sdk == null || !isAndroidSdk(sdk)) { return; } String sdkHomePath = sdk.getHomePath(); if (sdkHomePath == null) { return; } AndroidPlatform platform = AndroidPlatform.getInstance(module); if (platform != null && platform.needToAddAnnotationsJarToClasspath()) { String annotationsJarPath = toSystemIndependentName(sdkHomePath) + ANNOTATIONS_JAR_RELATIVE_PATH; VirtualFile annotationsJar = LocalFileSystem.getInstance().findFileByPath(annotationsJarPath); if (annotationsJar != null) { libs.add(annotationsJar); } } }
public static String[] getOutputPaths(Module[] modules) { final Set<String> outputPaths = new OrderedSet<String>(); for (Module module : modules) { final CompilerModuleExtension compilerModuleExtension = CompilerModuleExtension.getInstance(module); if (compilerModuleExtension == null) { continue; } String outputPathUrl = compilerModuleExtension.getCompilerOutputUrl(); if (outputPathUrl != null) { outputPaths.add(VirtualFileManager.extractPath(outputPathUrl).replace('/', File.separatorChar)); } String outputPathForTestsUrl = compilerModuleExtension.getCompilerOutputUrlForTests(); if (outputPathForTestsUrl != null) { outputPaths.add(VirtualFileManager.extractPath(outputPathForTestsUrl).replace('/', File.separatorChar)); } } return ArrayUtil.toStringArray(outputPaths); }
public void recalculateOutputDirs() { final Module[] allModules = ModuleManager.getInstance(myProject).getModules(); final Set<VirtualFile> allDirs = new OrderedSet<VirtualFile>(); final Set<VirtualFile> testOutputDirs = new java.util.HashSet<VirtualFile>(); final Set<VirtualFile> productionOutputDirs = new java.util.HashSet<VirtualFile>(); for (Module module : allModules) { final CompilerModuleExtension manager = CompilerModuleExtension.getInstance(module); final VirtualFile output = manager.getCompilerOutputPath(); if (output != null && output.isValid()) { allDirs.add(output); productionOutputDirs.add(output); } final VirtualFile testsOutput = manager.getCompilerOutputPathForTests(); if (testsOutput != null && testsOutput.isValid()) { allDirs.add(testsOutput); testOutputDirs.add(testsOutput); } } myOutputDirectories = VfsUtil.toVirtualFileArray(allDirs); // need this to ensure that the sent contains only _dedicated_ test output dirs // Directories that are configured for both test and production classes must not be added in the resulting set testOutputDirs.removeAll(productionOutputDirs); myTestOutputDirectories = Collections.unmodifiableSet(testOutputDirs); }
protected void collectAllElements(@NotNull PsiElement atCaret, @NotNull OrderedSet<PsiElement> res, boolean recurse) { res.add(0, atCaret); if (doNotStepInto(atCaret)) { if (!recurse) return; recurse = false; } PsiElement parent = atCaret.getParent(); if (atCaret instanceof GrClosableBlock && parent instanceof GrStringInjection && parent.getParent() instanceof GrString) { res.add(parent.getParent()); } if (parent instanceof GrArgumentList) { res.add(parent.getParent()); } //if (parent instanceof GrWhileStatement) { // res.add(parent); //} final PsiElement[] children = getChildren(atCaret); for (PsiElement child : children) { collectAllElements(child, res, recurse); } }
@NotNull @Override public Set<VirtualFile> getCompilationClasspath(@NotNull CompileContext compileContext, @NotNull ModuleChunk moduleChunk) { Sdk sdkForCompilation = getSdkForCompilation(); if(sdkForCompilation == null) { return Collections.emptySet(); } Set<VirtualFile> files = new OrderedSet<>(); ContainerUtil.addAll(files, sdkForCompilation.getRootProvider().getFiles(BinariesOrderRootType.getInstance())); files.addAll(moduleChunk.getCompilationClasspathFiles(IkvmBundleType.getInstance())); VirtualFile fileByPath = LocalFileSystem.getInstance().findFileByPath(PathManager.getSystemPath() + "/ikvm-stubs/" + getModule().getName() + "@" + getModule().getModuleDirUrl().hashCode()); if(fileByPath != null) { files.add(fileByPath); } return files; }
@NotNull @Override public Set<VirtualFile> getCompilationClasspath(@NotNull CompileContext compileContext, @NotNull ModuleChunk moduleChunk) { Sdk sdkForCompilation = getSdkForCompilation(); Set<VirtualFile> files = new OrderedSet<>(); ContainerUtil.addAll(files, sdkForCompilation.getRootProvider().getFiles(BinariesOrderRootType.getInstance())); VirtualFile fileByPath = LocalFileSystem.getInstance().findFileByPath(PathManager.getSystemPath() + "/ikvm-stubs/" + getModule().getName() + "@" + getModule().getModuleDirUrl().hashCode()); if(fileByPath != null) { files.add(fileByPath); } files.addAll(moduleChunk.getCompilationClasspathFiles(IkvmBundleType.getInstance())); return files; }
public static String[] getOutputPaths(Module[] modules) { if (modules.length == 0) { return ArrayUtil.EMPTY_STRING_ARRAY; } final Set<String> outputPaths = new OrderedSet<String>(); for (Module module : modules) { for (ContentFolderTypeProvider contentFolderType : ContentFolderTypeProvider.filter(ContentFolderScopes.productionAndTest())) { String outputPathUrl = ModuleCompilerPathsManager.getInstance(module).getCompilerOutputUrl(contentFolderType); if (outputPathUrl != null) { outputPaths.add(VirtualFileManager.extractPath(outputPathUrl).replace('/', File.separatorChar)); } } } return ArrayUtil.toStringArray(outputPaths); }
public static VirtualFile[] getOutputDirectories(final Module[] modules) { if (modules.length == 0) { return VirtualFile.EMPTY_ARRAY; } final Set<VirtualFile> dirs = new OrderedSet<VirtualFile>(); for (Module module : modules) { for (ContentFolderTypeProvider contentFolderType : ContentFolderTypeProvider.filter(ContentFolderScopes.productionAndTest())) { VirtualFile virtualFile = ModuleCompilerPathsManager.getInstance(module).getCompilerOutput(contentFolderType); if (virtualFile != null) { dirs.add(virtualFile); } } } return VfsUtilCore.toVirtualFileArray(dirs); }
/** * Loads the postfix templates from the given file and returns them. * * @param file templates file * @return set of postfix templates */ @SuppressWarnings("WeakerAccess") public Set<PostfixTemplate> loadTemplatesFrom(@NotNull File file) { VirtualFile vFile = LocalFileSystem.getInstance().findFileByIoFile(file); if (vFile != null) { return loadTemplatesFrom(vFile); } else { return new OrderedSet<>(); } }
/** * Loads the postfix templates from the given virtual file and returns them. * * @param vFile virtual templates file * @return set of postfix templates */ @SuppressWarnings("WeakerAccess") public Set<PostfixTemplate> loadTemplatesFrom(@NotNull VirtualFile vFile) { Set<PostfixTemplate> templates = new OrderedSet<>(); ApplicationManager.getApplication().runReadAction(() -> { Project project = ProjectManager.getInstance().getOpenProjects()[0]; CptFile cptFile = (CptFile) PsiManager.getInstance(project).findFile(vFile); if (cptFile != null) { CptTemplate[] cptTemplates = PsiTreeUtil.getChildrenOfType(cptFile, CptTemplate.class); if (cptTemplates != null) { for (CptTemplate cptTemplate : cptTemplates) { for (CptMapping mapping : cptTemplate.getMappings().getMappingList()) { StringBuilder sb = new StringBuilder(); for (PsiElement element : mapping.getReplacement().getChildren()) { sb.append(element.getText()); } templates.add(createTemplate(mapping.getMatchingClass(), mapping.getConditionClass(), cptTemplate.getTemplateName(), cptTemplate.getTemplateDescription(), sb.toString())); } } } } }); return combineTemplatesWithSameName(templates); }
/** * Returns the variable names used in the template. * * @param templateText template text * @return the variable names used in the template */ @NotNull static Set<String> parseVariableNames(@NotNull String templateText) { Set<String> variableNames = new OrderedSet<>(); int varStart = -1; int i = 0; while (i < templateText.length()) { char c = templateText.charAt(i); if (c == '\\') { i++; } else if (c == '$') { if (varStart == -1) { varStart = i; } else { String varName = templateText.substring(varStart + 1, i); variableNames.add(varName); varStart = -1; } } i++; } return variableNames; }
public final boolean isModified() { List<T> items = getItems(); OrderedSet<T> oldItems = helper.originalItems; if (items.size() != oldItems.size()) { return true; } else { for (int i = 0, size = items.size(); i < size; i++) { if (!items.get(i).equals(oldItems.get(i))) { return true; } } } return false; }
protected void collectAllElements(@NotNull PsiElement element, @NotNull OrderedSet<PsiElement> result, boolean recursive) { result.add(0, element); if (doNotStepInto(element)) { if (!recursive) return; recursive = false; } collectAdditionalElements(element, result); for (PsiElement child : element.getChildren()) { collectAllElements(child, result, recursive); } }
@NotNull public static String[] collectResourceDirsForCompilation(@NotNull JpsAndroidModuleExtension extension, boolean withCacheDirs, @NotNull BuildDataPaths dataPaths, boolean checkExistence) { final Collection<String> result = new OrderedSet<String>(); addCompilableResourceDirsForModule(extension, withCacheDirs, dataPaths, result, checkExistence); for (JpsAndroidModuleExtension depExtension : getAllAndroidDependencies(extension.getModule(), true)) { addCompilableResourceDirsForModule(depExtension, withCacheDirs, dataPaths, result, checkExistence); } return ArrayUtil.toStringArray(result); }
public static void doImportDependencies(@NotNull Project project, @NotNull List<Module> modules, boolean updateBackwardDependencies) { final List<ImportDependenciesTask> tasks = new OrderedSet<ImportDependenciesTask>(); final List<MyUnresolvedDependency> unresolvedDependencies = new ArrayList<MyUnresolvedDependency>(); for (Module module : modules) { importDependencies(module, updateBackwardDependencies, tasks, unresolvedDependencies); } final Map<VirtualFile, ModuleProvidingTask> libDir2ModuleProvidingTask = new HashMap<VirtualFile, ModuleProvidingTask>(); for (ImportDependenciesTask task : tasks) { if (task instanceof ModuleProvidingTask) { final ModuleProvidingTask moduleProvidingTask = (ModuleProvidingTask)task; libDir2ModuleProvidingTask.put(moduleProvidingTask.getContentRoot(), moduleProvidingTask); } } for (MyUnresolvedDependency unresolvedDependency : unresolvedDependencies) { final ModuleProvidingTask taskProvidingDepModule = libDir2ModuleProvidingTask.get(unresolvedDependency.myLibDir); if (taskProvidingDepModule != null) { tasks.add(new AddModuleDependencyTask(unresolvedDependency.myModuleProvider, ModuleProvider.create(taskProvidingDepModule))); } } if (tasks.size() > 0) { doImportDependencies(project, tasks); } }
@NotNull public static List<VirtualFile> getExternalLibraries(Module module) { Set<VirtualFile> files = new HashSet<VirtualFile>(); OrderedSet<VirtualFile> libs = new OrderedSet<VirtualFile>(); // In a module imported from Maven dependencies are transitive, so we don't need to traverse all dependency tree // and compute all jars referred by library modules. Moreover it would be incorrect, // because Maven has dependency resolving algorithm based on versioning boolean recursive = !isMavenizedModule(module); fillExternalLibrariesAndModules(module, files, new HashSet<Module>(), libs, false, recursive); addAnnotationsJar(module, libs); return libs; }
@Override protected void collectAllElements(@NotNull PsiElement atCaret, @NotNull OrderedSet<PsiElement> res, boolean recurse) { res.add(0, atCaret); if (doNotStepInto(atCaret)) { if (!recurse) return; recurse = false; } PsiElement parent = atCaret.getParent(); if (atCaret instanceof GrClosableBlock && parent instanceof GrStringInjection && parent.getParent() instanceof GrString) { res.add(parent.getParent()); } if (parent instanceof GrArgumentList) { res.add(parent.getParent()); } //if (parent instanceof GrWhileStatement) { // res.add(parent); //} final PsiElement[] children = getChildren(atCaret); for (PsiElement child : children) { collectAllElements(child, res, recurse); } }
public static VirtualFile[] getOutputDirectories(final Module[] modules) { final Set<VirtualFile> dirs = new OrderedSet<VirtualFile>(); for (Module module : modules) { final VirtualFile outputDir = getModuleOutputDirectory(module, false); if (outputDir != null) { dirs.add(outputDir); } VirtualFile testsOutputDir = getModuleOutputDirectory(module, true); if (testsOutputDir != null) { dirs.add(testsOutputDir); } } return VfsUtil.toVirtualFileArray(dirs); }
public OrderedSet<VirtualFile> getCompilationClasspathFiles(final boolean exportedOnly) { final Set<Module> modules = getNodes(); OrderedSet<VirtualFile> cpFiles = new OrderedSet<VirtualFile>(); for (final Module module : modules) { Collections.addAll(cpFiles, orderEnumerator(module, exportedOnly, new AfterJdkOrderEntryCondition()).getClassesRoots()); } return cpFiles; }
public OrderedSet<VirtualFile> getCompilationBootClasspathFiles(final boolean exportedOnly) { final Set<Module> modules = getNodes(); final OrderedSet<VirtualFile> cpFiles = new OrderedSet<VirtualFile>(); final OrderedSet<VirtualFile> jdkFiles = new OrderedSet<VirtualFile>(); for (final Module module : modules) { Collections.addAll(cpFiles, orderEnumerator(module, exportedOnly, new BeforeJdkOrderEntryCondition(module)).getClassesRoots()); Collections.addAll(jdkFiles, OrderEnumerator.orderEntries(module).sdkOnly().getClassesRoots()); } cpFiles.addAll(jdkFiles); return cpFiles; }
public OrderedSet<VirtualFile> getCompilationClasspathFiles(SdkType sdkType, final boolean exportedOnly) { final Set<Module> modules = getNodes(); OrderedSet<VirtualFile> cpFiles = new OrderedSet<VirtualFile>(); for (final Module module : modules) { Collections.addAll(cpFiles, orderEnumerator(module, exportedOnly, new AfterSdkOrderEntryCondition(sdkType)).getClassesRoots()); } return cpFiles; }
public OrderedSet<VirtualFile> getCompilationBootClasspathFiles(SdkType sdkType, final boolean exportedOnly) { final Set<Module> modules = getNodes(); final OrderedSet<VirtualFile> cpFiles = new OrderedSet<VirtualFile>(); final OrderedSet<VirtualFile> jdkFiles = new OrderedSet<VirtualFile>(); for (final Module module : modules) { Collections.addAll(cpFiles, orderEnumerator(module, exportedOnly, new BeforeSdkOrderEntryCondition(sdkType, module)).getClassesRoots()); Collections.addAll(jdkFiles, OrderEnumerator.orderEntries(module).sdkOnly().getClassesRoots()); } cpFiles.addAll(jdkFiles); return cpFiles; }
@Override public void recalculateOutputDirs() { final Module[] allModules = ModuleManager.getInstance(myProject).getModules(); final Set<VirtualFile> allDirs = new OrderedSet<VirtualFile>(); final Set<VirtualFile> testOutputDirs = new java.util.HashSet<VirtualFile>(); final Set<VirtualFile> productionOutputDirs = new java.util.HashSet<VirtualFile>(); for (Module module : allModules) { ModuleCompilerPathsManager moduleCompilerPathsManager = ModuleCompilerPathsManager.getInstance(module); final VirtualFile output = moduleCompilerPathsManager.getCompilerOutput(ProductionContentFolderTypeProvider.getInstance()); if (output != null && output.isValid()) { allDirs.add(output); productionOutputDirs.add(output); } final VirtualFile testsOutput = moduleCompilerPathsManager.getCompilerOutput(TestContentFolderTypeProvider.getInstance()); if (testsOutput != null && testsOutput.isValid()) { allDirs.add(testsOutput); testOutputDirs.add(testsOutput); } } myOutputDirectories = VfsUtil.toVirtualFileArray(allDirs); // need this to ensure that the sent contains only _dedicated_ test output dirs // Directories that are configured for both test and production classes must not be added in the resulting set testOutputDirs.removeAll(productionOutputDirs); myTestOutputDirectories = Collections.unmodifiableSet(testOutputDirs); }
protected void collectAllElements(@Nonnull PsiElement element, @Nonnull OrderedSet<PsiElement> result, boolean recursive) { result.add(0, element); if (doNotStepInto(element)) { if (!recursive) return; recursive = false; } collectAdditionalElements(element, result); for (PsiElement child : element.getChildren()) { collectAllElements(child, result, recursive); } }
@Override public void removeShortcut(String actionId, Shortcut toDelete) { OrderedSet<Shortcut> list = myActionId2ListOfShortcuts.get(actionId); if (list != null) { Iterator<Shortcut> it = list.iterator(); while (it.hasNext()) { Shortcut each = it.next(); if (toDelete.equals(each)) { it.remove(); if ((myParent != null && areShortcutsEqual(getParentShortcuts(actionId), getShortcuts(actionId))) || (myParent == null && list.isEmpty())) { myActionId2ListOfShortcuts.remove(actionId); } break; } } } else { Shortcut[] inherited = getBoundShortcuts(actionId); if (inherited == null && myParent != null) { inherited = getParentShortcuts(actionId); } if (inherited != null) { boolean affected = false; OrderedSet<Shortcut> newShortcuts = new OrderedSet<Shortcut>(inherited.length); for (Shortcut eachInherited : inherited) { if (toDelete.equals(eachInherited)) { // skip this one affected = true; } else { newShortcuts.add(eachInherited); } } if (affected) { myActionId2ListOfShortcuts.put(actionId, newShortcuts); } } } cleanShortcutsCache(); fireShortcutChanged(actionId); }
@Nullable private Shortcut[] getOwnShortcuts(String actionId) { OrderedSet<Shortcut> own = myActionId2ListOfShortcuts.get(actionId); if (own == null) return null; return own.isEmpty() ? ourEmptyShortcutsArray : own.toArray(new Shortcut[own.size()]); }
protected void process(@NotNull final Project project, @NotNull final Editor editor, @NotNull final PsiFile file, final int attempt) throws TooManyAttemptsException { FeatureUsageTracker.getInstance().triggerFeatureUsed("codeassists.complete.statement"); if (attempt > MAX_ATTEMPTS) throw new TooManyAttemptsException(); try { commit(editor); if (myFirstErrorOffset != Integer.MAX_VALUE) { editor.getCaretModel().moveToOffset(myFirstErrorOffset); } myFirstErrorOffset = Integer.MAX_VALUE; PsiElement atCaret = getStatementAtCaret(editor, file); if (atCaret == null) { return; } OrderedSet<PsiElement> queue = new OrderedSet<PsiElement>(); collectAllElements(atCaret, queue, true); queue.add(atCaret); for (PsiElement psiElement : queue) { for (Fixer fixer : myFixers) { fixer.apply(editor, this, psiElement); if (LookupManager.getInstance(project).getActiveLookup() != null) { return; } if (isUncommited(project) || !psiElement.isValid()) { moveCaretInsideBracesIfAny(editor, file); process(project, editor, file, attempt + 1); return; } } } doEnter(atCaret, file, editor); } catch (IncorrectOperationException e) { LOG.error(e); } }
@Override public List<PsiMethod> findReferencedMethods(final SourcePosition position) { final int line = position.getLine(); if (line < 0) { return Collections.emptyList(); // the document has been changed } final PsiFile file = position.getFile(); final VirtualFile vFile = file.getVirtualFile(); if (vFile == null) { // the file is not physical return Collections.emptyList(); } final Document doc = FileDocumentManager.getInstance().getDocument(vFile); if (doc == null) return Collections.emptyList(); if (line >= doc.getLineCount()) { return Collections.emptyList(); // the document has been changed } final int startOffset = doc.getLineStartOffset(line); final TextRange lineRange = new TextRange(startOffset, doc.getLineEndOffset(line)); final int offset = CharArrayUtil.shiftForward(doc.getCharsSequence(), startOffset, " \t"); PsiElement element = file.findElementAt(offset); if (element != null && !(element instanceof PsiCompiledElement)) { do { final PsiElement parent = element.getParent(); if (parent == null || (parent.getTextOffset() < lineRange.getStartOffset())) { break; } element = parent; } while(true); //noinspection unchecked final List<PsiMethod> methods = new OrderedSet<PsiMethod>(); final PsiElementVisitor methodCollector = new JavaRecursiveElementWalkingVisitor() { @Override public void visitAnonymousClass(PsiAnonymousClass aClass) { /*skip annonymous classes*/ } @Override public void visitStatement(PsiStatement statement) { if (lineRange.intersects(statement.getTextRange())) { super.visitStatement(statement); } } @Override public void visitCallExpression(final PsiCallExpression expression) { final PsiMethod psiMethod = expression.resolveMethod(); if (psiMethod != null) { methods.add(psiMethod); } super.visitCallExpression(expression); } }; element.accept(methodCollector); for (PsiElement sibling = element.getNextSibling(); sibling != null; sibling = sibling.getNextSibling()) { if (!lineRange.intersects(sibling.getTextRange())) { break; } sibling.accept(methodCollector); } return methods; } return Collections.emptyList(); }