OSDN Git Service

Combine missing class errors with logger errors
authorTor Norbye <tnorbye@google.com>
Sat, 15 Jan 2011 01:32:29 +0000 (17:32 -0800)
committerTor Norbye <tnorbye@google.com>
Mon, 17 Jan 2011 04:14:37 +0000 (20:14 -0800)
When there are missing custom classes, or classes that cannot be
instantiated, a special error display is shown with hyperlinks to the
classes. However, this view does not incorporate the other logging
errors, such as resource failures.

This changeset combines the output so that you see everything --
missing and broken classes, resource warnings, and any other rendering
problems.

It also makes the hyperlinks pointing to classes in the error output
*open* the class if it already exists, and if not, continue to open
the New Class wizard as before.

Change-Id: Ic79282b8f502f03f587028040150e2cca3395fd9

eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/GraphicalEditorPart.java
eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/xml/Hyperlinks.java

index 6cadd05..1783ab3 100644 (file)
@@ -54,6 +54,7 @@ import com.android.ide.eclipse.adt.internal.editors.layout.gre.RulesEngine;
 import com.android.ide.eclipse.adt.internal.editors.ui.DecorComposite;
 import com.android.ide.eclipse.adt.internal.editors.uimodel.UiDocumentNode;
 import com.android.ide.eclipse.adt.internal.editors.uimodel.UiElementNode;
+import com.android.ide.eclipse.adt.internal.editors.xml.Hyperlinks;
 import com.android.ide.eclipse.adt.internal.preferences.AdtPrefs;
 import com.android.ide.eclipse.adt.internal.resources.ResourceType;
 import com.android.ide.eclipse.adt.internal.resources.configurations.FolderConfiguration;
@@ -1488,20 +1489,23 @@ public class GraphicalEditorPart extends EditorPart
                 logger.error(null, "Unexpected error in rendering, no details given",
                         null /*data*/);
             }
+            // These errors will be included in the log warnings which are
+            // displayed regardless of render success status below
+        }
+
+        // We might have detected some missing classes and swapped them by a mock view,
+        // or run into fidelity warnings or missing resources, so emit all these
+        // warnings
+        Set<String> missingClasses = mProjectCallback.getMissingClasses();
+        Set<String> brokenClasses = mProjectCallback.getUninstantiatableClasses();
+        if (logger.hasProblems()) {
             displayLoggerProblems(iProject, logger);
+            displayFailingClasses(missingClasses, brokenClasses, true);
+        } else if (missingClasses.size() > 0 || brokenClasses.size() > 0) {
+            displayFailingClasses(missingClasses, brokenClasses, false);
         } else {
-            // Success means there was no exception. But we might have detected
-            // some missing classes and swapped them by a mock view.
-            Set<String> missingClasses = mProjectCallback.getMissingClasses();
-            Set<String> brokenClasses = mProjectCallback.getUninstantiatableClasses();
-            if (missingClasses.size() > 0 || brokenClasses.size() > 0) {
-                displayFailingClasses(missingClasses, brokenClasses);
-            } else if (logger.hasProblems()) {
-                displayLoggerProblems(iProject, logger);
-            } else {
-                // Nope, no missing or broken classes. Clear success, congrats!
-                hideError();
-            }
+            // Nope, no missing or broken classes. Clear success, congrats!
+            hideError();
         }
 
         model.refreshUi();
@@ -1795,8 +1799,15 @@ public class GraphicalEditorPart extends EditorPart
      * Switches the sash to display the error label to show a list of
      * missing classes and give options to create them.
      */
-    private void displayFailingClasses(Set<String> missingClasses, Set<String> brokenClasses) {
-        mErrorLabel.setText("");
+    private void displayFailingClasses(Set<String> missingClasses, Set<String> brokenClasses,
+            boolean append) {
+        if (missingClasses.size() == 0 && brokenClasses.size() == 0) {
+            return;
+        }
+
+        if (!append) {
+            mErrorLabel.setText("");
+        }
         if (missingClasses.size() > 0) {
             addText(mErrorLabel, "The following classes could not be found:\n");
             for (String clazz : missingClasses) {
@@ -2095,8 +2106,10 @@ public class GraphicalEditorPart extends EditorPart
             }
 
             if (r instanceof ClassLinkStyleRange) {
-                String link = mErrorLabel.getText(r.start, r.start + r.length - 1);
-                createNewClass(link);
+                String fqcn = mErrorLabel.getText(r.start, r.start + r.length - 1);
+                if (!Hyperlinks.openJavaClass(getProject(), fqcn)) {
+                    createNewClass(fqcn);
+                }
             }
 
             LayoutCanvas canvas = getCanvasControl();
index f593619..2fa42b1 100644 (file)
@@ -645,8 +645,14 @@ public class Hyperlinks {
         return null;
     }
 
-    /** Opens a Java class for the given fully qualified class name */
-    private static boolean openJavaClass(IProject project, String fqcn) {
+    /**
+     * Opens a Java class for the given fully qualified class name
+     *
+     * @param project the project containing the class
+     * @param fqcn the fully qualified class name of the class to be opened
+     * @return true if the class was opened, false otherwise
+     */
+    public static boolean openJavaClass(IProject project, String fqcn) {
         if (fqcn == null) {
             return false;
         }