CodeWriter add(CodeWriter code) { line--; for (Map.Entry<CodePosition, Object> entry : code.annotations.entrySet()) { CodePosition pos = entry.getKey(); attachAnnotation(entry.getValue(), new CodePosition(line + pos.getLine(), pos.getOffset())); } for (Map.Entry<Integer, Integer> entry : code.lineMap.entrySet()) { attachSourceLine(line + entry.getKey(), entry.getValue()); } line += code.line; offset = code.offset; buf.append(code.buf); return this; }
public void finish() { removeFirstEmptyLine(); buf.trimToSize(); code = buf.toString(); buf = null; Iterator<Map.Entry<CodePosition, Object>> it = annotations.entrySet().iterator(); while (it.hasNext()) { Map.Entry<CodePosition, Object> entry = it.next(); Object v = entry.getValue(); if (v instanceof DefinitionWrapper) { LineAttrNode l = ((DefinitionWrapper) v).getNode(); l.setDecompiledLine(entry.getKey().getLine()); it.remove(); } } }
public Position(CodePosition pos) { this.node = new JClass(pos.getJavaClass()); this.line = pos.getLine(); }
public void attachAnnotation(Object obj) { attachAnnotation(obj, new CodePosition(line, offset + 1)); }
static Position getPosition(JClass jCls, RSyntaxTextArea textArea, int offset) { try { int line = textArea.getLineOfOffset(offset); int lineOffset = offset - textArea.getLineStartOffset(line); CodePosition pos = jCls.getCls().getDefinitionPosition(line + 1, lineOffset + 1); if (pos != null && pos.isSet()) { return new Position(pos); } } catch (BadLocationException e) { LOG.error("Can't get line by offset", e); } return null; }
private void addUsage(JNode jNode, JavaClass javaClass, CodeLinesInfo linesInfo, CodePosition codePosition, List<StringRef> lines) { UsageInfo usageInfo = usageMap.computeIfAbsent(jNode, key -> new UsageInfo()); int line = codePosition.getLine(); JavaNode javaNodeByLine = linesInfo.getJavaNodeByLine(line); StringRef codeLine = lines.get(line - 1); JNode node = nodeCache.makeFrom(javaNodeByLine == null ? javaClass : javaNodeByLine); CodeNode codeNode = new CodeNode(node, line, codeLine); usageInfo.addUsage(codeNode); }
@Nullable public JavaNode getJavaNodeAtPosition(int line, int offset) { Map<CodePosition, Object> map = getCodeAnnotations(); if (map.isEmpty()) { return null; } Object obj = map.get(new CodePosition(line, offset)); if (obj == null) { return null; } return convertNode(obj); }
/** * Search node by offset in {@code jCls} code and return its definition position * (useful for jumps from usage) */ public JumpPosition getDefPosForNodeAtOffset(JClass jCls, int offset) { JavaNode foundNode = getJavaNodeAtOffset(jCls, offset); if (foundNode == null) { return null; } CodePosition pos = jCls.getCls().getDefinitionPosition(foundNode); if (pos == null) { return null; } JNode jNode = contentPanel.getTabbedPane().getMainWindow().getCacheObject().getNodeCache().makeFrom(foundNode); return new JumpPosition(jNode.getRootClass(), pos.getLine()); }
@Nullable public CodePosition getDefinitionPosition(JavaNode javaNode) { JavaClass jCls = javaNode.getTopParentClass(); jCls.decompile(); int defLine = javaNode.getDecompiledLine(); if (defLine == 0) { return null; } return new CodePosition(jCls, defLine, 0); }
public void attachDefinition(LineAttrNode obj) { attachAnnotation(obj); attachAnnotation(new DefinitionWrapper(obj), new CodePosition(line, offset)); }