use of com.android.tools.idea.gradle.project.sync.hyperlink.OpenFileHyperlink in project android by JetBrains.
the class JdkModuleSetupStep method reportWrongJdkError.
@NotNull
private SyncMessage reportWrongJdkError(@NotNull Project project, @NotNull String text, @NotNull VirtualFile buildFile) {
int line = -1;
int column = -1;
Document document = FileDocumentManager.getInstance().getDocument(buildFile);
if (document != null) {
int offset = myCompileSdkVersionFinder.findOffsetIn(document.getText());
if (offset > -1) {
line = document.getLineNumber(offset);
if (line > -1) {
int lineStartOffset = document.getLineStartOffset(line);
column = offset - lineStartOffset;
}
}
}
PositionInFile position = new PositionInFile(buildFile, line, column);
SyncMessage msg = new SyncMessage(project, PROJECT_CONFIGURATION_SYNC_MESSAGE_GROUP, ERROR, position, text);
List<NotificationHyperlink> quickFixes = Lists.newArrayList(myJdks.getWrongJdkQuickFixes(project));
quickFixes.add(new OpenFileHyperlink(buildFile.getPath(), "Open build.gradle File", line, column));
msg.add(quickFixes);
return msg;
}
use of com.android.tools.idea.gradle.project.sync.hyperlink.OpenFileHyperlink in project android by JetBrains.
the class GenericErrorHandler method getQuickFixHyperlinks.
@NotNull
private List<NotificationHyperlink> getQuickFixHyperlinks(@NotNull NotificationData notification, @NotNull String text) {
List<NotificationHyperlink> hyperlinks = new ArrayList<>();
List<String> message = Splitter.on('\n').omitEmptyStrings().trimResults().splitToList(text);
String lastLine = message.get(message.size() - 1);
if (lastLine != null) {
Pair<String, Integer> errorLocation = getErrorLocation(lastLine);
if (errorLocation != null) {
String filePath = errorLocation.getFirst();
int line = errorLocation.getSecond();
hyperlinks.add(new OpenFileHyperlink(filePath, line - 1));
return hyperlinks;
}
}
// Error messages may contain a file path and line number, but we need to add a hyperlink to open the file at those coordinates.
String filePath = notification.getFilePath();
if (isNotEmpty(filePath)) {
// lines are zero based.
int lineIndex = notification.getLine() - 1;
int column = notification.getColumn();
hyperlinks.add(new OpenFileHyperlink(filePath, "Open File", lineIndex, column));
}
return hyperlinks;
}
use of com.android.tools.idea.gradle.project.sync.hyperlink.OpenFileHyperlink in project android by JetBrains.
the class GradleDslMethodNotFoundErrorHandlerTest method testHandleErrorWithMethodNotFoundInSettingsFile.
public void testHandleErrorWithMethodNotFoundInSettingsFile() throws Exception {
loadSimpleApplication();
File settingsFile = new File(getBaseDirPath(getProject()), FN_SETTINGS_GRADLE);
assertAbout(file()).that(settingsFile).isFile();
writeToFile(settingsFile, "incude ':app'");
requestSyncAndGetExpectedFailure();
SyncMessagesStub.NotificationUpdate notificationUpdate = mySyncMessagesStub.getNotificationUpdate();
assertNotNull(notificationUpdate);
assertThat(notificationUpdate.getText()).contains("Gradle DSL method not found: 'incude()'");
// Verify hyperlinks are correct.
List<NotificationHyperlink> quickFixes = notificationUpdate.getFixes();
assertThat(quickFixes).hasSize(1);
NotificationHyperlink quickFix = quickFixes.get(0);
assertThat(quickFix).isInstanceOf(OpenFileHyperlink.class);
// Ensure the error message contains the location of the error.
OpenFileHyperlink openFileQuickFix = (OpenFileHyperlink) quickFix;
assertEquals(settingsFile.getPath(), openFileQuickFix.getFilePath());
assertEquals(0, openFileQuickFix.getLineNumber());
}
use of com.android.tools.idea.gradle.project.sync.hyperlink.OpenFileHyperlink in project android by JetBrains.
the class OldAndroidPluginErrorHandler method getQuickFixHyperlinks.
@Override
@NotNull
protected List<NotificationHyperlink> getQuickFixHyperlinks(@NotNull NotificationData notification, @NotNull Project project, @NotNull String text) {
List<NotificationHyperlink> hyperlinks = new ArrayList<>();
hyperlinks.add(new FixAndroidGradlePluginVersionHyperlink());
AndroidPluginInfo result = searchInBuildFilesOnly(project);
if (result != null && result.getPluginBuildFile() != null) {
hyperlinks.add(new OpenFileHyperlink(result.getPluginBuildFile().getPath()));
}
return hyperlinks;
}
use of com.android.tools.idea.gradle.project.sync.hyperlink.OpenFileHyperlink in project android by JetBrains.
the class SdkBuildToolsTooLowErrorHandler method getQuickFixHyperlinks.
@NotNull
public List<NotificationHyperlink> getQuickFixHyperlinks(@NotNull String minimumVersion, @NotNull Project project, @Nullable Module module) {
List<NotificationHyperlink> hyperlinks = new ArrayList<>();
boolean buildToolInstalled = false;
AndroidSdkHandler sdkHandler = null;
AndroidSdkData androidSdkData = AndroidSdks.getInstance().tryToChooseAndroidSdk();
if (androidSdkData != null) {
sdkHandler = androidSdkData.getSdkHandler();
}
if (sdkHandler != null) {
ProgressIndicator progress = new StudioLoggerProgressIndicator(SdkBuildToolsTooLowErrorHandler.class);
RepositoryPackages packages = sdkHandler.getSdkManager(progress).getPackages();
LocalPackage buildTool = packages.getLocalPackages().get(getBuildToolsPath(parseRevision(minimumVersion)));
buildToolInstalled = buildTool != null;
}
if (module != null) {
VirtualFile buildFile = getGradleBuildFile(module);
AndroidPluginInfo androidPluginInfo = AndroidPluginInfo.find(project);
if (!buildToolInstalled) {
if (androidPluginInfo != null && androidPluginInfo.isExperimental()) {
hyperlinks.add(new InstallBuildToolsHyperlink(minimumVersion, null));
} else {
hyperlinks.add(new InstallBuildToolsHyperlink(minimumVersion, buildFile));
}
} else if (buildFile != null && androidPluginInfo != null && !androidPluginInfo.isExperimental()) {
hyperlinks.add(new FixBuildToolsVersionHyperlink(buildFile, minimumVersion));
}
if (buildFile != null) {
hyperlinks.add(new OpenFileHyperlink(buildFile.getPath()));
}
}
return hyperlinks;
}
Aggregations