Search in sources :

Example 61 with Nullable

use of com.android.annotations.Nullable in project android by JetBrains.

the class ErrorReporter method submit.

@Override
public boolean submit(@NotNull IdeaLoggingEvent[] events, @Nullable String description, @Nullable Component parentComponent, @NotNull Consumer<SubmittedReportInfo> callback) {
    IdeaLoggingEvent event = events[0];
    ErrorBean bean = new ErrorBean(event.getThrowable(), IdeaLogger.ourLastActionId);
    final DataContext dataContext = DataManager.getInstance().getDataContext(parentComponent);
    bean.setDescription(description);
    bean.setMessage(event.getMessage());
    Throwable t = event.getThrowable();
    if (t != null) {
        final PluginId pluginId = IdeErrorsDialog.findPluginId(t);
        if (pluginId != null) {
            final IdeaPluginDescriptor ideaPluginDescriptor = PluginManager.getPlugin(pluginId);
            if (ideaPluginDescriptor != null && (!ideaPluginDescriptor.isBundled() || ideaPluginDescriptor.allowBundledUpdate())) {
                bean.setPluginName(ideaPluginDescriptor.getName());
                bean.setPluginVersion(ideaPluginDescriptor.getVersion());
            }
        }
    }
    Object data = event.getData();
    // Early escape (and no UI impact) if these are analytics events being pushed from the platform
    if (handleAnalyticsReports(t, data)) {
        return true;
    }
    if (data instanceof AbstractMessage) {
        bean.setAttachments(((AbstractMessage) data).getIncludedAttachments());
    }
    final Project project = CommonDataKeys.PROJECT.getData(dataContext);
    Consumer<String> successCallback = token -> {
        final SubmittedReportInfo reportInfo = new SubmittedReportInfo(null, "Issue " + token, SubmittedReportInfo.SubmissionStatus.NEW_ISSUE);
        callback.consume(reportInfo);
        ReportMessages.GROUP.createNotification(ReportMessages.ERROR_REPORT, "Submitted", NotificationType.INFORMATION, null).setImportant(false).notify(project);
    };
    Consumer<Exception> errorCallback = e -> {
        String message = AndroidBundle.message("error.report.at.b.android", e.getMessage());
        ReportMessages.GROUP.createNotification(ReportMessages.ERROR_REPORT, message, NotificationType.ERROR, NotificationListener.URL_OPENING_LISTENER).setImportant(false).notify(project);
    };
    Task.Backgroundable feedbackTask;
    if (data instanceof ErrorReportCustomizer) {
        feedbackTask = ((ErrorReportCustomizer) data).makeReportingTask(project, FEEDBACK_TASK_TITLE, true, bean, successCallback, errorCallback);
    } else {
        List<Pair<String, String>> kv = IdeaITNProxy.getKeyValuePairs(null, null, bean, IdeaLogger.getOurCompilationTimestamp(), ApplicationManager.getApplication(), (ApplicationInfoEx) ApplicationInfo.getInstance(), ApplicationNamesInfo.getInstance(), UpdateSettings.getInstance());
        feedbackTask = new SubmitCrashReportTask(project, FEEDBACK_TASK_TITLE, true, t, pair2map(kv), successCallback, errorCallback);
    }
    if (project == null) {
        feedbackTask.run(new EmptyProgressIndicator());
    } else {
        ProgressManager.getInstance().run(feedbackTask);
    }
    return true;
}
Also used : SubmittedReportInfo(com.intellij.openapi.diagnostic.SubmittedReportInfo) DataContext(com.intellij.openapi.actionSystem.DataContext) IdeErrorsDialog(com.intellij.diagnostic.IdeErrorsDialog) ReportMessages(com.intellij.diagnostic.ReportMessages) Task(com.intellij.openapi.progress.Task) CrashReport(com.android.tools.idea.diagnostics.crash.CrashReport) ApplicationInfo(com.intellij.openapi.application.ApplicationInfo) Map(java.util.Map) ApplicationNamesInfo(com.intellij.openapi.application.ApplicationNamesInfo) Project(com.intellij.openapi.project.Project) CommonDataKeys(com.intellij.openapi.actionSystem.CommonDataKeys) ApplicationInfoEx(com.intellij.openapi.application.ex.ApplicationInfoEx) ErrorReportSubmitter(com.intellij.openapi.diagnostic.ErrorReportSubmitter) DataManager(com.intellij.ide.DataManager) IdeaPluginDescriptor(com.intellij.ide.plugins.IdeaPluginDescriptor) PluginManager(com.intellij.ide.plugins.PluginManager) ProgressManager(com.intellij.openapi.progress.ProgressManager) AndroidBundle(org.jetbrains.android.util.AndroidBundle) IdeaLogger(com.intellij.idea.IdeaLogger) IdeaLoggingEvent(com.intellij.openapi.diagnostic.IdeaLoggingEvent) Nullable(com.android.annotations.Nullable) Maps(com.google.common.collect.Maps) NotificationListener(com.intellij.notification.NotificationListener) NotificationType(com.intellij.notification.NotificationType) java.awt(java.awt) EmptyProgressIndicator(com.intellij.openapi.progress.EmptyProgressIndicator) ErrorBean(com.intellij.errorreport.bean.ErrorBean) List(java.util.List) AbstractMessage(com.intellij.diagnostic.AbstractMessage) CrashReporter(com.android.tools.idea.diagnostics.crash.CrashReporter) UpdateSettings(com.intellij.openapi.updateSettings.impl.UpdateSettings) Pair(com.intellij.openapi.util.Pair) ApplicationManager(com.intellij.openapi.application.ApplicationManager) IdeaITNProxy(org.jetbrains.android.diagnostics.error.IdeaITNProxy) NotNull(org.jetbrains.annotations.NotNull) PluginId(com.intellij.openapi.extensions.PluginId) Consumer(com.intellij.util.Consumer) Task(com.intellij.openapi.progress.Task) AbstractMessage(com.intellij.diagnostic.AbstractMessage) EmptyProgressIndicator(com.intellij.openapi.progress.EmptyProgressIndicator) IdeaPluginDescriptor(com.intellij.ide.plugins.IdeaPluginDescriptor) PluginId(com.intellij.openapi.extensions.PluginId) IdeaLoggingEvent(com.intellij.openapi.diagnostic.IdeaLoggingEvent) Project(com.intellij.openapi.project.Project) DataContext(com.intellij.openapi.actionSystem.DataContext) ErrorBean(com.intellij.errorreport.bean.ErrorBean) SubmittedReportInfo(com.intellij.openapi.diagnostic.SubmittedReportInfo) Pair(com.intellij.openapi.util.Pair)

Example 62 with Nullable

use of com.android.annotations.Nullable in project android by JetBrains.

the class ClassLoadingErrorHandler method findErrorMessage.

@Nullable
private static String findErrorMessage(@NotNull Throwable rootCause) {
    String text = rootCause.getMessage();
    if (rootCause instanceof ClassNotFoundException) {
        String className = nullToEmpty(text);
        Matcher matcher = CLASS_NOT_FOUND_PATTERN.matcher(className);
        if (matcher.matches()) {
            className = matcher.group(1);
        }
        updateUsageTracker(CLASS_NOT_FOUND, className);
        return String.format("Unable to load class '%1$s'.", className);
    }
    if (rootCause instanceof NoSuchMethodError) {
        String methodName = nullToEmpty(text);
        updateUsageTracker(METHOD_NOT_FOUND, methodName);
        return String.format("Unable to find method '%1$s'.", methodName);
    }
    if (isNotEmpty(text) && text.contains("cannot be cast to")) {
        updateUsageTracker();
        return text;
    }
    return null;
}
Also used : Matcher(java.util.regex.Matcher) Nullable(com.android.annotations.Nullable)

Example 63 with Nullable

use of com.android.annotations.Nullable in project android by JetBrains.

the class NlPropertyInspectorFixture method findPropertyComponent.

@Nullable
private Component findPropertyComponent(@NotNull String name, @Nullable Icon icon) {
    try {
        JBLabel label = waitUntilFound(robot(), myPanel, new GenericTypeMatcher<JBLabel>(JBLabel.class) {

            @Override
            protected boolean isMatching(@NotNull JBLabel label) {
                return name.equals(label.getText()) && label.getIcon() == icon;
            }
        });
        Container parent = label.getParent();
        Component[] components = parent.getComponents();
        for (int i = 0; i < components.length; i++) {
            if (label == components[i]) {
                return components[i + 1];
            }
        }
        return null;
    } catch (WaitTimedOutError ex) {
        return null;
    }
}
Also used : JBLabel(com.intellij.ui.components.JBLabel) WaitTimedOutError(org.fest.swing.exception.WaitTimedOutError) Nullable(com.android.annotations.Nullable)

Example 64 with Nullable

use of com.android.annotations.Nullable in project kotlin by JetBrains.

the class TypoLookup method get.

/**
     * Returns an instance of the Typo database for the given locale
     *
     * @param client the client to associate with this database - used only for
     *            logging. The database object may be shared among repeated
     *            invocations, and in that case client used will be the one
     *            originally passed in. In other words, this parameter may be
     *            ignored if the client created is not new.
     * @param locale the locale to look up a typo database for (should be a
     *            language code (ISO 639-1, two lowercase character names)
     * @param region the region to look up a typo database for (should be a two
     *            letter ISO 3166-1 alpha-2 country code in upper case) language
     *            code
     * @return a (possibly shared) instance of the typo database, or null if its
     *         data can't be found
     */
@Nullable
public static TypoLookup get(@NonNull LintClient client, @NonNull String locale, @Nullable String region) {
    synchronized (TypoLookup.class) {
        String key = locale;
        if (region != null && region.length() == 2) {
            // http://en.wikipedia.org/wiki/American_and_British_English_spelling_differences
            assert region.length() == 2 && Character.isUpperCase(region.charAt(0)) && Character.isUpperCase(region.charAt(1)) : region;
            // Look for typos-en-rUS.txt etc
            key = locale + 'r' + region;
        }
        TypoLookup db = sInstanceMap.get(key);
        if (db == null) {
            String path = String.format(XML_FILE_PATH, key);
            File file = client.findResource(path);
            if (file == null) {
                // AOSP build environment?
                //$NON-NLS-1$
                String build = System.getenv("ANDROID_BUILD_TOP");
                if (build != null) {
                    file = new File(build, (//$NON-NLS-1$
                    "sdk/files/" + path.substring(path.lastIndexOf('/') + 1)).replace('/', File.separatorChar));
                }
            }
            if (file == null || !file.exists()) {
                //noinspection VariableNotUsedInsideIf
                if (region != null) {
                    // Fall back to the generic locale (non-region-specific) database
                    return get(client, locale, null);
                }
                db = NONE;
            } else {
                db = get(client, file);
                assert db != null : file;
            }
            sInstanceMap.put(key, db);
        }
        if (db == NONE) {
            return null;
        } else {
            return db;
        }
    }
}
Also used : File(java.io.File) Nullable(com.android.annotations.Nullable)

Example 65 with Nullable

use of com.android.annotations.Nullable in project kotlin by JetBrains.

the class StringFormatDetector method getFormatArgumentType.

//$NON-NLS-1$
/** Given a format string returns the format type of the given argument */
@VisibleForTesting
@Nullable
static String getFormatArgumentType(String s, int argument) {
    Matcher matcher = FORMAT.matcher(s);
    int index = 0;
    int prevIndex = 0;
    int nextNumber = 1;
    while (true) {
        if (matcher.find(index)) {
            String value = matcher.group(6);
            if ("%".equals(value) || "n".equals(value)) {
                //$NON-NLS-1$ //$NON-NLS-2$
                index = matcher.end();
                continue;
            }
            int matchStart = matcher.start();
            // Make sure this is not an escaped '%'
            for (; prevIndex < matchStart; prevIndex++) {
                char c = s.charAt(prevIndex);
                if (c == '\\') {
                    prevIndex++;
                }
            }
            if (prevIndex > matchStart) {
                // We're in an escape, ignore this result
                index = prevIndex;
                continue;
            }
            // Shouldn't throw a number format exception since we've already
            // matched the pattern in the regexp
            int number;
            String numberString = matcher.group(1);
            if (numberString != null) {
                // Strip off trailing $
                numberString = numberString.substring(0, numberString.length() - 1);
                number = Integer.parseInt(numberString);
                nextNumber = number + 1;
            } else {
                number = nextNumber++;
            }
            if (number == argument) {
                return matcher.group(6);
            }
            index = matcher.end();
        } else {
            break;
        }
    }
    return null;
}
Also used : Matcher(java.util.regex.Matcher) VisibleForTesting(com.android.annotations.VisibleForTesting) Nullable(com.android.annotations.Nullable)

Aggregations

Nullable (com.android.annotations.Nullable)83 File (java.io.File)21 IOException (java.io.IOException)9 ResourceType (com.android.resources.ResourceType)8 PsiClass (com.intellij.psi.PsiClass)7 PsiElement (com.intellij.psi.PsiElement)7 PsiReferenceExpression (com.intellij.psi.PsiReferenceExpression)7 ResourceUrl (com.android.ide.common.resources.ResourceUrl)6 PsiAssignmentExpression (com.intellij.psi.PsiAssignmentExpression)6 PsiDeclarationStatement (com.intellij.psi.PsiDeclarationStatement)6 PsiExpression (com.intellij.psi.PsiExpression)6 PsiExpressionStatement (com.intellij.psi.PsiExpressionStatement)6 PsiMethod (com.intellij.psi.PsiMethod)6 PsiStatement (com.intellij.psi.PsiStatement)6 ArrayList (java.util.ArrayList)6 PsiField (com.intellij.psi.PsiField)5 PsiFile (com.intellij.psi.PsiFile)4 Node (lombok.ast.Node)4 UReferenceExpression (org.jetbrains.uast.UReferenceExpression)4 AbstractResourceRepository (com.android.ide.common.res2.AbstractResourceRepository)3