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