Search in sources :

Example 16 with VisibleForTesting

use of com.android.annotations.VisibleForTesting in project android by JetBrains.

the class StyleFilter method isDerived.

@VisibleForTesting
boolean isDerived(@NotNull StyleResourceValue style) {
    String styleName = getStyleName(style);
    if (myDerivedStyles.contains(styleName)) {
        return true;
    }
    if (myOtherStyles.contains(styleName)) {
        return false;
    }
    StyleResourceValue parentStyle = myResolver.getParent(style);
    if (parentStyle != null && !myCurrentInheritanceChain.contains(styleName)) {
        myCurrentInheritanceChain.add(styleName);
        return found(styleName, isDerived(parentStyle));
    }
    return found(styleName, false);
}
Also used : StyleResourceValue(com.android.ide.common.rendering.api.StyleResourceValue) VisibleForTesting(com.android.annotations.VisibleForTesting)

Example 17 with VisibleForTesting

use of com.android.annotations.VisibleForTesting in project kotlin by JetBrains.

the class LayoutInflationDetector method hasLayoutParams.

@VisibleForTesting
static boolean hasLayoutParams(@NonNull Reader reader) throws XmlPullParserException, IOException {
    KXmlParser parser = new KXmlParser();
    parser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, true);
    parser.setInput(reader);
    while (true) {
        int event = parser.next();
        if (event == XmlPullParser.START_TAG) {
            for (int i = 0; i < parser.getAttributeCount(); i++) {
                if (parser.getAttributeName(i).startsWith(ATTR_LAYOUT_RESOURCE_PREFIX)) {
                    String prefix = parser.getAttributePrefix(i);
                    if (prefix != null && !prefix.isEmpty() && ANDROID_URI.equals(parser.getNamespace(prefix))) {
                        return true;
                    }
                }
            }
            return false;
        } else if (event == XmlPullParser.END_DOCUMENT) {
            return false;
        }
    }
}
Also used : KXmlParser(org.kxml2.io.KXmlParser) VisibleForTesting(com.android.annotations.VisibleForTesting)

Example 18 with VisibleForTesting

use of com.android.annotations.VisibleForTesting in project kotlin by JetBrains.

the class StringFormatDetector method getFormatArgumentType.

//$NON-NLS-1$
/** Given a format string returns the format type of the given argument */
@VisibleForTesting
@Nullable
static String getFormatArgumentType(String s, int argument) {
    Matcher matcher = FORMAT.matcher(s);
    int index = 0;
    int prevIndex = 0;
    int nextNumber = 1;
    while (true) {
        if (matcher.find(index)) {
            String value = matcher.group(6);
            if ("%".equals(value) || "n".equals(value)) {
                //$NON-NLS-1$ //$NON-NLS-2$
                index = matcher.end();
                continue;
            }
            int matchStart = matcher.start();
            // Make sure this is not an escaped '%'
            for (; prevIndex < matchStart; prevIndex++) {
                char c = s.charAt(prevIndex);
                if (c == '\\') {
                    prevIndex++;
                }
            }
            if (prevIndex > matchStart) {
                // We're in an escape, ignore this result
                index = prevIndex;
                continue;
            }
            // Shouldn't throw a number format exception since we've already
            // matched the pattern in the regexp
            int number;
            String numberString = matcher.group(1);
            if (numberString != null) {
                // Strip off trailing $
                numberString = numberString.substring(0, numberString.length() - 1);
                number = Integer.parseInt(numberString);
                nextNumber = number + 1;
            } else {
                number = nextNumber++;
            }
            if (number == argument) {
                return matcher.group(6);
            }
            index = matcher.end();
        } else {
            break;
        }
    }
    return null;
}
Also used : Matcher(java.util.regex.Matcher) VisibleForTesting(com.android.annotations.VisibleForTesting) Nullable(com.android.annotations.Nullable)

Example 19 with VisibleForTesting

use of com.android.annotations.VisibleForTesting in project android by JetBrains.

the class NewProjectImportGradleSyncListener method createTopLevelModule.

@VisibleForTesting
public static void createTopLevelModule(@NotNull Project project) {
    ModuleManager moduleManager = ModuleManager.getInstance(project);
    File projectRootDir = getBaseDirPath(project);
    VirtualFile contentRoot = findFileByIoFile(projectRootDir, true);
    if (contentRoot != null) {
        File moduleFile = new File(projectRootDir, projectRootDir.getName() + ".iml");
        Module module = moduleManager.newModule(moduleFile.getPath(), JAVA.getId());
        // This prevents the balloon "Unsupported Modules detected".
        ExternalSystemModulePropertyManager.getInstance(module).setExternalId(GRADLE_SYSTEM_ID);
        ModifiableRootModel model = ModuleRootManager.getInstance(module).getModifiableModel();
        model.addContentEntry(contentRoot);
        if (IdeInfo.getInstance().isAndroidStudio()) {
            // If sync fails, make sure that the project has a JDK, otherwise Groovy indices won't work (a common scenario where
            // users will update build.gradle files to fix Gradle sync.)
            // See: https://code.google.com/p/android/issues/detail?id=194621
            Sdk jdk = IdeSdks.getInstance().getJdk();
            if (jdk != null) {
                model.setSdk(jdk);
            }
        }
        model.commit();
        FacetManager facetManager = FacetManager.getInstance(module);
        ModifiableFacetModel facetModel = facetManager.createModifiableModel();
        try {
            GradleFacet gradleFacet = GradleFacet.getInstance(module);
            if (gradleFacet == null) {
                // Add "gradle" facet, to avoid balloons about unsupported compilation of modules.
                gradleFacet = facetManager.createFacet(GradleFacet.getFacetType(), GradleFacet.getFacetName(), null);
                facetModel.addFacet(gradleFacet);
            }
            gradleFacet.getConfiguration().GRADLE_PROJECT_PATH = GRADLE_PATH_SEPARATOR;
            // Add "android" facet to avoid the balloon "Android Framework detected".
            AndroidFacet androidFacet = AndroidFacet.getInstance(module);
            if (androidFacet == null) {
                androidFacet = facetManager.createFacet(AndroidFacet.getFacetType(), AndroidFacet.NAME, null);
                facetModel.addFacet(androidFacet);
            }
            // This is what actually stops Studio from showing the balloon.
            androidFacet.getProperties().ALLOW_USER_CONFIGURATION = false;
        } finally {
            facetModel.commit();
        }
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ModifiableRootModel(com.intellij.openapi.roots.ModifiableRootModel) ModifiableFacetModel(com.intellij.facet.ModifiableFacetModel) GradleFacet(com.android.tools.idea.gradle.project.facet.gradle.GradleFacet) Sdk(com.intellij.openapi.projectRoots.Sdk) ModuleManager(com.intellij.openapi.module.ModuleManager) Module(com.intellij.openapi.module.Module) VirtualFile(com.intellij.openapi.vfs.VirtualFile) VfsUtil.findFileByIoFile(com.intellij.openapi.vfs.VfsUtil.findFileByIoFile) File(java.io.File) FacetManager(com.intellij.facet.FacetManager) AndroidFacet(org.jetbrains.android.facet.AndroidFacet) VisibleForTesting(com.android.annotations.VisibleForTesting)

Example 20 with VisibleForTesting

use of com.android.annotations.VisibleForTesting in project android by JetBrains.

the class RenderErrorContributor method performClick.

@VisibleForTesting
public void performClick(@NotNull RenderResult result, @NotNull String url) {
    Module module = result.getModule();
    PsiFile file = result.getFile();
    myLinkManager.handleUrl(url, module, file, myDataContext, result);
}
Also used : PsiFile(com.intellij.psi.PsiFile) Module(com.intellij.openapi.module.Module) VisibleForTesting(com.android.annotations.VisibleForTesting)

Aggregations

VisibleForTesting (com.android.annotations.VisibleForTesting)32 VirtualFile (com.intellij.openapi.vfs.VirtualFile)10 File (java.io.File)7 NotNull (org.jetbrains.annotations.NotNull)7 Module (com.intellij.openapi.module.Module)5 ResourceType (com.android.resources.ResourceType)3 StudioLoggerProgressIndicator (com.android.tools.idea.sdk.progress.StudioLoggerProgressIndicator)3 Nullable (com.android.annotations.Nullable)2 GradleVersion (com.android.ide.common.repository.GradleVersion)2 Revision (com.android.repository.Revision)2 Device (com.android.sdklib.devices.Device)2 ModuleImporter (com.android.tools.idea.gradle.project.ModuleImporter)2 GradleFacet (com.android.tools.idea.gradle.project.facet.gradle.GradleFacet)2 NdkModuleModel (com.android.tools.idea.gradle.project.model.NdkModuleModel)2 VfsUtil.findFileByIoFile (com.intellij.openapi.vfs.VfsUtil.findFileByIoFile)2 PsiFile (com.intellij.psi.PsiFile)2 BufferedImage (java.awt.image.BufferedImage)2 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)2 Nullable (org.jetbrains.annotations.Nullable)2 ApiObjectFactory (com.android.build.gradle.internal.ApiObjectFactory)1