package com.chyod.camelcase.handlers;
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.jface.text.BadLocationException;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.TextSelection;
import org.eclipse.jface.viewers.ISelectionProvider;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.part.MultiPageEditorPart;
import org.eclipse.ui.texteditor.ITextEditor;
import org.eclipse.wst.sse.ui.StructuredTextEditor;
public class EditorShortcutsBaseHandler extends AbstractHandler {
public EditorShortcutsBaseHandler() {
}
public Object execute(ExecutionEvent event) throws ExecutionException {
IEditorPart iep = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
ITextEditor ite = null;
TextSelection selection = null;
IDocument document = null;
ISelectionProvider selectionProvider = null;
if (iep instanceof ITextEditor) {
ite = (ITextEditor)iep;
selectionProvider = ((ITextEditor)ite).getSelectionProvider();
selection = (TextSelection)selectionProvider.getSelection();
document = ((ITextEditor)ite).getDocumentProvider().getDocument(((ITextEditor)ite).getEditorInput());
} else {
if (!(iep instanceof MultiPageEditorPart)) {
return null;
}
MultiPageEditorPart part = (MultiPageEditorPart)iep;
Object sp = part.getSelectedPage();
if (!(sp instanceof StructuredTextEditor)) {
return null;
}
ite = (StructuredTextEditor)sp;
selectionProvider = ((ITextEditor)ite).getSelectionProvider();
selection = (TextSelection)selectionProvider.getSelection();
document = ((ITextEditor)ite).getDocumentProvider().getDocument(((ITextEditor)ite).getEditorInput());
}
if (selection != null && document != null && selectionProvider != null) {
String title = iep.getTitle();
EditorShortcutsBaseHandler.TextProcessResult result = this.process(document.get(), selection.getOffset(), selection.getLength(), title != null && title.endsWith(".java"));
if (result == null) {
return null;
} else {
try {
document.replace(result.replaceOffset, result.replaceLength, result.replaceText);
} catch (BadLocationException var10) {
return null;
}
((ITextEditor)ite).selectAndReveal(result.newSelectionOffset, result.newSelectionLength);
return null;
}
} else {
return null;
}
}
protected EditorShortcutsBaseHandler.TextProcessResult process(String text, int selectionOffset, int selectionLength, boolean isJavaFile) {
if (text != null && selectionOffset >= 0 && selectionLength > 2) {
String selected = text.substring(selectionOffset, selectionOffset + selectionLength);
if (selected.indexOf(95) != -1) {
selected = selected.replaceAll("_([A-Z])", "$1");
int i = -32;
for(char c = 'a'; c <= 'z'; ++c) {
selected = selected.replaceAll("_" + c, String.valueOf((char)(c + i)));
}
} else {
selected = selected.replaceAll("[A-Z]", "_$0");
selected = selected.toLowerCase();
if (selected.charAt(0) == '_') {
selected = selected.substring(1);
}
}
EditorShortcutsBaseHandler.TextProcessResult result = new EditorShortcutsBaseHandler.TextProcessResult();
result.replaceText = selected;
result.newSelectionOffset = selectionOffset;
result.newSelectionLength = selected.length();
result.replaceOffset = selectionOffset;
result.replaceLength = selectionLength;
return result;
} else {
return null;
}
}
protected static final class TextProcessResult {
int newSelectionOffset;
int newSelectionLength;
int replaceOffset;
int replaceLength;
String replaceText;
protected TextProcessResult() {
}
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
eclipse字符串驼峰转换插件及源码
共20个文件
class:4个
xml:2个
project:2个
需积分: 5 0 下载量 126 浏览量
2023-02-09
22:38:15
上传
评论
收藏 29KB ZIP 举报
温馨提示
eclipse字符串驼峰转换插件及源码,提供字符串转StringBuilder, snake_case转camalCase及互转功能。将文档中的plugins复制到eclipse中,重启即可生效。ctrl+shift+1 为转换StringBuilder快捷键, ctrl+alt+z为驼峰命名转换快捷键。
资源推荐
资源详情
资源评论
收起资源包目录
eclipse-plugins_sources.zip (20个子文件)
新建文件夹
plugins
com.chyod.camelCase1_ctrl_alt_z.202105222210.jar 5KB
com.chyod.stringBuilderUtils_ctrl_shift_1.202207290043.jar 5KB
sources
com.chyod.camelcase1
.classpath 376B
.settings
org.eclipse.jdt.core.prefs 364B
src
com
chyod
camelcase
handlers
EditorShortcutsBaseHandler.java 5KB
build.properties 188B
plugin.xml 1023B
bin
com
chyod
camelcase
handlers
EditorShortcutsBaseHandler.class 5KB
EditorShortcutsBaseHandler$TextProcessResult.class 666B
.project 877B
META-INF
MANIFEST.MF 506B
com.chyod.stringTypeUtils
.classpath 376B
.settings
org.eclipse.jdt.core.prefs 364B
src
com
chyod
stringTypeUtils
handlers
EditorShortcutsBaseHandler.java 4KB
build.properties 188B
plugin.xml 1KB
bin
com
chyod
stringTypeUtils
handlers
EditorShortcutsBaseHandler.class 4KB
EditorShortcutsBaseHandler$TextProcessResult.class 684B
.project 686B
META-INF
MANIFEST.MF 529B
共 20 条
- 1
资源评论
ChyoD1811
- 粉丝: 11
- 资源: 5
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 机械自动化与机器人控制中的速度与雅克比矩阵计算
- springboot社区医院信息平台(代码+数据库+LW)
- STM32+ESP8266(ESP32)+MQTT+阿里云物联网平台
- 宠物管理-JAVA-基于springBoot宠物管理系统设计与实现
- X230安装Sonoma成功 博通BCM94352HMB网卡 扩展坞引线改屏1080P
- 物业智慧-JAVA-基于springBoot物业智慧系统设计与实现
- 计算机专业设计思路,个人学习整理教程,分析给需要的同学
- 大学生就业-JAVA-基于springBoot大学生就业信息管理系统设计与实现
- 计算机软件课程设计思路,个人学习整理教程,分析给需要的同学
- VMware安装教程,个人学习整理教程,分析给需要的同学
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功