Search in sources :

Example 1 with RenderErrorModel

use of com.android.tools.idea.rendering.errors.ui.RenderErrorModel in project android by JetBrains.

the class NlUsageTrackerManager method logRenderResult.

@Override
public void logRenderResult(@Nullable NlModel.ChangeType trigger, @NotNull RenderResult result, long totalRenderTimeMs) {
    // Renders are a quite common event so we sample them
    if (!shouldLog(LOG_RENDER_PERCENT)) {
        return;
    }
    logStudioEvent(LayoutEditorEvent.LayoutEditorEventType.RENDER, (event) -> {
        LayoutEditorRenderResult.Builder builder = LayoutEditorRenderResult.newBuilder().setResultCode(result.getRenderResult().getStatus().ordinal()).setTotalRenderTimeMs(totalRenderTimeMs);
        if (trigger != null) {
            switch(trigger) {
                case RESOURCE_EDIT:
                case RESOURCE_CHANGED:
                    builder.setTrigger(LayoutEditorRenderResult.Trigger.RESOURCE_CHANGE);
                    break;
                case EDIT:
                case ADD_COMPONENTS:
                case DELETE:
                case DND_COMMIT:
                case DND_END:
                case DROP:
                case RESIZE_END:
                case RESIZE_COMMIT:
                    builder.setTrigger(LayoutEditorRenderResult.Trigger.EDIT);
                    break;
                case REQUEST_RENDER:
                    builder.setTrigger(LayoutEditorRenderResult.Trigger.USER);
                    break;
                case BUILD:
                    builder.setTrigger(LayoutEditorRenderResult.Trigger.BUILD);
                    break;
                case CONFIGURATION_CHANGE:
                case UPDATE_HIERARCHY:
                    break;
            }
        }
        builder.setComponentCount((int) result.getRootViews().stream().flatMap(s -> Stream.concat(s.getChildren().stream(), Stream.of(s))).count());
        RenderErrorModel errorModel = RenderErrorModelFactory.createErrorModel(result, null);
        builder.setTotalIssueCount(errorModel.getSize());
        if (errorModel.getSize() > 0) {
            int errorCount = 0;
            int fidelityWarningCount = 0;
            for (RenderErrorModel.Issue issue : errorModel.getIssues()) {
                if (HighlightSeverity.ERROR.equals(issue.getSeverity())) {
                    errorCount++;
                } else if (issue.getSummary().startsWith("Layout fid")) {
                    fidelityWarningCount++;
                }
            }
            builder.setErrorCount(errorCount).setFidelityWarningCount(fidelityWarningCount);
        }
        event.setRenderResult(builder.build());
    });
}
Also used : RenderResult(com.android.tools.idea.rendering.RenderResult) UIUtil(com.intellij.util.ui.UIUtil) RenderErrorModelFactory(com.android.tools.idea.rendering.RenderErrorModelFactory) DesignSurface(com.android.tools.idea.uibuilder.surface.DesignSurface) java.util.concurrent(java.util.concurrent) HighlightSeverity(com.intellij.lang.annotation.HighlightSeverity) com.google.wireless.android.sdk.stats(com.google.wireless.android.sdk.stats) Random(java.util.Random) NlModel(com.android.tools.idea.uibuilder.model.NlModel) UsageTracker(com.android.tools.analytics.UsageTracker) SystemInfo(com.intellij.openapi.util.SystemInfo) State(com.android.sdklib.devices.State) Consumer(java.util.function.Consumer) VisibleForTesting(com.android.annotations.VisibleForTesting) Nullable(org.jetbrains.annotations.Nullable) Stream(java.util.stream.Stream) CacheBuilder(com.google.common.cache.CacheBuilder) Cache(com.google.common.cache.Cache) NotNull(org.jetbrains.annotations.NotNull) WeakReference(java.lang.ref.WeakReference) Configuration(com.android.tools.idea.configurations.Configuration) RenderErrorModel(com.android.tools.idea.rendering.errors.ui.RenderErrorModel) RenderErrorModel(com.android.tools.idea.rendering.errors.ui.RenderErrorModel)

Example 2 with RenderErrorModel

use of com.android.tools.idea.rendering.errors.ui.RenderErrorModel in project android by JetBrains.

the class DesignSurface method updateErrors.

/**
   * When we have render errors for a given result, kick off a background computation
   * of the error panel HTML, which when done will update the UI thread
   */
private void updateErrors(@Nullable final RenderResult result) {
    assert result != null && result.getLogger().hasProblems();
    getErrorQueue().cancelAllUpdates();
    getErrorQueue().queue(new Update("errors") {

        @Override
        public void run() {
            // Look up *current* result; a newer one could be available
            final RenderResult result = myScreenView != null ? myScreenView.getResult() : null;
            if (result == null) {
                return;
            }
            RenderErrorModel model = BuildSettings.getInstance(myProject).getBuildMode() != null && result.getLogger().hasErrors() ? STILL_BUILDING_ERROR_MODEL : RenderErrorModelFactory.createErrorModel(result, DataManager.getInstance().getDataContext(myErrorPanel));
            myErrorPanel.setModel(model);
            setShowErrorPanel(model.getSize() != 0);
        }

        @Override
        public boolean canEat(Update update) {
            return true;
        }
    });
}
Also used : RenderResult(com.android.tools.idea.rendering.RenderResult) Update(com.intellij.util.ui.update.Update) RenderErrorModel(com.android.tools.idea.rendering.errors.ui.RenderErrorModel)

Example 3 with RenderErrorModel

use of com.android.tools.idea.rendering.errors.ui.RenderErrorModel in project intellij by bazelbuild.

the class BlazeRenderErrorContributorTest method testReportMissingClassDependencies.

@Test
public void testReportMissingClassDependencies() {
    createTargetMapWithMissingClassDependency();
    RenderErrorModel errorModel = createRenderErrorModelWithMissingClasses("com.google.example.independent.LibraryView", "com.google.example.independent.LibraryView2", "com.google.example.independent.Library2View", "com.google.example.dependent.LibraryView", "com.google.example.ResourceView");
    RenderErrorModel.Issue missingClassDependenciesIssue = Iterables.getOnlyElement(errorModel.getIssues().stream().filter(issue -> issue.getSummary().equals(MISSING_CLASS_DEPENDENCIES_ERROR)).collect(Collectors.toList()));
    assertThat(missingClassDependenciesIssue.getHtmlContent()).isEqualTo("<A HREF=\"file:///src/com/google/example/BUILD\">" + "//com/google/example:resources</A> " + "contains resource files that reference these classes:" + "<DL>" + "<DD>-&NBSP;" + "<A HREF=\"openClass:com.google.example.independent.Library2View\">" + "com.google.example.independent.Library2View</A> " + "from <A HREF=\"file:///src/com/google/example/BUILD\">" + "//com/google/example/independent:library2</A> " + "<DD>-&NBSP;" + "<A HREF=\"openClass:com.google.example.independent.LibraryView\">" + "com.google.example.independent.LibraryView</A> " + "from <A HREF=\"file:///src/com/google/example/BUILD\">" + "//com/google/example/independent:library</A> " + "<DD>-&NBSP;" + "<A HREF=\"openClass:com.google.example.independent.LibraryView2\">" + "com.google.example.independent.LibraryView2</A> " + "from <A HREF=\"file:///src/com/google/example/BUILD\">" + "//com/google/example/independent:library</A> " + "</DL>" + "Please fix your dependencies so that " + "<A HREF=\"file:///src/com/google/example/BUILD\">" + "//com/google/example:resources</A> " + "correctly depends on these classes, then " + "<A HREF=\"action:sync\">sync the project</A> and " + "<A HREF=\"refreshRender\">refresh the layout</A>." + "<BR/>" + "<BR/>" + "<B>NOTE: blaze can still build with the incorrect dependencies " + "due to the way it handles resources, " + "but the layout editor needs them to be correct.</B>");
}
Also used : RenderErrorModel(com.android.tools.idea.rendering.errors.ui.RenderErrorModel) Test(org.junit.Test)

Example 4 with RenderErrorModel

use of com.android.tools.idea.rendering.errors.ui.RenderErrorModel in project intellij by bazelbuild.

the class BlazeRenderErrorContributorTest method testReportNonStandardAndroidManifestName.

@Test
public void testReportNonStandardAndroidManifestName() {
    createTargetMapWithNonStandardAndroidManifestName();
    RenderErrorModel errorModel = createRenderErrorModelWithBrokenClasses();
    RenderErrorModel.Issue nonStandardManifestNameIssue = Iterables.getOnlyElement(errorModel.getIssues().stream().filter(issue -> issue.getSummary().equals(NON_STANDARD_MANIFEST_NAME_ERROR)).collect(Collectors.toList()));
    assertThat(nonStandardManifestNameIssue.getHtmlContent()).isEqualTo("<A HREF=\"file:///src/com/google/example/main/BUILD\">" + "//com/google/example:main</A> " + "uses a non-standard name for the Android manifest: " + "<A HREF=\"file:///src/com/google/example/main/WeirdManifest.xml\">" + "WeirdManifest.xml</A>" + "<BR/>" + "Please rename it to AndroidManifest.xml, then " + "<A HREF=\"action:sync\">sync the project</A> and " + "<A HREF=\"refreshRender\">refresh the layout</A>.");
}
Also used : RenderErrorModel(com.android.tools.idea.rendering.errors.ui.RenderErrorModel) Test(org.junit.Test)

Example 5 with RenderErrorModel

use of com.android.tools.idea.rendering.errors.ui.RenderErrorModel in project intellij by bazelbuild.

the class BlazeRenderErrorContributorTest method testNoIssuesIfNoErrors.

@Test
public void testNoIssuesIfNoErrors() {
    PsiFile file = new MockPsiFile(new MockPsiManager(project));
    file.putUserData(ModuleUtilCore.KEY_MODULE, module);
    RenderResult result = RenderResult.createBlank(file);
    RenderErrorModel errorModel = RenderErrorModelFactory.createErrorModel(result, null);
    assertThat(errorModel.getIssues()).isEmpty();
}
Also used : MockPsiFile(com.intellij.mock.MockPsiFile) RenderResult(com.android.tools.idea.rendering.RenderResult) MockPsiFile(com.intellij.mock.MockPsiFile) PsiFile(com.intellij.psi.PsiFile) MockPsiManager(com.intellij.mock.MockPsiManager) RenderErrorModel(com.android.tools.idea.rendering.errors.ui.RenderErrorModel) Test(org.junit.Test)

Aggregations

RenderErrorModel (com.android.tools.idea.rendering.errors.ui.RenderErrorModel)10 Test (org.junit.Test)8 RenderResult (com.android.tools.idea.rendering.RenderResult)3 VisibleForTesting (com.android.annotations.VisibleForTesting)1 State (com.android.sdklib.devices.State)1 UsageTracker (com.android.tools.analytics.UsageTracker)1 Configuration (com.android.tools.idea.configurations.Configuration)1 RenderErrorModelFactory (com.android.tools.idea.rendering.RenderErrorModelFactory)1 NlModel (com.android.tools.idea.uibuilder.model.NlModel)1 DesignSurface (com.android.tools.idea.uibuilder.surface.DesignSurface)1 Cache (com.google.common.cache.Cache)1 CacheBuilder (com.google.common.cache.CacheBuilder)1 com.google.wireless.android.sdk.stats (com.google.wireless.android.sdk.stats)1 HighlightSeverity (com.intellij.lang.annotation.HighlightSeverity)1 MockPsiFile (com.intellij.mock.MockPsiFile)1 MockPsiManager (com.intellij.mock.MockPsiManager)1 SystemInfo (com.intellij.openapi.util.SystemInfo)1 PsiFile (com.intellij.psi.PsiFile)1 UIUtil (com.intellij.util.ui.UIUtil)1 Update (com.intellij.util.ui.update.Update)1