Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
qq_39073359
jadx
提交
ff5f6fca
J
jadx
项目概览
qq_39073359
/
jadx
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
J
jadx
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
ff5f6fca
编写于
8月 11, 2019
作者:
S
Skylot
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix(gui): fix "Go to declaration" and "Find usage" menu actions
上级
3578f7d6
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
113 addition
and
124 deletion
+113
-124
jadx-gui/src/main/java/jadx/gui/ui/codearea/CodeArea.java
jadx-gui/src/main/java/jadx/gui/ui/codearea/CodeArea.java
+42
-5
jadx-gui/src/main/java/jadx/gui/ui/codearea/CodeLinkGenerator.java
...src/main/java/jadx/gui/ui/codearea/CodeLinkGenerator.java
+2
-27
jadx-gui/src/main/java/jadx/gui/ui/codearea/FindUsageAction.java
...i/src/main/java/jadx/gui/ui/codearea/FindUsageAction.java
+6
-47
jadx-gui/src/main/java/jadx/gui/ui/codearea/GoToDeclarationAction.java
...main/java/jadx/gui/ui/codearea/GoToDeclarationAction.java
+8
-45
jadx-gui/src/main/java/jadx/gui/ui/codearea/JNodeMenuAction.java
...i/src/main/java/jadx/gui/ui/codearea/JNodeMenuAction.java
+55
-0
未找到文件。
jadx-gui/src/main/java/jadx/gui/ui/codearea/CodeArea.java
浏览文件 @
ff5f6fca
...
...
@@ -3,6 +3,9 @@ package jadx.gui.ui.codearea;
import
javax.swing.*
;
import
org.fife.ui.rsyntaxtextarea.RSyntaxDocument
;
import
org.fife.ui.rsyntaxtextarea.Token
;
import
org.fife.ui.rsyntaxtextarea.TokenTypes
;
import
org.jetbrains.annotations.Nullable
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
...
...
@@ -28,9 +31,8 @@ public final class CodeArea extends AbstractCodeArea {
setSyntaxEditingStyle
(
node
.
getSyntaxName
());
if
(
node
instanceof
JClass
)
{
JClass
jClsNode
=
(
JClass
)
this
.
node
;
((
RSyntaxDocument
)
getDocument
()).
setSyntaxStyle
(
new
JadxTokenMaker
(
this
));
addMenuItems
(
jClsNode
);
addMenuItems
();
}
setHyperlinksEnabled
(
true
);
...
...
@@ -47,9 +49,9 @@ public final class CodeArea extends AbstractCodeArea {
}
}
private
void
addMenuItems
(
JClass
jCls
)
{
FindUsageAction
findUsage
=
new
FindUsageAction
(
contentPanel
,
this
);
GoToDeclarationAction
goToDeclaration
=
new
GoToDeclarationAction
(
contentPanel
,
this
,
jCl
s
);
private
void
addMenuItems
()
{
FindUsageAction
findUsage
=
new
FindUsageAction
(
this
);
GoToDeclarationAction
goToDeclaration
=
new
GoToDeclarationAction
(
thi
s
);
JPopupMenu
popup
=
getPopupMenu
();
popup
.
addSeparator
();
...
...
@@ -59,11 +61,46 @@ public final class CodeArea extends AbstractCodeArea {
popup
.
addPopupMenuListener
(
goToDeclaration
);
}
public
int
adjustOffsetForToken
(
@Nullable
Token
token
)
{
if
(
token
==
null
)
{
return
-
1
;
}
int
type
=
token
.
getType
();
final
int
sourceOffset
;
if
(
node
instanceof
JClass
)
{
if
(
type
==
TokenTypes
.
IDENTIFIER
)
{
sourceOffset
=
token
.
getOffset
();
}
else
if
(
type
==
TokenTypes
.
ANNOTATION
&&
token
.
length
()
>
1
)
{
sourceOffset
=
token
.
getOffset
()
+
1
;
}
else
{
return
-
1
;
}
}
else
{
if
(
type
==
TokenTypes
.
MARKUP_TAG_ATTRIBUTE_VALUE
)
{
sourceOffset
=
token
.
getOffset
()
+
1
;
// skip quote at start (")
}
else
{
return
-
1
;
}
}
// fast skip
if
(
token
.
length
()
==
1
)
{
char
ch
=
token
.
getTextArray
()[
token
.
getTextOffset
()];
if
(
ch
==
'.'
||
ch
==
','
||
ch
==
';'
)
{
return
-
1
;
}
}
return
sourceOffset
;
}
/**
* Search node by offset in {@code jCls} code and return its definition position
* (useful for jumps from usage)
*/
@Nullable
public
JumpPosition
getDefPosForNodeAtOffset
(
int
offset
)
{
if
(
offset
==
-
1
)
{
return
null
;
}
JavaNode
foundNode
=
getJavaNodeAtOffset
(
offset
);
if
(
foundNode
==
null
)
{
return
null
;
...
...
jadx-gui/src/main/java/jadx/gui/ui/codearea/CodeLinkGenerator.java
浏览文件 @
ff5f6fca
...
...
@@ -9,11 +9,9 @@ import org.fife.ui.rsyntaxtextarea.LinkGenerator;
import
org.fife.ui.rsyntaxtextarea.LinkGeneratorResult
;
import
org.fife.ui.rsyntaxtextarea.RSyntaxTextArea
;
import
org.fife.ui.rsyntaxtextarea.Token
;
import
org.fife.ui.rsyntaxtextarea.TokenTypes
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
jadx.gui.treemodel.JClass
;
import
jadx.gui.treemodel.JNode
;
import
jadx.gui.ui.ContentPanel
;
import
jadx.gui.utils.JumpPosition
;
...
...
@@ -38,33 +36,10 @@ public class CodeLinkGenerator implements LinkGenerator, HyperlinkListener {
return
null
;
}
Token
token
=
textArea
.
modelToToken
(
offset
);
if
(
token
==
null
)
{
int
sourceOffset
=
codeArea
.
adjustOffsetForToken
(
token
);
if
(
sourceOffset
==
-
1
)
{
return
null
;
}
int
type
=
token
.
getType
();
final
int
sourceOffset
;
if
(
jNode
instanceof
JClass
)
{
if
(
type
==
TokenTypes
.
IDENTIFIER
)
{
sourceOffset
=
token
.
getOffset
();
}
else
if
(
type
==
TokenTypes
.
ANNOTATION
&&
token
.
length
()
>
1
)
{
sourceOffset
=
token
.
getOffset
()
+
1
;
}
else
{
return
null
;
}
}
else
{
if
(
type
==
TokenTypes
.
MARKUP_TAG_ATTRIBUTE_VALUE
)
{
sourceOffset
=
token
.
getOffset
()
+
1
;
// skip quote at start (")
}
else
{
return
null
;
}
}
// fast skip
if
(
token
.
length
()
==
1
)
{
char
ch
=
token
.
getTextArray
()[
token
.
getTextOffset
()];
if
(
ch
==
'.'
||
ch
==
','
||
ch
==
';'
)
{
return
null
;
}
}
final
JumpPosition
defPos
=
codeArea
.
getDefPosForNodeAtOffset
(
sourceOffset
);
if
(
defPos
==
null
)
{
return
null
;
...
...
jadx-gui/src/main/java/jadx/gui/ui/codearea/FindUsageAction.java
浏览文件 @
ff5f6fca
package
jadx.gui.ui.codearea
;
import
java.awt.*
;
import
java.awt.event.ActionEvent
;
import
javax.swing.*
;
import
javax.swing.event.PopupMenuEvent
;
import
javax.swing.event.PopupMenuListener
;
import
org.fife.ui.rsyntaxtextarea.Token
;
import
jadx.api.JavaNode
;
import
jadx.gui.treemodel.JNode
;
import
jadx.gui.ui.ContentPanel
;
import
jadx.gui.ui.MainWindow
;
import
jadx.gui.ui.UsageDialog
;
import
jadx.gui.utils.NLS
;
public
final
class
FindUsageAction
extends
AbstractAction
implements
PopupMenuListener
{
public
final
class
FindUsageAction
extends
JNodeMenuAction
{
private
static
final
long
serialVersionUID
=
4692546569977976384L
;
private
final
transient
ContentPanel
contentPanel
;
private
final
transient
CodeArea
codeArea
;
private
transient
JavaNode
node
;
public
FindUsageAction
(
ContentPanel
contentPanel
,
CodeArea
codeArea
)
{
super
(
NLS
.
str
(
"popup.find_usage"
));
this
.
contentPanel
=
contentPanel
;
this
.
codeArea
=
codeArea
;
public
FindUsageAction
(
CodeArea
codeArea
)
{
super
(
NLS
.
str
(
"popup.find_usage"
),
codeArea
);
}
@Override
public
void
actionPerformed
(
ActionEvent
e
)
{
if
(
node
==
null
)
{
if
(
jumpPos
==
null
)
{
return
;
}
MainWindow
mainWindow
=
contentPanel
.
getTabbedPane
().
getMainWindow
();
JNode
jNode
=
mainWindow
.
getCacheObject
().
getNodeCache
().
makeFrom
(
node
);
UsageDialog
usageDialog
=
new
UsageDialog
(
mainWindow
,
jNode
);
MainWindow
mainWindow
=
codeArea
.
getContentPanel
().
getTabbedPane
().
getMainWindow
();
UsageDialog
usageDialog
=
new
UsageDialog
(
mainWindow
,
jumpPos
.
getNode
());
usageDialog
.
setVisible
(
true
);
}
@Override
public
void
popupMenuWillBecomeVisible
(
PopupMenuEvent
e
)
{
node
=
null
;
Point
pos
=
codeArea
.
getMousePosition
();
if
(
pos
!=
null
)
{
Token
token
=
codeArea
.
viewToToken
(
pos
);
if
(
token
!=
null
)
{
node
=
codeArea
.
getJavaNodeAtOffset
(
token
.
getOffset
());
}
}
setEnabled
(
node
!=
null
);
}
@Override
public
void
popupMenuWillBecomeInvisible
(
PopupMenuEvent
e
)
{
// do nothing
}
@Override
public
void
popupMenuCanceled
(
PopupMenuEvent
e
)
{
// do nothing
}
}
jadx-gui/src/main/java/jadx/gui/ui/codearea/GoToDeclarationAction.java
浏览文件 @
ff5f6fca
package
jadx.gui.ui.codearea
;
import
java.awt.Point
;
import
java.awt.event.ActionEvent
;
import
javax.swing.
AbstractAction
;
import
javax.swing.
*
;
import
javax.swing.event.PopupMenuEvent
;
import
javax.swing.event.PopupMenuListener
;
import
org.fife.ui.rsyntaxtextarea.Token
;
import
jadx.api.JavaNode
;
import
jadx.gui.treemodel.JClass
;
import
jadx.gui.treemodel.JNode
;
import
jadx.gui.ui.ContentPanel
;
import
jadx.gui.ui.MainWindow
;
import
jadx.gui.utils.JumpPosition
;
import
jadx.gui.utils.NLS
;
public
final
class
GoToDeclarationAction
extends
AbstractAction
implements
PopupMenuListener
{
public
final
class
GoToDeclarationAction
extends
JNodeMenuAction
{
private
static
final
long
serialVersionUID
=
-
1186470538894941301L
;
private
final
transient
ContentPanel
contentPanel
;
private
final
transient
CodeArea
codeArea
;
private
final
transient
JClass
jCls
;
private
transient
JavaNode
node
;
public
GoToDeclarationAction
(
ContentPanel
contentPanel
,
CodeArea
codeArea
,
JClass
jCls
)
{
super
(
NLS
.
str
(
"popup.go_to_declaration"
));
this
.
contentPanel
=
contentPanel
;
this
.
codeArea
=
codeArea
;
this
.
jCls
=
jCls
;
public
GoToDeclarationAction
(
CodeArea
codeArea
)
{
super
(
NLS
.
str
(
"popup.go_to_declaration"
),
codeArea
);
}
@Override
public
void
actionPerformed
(
ActionEvent
e
)
{
if
(
node
=
=
null
)
{
return
;
if
(
jumpPos
!
=
null
)
{
codeArea
.
getContentPanel
().
getTabbedPane
().
codeJump
(
jumpPos
)
;
}
MainWindow
mainWindow
=
contentPanel
.
getTabbedPane
().
getMainWindow
();
JNode
jNode
=
mainWindow
.
getCacheObject
().
getNodeCache
().
makeFrom
(
node
);
mainWindow
.
getTabbedPane
().
codeJump
(
new
JumpPosition
(
jNode
,
jNode
.
getLine
()));
}
@Override
public
void
popupMenuWillBecomeVisible
(
PopupMenuEvent
e
)
{
node
=
null
;
Point
pos
=
codeArea
.
getMousePosition
();
if
(
pos
!=
null
)
{
Token
token
=
codeArea
.
viewToToken
(
pos
);
if
(
token
!=
null
)
{
node
=
codeArea
.
getJavaNodeAtOffset
(
token
.
getOffset
());
}
}
setEnabled
(
node
!=
null
);
}
super
.
popupMenuWillBecomeVisible
(
e
);
@Override
public
void
popupMenuWillBecomeInvisible
(
PopupMenuEvent
e
)
{
// do nothing
}
@Override
public
void
popupMenuCanceled
(
PopupMenuEvent
e
)
{
// do nothing
putValue
(
Action
.
SMALL_ICON
,
jumpPos
==
null
?
null
:
jumpPos
.
getNode
().
getIcon
());
}
}
jadx-gui/src/main/java/jadx/gui/ui/codearea/JNodeMenuAction.java
0 → 100644
浏览文件 @
ff5f6fca
package
jadx.gui.ui.codearea
;
import
java.awt.*
;
import
java.awt.event.ActionEvent
;
import
javax.swing.*
;
import
javax.swing.event.PopupMenuEvent
;
import
javax.swing.event.PopupMenuListener
;
import
org.fife.ui.rsyntaxtextarea.Token
;
import
org.jetbrains.annotations.Nullable
;
import
jadx.gui.utils.JumpPosition
;
public
abstract
class
JNodeMenuAction
extends
AbstractAction
implements
PopupMenuListener
{
protected
final
transient
CodeArea
codeArea
;
@Nullable
protected
transient
JumpPosition
jumpPos
;
public
JNodeMenuAction
(
String
name
,
CodeArea
codeArea
)
{
super
(
name
);
this
.
codeArea
=
codeArea
;
}
@Override
public
abstract
void
actionPerformed
(
ActionEvent
e
);
@Override
public
void
popupMenuWillBecomeVisible
(
PopupMenuEvent
e
)
{
jumpPos
=
getJumpPos
();
setEnabled
(
jumpPos
!=
null
);
}
@Nullable
private
JumpPosition
getJumpPos
()
{
Point
pos
=
codeArea
.
getMousePosition
();
if
(
pos
!=
null
)
{
Token
token
=
codeArea
.
viewToToken
(
pos
);
int
offset
=
codeArea
.
adjustOffsetForToken
(
token
);
return
codeArea
.
getDefPosForNodeAtOffset
(
offset
);
}
return
null
;
}
@Override
public
void
popupMenuWillBecomeInvisible
(
PopupMenuEvent
e
)
{
// do nothing
}
@Override
public
void
popupMenuCanceled
(
PopupMenuEvent
e
)
{
// do nothing
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录