Search in sources :

Example 21 with AndroidFacet

use of org.jetbrains.android.facet.AndroidFacet in project android by JetBrains.

the class AppResourceRepository method findAarLibrariesFromIntelliJ.

/**
   * Reads IntelliJ library definitions ({@link com.intellij.openapi.roots.LibraryOrSdkOrderEntry}) and if possible, finds a corresponding
   * {@code .aar} resource library to include. This works before the Gradle project has been initialized.
   */
private static Map<File, String> findAarLibrariesFromIntelliJ(AndroidFacet facet, List<AndroidFacet> dependentFacets) {
    // Find .aar libraries from old IntelliJ library definitions
    Map<File, String> dirs = new HashMap<>();
    addAarsFromModuleLibraries(facet, dirs);
    for (AndroidFacet f : dependentFacets) {
        addAarsFromModuleLibraries(f, dirs);
    }
    return dirs;
}
Also used : TObjectIntHashMap(gnu.trove.TObjectIntHashMap) TIntObjectHashMap(gnu.trove.TIntObjectHashMap) File(java.io.File) AndroidFacet(org.jetbrains.android.facet.AndroidFacet)

Example 22 with AndroidFacet

use of org.jetbrains.android.facet.AndroidFacet in project android by JetBrains.

the class AppResourceRepository method computeLibraries.

private static List<FileResourceRepository> computeLibraries(@NotNull final AndroidFacet facet) {
    if (LOG.isDebugEnabled()) {
        LOG.debug("computeLibraries");
    }
    List<AndroidFacet> dependentFacets = AndroidUtils.getAllAndroidDependencies(facet.getModule(), true);
    Map<File, String> aarDirs = findAarLibraries(facet, dependentFacets);
    if (aarDirs.isEmpty()) {
        if (LOG.isDebugEnabled()) {
            LOG.debug("  No AARs");
        }
        return Collections.emptyList();
    }
    List<File> dirs = Lists.newArrayList(aarDirs.keySet());
    // Sort alphabetically to ensure that we keep a consistent order of these libraries;
    // otherwise when we jump from libraries initialized from IntelliJ library binary paths
    // to gradle project state, the order difference will cause the merged project resource
    // maps to have to be recomputed
    Collections.sort(dirs);
    if (LOG.isDebugEnabled()) {
        for (File root : dirs) {
            LOG.debug("  Dependency: " + anonymizeClassName(aarDirs.get(root)));
        }
    }
    List<FileResourceRepository> resources = Lists.newArrayListWithExpectedSize(aarDirs.size());
    for (File root : dirs) {
        resources.add(FileResourceRepository.get(root, aarDirs.get(root)));
    }
    return resources;
}
Also used : File(java.io.File) AndroidFacet(org.jetbrains.android.facet.AndroidFacet)

Example 23 with AndroidFacet

use of org.jetbrains.android.facet.AndroidFacet in project android by JetBrains.

the class GraphicsLayoutRenderer method create.

/**
   * Creates a new {@link GraphicsLayoutRenderer}.
   * @param configuration The configuration to use when rendering.
   * @param parser A layout pull-parser.
   * @param backgroundColor If not null, this will be use to set the global Android window background
   * @throws AlreadyDisposedException if the module is disposed while create is running
   * @throws InitializationException if layoutlib fails to initialize.
   * @throws UnsupportedLayoutlibException if the used layoutlib version is too old to run with this class
   */
@NotNull
public static GraphicsLayoutRenderer create(@NotNull Configuration configuration, @NotNull ILayoutPullParser parser, @Nullable Color backgroundColor, boolean hasHorizontalScroll, boolean hasVerticalScroll) throws InitializationException {
    Module module = configuration.getModule();
    if (module.isDisposed()) {
        throw new AlreadyDisposedException("Module was already disposed");
    }
    AndroidFacet facet = AndroidFacet.getInstance(configuration.getModule());
    if (facet == null) {
        throw new InitializationException("Unable to get AndroidFacet");
    }
    AndroidPlatform platform = AndroidPlatform.getInstance(module);
    if (platform == null) {
        throw new UnsupportedLayoutlibException("No Android SDK found.");
    }
    SessionParams.RenderingMode renderingMode;
    if (hasVerticalScroll && hasHorizontalScroll) {
        renderingMode = SessionParams.RenderingMode.FULL_EXPAND;
    } else if (hasVerticalScroll) {
        renderingMode = SessionParams.RenderingMode.V_SCROLL;
    } else if (hasHorizontalScroll) {
        renderingMode = SessionParams.RenderingMode.H_SCROLL;
    } else {
        renderingMode = SessionParams.RenderingMode.NORMAL;
    }
    return create(facet, platform, module.getProject(), configuration, parser, backgroundColor, renderingMode, true);
}
Also used : AndroidPlatform(org.jetbrains.android.sdk.AndroidPlatform) Module(com.intellij.openapi.module.Module) AndroidFacet(org.jetbrains.android.facet.AndroidFacet) NotNull(org.jetbrains.annotations.NotNull)

Example 24 with AndroidFacet

use of org.jetbrains.android.facet.AndroidFacet in project android by JetBrains.

the class AndroidXmlDocumentationProvider method generateDoc.

@Override
public String generateDoc(PsiElement element, @Nullable PsiElement originalElement) {
    if (element instanceof ProvidedDocumentationPsiElement) {
        return ((ProvidedDocumentationPsiElement) element).getDocumentation();
    }
    if (element instanceof LazyValueResourceElementWrapper) {
        LazyValueResourceElementWrapper wrapper = (LazyValueResourceElementWrapper) element;
        ValueResourceInfo resourceInfo = wrapper.getResourceInfo();
        ResourceType type = resourceInfo.getType();
        String name = resourceInfo.getName();
        Module module = ModuleUtilCore.findModuleForPsiElement(element);
        if (module == null) {
            return null;
        }
        AndroidFacet facet = AndroidFacet.getInstance(element);
        if (facet == null) {
            return null;
        }
        ResourceUrl url;
        ResourceUrl originalUrl = originalElement != null ? ResourceUrl.parse(originalElement.getText()) : null;
        if (originalUrl != null && name.equals(originalUrl.name)) {
            url = originalUrl;
        } else {
            boolean isFramework = false;
            if (originalUrl != null) {
                isFramework = originalUrl.framework;
            } else {
                // Figure out if this resource is a framework file.
                // We really should store that info in the ValueResourceInfo instances themselves.
                // For now, attempt to figure it out
                SystemResourceManager systemResourceManager = facet.getSystemResourceManager();
                VirtualFile containingFile = resourceInfo.getContainingFile();
                if (systemResourceManager != null) {
                    VirtualFile parent = containingFile.getParent();
                    if (parent != null) {
                        VirtualFile resDir = parent.getParent();
                        if (resDir != null) {
                            isFramework = systemResourceManager.isResourceDir(resDir);
                        }
                    }
                }
            }
            url = ResourceUrl.create(type, name, isFramework, false);
        }
        return generateDoc(element, url);
    } else if (element instanceof MyResourceElement) {
        return getResourceDocumentation(element, ((MyResourceElement) element).myResource);
    } else if (element instanceof XmlAttributeValue) {
        return getResourceDocumentation(element, ((XmlAttributeValue) element).getValue());
    }
    if (originalElement instanceof XmlToken) {
        XmlToken token = (XmlToken) originalElement;
        if (token.getTokenType() == XML_ATTRIBUTE_VALUE_START_DELIMITER) {
            PsiElement next = token.getNextSibling();
            if (next instanceof XmlToken) {
                token = (XmlToken) next;
            }
        } else if (token.getTokenType() == XML_ATTRIBUTE_VALUE_END_DELIMITER) {
            PsiElement prev = token.getPrevSibling();
            if (prev instanceof XmlToken) {
                token = (XmlToken) prev;
            }
        }
        if (token.getTokenType() == XML_ATTRIBUTE_VALUE_TOKEN) {
            String documentation = getResourceDocumentation(originalElement, token.getText());
            if (documentation != null) {
                return documentation;
            }
        } else if (token.getTokenType() == XML_DATA_CHARACTERS) {
            String text = token.getText().trim();
            String documentation = getResourceDocumentation(originalElement, text);
            if (documentation != null) {
                return documentation;
            }
        }
    }
    if (element instanceof PomTargetPsiElement && originalElement != null) {
        final PomTarget target = ((PomTargetPsiElement) element).getTarget();
        if (target instanceof DomAttributeChildDescription) {
            synchronized (ANDROID_ATTRIBUTE_DOCUMENTATION_CACHE_KEY) {
                return generateDocForXmlAttribute((DomAttributeChildDescription) target, originalElement);
            }
        }
    }
    if (element instanceof MyDocElement) {
        return ((MyDocElement) element).myDocumentation;
    }
    return null;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ResourceType(com.android.resources.ResourceType) XmlAttributeValue(com.intellij.psi.xml.XmlAttributeValue) AndroidFacet(org.jetbrains.android.facet.AndroidFacet) DomAttributeChildDescription(com.intellij.util.xml.reflect.DomAttributeChildDescription) XmlToken(com.intellij.psi.xml.XmlToken) PomTarget(com.intellij.pom.PomTarget) LazyValueResourceElementWrapper(org.jetbrains.android.dom.wrappers.LazyValueResourceElementWrapper) PomTargetPsiElement(com.intellij.pom.PomTargetPsiElement) Module(com.intellij.openapi.module.Module) ResourceUrl(com.android.ide.common.resources.ResourceUrl) SystemResourceManager(org.jetbrains.android.resourceManagers.SystemResourceManager) FakePsiElement(com.intellij.psi.impl.FakePsiElement) PsiElement(com.intellij.psi.PsiElement) PomTargetPsiElement(com.intellij.pom.PomTargetPsiElement) ValueResourceInfo(org.jetbrains.android.resourceManagers.ValueResourceInfo)

Example 25 with AndroidFacet

use of org.jetbrains.android.facet.AndroidFacet in project android by JetBrains.

the class AndroidXmlTagDescriptor method getElementsDescriptors.

@Override
public XmlElementDescriptor[] getElementsDescriptors(XmlTag context) {
    final XmlElementDescriptor[] descriptors = myParentDescriptor.getElementsDescriptors(context);
    if (myBaseClassName == null || context == null) {
        return descriptors;
    }
    final AndroidFacet facet = AndroidFacet.getInstance(context);
    if (facet == null) {
        return descriptors;
    }
    final XmlElementDescriptor[] androidDescriptors = new XmlElementDescriptor[descriptors.length];
    final DomElement domElement = DomManager.getDomManager(context.getProject()).getDomElement(context);
    final PsiClass baseClass = JavaPsiFacade.getInstance(context.getProject()).findClass(myBaseClassName, facet.getModule().getModuleWithLibrariesScope());
    for (int i = 0; i < descriptors.length; i++) {
        final XmlElementDescriptor descriptor = descriptors[i];
        final String tagName = descriptor.getName();
        final PsiClass aClass = tagName != null && baseClass != null ? LayoutViewClassUtils.findClassByTagName(facet, tagName, baseClass) : null;
        final Icon icon = AndroidDomElementDescriptorProvider.getIconForTag(tagName, domElement);
        androidDescriptors[i] = new AndroidXmlTagDescriptor(aClass, descriptor, myBaseClassName, icon);
    }
    return androidDescriptors;
}
Also used : DomElement(com.intellij.util.xml.DomElement) PsiClass(com.intellij.psi.PsiClass) XmlElementDescriptor(com.intellij.xml.XmlElementDescriptor) AndroidFacet(org.jetbrains.android.facet.AndroidFacet)

Aggregations

AndroidFacet (org.jetbrains.android.facet.AndroidFacet)299 Module (com.intellij.openapi.module.Module)122 VirtualFile (com.intellij.openapi.vfs.VirtualFile)73 NotNull (org.jetbrains.annotations.NotNull)61 Nullable (org.jetbrains.annotations.Nullable)51 Project (com.intellij.openapi.project.Project)39 File (java.io.File)29 AndroidModuleModel (com.android.tools.idea.gradle.project.model.AndroidModuleModel)28 PsiFile (com.intellij.psi.PsiFile)24 XmlFile (com.intellij.psi.xml.XmlFile)20 PsiElement (com.intellij.psi.PsiElement)17 FolderConfiguration (com.android.ide.common.resources.configuration.FolderConfiguration)16 XmlTag (com.intellij.psi.xml.XmlTag)16 ArrayList (java.util.ArrayList)16 Manifest (org.jetbrains.android.dom.manifest.Manifest)14 IAndroidTarget (com.android.sdklib.IAndroidTarget)13 ResourceFolderType (com.android.resources.ResourceFolderType)11 Configuration (com.android.tools.idea.configurations.Configuration)10 PsiClass (com.intellij.psi.PsiClass)10 XmlAttributeValue (com.intellij.psi.xml.XmlAttributeValue)10