@Nullable private VirtualFile setupGradleSettingsFile( @NotNull VirtualFile modelContentRootDir, @NotNull ModifiableRootModel model) throws ConfigurationException { VirtualFile file = null; if (myWizardContext.isCreatingNewProject()) { final String moduleDirName = VfsUtilCore.getRelativePath(modelContentRootDir, model.getProject().getBaseDir(), '/'); file = getExternalProjectConfigFile( model.getProject().getBasePath(), GradleConstants.SETTINGS_FILE_NAME); if (file == null) return null; Map<String, String> attributes = ContainerUtil.newHashMap(); final String projectName = model.getProject().getName(); attributes.put(TEMPLATE_ATTRIBUTE_PROJECT_NAME, projectName); attributes.put(TEMPLATE_ATTRIBUTE_MODULE_DIR_NAME, moduleDirName); attributes.put(TEMPLATE_ATTRIBUTE_MODULE_NAME, model.getModule().getName()); saveFile(file, TEMPLATE_GRADLE_SETTINGS, attributes); } else { Map<String, Module> moduleMap = ContainerUtil.newHashMap(); for (Module module : ModuleManager.getInstance(model.getProject()).getModules()) { for (ContentEntry contentEntry : model.getContentEntries()) { if (contentEntry.getFile() != null) { moduleMap.put(contentEntry.getFile().getPath(), module); } } } VirtualFile virtualFile = modelContentRootDir; Module module = null; while (virtualFile != null && module == null) { module = moduleMap.get(virtualFile.getPath()); virtualFile = virtualFile.getParent(); } if (module != null) { String rootProjectPath = module.getOptionValue(ExternalSystemConstants.ROOT_PROJECT_PATH_KEY); if (!StringUtil.isEmpty(rootProjectPath)) { VirtualFile rootProjectFile = VfsUtil.findFileByIoFile(new File(rootProjectPath), true); if (rootProjectFile == null) return null; final String moduleDirName = VfsUtilCore.getRelativePath(modelContentRootDir, rootProjectFile, '/'); file = getExternalProjectConfigFile(rootProjectPath, GradleConstants.SETTINGS_FILE_NAME); if (file == null) return null; Map<String, String> attributes = ContainerUtil.newHashMap(); attributes.put(TEMPLATE_ATTRIBUTE_MODULE_DIR_NAME, moduleDirName); attributes.put(TEMPLATE_ATTRIBUTE_MODULE_NAME, model.getModule().getName()); appendToFile(file, TEMPLATE_GRADLE_SETTINGS_MERGE, attributes); } } } return file; }
public static class Factory { private final Map<DfaPsiType, ArrayList<DfaTypeValue>> myCache = ContainerUtil.newHashMap(); private final DfaValueFactory myFactory; Factory(DfaValueFactory factory) { myFactory = factory; } @NotNull public DfaTypeValue createTypeValue(@NotNull DfaPsiType type, @NotNull Nullness nullness) { ArrayList<DfaTypeValue> conditions = myCache.get(type); if (conditions == null) { conditions = new ArrayList<DfaTypeValue>(); myCache.put(type, conditions); } else { for (DfaTypeValue aType : conditions) { if (aType.myNullness == nullness) return aType; } } DfaTypeValue result = new DfaTypeValue(type, nullness, myFactory); conditions.add(result); return new DfaTypeValue(type, nullness, myFactory); } }
private ClassMapCachingNulls<MultiHostInjector> getInjectorMap() { ClassMapCachingNulls<MultiHostInjector> cached = cachedInjectors; if (cached != null) { return cached; } Map<Class, MultiHostInjector[]> injectors = ContainerUtil.newHashMap(); List<MultiHostInjector> allInjectors = ContainerUtil.newArrayList(); allInjectors.addAll(myManualInjectors); Collections.addAll( allInjectors, MultiHostInjector.MULTIHOST_INJECTOR_EP_NAME.getExtensions(myProject)); if (LanguageInjector.EXTENSION_POINT_NAME.getExtensions().length > 0) { allInjectors.add(PsiManagerRegisteredInjectorsAdapter.INSTANCE); } for (MultiHostInjector injector : allInjectors) { for (Class<? extends PsiElement> place : injector.elementsToInjectIn()) { LOG.assertTrue(place != null, injector); MultiHostInjector[] existing = injectors.get(place); injectors.put( place, existing == null ? new MultiHostInjector[] {injector} : ArrayUtil.append(existing, injector)); } } ClassMapCachingNulls<MultiHostInjector> result = new ClassMapCachingNulls<>(injectors, new MultiHostInjector[0], allInjectors); cachedInjectors = result; return result; }
private static void patchGtkDefaults(UIDefaults defaults) { if (!UIUtil.isUnderGTKLookAndFeel()) return; Map<String, Icon> map = ContainerUtil.newHashMap( Arrays.asList( "OptionPane.errorIcon", "OptionPane.informationIcon", "OptionPane.warningIcon", "OptionPane.questionIcon"), Arrays.asList( AllIcons.General.ErrorDialog, AllIcons.General.InformationDialog, AllIcons.General.WarningDialog, AllIcons.General.QuestionDialog)); // GTK+ L&F keeps icons hidden in style SynthStyle style = SynthLookAndFeel.getStyle(new JOptionPane(""), Region.DESKTOP_ICON); for (String key : map.keySet()) { if (defaults.get(key) != null) continue; Object icon = style == null ? null : style.get(null, key); defaults.put(key, icon instanceof Icon ? icon : map.get(key)); } Color fg = defaults.getColor("Label.foreground"); Color bg = defaults.getColor("Label.background"); if (fg != null && bg != null) { defaults.put("Label.disabledForeground", UIUtil.mix(fg, bg, 0.5)); } }
private static BundleManifest readProperties(PsiFile propertiesFile) { try { UTF8Properties properties = new UTF8Properties(); properties.load(new StringReader(propertiesFile.getText())); Map<String, String> map = ContainerUtil.newHashMap(); for (Object key : properties.keySet()) { String name = key.toString(); map.put(name, properties.getProperty(name)); } if (map.get(Constants.BUNDLE_SYMBOLICNAME) == null) { VirtualFile file = propertiesFile.getVirtualFile(); if (file != null) { if (!BndProjectImporter.BND_FILE.equals(file.getName())) { map.put( Constants.BUNDLE_SYMBOLICNAME, FileUtil.getNameWithoutExtension(file.getName())); } else if (file.getParent() != null) { map.put(Constants.BUNDLE_SYMBOLICNAME, file.getParent().getName()); } } } return new BundleManifest(map, propertiesFile); } catch (IOException ignored) { } catch (InvalidVirtualFileAccessException ignored) { } return null; }
@NotNull static List<HighlightInfo> checkDuplicateRequires(@NotNull PsiJavaModule module) { List<HighlightInfo> results = ContainerUtil.newSmartList(); Map<String, PsiElement> map = ContainerUtil.newHashMap(); for (PsiElement child = module.getFirstChild(); child != null; child = child.getNextSibling()) { if (child instanceof PsiRequiresStatement) { PsiJavaModuleReferenceElement ref = ((PsiRequiresStatement) child).getReferenceElement(); if (ref != null) { String text = ref.getReferenceText(); if (!map.containsKey(text)) { map.put(text, child); } else { String message = JavaErrorMessages.message("module.duplicate.requires", text); HighlightInfo info = HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR) .range(child) .description(message) .create(); QuickFixAction.registerQuickFixAction(info, new DeleteElementFix(child)); results.add(info); } } } } return results; }
@Override public <T> void putUserData(@NotNull final Key<T> key, @Nullable final T value) { if (myUserData == null) { myUserData = ContainerUtil.newHashMap(); } myUserData.put(key, value); }
class RunConfigurationByRecordProvider implements ConfigurationByRecordProvider { private final Project myProject; private final Map<Integer, RunnerAndConfigurationSettings> myConfigurationsMap = ContainerUtil.newHashMap(); public RunConfigurationByRecordProvider(Project project) { myProject = project; initRunConfigurationsMap(); } @Override public RunnerAndConfigurationSettings getConfiguration(TestStateStorage.Record record) { Integer runConfigurationHash = new Integer((int) record.configurationHash); return myConfigurationsMap.get(runConfigurationHash); } private void initRunConfigurationsMap() { RunManagerEx manager = RunManagerEx.getInstanceEx(myProject); ConfigurationType[] types = manager.getConfigurationFactories(); for (ConfigurationType type : types) { Map<String, List<RunnerAndConfigurationSettings>> structure = manager.getStructure(type); for (Map.Entry<String, List<RunnerAndConfigurationSettings>> e : structure.entrySet()) { for (RunnerAndConfigurationSettings settings : e.getValue()) { myConfigurationsMap.put(settings.getName().hashCode(), settings); } } } } }
private boolean performCompilation( List<String> args, StringWriter out, StringWriter err, Map<String, List<String>> outputs, CompileContext context, ModuleChunk chunk) { try { Class<?> mainClass = Class.forName(GreclipseMain.class.getName(), true, myGreclipseLoader); Constructor<?> constructor = mainClass.getConstructor(PrintWriter.class, PrintWriter.class, Map.class, Map.class); Method compileMethod = mainClass.getMethod("compile", String[].class); HashMap<String, Object> customDefaultOptions = ContainerUtil.newHashMap(); // without this greclipse won't load AST transformations customDefaultOptions.put( "org.eclipse.jdt.core.compiler.groovy.groovyClassLoaderPath", getClasspathString(chunk)); // used by greclipse to cache transform loaders // names should be different for production & tests customDefaultOptions.put( "org.eclipse.jdt.core.compiler.groovy.groovyProjectName", chunk.getPresentableShortName()); Object main = constructor.newInstance( new PrintWriter(out), new PrintWriter(err), customDefaultOptions, outputs); return (Boolean) compileMethod.invoke(main, new Object[] {ArrayUtil.toStringArray(args)}); } catch (Exception e) { context.processMessage(new CompilerMessage(getPresentableName(), e)); return false; } }
public void annotate( @NotNull final VirtualFile contentRoot, @NotNull final CoverageSuitesBundle suite, final @NotNull CoverageDataManager dataManager, @NotNull final ProjectData data, final Project project, final Annotator annotator) { if (!contentRoot.isValid()) { return; } // TODO: check name filter!!!!! final ProjectFileIndex index = ProjectRootManager.getInstance(project).getFileIndex(); @SuppressWarnings("unchecked") final Set<String> files = data.getClasses().keySet(); final Map<String, String> normalizedFiles2Files = ContainerUtil.newHashMap(); for (final String file : files) { normalizedFiles2Files.put(normalizeFilePath(file), file); } collectFolderCoverage( contentRoot, dataManager, annotator, data, suite.isTrackTestFolders(), index, suite.getCoverageEngine(), ContainerUtil.newHashSet(), Collections.unmodifiableMap(normalizedFiles2Files)); }
private static class DataFlowInstructionVisitor extends StandardInstructionVisitor { private final StandardDataFlowRunner myRunner; private final MultiMap<NullabilityProblem, PsiElement> myProblems = new MultiMap<NullabilityProblem, PsiElement>(); private final Map<Pair<NullabilityProblem, PsiElement>, StateInfo> myStateInfos = ContainerUtil.newHashMap(); private DataFlowInstructionVisitor(StandardDataFlowRunner runner) { myRunner = runner; } @Override protected void onInstructionProducesCCE(TypeCastInstruction instruction) { myRunner.onInstructionProducesCCE(instruction); } Collection<PsiElement> getProblems(final NullabilityProblem kind) { return ContainerUtil.filter( myProblems.get(kind), new Condition<PsiElement>() { @Override public boolean value(PsiElement psiElement) { StateInfo info = myStateInfos.get(Pair.create(kind, psiElement)); // non-ephemeral NPE should be reported // ephemeral NPE should also be reported if only ephemeral states have reached a // particular problematic instruction // (e.g. if it's inside "if (var == null)" check after contract method invocation return info.normalNpe || info.ephemeralNpe && !info.normalOk; } }); } @Override protected boolean checkNotNullable( DfaMemoryState state, DfaValue value, NullabilityProblem problem, PsiElement anchor) { boolean ok = super.checkNotNullable(state, value, problem, anchor); if (!ok && anchor != null) { myProblems.putValue(problem, anchor); } Pair<NullabilityProblem, PsiElement> key = Pair.create(problem, anchor); StateInfo info = myStateInfos.get(key); if (info == null) { myStateInfos.put(key, info = new StateInfo()); } if (state.isEphemeral() && !ok) { info.ephemeralNpe = true; } else if (!state.isEphemeral()) { if (ok) info.normalOk = true; else info.normalNpe = true; } return ok; } private static class StateInfo { boolean ephemeralNpe; boolean normalNpe; boolean normalOk; } }
@NotNull private Map<VirtualFile, OrderEntry[]> getOrderEntries() { Map<VirtualFile, OrderEntry[]> result = myOrderEntries; if (result != null) return result; MultiMap<VirtualFile, OrderEntry> libClassRootEntries = MultiMap.createSmart(); MultiMap<VirtualFile, OrderEntry> libSourceRootEntries = MultiMap.createSmart(); MultiMap<VirtualFile, OrderEntry> depEntries = MultiMap.createSmart(); for (final Module module : ModuleManager.getInstance(myProject).getModules()) { final ModuleRootManager moduleRootManager = ModuleRootManager.getInstance(module); for (OrderEntry orderEntry : moduleRootManager.getOrderEntries()) { if (orderEntry instanceof ModuleOrderEntry) { final Module depModule = ((ModuleOrderEntry) orderEntry).getModule(); if (depModule != null) { VirtualFile[] importedClassRoots = OrderEnumerator.orderEntries(depModule) .exportedOnly() .recursively() .classes() .usingCache() .getRoots(); for (VirtualFile importedClassRoot : importedClassRoots) { depEntries.putValue(importedClassRoot, orderEntry); } } for (VirtualFile sourceRoot : orderEntry.getFiles(OrderRootType.SOURCES)) { depEntries.putValue(sourceRoot, orderEntry); } } else if (orderEntry instanceof LibraryOrSdkOrderEntry) { final LibraryOrSdkOrderEntry entry = (LibraryOrSdkOrderEntry) orderEntry; for (final VirtualFile sourceRoot : entry.getRootFiles(OrderRootType.SOURCES)) { libSourceRootEntries.putValue(sourceRoot, orderEntry); } for (final VirtualFile classRoot : entry.getRootFiles(OrderRootType.CLASSES)) { libClassRootEntries.putValue(classRoot, orderEntry); } } } } RootInfo rootInfo = buildRootInfo(myProject); result = ContainerUtil.newHashMap(); Set<VirtualFile> allRoots = rootInfo.getAllRoots(); for (VirtualFile file : allRoots) { List<VirtualFile> hierarchy = getHierarchy(file, allRoots, rootInfo); result.put( file, hierarchy == null ? OrderEntry.EMPTY_ARRAY : calcOrderEntries( rootInfo, depEntries, libClassRootEntries, libSourceRootEntries, hierarchy)); } myOrderEntries = result; return result; }
private static void writeContextData( @NotNull DiffContext context, @NotNull TransferableFileEditorState state) { Map<String, Map<String, String>> map = context.getUserData(TRANSFERABLE_FILE_EDITOR_STATE); if (map == null) { map = ContainerUtil.newHashMap(); context.putUserData(TRANSFERABLE_FILE_EDITOR_STATE, map); } map.put(state.getEditorId(), state.getTransferableOptions()); }
public MergeInfoHolder( @NotNull Project project, @NotNull DecoratorManager manager, @NotNull RootsAndBranches mainPanel, @NotNull SvnMergeInfoRootPanelManual panel) { myManager = manager; myMainPanel = mainPanel; myPanel = panel; myMergeInfoCache = SvnMergeInfoCache.getInstance(project); myCachedMap = ContainerUtil.newHashMap(); }
/** * Parses "svn:externals" property in format starting from svn 1.5. * * @return map of externals definitions: key - relative directory, value - corresponding complete * externals definition. */ @NotNull public static Map<String, String> parseExternalsProperty(@NotNull String externals) throws SvnBindException { HashMap<String, String> map = ContainerUtil.newHashMap(); for (String external : StringUtil.splitByLines(externals, true)) { map.put(parseRelativeDirectory(external), external); } return map; }
@NotNull private static DataContext createEditorContext(@NotNull Editor editor) { Object e = editor; Object hostEditor = editor instanceof EditorWindow ? ((EditorWindow) editor).getDelegate() : editor; Map<String, Object> map = ContainerUtil.newHashMap( Pair.create(CommonDataKeys.HOST_EDITOR.getName(), hostEditor), Pair.createNonNull(CommonDataKeys.EDITOR.getName(), e)); DataContext parent = DataManager.getInstance().getDataContext(editor.getContentComponent()); return SimpleDataContext.getSimpleContext(map, parent); }
protected VirtualFileVisitor(@NotNull Option... options) { for (Option option : options) { if (option == NO_FOLLOW_SYMLINKS) { myFollowSymLinks = false; } else if (option == SKIP_ROOT) { mySkipRoot = true; } else if (option instanceof Option.LimitOption) { myDepthLimit = ((Option.LimitOption) option).limit; } } if (myFollowSymLinks) { myVisitedTargets = ContainerUtil.newHashMap(); } }
protected SettingsGroup getAssociatedSettingsGroup(String fieldName) { if (myFieldNameToGroup == null) { myFieldNameToGroup = ContainerUtil.newHashMap(); Set<String> groups = myGroupToFields.keySet(); for (String group : groups) { Collection<String> fields = myGroupToFields.get(group); SettingsGroup settingsGroup = new SettingsGroup(group, fields); for (String field : fields) { myFieldNameToGroup.put(field, settingsGroup); } } } return myFieldNameToGroup.get(fieldName); }
/** * Returns a map with properties to be added to the bundle manifest definition of all * libraries * which this rule applies to. */ @Transient public Map<String, String> getAdditionalPropertiesMap() { try { Properties p = new Properties(); p.load(new ByteArrayInputStream(myAdditionalProperties.getBytes("UTF-8"))); Map<String, String> result = ContainerUtil.newHashMap(); for (Map.Entry<Object, Object> entry : p.entrySet()) { result.put(String.valueOf(entry.getKey()), String.valueOf(entry.getValue())); } return result; } catch (IOException ignored) { } return Collections.emptyMap(); }
@NotNull public Map<String, NamedArgumentDescriptor> getNamedParameters() { final GrFieldStub stub = getStub(); if (stub != null) { String[] namedParameters = stub.getNamedParameters(); if (namedParameters.length == 0) return Collections.emptyMap(); Map<String, NamedArgumentDescriptor> result = ContainerUtil.newHashMap(); for (String parameter : namedParameters) { result.put(parameter, GrNamedArgumentSearchVisitor.CODE_NAMED_ARGUMENTS_DESCR); } return result; } return GrNamedArgumentSearchVisitor.find(this); }
@NotNull public Map<VirtualFile, VcsLogProvider> findLogProviders() { Map<VirtualFile, VcsLogProvider> logProviders = ContainerUtil.newHashMap(); VcsLogProvider[] allLogProviders = Extensions.getExtensions(LOG_PROVIDER_EP, myProject); for (AbstractVcs vcs : myVcsManager.getAllActiveVcss()) { for (VcsLogProvider provider : allLogProviders) { if (provider.getSupportedVcs().equals(vcs.getKeyInstanceMethod())) { for (VirtualFile root : myVcsManager.getRootsUnderVcs(vcs)) { logProviders.put(root, provider); } break; } } } return logProviders; }
private static BundleManifest readManifest(PsiFile manifestFile) { try { ByteArrayInputStream stream = new ByteArrayInputStream(manifestFile.getText().getBytes(CharsetToolkit.UTF8)); Attributes attributes = new Manifest(stream).getMainAttributes(); Map<String, String> map = ContainerUtil.newHashMap(); for (Object key : attributes.keySet()) { String name = key.toString(); map.put(name, attributes.getValue(name)); } return new BundleManifest(map, manifestFile); } catch (IOException ignored) { } catch (InvalidVirtualFileAccessException ignored) { } return null; }
@Nullable private VirtualFile setupGradleBuildFile(@NotNull VirtualFile modelContentRootDir) throws ConfigurationException { final VirtualFile file = getExternalProjectConfigFile( modelContentRootDir.getPath(), GradleConstants.DEFAULT_SCRIPT_NAME); final String templateName = getExternalProjectSettings().getDistributionType() == DistributionType.WRAPPED ? TEMPLATE_GRADLE_BUILD_WITH_WRAPPER : DEFAULT_TEMPLATE_GRADLE_BUILD; Map attributes = ContainerUtil.newHashMap(); if (file != null) { saveFile(file, templateName, attributes); } return file; }
@NotNull public static <CommitId> PermanentGraphImpl<CommitId> newInstance( @NotNull List<? extends GraphCommit<CommitId>> graphCommits, @NotNull final GraphColorManager<CommitId> graphColorManager, @NotNull Set<CommitId> branchesCommitId) { PermanentLinearGraphBuilder<CommitId> permanentLinearGraphBuilder = PermanentLinearGraphBuilder.newInstance(graphCommits); final Map<Integer, CommitId> notLoadCommits = ContainerUtil.newHashMap(); PermanentLinearGraphImpl linearGraph = permanentLinearGraphBuilder.build( new NotNullFunction<CommitId, Integer>() { @NotNull @Override public Integer fun(CommitId dom) { int nodeId = -(notLoadCommits.size() + 2); notLoadCommits.put(nodeId, dom); return nodeId; } }); final PermanentCommitsInfoIml<CommitId> commitIdPermanentCommitsInfo = PermanentCommitsInfoIml.newInstance(graphCommits, notLoadCommits); GraphLayoutImpl permanentGraphLayout = GraphLayoutBuilder.build( linearGraph, new Comparator<Integer>() { @Override public int compare(@NotNull Integer nodeIndex1, @NotNull Integer nodeIndex2) { CommitId commitId1 = commitIdPermanentCommitsInfo.getCommitId(nodeIndex1); CommitId commitId2 = commitIdPermanentCommitsInfo.getCommitId(nodeIndex2); return graphColorManager.compareHeads(commitId2, commitId1); } }); return new PermanentGraphImpl<CommitId>( linearGraph, permanentGraphLayout, commitIdPermanentCommitsInfo, graphColorManager, branchesCommitId); }
@NotNull public static <R extends Repository> Map<R, List<VcsFullCommitDetails>> groupCommitsByRoots( @NotNull RepositoryManager<R> repoManager, @NotNull List<? extends VcsFullCommitDetails> commits) { Map<R, List<VcsFullCommitDetails>> groupedCommits = ContainerUtil.newHashMap(); for (VcsFullCommitDetails commit : commits) { R repository = repoManager.getRepositoryForRoot(commit.getRoot()); if (repository == null) { LOGGER.info("No repository found for commit " + commit); continue; } List<VcsFullCommitDetails> commitsInRoot = groupedCommits.get(repository); if (commitsInRoot == null) { commitsInRoot = ContainerUtil.newArrayList(); groupedCommits.put(repository, commitsInRoot); } commitsInRoot.add(commit); } return groupedCommits; }
@NotNull private Map<String, PsiMethod[]> getMethodsMap() { PsiMethod[] methods = getMethods(); if (methods.length == 0) return Collections.emptyMap(); Map<String, List<PsiMethod>> collectedMethods = ContainerUtil.newHashMap(); for (PsiMethod method : methods) { List<PsiMethod> list = collectedMethods.get(method.getName()); if (list == null) { collectedMethods.put(method.getName(), list = ContainerUtil.newSmartList()); } list.add(method); } Map<String, PsiMethod[]> cachedMethods = ContainerUtil.newTroveMap(); for (Map.Entry<String, List<PsiMethod>> entry : collectedMethods.entrySet()) { List<PsiMethod> list = entry.getValue(); cachedMethods.put(entry.getKey(), list.toArray(new PsiMethod[list.size()])); } return cachedMethods; }
@Override @NotNull public Map<String, NamedArgumentDescriptor> getNamedParameters() { final GrMethodStub stub = getStub(); if (stub != null) { String[] namedParameters = stub.getNamedParameters(); if (namedParameters.length == 0) return Collections.emptyMap(); Map<String, NamedArgumentDescriptor> result = ContainerUtil.newHashMap(); for (String parameter : namedParameters) { result.put(parameter, GrNamedArgumentSearchVisitor.CODE_NAMED_ARGUMENTS_DESCR); } return result; } GrOpenBlock body = getBlock(); if (body == null) return Collections.emptyMap(); GrParameter[] parameters = getParameters(); if (parameters.length == 0) return Collections.emptyMap(); GrParameter firstParameter = parameters[0]; PsiType type = firstParameter.getTypeGroovy(); GrTypeElement typeElement = firstParameter.getTypeElementGroovy(); // equalsToText can't be called here because of stub creating if (type != null && typeElement != null && type.getPresentableText() != null && !type.getPresentableText().endsWith("Map")) { return Collections.emptyMap(); } GrNamedArgumentSearchVisitor visitor = new GrNamedArgumentSearchVisitor(firstParameter.getNameIdentifierGroovy().getText()); body.accept(visitor); return visitor.getResult(); }
/** @author erokhins */ public class DefaultColorGenerator implements ColorGenerator { private static final Map<Integer, JBColor> ourColorMap = ContainerUtil.newHashMap(); static { ourColorMap.put(GraphColorManagerImpl.DEFAULT_COLOR, JBColor.BLACK); } @NotNull @Override public JBColor getColor(int branchNumber) { JBColor color = ourColorMap.get(branchNumber); if (color == null) { color = calcColor(branchNumber); ourColorMap.put(branchNumber, color); } return color; } private static int rangeFix(int n) { return Math.abs(n) % 100 + 70; } @NotNull private static JBColor calcColor(int indexColor) { int r = indexColor * 200 + 30; int g = indexColor * 130 + 50; int b = indexColor * 90 + 100; try { Color color = new Color(rangeFix(r), rangeFix(g), rangeFix(b)); return new JBColor(color, color); } catch (IllegalArgumentException a) { throw new IllegalArgumentException( "indexColor: " + indexColor + " " + r % 256 + " " + (g % 256) + " " + (b % 256)); } } }
@Override public int compareHeads(int head1, int head2) { if (head1 == head2) { return 0; } Collection<VcsRef> refs1 = myRefsModel.refsToCommit(head1); Collection<VcsRef> refs2 = myRefsModel.refsToCommit(head2); boolean firstEmpty = isEmptyRefs(refs1, head1); boolean secondEmpty = isEmptyRefs(refs2, head2); if (firstEmpty && secondEmpty) { return 0; } if (firstEmpty) { return -1; } if (secondEmpty) { return 1; } VcsLogRefManager refManager1 = getRefManager(refs1); VcsLogRefManager refManager2 = getRefManager(refs2); if (!refManager1.equals(refManager2)) { return 0; } Map<VcsRef, Boolean> positions = ContainerUtil.newHashMap(); for (VcsRef ref : refs1) { positions.put(ref, true); } for (VcsRef ref : refs2) { positions.put(ref, false); } VcsRef firstRef = refManager1.sort(positions.keySet()).get(0); return positions.get(firstRef) ? 1 : -1; }
@NotNull @Override public Collection<? extends CustomLiveTemplateLookupElement> getLookupElements( @NotNull PsiFile file, @NotNull Editor editor, int offset) { String key = computeTemplateKeyWithoutContextChecking(editor.getDocument().getCharsSequence(), offset); if (key != null) { Map<String, CustomLiveTemplateLookupElement> result = ContainerUtil.newHashMap(); Condition<PostfixTemplate> isApplicationTemplateFunction = createIsApplicationTemplateFunction(key, file, editor); for (Map.Entry<String, PostfixTemplate> entry : myTemplates.entrySet()) { PostfixTemplate postfixTemplate = entry.getValue(); if (entry.getKey().startsWith(key) && isApplicationTemplateFunction.value(postfixTemplate)) { result.put( postfixTemplate.getKey(), new PostfixTemplateLookupElement( this, postfixTemplate, postfixTemplate.getKey(), false)); } } return result.values(); } return super.getLookupElements(file, editor, offset); }