use of org.jetbrains.android.facet.AndroidFacet in project kotlin by JetBrains.
the class IntellijLintProject method findAndroidModule.
/** Find an Android module that depends on this module; prefer app modules over library modules */
@Nullable
private static Module findAndroidModule(@NonNull final Module module) {
// Search for dependencies of this module
Graph<Module> graph = ApplicationManager.getApplication().runReadAction(new Computable<Graph<Module>>() {
@Override
public Graph<Module> compute() {
com.intellij.openapi.project.Project project = module.getProject();
if (project.isDisposed()) {
return null;
}
return ModuleManager.getInstance(project).moduleGraph();
}
});
if (graph == null) {
return null;
}
Set<AndroidFacet> facets = Sets.newHashSet();
HashSet<Module> seen = Sets.newHashSet();
seen.add(module);
addAndroidModules(facets, seen, graph, module);
// Prefer Android app modules
for (AndroidFacet facet : facets) {
if (!facet.isLibraryProject()) {
return facet.getModule();
}
}
// Resort to library modules if no app module depends directly on it
if (!facets.isEmpty()) {
return facets.iterator().next().getModule();
}
return null;
}
use of org.jetbrains.android.facet.AndroidFacet in project kotlin by JetBrains.
the class AndroidLintExternalAnnotator method collectInformation.
@Override
public State collectInformation(@NotNull PsiFile file) {
final Module module = ModuleUtilCore.findModuleForPsiElement(file);
if (module == null) {
return null;
}
final AndroidFacet facet = AndroidFacet.getInstance(module);
if (facet == null && !IntellijLintProject.hasAndroidModule(module.getProject())) {
return null;
}
final VirtualFile vFile = file.getVirtualFile();
if (vFile == null) {
return null;
}
final FileType fileType = file.getFileType();
if (fileType == FileTypes.PLAIN_TEXT) {
if (!AndroidCommonUtils.PROGUARD_CFG_FILE_NAME.equals(file.getName()) && !AndroidCompileUtil.OLD_PROGUARD_CFG_FILE_NAME.equals(file.getName())) {
return null;
}
} else if (fileType != KotlinFileType.INSTANCE && fileType != StdFileTypes.PROPERTIES) {
return null;
}
final List<Issue> issues = getIssuesFromInspections(file.getProject(), file);
if (issues.size() == 0) {
return null;
}
return new State(module, vFile, file.getText(), issues);
}
use of org.jetbrains.android.facet.AndroidFacet in project android by JetBrains.
the class PostProjectBuildTasksExecutorTest method addAndroidFacet.
private static void addAndroidFacet(@NotNull Module module) {
FacetManager facetManager = FacetManager.getInstance(module);
ModifiableFacetModel facetModel = facetManager.createModifiableModel();
try {
AndroidFacet facet = facetManager.createFacet(AndroidFacet.getFacetType(), AndroidFacet.NAME, null);
facetModel.addFacet(facet);
} finally {
facetModel.commit();
}
}
use of org.jetbrains.android.facet.AndroidFacet in project android by JetBrains.
the class AndroidRunConfigurationSetupStepTest method testSetUpModuleWithAndroidFacetAndAppProject.
public void testSetUpModuleWithAndroidFacetAndAppProject() {
Module module = getModule();
AndroidFacet androidFacet = createAndAddAndroidFacet(module);
androidFacet.getProperties().PROJECT_TYPE = PROJECT_TYPE_APP;
mySetupStep.setUpModule(module, null);
verify(myRunConfigurations).createRunConfiguration(androidFacet);
}
use of org.jetbrains.android.facet.AndroidFacet in project android by JetBrains.
the class AndroidPreviewPanelTest method testSimpleRender.
public void testSimpleRender() throws ParserConfigurationException, IOException, SAXException, InterruptedException {
VirtualFile layout = myFixture.copyFileToProject("themeEditor/theme_preview_layout.xml", "res/layout/theme_preview_layout.xml");
Configuration configuration = myFacet.getConfigurationManager().getConfiguration(layout);
AtomicBoolean executorCalled = new AtomicBoolean(false);
ExecutorService threadPool = Executors.newFixedThreadPool(1);
Executor executor = (r) -> {
// Run in a separate thread and wait for the result
try {
threadPool.submit(r).get(60, TimeUnit.SECONDS);
executorCalled.set(true);
} catch (InterruptedException | ExecutionException | TimeoutException e) {
throw new AssertionError("Unexpected exception", e);
}
};
AndroidPreviewPanel.GraphicsLayoutRendererFactory graphicsFactory = (configuration1, parser, background) -> {
Module module = configuration.getModule();
AndroidFacet facet = AndroidFacet.getInstance(configuration.getModule());
assertNotNull(facet);
AndroidPlatform platform = AndroidPlatform.getInstance(module);
assertNotNull(platform);
return GraphicsLayoutRenderer.create(facet, platform, getProject(), configuration, parser, background, SessionParams.RenderingMode.V_SCROLL, false);
};
AndroidPreviewPanel panel = new AndroidPreviewPanel(configuration, executor, graphicsFactory) {
@Override
public void invalidateGraphicsRenderer() {
myInvalidateRunnable.run();
}
};
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setNamespaceAware(true);
Document document = factory.newDocumentBuilder().parse(new InputSource(new StringReader("<LinearLayout xmlns:android=\"http://schemas.android.com/apk/res/android\"" + " android:layout_width=\"match_parent\"" + " android:layout_height=\"match_parent\"" + " android:background=\"#0F0\">" + " <TextView" + " android:layout_width=\"wrap_content\"" + " android:layout_height=\"wrap_content\"" + " android:text=\"Hello world\"" + " android:background=\"#F00\"/>" + "</LinearLayout>")));
panel.setDocument(document);
panel.setBounds(0, 0, 400, 100);
//noinspection UndesirableClassUsage (we don't want to use HDPI images here)
BufferedImage output = new BufferedImage(400, 100, BufferedImage.TYPE_INT_ARGB);
panel.paintComponent(output.getGraphics());
// Make sure that the executor got called since we were trying to render on the UI thread.
assertTrue(executorCalled.get());
BufferedImage goldenImage = ImageIO.read(new File(getTestDataPath() + "/themeEditor/previewPanel/golden.png"));
assertImageSimilar("layout", goldenImage, output, 3);
ViewInfo textView = panel.findViewAtPoint(new Point(0, 0));
assertEquals("android.widget.TextView", textView.getClassName());
threadPool.shutdownNow();
threadPool.awaitTermination(30, TimeUnit.SECONDS);
Disposer.dispose(panel);
}
Aggregations