Search in sources :

Example 11 with PositionInFile

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);
}
Also used : PositionInFile(com.android.tools.idea.gradle.util.PositionInFile) TextRange(com.intellij.openapi.util.TextRange) Document(com.intellij.openapi.editor.Document) NotNull(org.jetbrains.annotations.NotNull)

Example 12 with PositionInFile

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());
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) SyncMessage(com.android.tools.idea.gradle.project.sync.messages.SyncMessage) SourceFilePosition(com.android.ide.common.blame.SourceFilePosition) SyncMessageSubject.syncMessage(com.android.tools.idea.gradle.project.sync.messages.SyncMessageSubject.syncMessage) SyncMessage(com.android.tools.idea.gradle.project.sync.messages.SyncMessage) Message(com.android.ide.common.blame.Message) SourcePosition(com.android.ide.common.blame.SourcePosition) PositionInFile(com.android.tools.idea.gradle.util.PositionInFile) Module(com.intellij.openapi.module.Module)

Aggregations

PositionInFile (com.android.tools.idea.gradle.util.PositionInFile)12 SyncMessage (com.android.tools.idea.gradle.project.sync.messages.SyncMessage)9 Module (com.intellij.openapi.module.Module)4 VirtualFile (com.intellij.openapi.vfs.VirtualFile)4 MessageType (com.android.tools.idea.gradle.project.sync.messages.MessageType)3 Message (com.android.ide.common.blame.Message)2 SourcePosition (com.android.ide.common.blame.SourcePosition)2 NotificationHyperlink (com.android.tools.idea.gradle.project.sync.hyperlink.NotificationHyperlink)2 Document (com.intellij.openapi.editor.Document)2 NotificationCategory (com.intellij.openapi.externalSystem.service.notification.NotificationCategory)2 NotificationData (com.intellij.openapi.externalSystem.service.notification.NotificationData)2 Project (com.intellij.openapi.project.Project)2 ArrayList (java.util.ArrayList)2 NotNull (org.jetbrains.annotations.NotNull)2 SourceFile (com.android.ide.common.blame.SourceFile)1 SourceFilePosition (com.android.ide.common.blame.SourceFilePosition)1 GradleCoordinate (com.android.ide.common.repository.GradleCoordinate)1 ProgressIndicator (com.android.repository.api.ProgressIndicator)1 RemotePackage (com.android.repository.api.RemotePackage)1 RepoPackage (com.android.repository.api.RepoPackage)1