public Map<String, HotSwapFile> scanForModifiedClasses( DebuggerSession session, HotSwapProgress progress ) { DebuggerManagerThreadImpl.assertIsManagerThread(); Map<String, HotSwapFile> modifiedClasses = new HashMap<>(); List<File> outputRoots = new ArrayList<>(); ApplicationManager.getApplication().runReadAction( () -> { VirtualFile[] allDirs = OrderEnumerator.orderEntries( getIjProject() ).getAllSourceRoots(); for( VirtualFile dir : allDirs ) { outputRoots.add( new File( dir.getPath() ) ); } } ); long timeStamp = getTimeStamp( session ); for( File root : outputRoots ) { String rootPath = FileUtil.toCanonicalPath( root.getPath() ); collectModifiedClasses( root, rootPath, modifiedClasses, progress, timeStamp ); } setTimeStamp( session, System.currentTimeMillis() ); return modifiedClasses; }
@NotNull public static Map<String, PsiFile> findComponents(@NotNull final Project project) { Map<String, PsiFile> result = new HashMap<String, PsiFile>(); Collection<VirtualFile> virtualFiles = FileBasedIndex.getInstance().getContainingFiles(FilenameIndex.NAME, CatberryConstants.CAT_COMPONENT_JSON, GlobalSearchScope.allScope(project)); for (VirtualFile virtualFile : virtualFiles) { JsonFile psiFile = (JsonFile) PsiManager.getInstance(project).findFile(virtualFile); if (psiFile != null) { JsonProperty[] properties = PsiTreeUtil.getChildrenOfType(psiFile.getTopLevelValue(), JsonProperty.class); if (properties != null) { for (JsonProperty property : properties) { if (!property.getName().equals("name")) continue; if (property.getValue() != null && property.getValue() instanceof JsonStringLiteral) result.put(((JsonStringLiteral) property.getValue()).getValue(), psiFile); break; } } } } return result; }
/** * Create EntityPresenter.class */ public static void create() { // Create presenter directory presenterDirectory = createDirectory(getViewPackage(), PRESENTER.toLowerCase()); // Create presenter class String className = getEntityConfig().getEntityName() + PRESENTER; HashMap<String, String> varTemplate = new HashMap<>(); varTemplate.put("PACKAGE_PRESENTER_IMPL", getPackageNameProject(Presenter.getPresenterDirectory())); varTemplate.put("PRESENTER_IMPL", PRESENTER_IMPL); Runnable runnable = () -> JavaDirectoryService.getInstance().createClass(presenterDirectory, className, PRESENTER_TEMPLATE, false, varTemplate); WriteCommandAction.runWriteCommandAction(getProject(), runnable); }
@Override protected PsiClassType calcType() { final PsiElement classElement = myClass.getElement(); if (!(classElement instanceof PsiClass)) return null; Map<PsiTypeParameter, PsiType> resurrected = new HashMap<PsiTypeParameter, PsiType>(); final Set<Map.Entry<SmartPsiElementPointer, SmartTypePointer>> set = myMap.entrySet(); for (Map.Entry<SmartPsiElementPointer, SmartTypePointer> entry : set) { PsiElement element = entry.getKey().getElement(); if (element instanceof PsiTypeParameter) { SmartTypePointer typePointer = entry.getValue(); resurrected.put((PsiTypeParameter)element, typePointer == null ? null : typePointer.getType()); } } for (PsiTypeParameter typeParameter : PsiUtil.typeParametersIterable((PsiClass)classElement)) { if (!resurrected.containsKey(typeParameter)) { resurrected.put(typeParameter, null); } } final PsiSubstitutor resurrectedSubstitutor = PsiSubstitutorImpl.createSubstitutor(resurrected); return new PsiImmediateClassType((PsiClass)classElement, resurrectedSubstitutor); }
public static Result searchForVarsToWrap(GroovyPsiElement root, Result analyzedVars, ExpressionContext context) { LocalVarAnalyzer visitor = new LocalVarAnalyzer(); root.accept(visitor); Map<PsiVariable, String> varToName = analyzedVars == null ? new HashMap<PsiVariable, String>() : analyzedVars.varToName; Set<PsiVariable> toWrap = analyzedVars == null ? new HashSet<PsiVariable>() : analyzedVars.toWrap; Set<PsiVariable> toMakeFinal = analyzedVars == null ? new HashSet<PsiVariable>() : analyzedVars.toMakeFinal; for (PsiVariable v : visitor.touched) { if (visitor.rewritten.contains(v)) { toWrap.add(v); if (v instanceof PsiParameter) { varToName.put(v, GenerationUtil.suggestVarName(v.getType(), root, context)); } else { varToName.put(v, v.getName()); } } else { toMakeFinal.add(v); varToName.put(v, v.getName()); } } return analyzedVars == null ? new Result(toMakeFinal, toWrap, varToName) : analyzedVars; }
@Nullable protected DomElement createElement(final T context, final Editor editor, final PsiFile file, final Project project, PsiClass selectedClass) { final Map<String,String> map = new HashMap<String, String>(); map.put("CLASS_NAME", selectedClass.getQualifiedName()); new WriteCommandAction.Simple(project, file) { @Override protected void run() throws Throwable { DomTemplateRunner.getInstance(project).runTemplate(createElement(context), myTemplate, editor, map); } }.execute(); return null; }
@Override public Set<? extends T> getDependent() { if(myDependencies == null) { myDependencies = new HashSet<T>(); myDependenciesToDependent = new HashMap<T, HashSet<T>>(); for (T member : myMembers) { Set<T> dependent = myMemberDependenciesStorage.getMemberDependencies(member); if (dependent != null) { for (final T aDependent : dependent) { if (mySelectedNormal.contains(aDependent) && !mySelectedAbstract.contains(aDependent)) { myDependencies.add(member); HashSet<T> deps = myDependenciesToDependent.get(member); if (deps == null) { deps = new HashSet<T>(); myDependenciesToDependent.put(member, deps); } deps.add(aDependent); } } } } } return myDependencies; }
static Map<PsiMethodCallExpression, PsiMethod> encodeOverloadTargets(final PsiClass targetClass, final SearchScope processConflictsScope, final String overloadName, final PsiElement extractedFragment) { final Map<PsiMethodCallExpression, PsiMethod> ret = new HashMap<PsiMethodCallExpression, PsiMethod>(); encodeInClass(targetClass, overloadName, extractedFragment, ret); ClassInheritorsSearch.search(targetClass, processConflictsScope, true).forEach(new Processor<PsiClass>() { public boolean process(PsiClass inheritor) { encodeInClass(inheritor, overloadName, extractedFragment, ret); return true; } }); return ret; }
@NotNull private static PsiSubstitutor substituteTypeParameters(@NotNull JVMElementFactory factory, @Nullable PsiElement target, @Nullable PsiTypeParameterList sourceTypeParameterList, @Nullable PsiTypeParameterList targetTypeParameterList, @NotNull PsiSubstitutor substitutor, @NotNull PsiMethod sourceMethod) { if (sourceTypeParameterList == null || targetTypeParameterList == null || PsiUtil.isRawSubstitutor(sourceMethod, substitutor)) { return substitutor; } final Map<PsiTypeParameter, PsiType> substitutionMap = new HashMap<PsiTypeParameter, PsiType>(substitutor.getSubstitutionMap()); for (PsiTypeParameter typeParam : sourceTypeParameterList.getTypeParameters()) { final PsiTypeParameter substitutedTypeParam = substituteTypeParameter(factory, typeParam, substitutor, sourceMethod); final PsiTypeParameter resolvedTypeParam = resolveTypeParametersCollision(factory, sourceTypeParameterList, target, substitutedTypeParam, substitutor); targetTypeParameterList.add(resolvedTypeParam); if (substitutedTypeParam != resolvedTypeParam) { substitutionMap.put(typeParam, factory.createType(resolvedTypeParam)); } } return substitutionMap.isEmpty() ? substitutor : factory.createSubstitutor(substitutionMap); }
@NotNull private static PsiTypeParameter substituteTypeParameter(final @NotNull JVMElementFactory factory, @NotNull PsiTypeParameter typeParameter, final @NotNull PsiSubstitutor substitutor, @NotNull final PsiMethod sourceMethod) { final PsiElement copy = typeParameter.copy(); final Map<PsiElement, PsiElement> replacementMap = new HashMap<PsiElement, PsiElement>(); copy.accept(new JavaRecursiveElementVisitor() { @Override public void visitReferenceElement(PsiJavaCodeReferenceElement reference) { super.visitReferenceElement(reference); final PsiElement resolve = reference.resolve(); if (resolve instanceof PsiTypeParameter) { final PsiType type = factory.createType((PsiTypeParameter)resolve); replacementMap.put(reference, factory.createReferenceElementByType((PsiClassType)substituteType(substitutor, type, sourceMethod))); } } }); return (PsiTypeParameter)RefactoringUtil.replaceElementsWithMap(copy, replacementMap); }
@Override public Result<Map<String, XmlTag>> compute() { final Map<String,XmlTag> resultMap = new HashMap<String, XmlTag>(); XmlDocument document = HtmlUtil.getRealXmlDocument(myFile.getDocument()); final XmlTag rootTag = document != null ? document.getRootTag():null; if (rootTag != null) { processXmlElements(rootTag, new PsiElementProcessor<XmlTag>() { @Override public boolean execute(@NotNull final XmlTag element) { final String anchorValue = getAnchorValue(element); if (anchorValue!=null) { resultMap.put(anchorValue, element); } return true; } } ); } return new Result<Map<String, XmlTag>>(resultMap, myFile); }
@Override public void visitForeachStatement(@NotNull PsiForeachStatement statement) { if (myExpr.equals(statement.getIteratedValue())) { PsiType type = statement.getIterationParameter().getType(); PsiType arrayType = type.createArrayType(); myResult.add(createInfoImpl(arrayType, arrayType)); PsiManager manager = statement.getManager(); PsiElementFactory factory = JavaPsiFacade.getInstance(manager.getProject()).getElementFactory(); PsiClass iterableClass = JavaPsiFacade.getInstance(manager.getProject()).findClass("java.lang.Iterable", statement.getResolveScope()); if (iterableClass != null && iterableClass.getTypeParameters().length == 1) { Map<PsiTypeParameter, PsiType> map = new HashMap<PsiTypeParameter, PsiType>(); map.put(iterableClass.getTypeParameters()[0], PsiWildcardType.createExtends(manager, type)); PsiType iterableType = factory.createType(iterableClass, factory.createSubstitutor(map)); myResult.add(createInfoImpl(iterableType, iterableType)); } } }
@NotNull @Override public PsiPackage[] getSubPackages(@NotNull PsiPackage psiPackage, @NotNull GlobalSearchScope scope) { final Map<String, PsiPackage> packagesMap = new HashMap<String, PsiPackage>(); final String qualifiedName = psiPackage.getQualifiedName(); for (final String prefix : myPackagePrefixIndex.getAllPackagePrefixes(scope)) { if (StringUtil.isEmpty(qualifiedName) || StringUtil.startsWithConcatenation(prefix, qualifiedName, ".")) { final int i = prefix.indexOf('.', qualifiedName.length() + 1); String childName = i >= 0 ? prefix.substring(0, i) : prefix; if (!packagesMap.containsKey(childName)) { packagesMap.put(childName, new PsiPackageImpl(psiPackage.getManager(), childName)); } } } packagesMap.remove(qualifiedName); // avoid SOE caused by returning a package as a subpackage of itself return packagesMap.values().toArray(new PsiPackage[packagesMap.size()]); }
private PsiMethod addOrChangeAccessor(PsiMethod prototype, HashMap<String,PsiMethod> nameToAncestor) { PsiMethod existing = myClass.findMethodBySignature(prototype, false); PsiMethod result = existing; try{ if (existing == null){ PsiUtil.setModifierProperty(prototype, myDescriptor.getAccessorsVisibility(), true); result = (PsiMethod) myClass.add(prototype); } else{ //TODO : change visibility } nameToAncestor.put(prototype.getName(), result); return result; } catch(IncorrectOperationException e){ LOG.error(e); } return null; }
@Nullable private static Map<PsiTypeParameter, PsiTypeParameter> calculateReplacementMap(final PsiSubstitutor substitutor, final PsiClass targetClass, final PsiElement containingElement) { final HashMap<PsiTypeParameter, PsiTypeParameter> result = new HashMap<PsiTypeParameter, PsiTypeParameter>(); for (PsiTypeParameter classTypeParameter : PsiUtil.typeParametersIterable(targetClass)) { final PsiType substitution = substitutor.substitute(classTypeParameter); if (!(substitution instanceof PsiClassType)) return null; final PsiClass aClass = ((PsiClassType)substitution).resolve(); if (!(aClass instanceof PsiTypeParameter)) return null; final PsiTypeParameter methodTypeParameter = (PsiTypeParameter)aClass; if (methodTypeParameter.getOwner() != containingElement) return null; if (result.keySet().contains(methodTypeParameter)) return null; result.put(methodTypeParameter, classTypeParameter); } return result; }
JavaResolveSnapshot(final PsiElement scope) { myProject = scope.getProject(); myDocument = PsiDocumentManager.getInstance(myProject).getDocument(scope.getContainingFile()); final SmartPointerManager pointerManager = SmartPointerManager.getInstance(myProject); final Map<PsiElement, SmartPsiElementPointer> pointers = new HashMap<PsiElement, SmartPsiElementPointer>(); scope.accept(new JavaRecursiveElementWalkingVisitor() { @Override public void visitReferenceExpression(PsiReferenceExpression refExpr) { if (!refExpr.isQualified()) { JavaResolveResult resolveResult = refExpr.advancedResolve(false); final PsiElement resolved = resolveResult.getElement(); if (resolved instanceof PsiField && resolveResult.isStaticsScopeCorrect()) { SmartPsiElementPointer key = pointerManager.createSmartPsiElementPointer(refExpr); SmartPsiElementPointer value = pointers.get(resolved); if (value == null) { value = pointerManager.createSmartPsiElementPointer(resolved); pointers.put(resolved, value); } myReferencesMap.put(key, value); } } super.visitReferenceExpression(refExpr); } }); }
@Nullable private JPanel createParametersPanel () { myThisClassesMap = MoveInstanceMembersUtil.getThisClassesToMembers(myMethod); myOldClassParameterNameFields = new HashMap<PsiClass, EditorTextField>(); if (myThisClassesMap.size() == 0) return null; JPanel panel = new JPanel(new VerticalFlowLayout(VerticalFlowLayout.TOP, 0, 0, true, true)); for (PsiClass aClass : myThisClassesMap.keySet()) { final String text = RefactoringBundle.message("move.method.this.parameter.label", aClass.getName()); panel.add(new TitledSeparator(text, null)); String suggestedName = MoveInstanceMethodHandler.suggestParameterNameForThisClass(aClass); final EditorTextField field = new EditorTextField(suggestedName, getProject(), StdFileTypes.JAVA); field.setMinimumSize(new Dimension(field.getPreferredSize())); myOldClassParameterNameFields.put(aClass, field); panel.add(field); } panel.setBorder(BorderFactory.createEmptyBorder(5, 0, 5, 0)); return panel; }
public static VirtualFile chooseSourceRoot(final PackageWrapper targetPackage, final List<VirtualFile> contentSourceRoots, final PsiDirectory initialDirectory) { Project project = targetPackage.getManager().getProject(); //ensure that there would be no duplicates: e.g. when one content root is subfolder of another root (configured via excluded roots) LinkedHashSet<PsiDirectory> targetDirectories = new LinkedHashSet<PsiDirectory>(); Map<PsiDirectory, String> relativePathsToCreate = new HashMap<PsiDirectory,String>(); buildDirectoryList(targetPackage, contentSourceRoots, targetDirectories, relativePathsToCreate); final PsiDirectory selectedDirectory = DirectoryChooserUtil.chooseDirectory( targetDirectories.toArray(new PsiDirectory[targetDirectories.size()]), initialDirectory, project, relativePathsToCreate ); if (selectedDirectory == null) return null; final VirtualFile virt = selectedDirectory.getVirtualFile(); final VirtualFile sourceRootForFile = ProjectRootManager.getInstance(project).getFileIndex().getSourceRootForFile(virt); LOG.assertTrue(sourceRootForFile != null); return sourceRootForFile; }
public Settings(boolean replaceUsages, @Nullable String classParameterName, @Nullable VariableData[] variableDatum, boolean delegate) { myReplaceUsages = replaceUsages; myDelegate = delegate; myMakeClassParameter = classParameterName != null; myClassParameterName = classParameterName; myMakeFieldParameters = variableDatum != null; myFieldToNameList = new ArrayList<FieldParameter>(); if(myMakeFieldParameters) { myFieldToNameMapping = new HashMap<PsiField, String>(); for (VariableData data : variableDatum) { if (data.passAsParameter) { myFieldToNameMapping.put((PsiField)data.variable, data.name); myFieldToNameList.add(new FieldParameter((PsiField)data.variable, data.name, data.type)); } } } else { myFieldToNameMapping = null; } }
public Settings(boolean replaceUsages, String classParameterName, PsiField[] fields, String[] names) { myReplaceUsages = replaceUsages; myMakeClassParameter = classParameterName != null; myClassParameterName = classParameterName; myMakeFieldParameters = fields.length > 0; myFieldToNameList = new ArrayList<FieldParameter>(); if (myMakeFieldParameters) { myFieldToNameMapping = new HashMap<PsiField, String>(); for (int i = 0; i < fields.length; i++) { final PsiField field = fields[i]; final String name = names[i]; myFieldToNameMapping.put(field, name); myFieldToNameList.add(new FieldParameter(field, name, field.getType())); } } else { myFieldToNameMapping = null; } myDelegate = false; }
@NotNull public static Collection<String> removeUnambiguousNames(@NotNull Map<String, PsiClass> viewClassMap) { final Map<String, String> class2Name = new HashMap<String, String>(); for (String tagName : viewClassMap.keySet()) { final PsiClass viewClass = viewClassMap.get(tagName); if (!AndroidUtils.isAbstract(viewClass)) { final String qName = viewClass.getQualifiedName(); final String prevTagName = class2Name.get(qName); if (prevTagName == null || tagName.indexOf('.') == -1) { class2Name.put(qName, tagName); } } } return class2Name.values(); }
protected XmlAttributeDescriptor[] computeAttributeDescriptors(final Map<DAttributePattern, Pair<? extends Map<String, String>, Boolean>> map) { final Map<QName, RngXmlAttributeDescriptor> name2descriptor = new HashMap<QName, RngXmlAttributeDescriptor>(); for (DAttributePattern pattern : map.keySet()) { final Pair<? extends Map<String, String>, Boolean> value = map.get(pattern); for (QName name : pattern.getName().listNames()) { RngXmlAttributeDescriptor descriptor = name2descriptor.get(name); final RngXmlAttributeDescriptor newDescriptor = new RngXmlAttributeDescriptor(this, pattern, value.first, value.second); if (descriptor == null) { descriptor = newDescriptor; } else { descriptor = descriptor.mergeWith(newDescriptor); } name2descriptor.put(name, descriptor); } } final Collection<RngXmlAttributeDescriptor> result = name2descriptor.values(); return result.toArray(new RngXmlAttributeDescriptor[result.size()]); }
@NotNull private static Map<JpsModule, String> getDepLibPackages(@NotNull JpsModule module) throws IOException { final Map<JpsModule, String> result = new HashMap<JpsModule, String>(); for (JpsAndroidModuleExtension depExtension : AndroidJpsUtil.getAllAndroidDependencies(module, true)) { final File depManifestFile = AndroidJpsUtil.getManifestFileForCompilationPath(depExtension); if (depManifestFile != null && depManifestFile.exists()) { final String packageName = AndroidJpsUtil.parsePackageNameFromManifestFile(depManifestFile); if (packageName != null) { result.put(depExtension.getModule(), packageName); } } } return result; }
@NotNull public static <T> Map<CompilerMessageCategory, T> toCompilerMessageCategoryKeys(@NotNull Map<AndroidCompilerMessageKind, T> map) { final Map<CompilerMessageCategory, T> result = new HashMap<CompilerMessageCategory, T>(); for (Map.Entry<AndroidCompilerMessageKind, T> entry : map.entrySet()) { final AndroidCompilerMessageKind key = entry.getKey(); final T value = entry.getValue(); switch (key) { case ERROR: result.put(CompilerMessageCategory.ERROR, value); break; case INFORMATION: result.put(CompilerMessageCategory.INFORMATION, value); break; case WARNING: result.put(CompilerMessageCategory.WARNING, value); break; } } return result; }
private static List<VariableInfo> mustAddVariableDeclaration(@NotNull GrStatement[] statements, @NotNull VariableInfo[] vars) { Map<String, VariableInfo> names = new HashMap<String, VariableInfo>(); for (VariableInfo var : vars) { names.put(var.getName(), var); } List<VariableInfo> result = new ArrayList<VariableInfo>(); for (GrStatement statement : statements) { if (statement instanceof GrVariableDeclaration) { GrVariableDeclaration declaration = (GrVariableDeclaration)statement; for (GrVariable variable : declaration.getVariables()) { final VariableInfo removed = names.remove(variable.getName()); if (removed != null) { result.add(removed); } } } } for (String varName : names.keySet()) { if (ResolveUtil.resolveProperty(statements[0], varName) == null) { result.add(names.get(varName)); } } return result; }
@NotNull @Override public DataIndexer<TokenIndexKey, List<Token>, FileContent> getIndexer() { return new DataIndexer<TokenIndexKey, List<Token>, FileContent>() { @Override @NotNull public Map<TokenIndexKey, List<Token>> map(@NotNull FileContent inputData) { if (true) return Collections.EMPTY_MAP; // TODO: Eugene index is VERY unefficient and leads to OME Map<TokenIndexKey, List<Token>> result = new HashMap<TokenIndexKey, List<Token>>(1); RecursiveTokenizingVisitor visitor = new RecursiveTokenizingVisitor(); inputData.getPsiFile().accept(visitor); List<Token> tokens = visitor.getTokens(); if (tokens.size() > 0) { String path = inputData.getFile().getPath(); tokens.add(new PathMarkerToken(path)); TokenIndexKey key = new TokenIndexKey(visitor.getLanguages(), getBlockId(path)); result.put(key, tokens); } return result; } }; }
private static Map<String, List<String>> getOrder(final File loadingFile) throws IOException { final Map<String, List<String>> entriesOrder = new HashMap<String, List<String>>(); final String[] lines = FileUtil.loadFile(loadingFile).split("\n"); for (String line : lines) { line = line.trim(); final int i = line.indexOf(":"); if (i != -1) { final String entry = line.substring(0, i); final String jarUrl = line.substring(i + 1); List<String> entries = entriesOrder.get(jarUrl); if (entries == null) { entries = new ArrayList<String>(); entriesOrder.put(jarUrl, entries); } entries.add(entry); } } return entriesOrder; }
public static String getInspectionShortNameByIssue(@NotNull Project project, @NotNull Issue issue) { synchronized (ISSUE_MAP_LOCK) { if (ourIssue2InspectionShortName == null) { ourIssue2InspectionShortName = new HashMap<Issue, String>(); final InspectionProfile profile = InspectionProjectProfileManager.getInstance(project).getInspectionProfile(); for (InspectionToolWrapper e : profile.getInspectionTools(null)) { final String shortName = e.getShortName(); if (shortName.startsWith("AndroidLint")) { final InspectionProfileEntry entry = e.getTool(); if (entry instanceof AndroidLintInspectionBase) { final Issue s = ((AndroidLintInspectionBase)entry).getIssue(); ourIssue2InspectionShortName.put(s, shortName); } } } } return ourIssue2InspectionShortName.get(issue); } }
public void testTNumberingSimple() { final TestNode nA = new TestNode("A"); final TestNode nB = new TestNode("B"); final TestNode nC = new TestNode("C"); final TestNode nD = new TestNode("D"); final TestNode[] allNodes = {nA, nB, nC, nD}; final Map<TestNode, TestNode[]> map = new HashMap<TestNode, TestNode[]>(); map.put(nA, new TestNode[]{nC}); map.put(nB, new TestNode[]{nA}); map.put(nC, new TestNode[]{nB}); map.put(nD, new TestNode[]{nB}); GraphGenerator<TestNode> graph = graphByNodes(allNodes, map); final DFSTBuilder<TestNode> dfstBuilder = new DFSTBuilder<TestNode>(graph); assertFalse(dfstBuilder.isAcyclic()); Comparator<TestNode> comparator = dfstBuilder.comparator(); assertTrue(comparator.compare(nA, nD) < 0); assertTrue(comparator.compare(nB, nD) < 0); assertTrue(comparator.compare(nC, nD) < 0); }
public void testSccsReportedInLoadingOrder() { final TestNode main = new TestNode("main"); final TestNode dep = new TestNode("dep"); final TestNode d = new TestNode("d"); final TestNode d2 = new TestNode("d2"); final TestNode resMain = new TestNode("resMain"); final TestNode resDep = new TestNode("resDep"); final TestNode[] allNodes = {main, dep, d, d2, resMain, resDep}; final Map<TestNode, TestNode[]> mapIn = new HashMap<TestNode, TestNode[]>(); mapIn.put(main, new TestNode[]{d, resMain}); mapIn.put(dep, new TestNode[]{main,resDep}); mapIn.put(d, new TestNode[]{d2}); mapIn.put(d2, new TestNode[]{dep, d}); GraphGenerator<TestNode> graph = graphByNodes(allNodes, mapIn); final DFSTBuilder<TestNode> dfstBuilder = new DFSTBuilder<TestNode>(graph); assertTrue (!dfstBuilder.isAcyclic()); Comparator<TestNode> comparator = dfstBuilder.comparator(); assertTrue(comparator.compare(resMain, main) < 0); assertTrue(comparator.compare(resMain, d) < 0); assertTrue(comparator.compare(resMain, d2) < 0); assertTrue(comparator.compare(resDep, dep) < 0); assertTrue(comparator.compare(resMain, resDep) > 0); //reversed loading order }
public void testReportedInLoadingOrder() { final TestNode o = new TestNode("o"); final TestNode a = new TestNode("a"); final TestNode b = new TestNode("b"); final TestNode c = new TestNode("c"); for (int oIndex = 0; oIndex<4; oIndex++) { List<TestNode> list = new ArrayList<TestNode>(Arrays.asList(a,b,c)); list.add(oIndex, o); TestNode[] allNodes = list.toArray(new TestNode[list.size()]); Map<TestNode, TestNode[]> mapIn = new HashMap<TestNode, TestNode[]>(); mapIn.put(o, new TestNode[]{a,b,c}); final DFSTBuilder<TestNode> dfstBuilder = new DFSTBuilder<TestNode>(graphByNodes(allNodes, mapIn)); assertTrue (dfstBuilder.isAcyclic()); Comparator<TestNode> comparator = dfstBuilder.comparator(); TestNode[] sorted = allNodes.clone(); Arrays.sort(sorted, comparator); assertEquals("All nodes: "+list, Arrays.asList(c,b,a,o), Arrays.asList(sorted)); } }
public Map<DebuggerSession, Map<String, HotSwapFile>> scanForModifiedClasses( List<DebuggerSession> sessions, HotSwapProgress swapProgress ) { Map<DebuggerSession, Map<String, HotSwapFile>> modifiedClasses = new HashMap<>(); MultiProcessCommand scanClassesCommand = new MultiProcessCommand(); swapProgress.setCancelWorker( scanClassesCommand::cancel ); for( final DebuggerSession debuggerSession : sessions ) { if( debuggerSession.isAttached() ) { scanClassesCommand.addCommand( debuggerSession.getProcess(), new DebuggerCommandImpl() { protected void action() throws Exception { swapProgress.setDebuggerSession( debuggerSession ); Map<String, HotSwapFile> sessionClasses = scanForModifiedClasses( debuggerSession, swapProgress ); if( !sessionClasses.isEmpty() ) { modifiedClasses.put( debuggerSession, sessionClasses ); } } } ); } } swapProgress.setTitle( DebuggerBundle.message( "progress.hotswap.scanning.classes" ) ); scanClassesCommand.run(); if( swapProgress.isCancelled() ) { for( DebuggerSession session : sessions ) { session.setModifiedClassesScanRequired( true ); } return new HashMap<>(); } return modifiedClasses; }
private Map<String, File> makeTempFiles( Collection<InMemoryClassJavaFileObject> result ) { Map<String, File> map = new HashMap<>(); for( InMemoryClassJavaFileObject obj: result ) { map.put( obj.getClassName(), createTempFile( obj.getBytes() ) ); } return map; }
public static Map<String, AbstractVariableData> createVariableMap(final AbstractVariableData[] data) { final HashMap<String, AbstractVariableData> map = new HashMap<String, AbstractVariableData>(); for (AbstractVariableData variableData : data) { map.put(variableData.getOriginalName(), variableData); } return map; }
@Override protected PtyProcess createProcess(@Nullable String directory) throws ExecutionException { Map<String, String> envs = new HashMap<String, String>(System.getenv()); envs.put("TERM", "xterm-256color"); EncodingEnvironmentUtil.setLocaleEnvironmentIfMac(envs, myDefaultCharset); try { return PtyProcess.exec(getCommand(), envs, directory != null ? directory : currentProjectFolder()); } catch (IOException e) { throw new ExecutionException(e); } }
@NotNull @Override public PsiSubstitutor createRawSubstitutor(@NotNull final PsiTypeParameterListOwner owner) { Map<PsiTypeParameter, PsiType> substitutorMap = null; for (PsiTypeParameter parameter : PsiUtil.typeParametersIterable(owner)) { if (substitutorMap == null) substitutorMap = new HashMap<PsiTypeParameter, PsiType>(); substitutorMap.put(parameter, null); } return PsiSubstitutorImpl.createSubstitutor(substitutorMap); }
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); } }
protected void addEnvVars(final JavaParameters params) { Map<String, String> envVars = new HashMap<String, String>(envs); envVars.putAll(params.getEnv()); params.setupEnvs(envVars, passParentEnv); MvcFramework.addJavaHome(params, myModule); }
private void initializeMaps() { Map<String, PsiImportStatement> classNameToImportMap = new HashMap<String, PsiImportStatement>(); Map<String, PsiImportStatement> packageNameToImportMap = new HashMap<String, PsiImportStatement>(); Map<String, PsiImportStatementBase> nameToSingleImportMap = new HashMap<String, PsiImportStatementBase>(); PsiImportStatement[] imports = getImportStatements(); for (PsiImportStatement anImport : imports) { String qName = anImport.getQualifiedName(); if (qName == null) continue; if (anImport.isOnDemand()) { packageNameToImportMap.put(qName, anImport); } else { classNameToImportMap.put(qName, anImport); PsiJavaCodeReferenceElement importReference = anImport.getImportReference(); if (importReference == null) continue; nameToSingleImportMap.put(importReference.getReferenceName(), anImport); } } PsiImportStaticStatement[] importStatics = getImportStaticStatements(); for (PsiImportStaticStatement importStatic : importStatics) { if (!importStatic.isOnDemand()) { String referenceName = importStatic.getReferenceName(); if (referenceName != null) { nameToSingleImportMap.put(referenceName, importStatic); } } } myClassNameToImportMap = classNameToImportMap; myPackageNameToImportMap = packageNameToImportMap; myNameToSingleImportMap = nameToSingleImportMap; }
private Map<CvsRootProvider, ArrayList<File>> buildRootsToFilesMap() throws CannotFindCvsRootException { HashMap<CvsRootProvider,ArrayList<File>> result = new HashMap<CvsRootProvider, ArrayList<File>>(); for (File file : myFiles) { CvsRootProvider cvsRoot = CvsRootProvider.createOn(file); if (cvsRoot == null) { throw new CannotFindCvsRootException(file); } else { if (!result.containsKey(cvsRoot)) result.put(cvsRoot, new ArrayList<File>()); (result.get(cvsRoot)).add(file); } } return result; }