use of jadx.gui.utils.CodeLinesInfo in project jadx by skylot.
the class IndexService method indexCls.
/**
* Warning! Not ready for parallel execution. Use only in a single thread.
*/
public boolean indexCls(JavaClass cls) {
try {
TextSearchIndex index = cache.getTextIndex();
if (index == null) {
return false;
}
// get code from cache to avoid decompilation here
String code = getCodeFromCache(cls);
if (code == null) {
return cls.isNoCode();
}
List<StringRef> lines = splitLines(code);
CodeLinesInfo linesInfo = new CodeLinesInfo(cls);
index.indexCode(cls, linesInfo, lines);
index.indexNames(cls);
indexSet.add(cls);
return true;
} catch (Exception e) {
LOG.error("Index error in class: {}", cls.getFullName(), e);
return false;
}
}
use of jadx.gui.utils.CodeLinesInfo in project jadx by skylot.
the class CommentAction method getCommentRef.
/**
* Check if possible insert comment at current line.
*
* @return blank code comment object (comment string empty)
*/
@Nullable
private ICodeComment getCommentRef(int line) {
if (line == -1 || this.topCls == null) {
return null;
}
try {
// TODO: cache and update on class refresh
CodeLinesInfo linesInfo = new CodeLinesInfo(topCls, true);
// add comment if node definition at this line
JavaNode nodeAtLine = linesInfo.getDefAtLine(line);
if (nodeAtLine != null) {
// at node definition -> add comment for it
JadxNodeRef nodeRef = JadxNodeRef.forJavaNode(nodeAtLine);
return new JadxCodeComment(nodeRef, "");
}
Object ann = topCls.getAnnotationAt(new CodePosition(line));
if (ann == null) {
// check if line with comment above node definition
try {
JavaNode defNode = linesInfo.getJavaNodeBelowLine(line);
if (defNode != null) {
String lineStr = codeArea.getLineText(line).trim();
if (lineStr.startsWith("//")) {
return new JadxCodeComment(JadxNodeRef.forJavaNode(defNode), "");
}
}
} catch (Exception e) {
LOG.error("Failed to check comment line: " + line, e);
}
return null;
}
// try to add method line comment
JavaNode node = linesInfo.getJavaNodeByLine(line);
if (node instanceof JavaMethod) {
JadxNodeRef nodeRef = JadxNodeRef.forMth((JavaMethod) node);
if (ann instanceof InsnCodeOffset) {
int rawOffset = ((InsnCodeOffset) ann).getOffset();
return new JadxCodeComment(nodeRef, JadxCodeRef.forInsn(rawOffset), "");
}
}
} catch (Exception e) {
LOG.error("Failed to add comment at line: " + line, e);
}
return null;
}
use of jadx.gui.utils.CodeLinesInfo in project jadx by skylot.
the class UsageDialog method processUsageClass.
private void processUsageClass(JavaNode usageNode) {
JavaClass cls = usageNode.getTopParentClass();
String code = cls.getCodeInfo().getCodeStr();
CodeLinesInfo linesInfo = new CodeLinesInfo(cls);
List<? extends JavaNode> targetNodes = getMethodWithOverride();
for (JavaNode javaNode : targetNodes) {
List<CodePosition> usage = cls.getUsageFor(javaNode);
for (CodePosition pos : usage) {
if (javaNode.getTopParentClass().equals(cls) && pos.getPos() == javaNode.getDefPos()) {
// skip declaration
continue;
}
StringRef line = getLineStrAt(code, pos.getPos());
if (line.startsWith("import ")) {
continue;
}
JavaNode javaNodeByLine = linesInfo.getJavaNodeByLine(pos.getLine());
JNode useAtNode = javaNodeByLine == null ? node : getNodeCache().makeFrom(javaNodeByLine);
usageList.add(new CodeNode(useAtNode, line, pos.getLine(), pos.getPos()));
}
}
}
use of jadx.gui.utils.CodeLinesInfo in project jadx by skylot.
the class IndexJob method runJob.
protected void runJob() {
JNodeCache nodeCache = cache.getNodeCache();
final TextSearchIndex index = new TextSearchIndex(nodeCache);
final CodeUsageInfo usageInfo = new CodeUsageInfo(nodeCache);
cache.setTextIndex(index);
cache.setUsageInfo(usageInfo);
for (final JavaClass cls : wrapper.getClasses()) {
addTask(new Runnable() {
@Override
public void run() {
try {
index.indexNames(cls);
CodeLinesInfo linesInfo = new CodeLinesInfo(cls);
List<StringRef> lines = splitLines(cls);
usageInfo.processClass(cls, linesInfo, lines);
if (Utils.isFreeMemoryAvailable()) {
index.indexCode(cls, linesInfo, lines);
} else {
index.classCodeIndexSkipped(cls);
}
} catch (Exception e) {
LOG.error("Index error in class: {}", cls.getFullName(), e);
}
}
});
}
}
Aggregations