use of com.android.ide.common.blame.SourcePosition in project android by JetBrains.
the class ExternalNdkBuildIssuesReporterTest method testReportWithError.
public void testReportWithError() throws Exception {
if (SystemInfo.isWindows) {
// Do not run tests on Windows (see http://b.android.com/222904)
return;
}
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(ERROR, nativeToolOutput, sourceFilePosition);
List<Message> compilerMessages = Lists.newArrayList(compilerMessage);
when(myOutputParser.parseGradleOutput(nativeToolOutput)).thenReturn(compilerMessages);
myReporter.report(mySyncIssue, appModule, buildFile);
assertNull(mySyncMessagesStub.getFirstReportedMessage());
NotificationData notification = mySyncMessagesStub.getNotification();
assertNotNull(notification);
assertTrue(myErrorHandler.isInvoked());
}
use of com.android.ide.common.blame.SourcePosition in project android by JetBrains.
the class AndroidGradleJps method createCompilerMessages.
/**
* Adapter method to create IDEA CompilerMessages from an Android build Message.
*
* If the Android build message has multiple source locations, this will create multiple CompilerMesssages with the same kind and
* messageText, but different source positions.
*/
@NotNull
public static List<CompilerMessage> createCompilerMessages(@NotNull Message message) {
final BuildMessage.Kind kind;
switch(message.getKind()) {
case INFO:
kind = BuildMessage.Kind.INFO;
break;
case WARNING:
kind = BuildMessage.Kind.WARNING;
break;
case ERROR:
kind = BuildMessage.Kind.ERROR;
break;
default:
kind = BuildMessage.Kind.PROGRESS;
}
List<CompilerMessage> compilerMessages = new ArrayList<CompilerMessage>();
for (SourceFilePosition filePosition : message.getSourceFilePositions()) {
File sourceFile = filePosition.getFile().getSourceFile();
String sourceFilePath = sourceFile != null ? sourceFile.getAbsolutePath() : null;
SourcePosition pos = filePosition.getPosition();
compilerMessages.add(new CompilerMessage(COMPILER_NAME, kind, message.getText().trim(), sourceFilePath, pos.getStartOffset(), pos.getEndOffset(), pos.getEndOffset(), pos.getEndLine(), pos.getEndColumn()));
}
return Collections.unmodifiableList(compilerMessages);
}
use of com.android.ide.common.blame.SourcePosition in project android by JetBrains.
the class ManifestPanel method goToDeclaration.
private void goToDeclaration(Node element) {
List<? extends Actions.Record> records = ManifestUtils.getRecords(myManifest, element);
for (Actions.Record record : records) {
SourceFilePosition sourceFilePosition = ManifestUtils.getActionLocation(myFacet.getModule(), record);
SourceFile sourceFile = sourceFilePosition.getFile();
if (!SourceFile.UNKNOWN.equals(sourceFile)) {
File ioFile = sourceFile.getSourceFile();
if (ioFile != null) {
VirtualFile file = LocalFileSystem.getInstance().findFileByIoFile(ioFile);
assert file != null;
int line = -1;
int column = 0;
SourcePosition sourcePosition = sourceFilePosition.getPosition();
if (!SourcePosition.UNKNOWN.equals(sourcePosition)) {
line = sourcePosition.getStartLine();
column = sourcePosition.getStartColumn();
}
Project project = myFacet.getModule().getProject();
OpenFileDescriptor descriptor = new OpenFileDescriptor(project, file, line, column);
FileEditorManager.getInstance(project).openEditor(descriptor, true);
break;
}
}
}
}
use of com.android.ide.common.blame.SourcePosition in project android by JetBrains.
the class ManifestMergeFailureParser method parse.
@Override
public boolean parse(@NotNull String line, @NotNull OutputLineReader reader, @NotNull List<Message> messages, @NotNull ILogger logger) throws ParsingFailedException {
Matcher m = ERROR1.matcher(line);
if (m.matches()) {
String sourcePath = m.group(1);
int lineNumber;
try {
lineNumber = Integer.parseInt(m.group(2));
} catch (NumberFormatException e) {
throw new ParsingFailedException(e);
}
String message = m.group(3);
messages.add(new Message(Message.Kind.ERROR, message, new SourceFilePosition(new File(sourcePath), new SourcePosition(lineNumber - 1, -1, -1))));
return true;
}
m = ERROR2.matcher(line);
if (m.matches()) {
String sourcePath = removeLeadingTab(m.group(1)).trim();
int lineNumber;
try {
lineNumber = Integer.parseInt(m.group(2));
} catch (NumberFormatException e) {
throw new ParsingFailedException(e);
}
int column;
try {
column = Integer.parseInt(m.group(3));
} catch (NumberFormatException e) {
throw new ParsingFailedException(e);
}
if (lineNumber == 0 && column == 0) {
// When both line number and column is zero, it is just a message saying "Validation failed, exiting". No need to display it.
String next = reader.peek(0);
if (next != null && next.contains("Validation failed, exiting")) {
reader.readLine();
return true;
}
} else {
String msg = reader.readLine();
if (msg != null) {
msg = removeLeadingTab(msg).trim();
Message.Kind kind = Message.Kind.findIgnoringCase(m.group(4), Message.Kind.ERROR);
messages.add(new Message(kind, msg.trim(), new SourceFilePosition(new File(sourcePath), new SourcePosition(lineNumber - 1, column - 1, -1))));
return true;
}
}
}
return false;
}
use of com.android.ide.common.blame.SourcePosition in project android by JetBrains.
the class ManifestUtils method getActionLocation.
@NotNull
static SourceFilePosition getActionLocation(@NotNull Module module, @NotNull Actions.Record record) {
SourceFilePosition sourceFilePosition = record.getActionLocation();
SourceFile sourceFile = sourceFilePosition.getFile();
File file = sourceFile.getSourceFile();
SourcePosition sourcePosition = sourceFilePosition.getPosition();
if (file != null && !SourcePosition.UNKNOWN.equals(sourcePosition)) {
VirtualFile vFile = VfsUtil.findFileByIoFile(file, false);
assert vFile != null;
Module fileModule = ModuleUtilCore.findModuleForFile(vFile, module.getProject());
if (fileModule != null && !fileModule.equals(module)) {
MergedManifest manifest = MergedManifest.get(fileModule);
Document document = manifest.getDocument();
assert document != null;
Element root = document.getDocumentElement();
assert root != null;
int startLine = sourcePosition.getStartLine();
int startColumn = sourcePosition.getStartColumn();
Node node = PositionXmlParser.findNodeAtLineAndCol(document, startLine, startColumn);
if (node == null) {
Logger.getInstance(ManifestPanel.class).warn("Can not find node in " + fileModule + " for " + sourceFilePosition);
} else {
List<? extends Actions.Record> records = getRecords(manifest, node);
if (!records.isEmpty()) {
return getActionLocation(fileModule, records.get(0));
}
}
}
}
return sourceFilePosition;
}
Aggregations