use of com.android.ide.common.blame.SourceFile 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.SourceFile in project android by JetBrains.
the class AndroidPluginOutputParser method parse.
@Override
public boolean parse(@NotNull String line, @NotNull OutputLineReader reader, @NotNull List<Message> messages, @NotNull ILogger logger) throws ParsingFailedException {
if (line.contains("[DEBUG] ") || line.contains("[INFO] ")) {
// Ignore 'debug' and 'info' messages.
return false;
}
if (IGNORED_MESSAGE_PATTERN.matcher(line).matches()) {
return false;
}
// pattern is type|path|message
String[] segments = line.split("\\|", SEGMENT_COUNT);
if (segments.length == SEGMENT_COUNT) {
Message.Kind kind = Message.Kind.findIgnoringCase(segments[0], Message.Kind.ERROR);
String path = segments[1];
if (StringUtil.isEmpty(path)) {
return false;
}
String msg = StringUtil.notNullize(segments[2]);
// The SourceFile description is the Gradle path of the project.
messages.add(new Message(kind, msg.trim(), new SourceFilePosition(new SourceFile(path.trim()), SourcePosition.UNKNOWN)));
return true;
}
return false;
}
use of com.android.ide.common.blame.SourceFile in project atlas by alibaba.
the class AwbXmlProcessor method getLayoutXmlProcessor.
public static LayoutXmlProcessor getLayoutXmlProcessor(AppVariantContext appVariantContext, AwbBundle awbBundle, DataBindingBuilder dataBindingBuilder) {
File resourceBlameLogDir = appVariantContext.getAwbBlameLogFolder(awbBundle);
// if (!resourceBlameLogDir.exists()) {
// resourceBlameLogDir = appVariantContext.getScope().getResourceBlameLogDir();
// }
final MergingLog mergingLog = new MergingLog(resourceBlameLogDir);
LayoutXmlProcessor layoutXmlProcessor = new LayoutXmlProcessor(awbBundle.getPackageName(), dataBindingBuilder.createJavaFileWriter(appVariantContext.getAwbClassOutputForDataBinding(awbBundle)), // appVariantContext.getVariantData().getType() == VariantType.LIBRARY,
new LayoutXmlProcessor.OriginalFileLookup() {
@Override
public File getOriginalFileFor(File file) {
SourceFile input = new SourceFile(file);
SourceFile original = mergingLog.find(input);
// it is not what we want so we alter the response.
return original == input ? input.getSourceFile() : original.getSourceFile();
}
});
return layoutXmlProcessor;
}
use of com.android.ide.common.blame.SourceFile 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;
}
use of com.android.ide.common.blame.SourceFile in project android by JetBrains.
the class ManifestPanel method describePosition.
private void describePosition(@NotNull HtmlBuilder sb, @NotNull AndroidFacet facet, @NotNull SourceFilePosition sourceFilePosition) {
SourceFile sourceFile = sourceFilePosition.getFile();
SourcePosition sourcePosition = sourceFilePosition.getPosition();
File file = sourceFile.getSourceFile();
if (file == GRADLE_MODEL_MARKER_FILE) {
VirtualFile gradleBuildFile = GradleUtil.getGradleBuildFile(facet.getModule());
if (gradleBuildFile != null) {
file = VfsUtilCore.virtualToIoFile(gradleBuildFile);
sb.addHtml("<a href=\"");
sb.add(file.toURI().toString());
sb.addHtml("\">");
sb.add(file.getName());
sb.addHtml("</a>");
sb.add(" injection");
} else {
sb.add("build.gradle injection (source location unknown)");
}
return;
}
AndroidLibrary library;
if (file != null) {
String source = null;
Module libraryModule = null;
Module[] modules = ModuleManager.getInstance(facet.getModule().getProject()).getModules();
VirtualFile vFile = LocalFileSystem.getInstance().findFileByIoFile(file);
if (vFile != null) {
Module module = ModuleUtilCore.findModuleForFile(vFile, facet.getModule().getProject());
if (module != null) {
if (modules.length >= 2) {
source = module.getName();
}
// AAR Library?
if (file.getPath().contains(EXPLODED_AAR)) {
AndroidModuleModel androidModel = AndroidModuleModel.get(module);
if (androidModel != null) {
library = GradleUtil.findLibrary(file.getParentFile(), androidModel.getSelectedVariant(), androidModel.getModelVersion());
if (library != null) {
if (library.getProject() != null) {
libraryModule = GradleUtil.findModuleByGradlePath(facet.getModule().getProject(), library.getProject());
if (libraryModule != null) {
module = libraryModule;
source = module.getName();
} else {
source = library.getProject();
source = StringUtil.trimStart(source, ":");
}
} else {
MavenCoordinates coordinates = library.getResolvedCoordinates();
source = /*coordinates.getGroupId() + ":" +*/
coordinates.getArtifactId() + ":" + coordinates.getVersion();
}
}
}
}
}
IdeaSourceProvider provider = ManifestUtils.findManifestSourceProvider(facet, vFile);
if (provider != null) /*&& !provider.equals(facet.getMainIdeaSourceProvider())*/
{
String providerName = provider.getName();
if (source == null) {
source = providerName;
} else {
// "the app main manifest" - "app" is the module name, "main" is the source provider name
source = source + " " + providerName;
}
}
}
if (source == null) {
source = file.getName();
if (!SourcePosition.UNKNOWN.equals(sourcePosition)) {
source += ":" + String.valueOf(sourcePosition);
}
}
sb.addHtml("<a href=\"");
boolean redirected = false;
if (libraryModule != null) {
AndroidFacet libraryFacet = AndroidFacet.getInstance(libraryModule);
if (libraryFacet != null) {
File manifestFile = libraryFacet.getMainSourceProvider().getManifestFile();
if (manifestFile.exists()) {
sb.add(manifestFile.toURI().toString());
redirected = true;
// Line numbers probably aren't right
sourcePosition = SourcePosition.UNKNOWN;
// TODO: Set URL which points to the element/attribute path
}
}
}
if (!redirected) {
sb.add(file.toURI().toString());
if (!SourcePosition.UNKNOWN.equals(sourcePosition)) {
sb.add(":");
sb.add(String.valueOf(sourcePosition.getStartLine()));
sb.add(":");
sb.add(String.valueOf(sourcePosition.getStartColumn()));
}
}
sb.addHtml("\">");
sb.add(source);
sb.addHtml("</a>");
sb.add(" manifest");
if (FileUtil.filesEqual(file, VfsUtilCore.virtualToIoFile(myFile))) {
sb.add(" (this file)");
}
if (!SourcePosition.UNKNOWN.equals(sourcePosition)) {
sb.add(", line ");
sb.add(Integer.toString(sourcePosition.getStartLine()));
}
}
}
Aggregations