use of com.android.tools.idea.gradle.util.PositionInFile in project android by JetBrains.
the class UnresolvedDependenciesReporter method findDependencyPosition.
@NotNull
private static PositionInFile findDependencyPosition(@NotNull String dependency, @NotNull VirtualFile buildFile) {
int line = -1;
int column = -1;
Document document = FileDocumentManager.getInstance().getDocument(buildFile);
if (document != null) {
TextRange textRange = findDependency(dependency, document);
if (textRange != null) {
line = document.getLineNumber(textRange.getStartOffset());
if (line > -1) {
int lineStartOffset = document.getLineStartOffset(line);
column = textRange.getStartOffset() - lineStartOffset;
}
}
}
return new PositionInFile(buildFile, line, column);
}
use of com.android.tools.idea.gradle.util.PositionInFile in project android by JetBrains.
the class ExternalNdkBuildIssuesReporterTest method testReportWithWarning.
public void testReportWithWarning() throws Exception {
loadSimpleApplication();
mySyncMessagesStub.clearReportedMessages();
Module appModule = myModules.getAppModule();
String nativeToolOutput = "Failed to compile something";
when(mySyncIssue.getData()).thenReturn(nativeToolOutput);
VirtualFile buildFile = getGradleBuildFile(appModule);
assertNotNull(buildFile);
int line = 6;
int column = 8;
SourcePosition sourcePosition = new SourcePosition(line, column, 0);
SourceFilePosition sourceFilePosition = new SourceFilePosition(virtualToIoFile(buildFile), sourcePosition);
Message compilerMessage = new Message(WARNING, nativeToolOutput, sourceFilePosition);
List<Message> compilerMessages = Lists.newArrayList(compilerMessage);
when(myOutputParser.parseGradleOutput(nativeToolOutput)).thenReturn(compilerMessages);
myReporter.report(mySyncIssue, appModule, buildFile);
SyncMessage message = mySyncMessagesStub.getFirstReportedMessage();
assertNotNull(message);
assertThat(message.getText()).hasLength(1);
assertAbout(syncMessage()).that(message).hasMessageLine(nativeToolOutput, 0);
PositionInFile position = message.getPosition();
assertNotNull(position);
assertEquals(buildFile, position.file);
assertEquals(line, position.line);
assertEquals(column, position.column);
assertThat(message.getQuickFixes()).isEmpty();
assertFalse(myErrorHandler.isInvoked());
}
Aggregations