Search in sources :

Example 61 with HashMap

use of com.intellij.util.containers.HashMap in project android by JetBrains.

the class BasicNativeDebuggerTest method testMultiBreakAndResume.

@Test
public void testMultiBreakAndResume() throws IOException, ClassNotFoundException {
    guiTest.importProjectAndWaitForProjectSyncToFinish("BasicJniApp");
    createAVD();
    final IdeFrameFixture projectFrame = guiTest.ideFrame();
    // Setup breakpoints
    final String[] breakPoints = { "return sum;", "return product;", "return quotient;", "return (*env)->NewStringUTF(env, message);" };
    openAndToggleBreakPoints("app/src/main/jni/multifunction-jni.c", breakPoints);
    // Setup the expected patterns to match the variable values displayed in Debug windows's 'Variables' tab.
    final Map<String, String[]> breakpointToExpectedPatterns = new HashMap<>();
    breakpointToExpectedPatterns.put(breakPoints[0], new String[] { variableToSearchPattern("x1", "int", "1"), variableToSearchPattern("x2", "int", "2"), variableToSearchPattern("x3", "int", "3"), variableToSearchPattern("x4", "int", "4"), variableToSearchPattern("x5", "int", "5"), variableToSearchPattern("x6", "int", "6"), variableToSearchPattern("x7", "int", "7"), variableToSearchPattern("x8", "int", "8"), variableToSearchPattern("x9", "int", "9"), variableToSearchPattern("x10", "int", "10"), variableToSearchPattern("sum", "int", "55") });
    breakpointToExpectedPatterns.put(breakPoints[1], new String[] { variableToSearchPattern("x1", "int", "1"), variableToSearchPattern("x2", "int", "2"), variableToSearchPattern("x3", "int", "3"), variableToSearchPattern("x4", "int", "4"), variableToSearchPattern("x5", "int", "5"), variableToSearchPattern("x6", "int", "6"), variableToSearchPattern("x7", "int", "7"), variableToSearchPattern("x8", "int", "8"), variableToSearchPattern("x9", "int", "9"), variableToSearchPattern("x10", "int", "10"), variableToSearchPattern("product", "int", "3628800") });
    breakpointToExpectedPatterns.put(breakPoints[2], new String[] { variableToSearchPattern("x1", "int", "1024"), variableToSearchPattern("x2", "int", "2"), variableToSearchPattern("quotient", "int", "512") });
    breakpointToExpectedPatterns.put(breakPoints[3], new String[] { variableToSearchPattern("sum_of_10_ints", "int", "55"), variableToSearchPattern("product_of_10_ints", "int", "3628800"), variableToSearchPattern("quotient", "int", "512") });
    projectFrame.debugApp(DEBUG_CONFIG_NAME).selectDevice(AVD_NAME).clickOk();
    // Wait for "Debugger attached to process.*" to be printed on the app-native debug console.
    DebugToolWindowFixture debugToolWindowFixture = new DebugToolWindowFixture(projectFrame);
    {
        final ExecutionToolWindowFixture.ContentFixture contentFixture = debugToolWindowFixture.findContent(DEBUG_CONFIG_NAME);
        contentFixture.waitForOutput(new PatternTextMatcher(Pattern.compile(".*Debugger attached to process.*", Pattern.DOTALL)), 50);
    }
    // breakpointToExpectedPatterns.
    for (int i = 0; i < breakPoints.length; ++i) {
        if (i > 0) {
            resumeProgram();
        }
        final String[] expectedPatterns = breakpointToExpectedPatterns.get(breakPoints[i]);
        Wait.seconds(1).expecting("the debugger tree to appear").until(() -> verifyVariablesAtBreakpoint(expectedPatterns, DEBUG_CONFIG_NAME));
    }
    {
        // We cannot reuse the context fixture we got above, as its windows could have been repurposed for other things.
        final ExecutionToolWindowFixture.ContentFixture contentFixture = debugToolWindowFixture.findContent(DEBUG_CONFIG_NAME);
        contentFixture.stop();
        contentFixture.waitForExecutionToFinish();
    }
}
Also used : HashMap(com.intellij.util.containers.HashMap) IdeFrameFixture(com.android.tools.idea.tests.gui.framework.fixture.IdeFrameFixture) DebugToolWindowFixture(com.android.tools.idea.tests.gui.framework.fixture.DebugToolWindowFixture) PatternTextMatcher(org.fest.swing.util.PatternTextMatcher)

Example 62 with HashMap

use of com.intellij.util.containers.HashMap in project android by JetBrains.

the class AndroidApplicationPackageRenameProcessor method renameElement.

@Override
public void renameElement(PsiElement element, String newName, UsageInfo[] usages, @Nullable RefactoringElementListener listener) throws IncorrectOperationException {
    if (element instanceof PsiPackage) {
        final Map<GenericAttributeValue, String> newAttrValues = new HashMap<GenericAttributeValue, String>();
        final Project project = element.getProject();
        final String oldPackageQName = ((PsiPackage) element).getQualifiedName();
        final String newPackageQName = PsiUtilCore.getQualifiedNameAfterRename(oldPackageQName, newName);
        for (Module module : ModuleManager.getInstance(project).getModules()) {
            final AndroidFacet facet = AndroidFacet.getInstance(module);
            final Manifest manifest = facet != null ? facet.getManifest() : null;
            if (manifest != null) {
                final XmlElement manifestElement = manifest.getXmlElement();
                final PsiFile manifestPsiFile = manifestElement != null ? manifestElement.getContainingFile() : null;
                if (manifestPsiFile instanceof XmlFile) {
                    final String basePackage = manifest.getPackage().getValue();
                    if (basePackage == null) {
                        continue;
                    }
                    processAllAttributesToUpdate((XmlFile) manifestPsiFile, basePackage, oldPackageQName, newPackageQName, new Processor<Pair<GenericAttributeValue, String>>() {

                        @Override
                        public boolean process(Pair<GenericAttributeValue, String> pair) {
                            newAttrValues.put(pair.getFirst(), pair.getSecond());
                            return true;
                        }
                    });
                }
            }
        }
        new RenamePsiPackageProcessor().renameElement(element, newName, usages, listener);
        for (Map.Entry<GenericAttributeValue, String> e : newAttrValues.entrySet()) {
            //noinspection unchecked
            e.getKey().setStringValue(e.getValue());
        }
        return;
    }
    final PsiFile file = element.getContainingFile();
    if (!(file instanceof XmlFile)) {
        return;
    }
    final Map<GenericAttributeValue, PsiClass> attr2class = buildAttr2ClassMap((XmlFile) file);
    new RenameXmlAttributeProcessor().renameElement(element, newName, usages, listener);
    for (Map.Entry<GenericAttributeValue, PsiClass> e : attr2class.entrySet()) {
        //noinspection unchecked
        e.getKey().setValue(e.getValue());
    }
}
Also used : XmlFile(com.intellij.psi.xml.XmlFile) HashMap(com.intellij.util.containers.HashMap) RenamePsiPackageProcessor(com.intellij.refactoring.rename.RenamePsiPackageProcessor) Manifest(org.jetbrains.android.dom.manifest.Manifest) AndroidFacet(org.jetbrains.android.facet.AndroidFacet) Project(com.intellij.openapi.project.Project) RenameXmlAttributeProcessor(com.intellij.refactoring.rename.RenameXmlAttributeProcessor) XmlElement(com.intellij.psi.xml.XmlElement) Module(com.intellij.openapi.module.Module) HashMap(com.intellij.util.containers.HashMap) Map(java.util.Map) GenericAttributeValue(com.intellij.util.xml.GenericAttributeValue) Pair(com.intellij.openapi.util.Pair)

Example 63 with HashMap

use of com.intellij.util.containers.HashMap in project android by JetBrains.

the class AndroidDxWrapper method execute.

@SuppressWarnings({ "IOResourceOpenedButNotSafelyClosed" })
public static Map<AndroidCompilerMessageKind, List<String>> execute(@NotNull Module module, @NotNull IAndroidTarget target, @NotNull String outputDir, @NotNull String[] compileTargets, @NotNull String additionalVmParams, int maxHeapSize, boolean optimize) {
    BuildToolInfo buildToolInfo = target.getBuildToolInfo();
    if (buildToolInfo == null) {
        return Collections.singletonMap(AndroidCompilerMessageKind.ERROR, Collections.singletonList("No Build Tools in the Android SDK."));
    }
    String outFile = outputDir + File.separatorChar + AndroidCommonUtils.CLASSES_FILE_NAME;
    final Map<AndroidCompilerMessageKind, List<String>> messages = new HashMap<AndroidCompilerMessageKind, List<String>>(2);
    messages.put(AndroidCompilerMessageKind.ERROR, new ArrayList<String>());
    messages.put(AndroidCompilerMessageKind.INFORMATION, new ArrayList<String>());
    messages.put(AndroidCompilerMessageKind.WARNING, new ArrayList<String>());
    String dxJarPath = buildToolInfo.getPath(BuildToolInfo.PathId.DX_JAR);
    File dxJar = new File(dxJarPath);
    if (!dxJar.isFile()) {
        messages.get(AndroidCompilerMessageKind.ERROR).add(AndroidBundle.message("android.file.not.exist.error", dxJarPath));
        return messages;
    }
    JavaParameters parameters = new JavaParameters();
    Sdk sdk = ModuleRootManager.getInstance(module).getSdk();
    // dex runs after simple java compilation, so JDK must be specified
    assert sdk != null;
    parameters.setJdk(sdk);
    parameters.setMainClass(AndroidDxRunner.class.getName());
    ParametersList programParamList = parameters.getProgramParametersList();
    programParamList.add(dxJarPath);
    programParamList.add(outFile);
    programParamList.add("--optimize", Boolean.toString(optimize));
    programParamList.addAll(compileTargets);
    programParamList.add("--exclude");
    ParametersList vmParamList = parameters.getVMParametersList();
    if (additionalVmParams.length() > 0) {
        vmParamList.addParametersString(additionalVmParams);
    }
    if (!AndroidCommonUtils.hasXmxParam(vmParamList.getParameters())) {
        vmParamList.add("-Xmx" + maxHeapSize + "M");
    }
    final PathsList classPath = parameters.getClassPath();
    classPath.add(PathUtil.getJarPathForClass(AndroidDxRunner.class));
    classPath.add(PathUtil.getJarPathForClass(FileUtilRt.class));
    // delete file to check if it will exist after dex compilation
    if (!new File(outFile).delete()) {
        LOG.info("Cannot delete file " + outFile);
    }
    Process process;
    try {
        parameters.setUseDynamicClasspath(true);
        GeneralCommandLine commandLine = parameters.toCommandLine();
        LOG.info(commandLine.getCommandLineString());
        process = commandLine.createProcess();
        AndroidCommonUtils.handleDexCompilationResult(process, commandLine.getCommandLineString(), outFile, messages, false);
    } catch (ExecutionException e) {
        messages.get(AndroidCompilerMessageKind.ERROR).add("ExecutionException: " + e.getMessage());
        LOG.info(e);
        return messages;
    }
    return messages;
}
Also used : BuildToolInfo(com.android.sdklib.BuildToolInfo) HashMap(com.intellij.util.containers.HashMap) AndroidCompilerMessageKind(org.jetbrains.android.util.AndroidCompilerMessageKind) PathsList(com.intellij.util.PathsList) PathsList(com.intellij.util.PathsList) ArrayList(java.util.ArrayList) List(java.util.List) FileUtilRt(com.intellij.openapi.util.io.FileUtilRt) Sdk(com.intellij.openapi.projectRoots.Sdk) ExecutionException(com.intellij.execution.ExecutionException) File(java.io.File)

Example 64 with HashMap

use of com.intellij.util.containers.HashMap in project android by JetBrains.

the class SubtagsProcessingUtil method registerClassNameSubtags.

private static void registerClassNameSubtags(XmlTag tag, Map<String, PsiClass> classMap, Type type, SubtagProcessor subtagProcessor) {
    final Set<String> allAllowedTags = new HashSet<>();
    final Map<String, String> class2Name = new HashMap<>();
    for (Map.Entry<String, PsiClass> entry : classMap.entrySet()) {
        final String tagName = entry.getKey();
        final PsiClass aClass = entry.getValue();
        if (!AndroidUtils.isAbstract(aClass)) {
            allAllowedTags.add(tagName);
            final String qName = aClass.getQualifiedName();
            final String prevTagName = class2Name.get(qName);
            if (prevTagName == null || tagName.indexOf('.') == -1) {
                class2Name.put(qName, tagName);
            }
        }
    }
    registerSubtags(tag, allAllowedTags, class2Name.values(), type, subtagProcessor);
}
Also used : HashMap(com.intellij.util.containers.HashMap) PsiClass(com.intellij.psi.PsiClass) HashMap(com.intellij.util.containers.HashMap) Map(java.util.Map) HashSet(java.util.HashSet)

Example 65 with HashMap

use of com.intellij.util.containers.HashMap in project android by JetBrains.

the class AttributeDefinitionsImpl method addAttrsFromFile.

private void addAttrsFromFile(XmlFile file) {
    Map<StyleableDefinitionImpl, String[]> parentMap = new HashMap<>();
    final XmlDocument document = file.getDocument();
    if (document == null)
        return;
    final XmlTag rootTag = document.getRootTag();
    if (rootTag == null || !TAG_RESOURCES.equals(rootTag.getName()))
        return;
    String attrGroup = null;
    for (XmlTag tag : rootTag.getSubTags()) {
        String tagName = tag.getName();
        if (TAG_ATTR.equals(tagName)) {
            AttributeDefinition def = parseAttrTag(tag, null);
            // Sets group for attribute, for example: sets "Button Styles" group for "buttonStyleSmall" attribute
            if (def != null) {
                def.setAttrGroup(attrGroup);
            }
        } else if (TAG_DECLARE_STYLEABLE.equals(tagName)) {
            StyleableDefinitionImpl def = parseDeclareStyleableTag(tag, parentMap);
            // Only "Theme" Styleable has attribute groups
            if (def != null && def.getName().equals("Theme")) {
                parseAndAddAttrGroups(tag);
            }
        } else if (TAG_EAT_COMMENT.equals(tagName)) {
            // The framework attribute file follows a special convention where related attributes are grouped together,
            // and there is always a set of comments that indicate these sections which look like this:
            //     <!-- =========== -->
            //     <!-- Text styles -->
            //     <!-- =========== -->
            //     <eat-comment />
            // These section headers are always immediately followed by an <eat-comment>,
            // so to identify these we just look for <eat-comments>, and then we look for the comment within the block that isn't ascii art.
            String newAttrGroup = getCommentBeforeEatComment(tag);
            // We identify these by looking at the line length; category comments are short, and descriptive comments are longer
            if (newAttrGroup != null && newAttrGroup.length() <= ATTR_GROUP_MAX_CHARACTERS) {
                attrGroup = newAttrGroup;
            }
        }
    }
    for (Map.Entry<StyleableDefinitionImpl, String[]> entry : parentMap.entrySet()) {
        StyleableDefinitionImpl definition = entry.getKey();
        String[] parentNames = entry.getValue();
        for (String parentName : parentNames) {
            StyleableDefinitionImpl parent = getStyleableByName(parentName);
            if (parent != null) {
                definition.addParent(parent);
                parent.addChild(definition);
            } else {
                LOG.info("Found tag with unknown parent: " + parentName);
            }
        }
    }
}
Also used : HashMap(com.intellij.util.containers.HashMap) XmlDocument(com.intellij.psi.xml.XmlDocument) HashMap(com.intellij.util.containers.HashMap) Map(java.util.Map) XmlTag(com.intellij.psi.xml.XmlTag)

Aggregations

HashMap (com.intellij.util.containers.HashMap)118 NotNull (org.jetbrains.annotations.NotNull)23 VirtualFile (com.intellij.openapi.vfs.VirtualFile)22 File (java.io.File)22 Nullable (org.jetbrains.annotations.Nullable)18 Map (java.util.Map)17 Module (com.intellij.openapi.module.Module)15 Project (com.intellij.openapi.project.Project)15 ArrayList (java.util.ArrayList)14 PsiElement (com.intellij.psi.PsiElement)11 HashSet (com.intellij.util.containers.HashSet)10 List (java.util.List)9 IncorrectOperationException (com.intellij.util.IncorrectOperationException)8 IOException (java.io.IOException)8 Pair (com.intellij.openapi.util.Pair)6 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)6 SearchScope (com.intellij.psi.search.SearchScope)6 Logger (com.intellij.openapi.diagnostic.Logger)5 PsiFile (com.intellij.psi.PsiFile)5 UsageInfo (com.intellij.usageView.UsageInfo)5