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;
}
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;
}
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);
}
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;
}
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;
}
Aggregations