<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Tutorial: Adding find* Methods to Grails Domain Objects</title>
<link rel="stylesheet" type="text/css" href="PLUGINS_ROOT/PRODUCT_PLUGIN/book.css">
</head>
<body>
<h1>Tutorial: Adding support for Grails Dynamic Types</h1>
This tutorial demonstrates how to add lookups for Grails dynamic types. Basic lookup on domain class 'find' members is
implemented.
<br>
Note that it is a demo and might be useful as a starting point for a full implementation. The source code for this
sample is available in the Codehaus Subversion repository - you can browse right away at
<a href="http://svn.groovy.codehaus.org/browse/groovy/trunk/groovy/ide/grails-eclipse">http://svn.groovy.codehaus.org/browse/groovy/trunk/groovy/ide/grails-eclipse</a>
.
<br>
<br>
The first step is to create a new plug-in project using the New wizard:
<br>
<br>
<img src="images/newProject1.png">
<br>
<br>
<br>
Enter
<em>org.codehaus.grails.eclipse.samples.types</em>
for the project name:
<br>
<br>
<img src="images/newProject2.png">
<br>
<br>
<br>
Next we configure the project. An activator is not needed nor does this plug-in contribute to the UI, so uncheck
the two options.
<br>
Click on finish and we are ready to set up the project environment.
<br>
<br>
<img src="images/newProject3.png">
<br>
<br>
<br>
The first step is to add the Groovy Nature. Normally this would happen automatically when the first Groovy
source file is created. However, since we are adding to GroovyEclipse itself, some additional steps are required.
<br>
<br>
First add the nature:
<br>
<br>
<img src="images/groovyNature1.png">
<br>
<br>
<br>
Next open the .classpath file and remove Groovy related libaries. This is required as this plug-in will import
the libraries from the core Groovy plugin. If these libraries are not removed there will be problems at runtime as
Groovy classes created with different class loaders attempt to interact.
<br>
<br>
The libraries to remove are highlighted:
<br>
<br>
<img src="images/groovyNature2.png">
<br>
<br>
<br>
Remove them and save and close the .classpath file:
<br>
<br>
<img src="images/groovyNature3.png">
<br>
<br>
<br>
By default, the Groovy plugin has set the output folder for compiled Groovy classes to bin-groovy. This folder must be
added as a library to the plugin configuration. Press the 'Add' button:
<br>
<br>
<img src="images/runtime1.png">
<br>
<br>
<br>
And add bin-groovy:
<br>
<br>
<img src="images/runtime2.png">
<br>
<br>
<br>
Finally, the dependency to the core GroovyEclipse plugin is added.
<br>
Press the 'Add' button:
<br>
<br>
<img src="images/dependencies1.png">
<br>
<br>
<br>
And select the core GroovyEclipse plugin. This is the plugin which exports the Groovy runtime libraries and defines the
extension points for the member lookup.
<br>
<br>
<img src="images/dependencies2.png">
<br>
<br>
<br>
<img src="images/dependencies3.png">
<br>
<br>
<br>
Finally we are ready to implement the extension. In the plugin editor, select the 'Extensions' tab and configure
the extention.
<br>
Press the 'Add' button and select the extension point. There should be only one visible. Afterwards it appears in the
extensions list:
<br>
<br>
<img src="images/extensions1.png">
<br>
<br>
<br>
Add a new 'memberLookup':
<br>
<br>
<img src="images/extensions2.png">
<br>
<br>
<br>
In the next step the class name implementing the lookup is added, as well as the source code contexts in which this lookup
is valid. Note that it is not necessary to use the qualified names for the contexts. We add both methodScope and
closureScope. If closureScope is not added, then this lookup will not work inside of closures which are nested within
methods.
<br>
<br>
<img src="images/extensions3.png">
<br>
<br>
<br>
Finally we are ready to code!
<br>
In the next two steps, a new package for our Groovy implementation is created:
<br>
<br>
<img src="images/newPackage1.png">
<br>
<br>
<br>
<img src="images/newPackage2.png">
<br>
<br>
<br>
And finally the Groovy source file to implement the Grails find methods lookup is created:
<br>
<br>
<img src="images/newGroovy1.png">
<br>
<br>
<br>
<img src="images/newGroovy2.png">
<br>
<br>
<h2>The Code</h2>
Lets start with the following code:
<br>
<p class="Code">package org.codehaus.grails.eclipse.samples.types <br>
<br>
import org.codehaus.groovy.eclipse.core.IGroovyProjectAware <br>
import org.codehaus.groovy.eclipse.core.context.ISourceCodeContext <br>
import org.codehaus.groovy.eclipse.core.context.ISourceCodeContextAware <br>
import org.codehaus.groovy.eclipse.core.model.GroovyProject <br>
import org.codehaus.groovy.eclipse.core.types.IMemberLookup <br>
<br>
class DomainFindMethodsLookup implements IMemberLookup, ISourceCodeContextAware, IGroovyProjectAware { <br>
ISourceCodeContext context <br>
GroovyProject project <br>
<br>
void setSourceCodeContext(ISourceCodeContext context) { <br>
this.context = context <br>
} <br>
<br>
void setGroovyProject(GroovyProject project) { <br>
this.project = project <br>
} <br>
}</p>
<br>
<br>
The two interfaces, ISourceCodeContextAware and IGroovyProjectAware indicate that this lookup wants to know about the
current project and context. This does not guarantee that a project and context will be set on this lookup, so care must
be taken to check that they have actually been set.
<br>
<br>
Next implement the IMemberLookup methods:
<br>
<p class="Code">import org.codehaus.groovy.eclipse.core.types.Field <br>
import org.codehaus.groovy.eclipse.core.types.Method <br>
import org.codehaus.groovy.eclipse.core.types.Modifiers <br>
import org.codehaus.groovy.eclipse.core.types.Parameter <br>
import org.codehaus.groovy.eclipse.core.types.Property <br>
import org.codehaus.groovy.eclipse.core.types.TypeUtil <br>
<br>
class DomainFindMethodsLookup implements IMemberLookup, ISourceCodeContextAware, IGroovyProjectAware { <br>
... <br>
<br>
Field[] lookupFields(String type, String name, boolean accessible, boolean staticAccess, boolean
exact) { <br>
return TypeUtil.NO_FIELDS <br>
} <br>
<br>
Property[] lookupProperties(String type, String name, boolean accessible, boolean staticAccess,
boolean exact) { <br>
return TypeUtil.NO_PROPERTIES <br>
} <br>
<br>
Method[] lookupMethods(String type, String name, boolean accessible, boolean staticAccess, boolean
exact) { <br>
} <br>
<br>
Method[] lookupMethods(String type, String name, String[] paramTypes, boolean accessible, <br>
boolean staticAccess, boolean exact) { <br>
return lookupMethods(type, name, accessible, staticAccess, exact) <br>
} <br>
<br>
... <br>
}</p>
<br>
<br>
TypeUtil is a class with many handly static helper methods, and is used above to return empty arrays.
<br>
<br>
In the next step we add some sanity checks, one of which checks that the object we are looking up methods for is in fact
a domain class:
<br>
<p class="Code"> Method[] lookupMethods(String type, String name, boolean accessible, boolean
staticAccess, boolean exact) { <br>
if (!staticAccess || !context || !project || !isDomainClass(type)) { <br>
return TypeUtil.NO_METHODS <br>
 
没有合适的资源?快使用搜索试试~ 我知道了~
Eclipse Groovy离线插件下载
共237个文件
gif:130个
jar:27个
png:25个
4星 · 超过85%的资源 需积分: 9 11 下载量 28 浏览量
2017-10-11
20:02:11
上传
评论
收藏 14.18MB ZIP 举报
温馨提示
Eclipse Groovy离线插件下载,Eclipse Groovy离线插件下载
资源推荐
资源详情
资源评论
收起资源包目录
Eclipse Groovy离线插件下载 (237个子文件)
JavaElementCategoryLookup.class 15KB
JavaClassCategoryLookup.class 11KB
CategoryLookup.class 11KB
MemberLookupRegistry.class 9KB
CSTUtil.class 8KB
ContextUtil.class 6KB
JavaElementCategoryLookup$_mapCategory_closure6.class 3KB
CategoryLookup$_collectCategoryClassNames_closure4.class 3KB
CategoryLookup$_collectAllMethods_closure1.class 3KB
CategoryLookup$_createLookupsForClassNames_closure2.class 3KB
MemberLookupRegistry$_createMemberLookup_closure2.class 3KB
JavaClassCategoryLookup$_collectAllMethods_closure1.class 3KB
JavaElementCategoryLookup$_collectAllMethods_closure1.class 2KB
CategoryLookup$_collectCategoryClassNames_closure4_closure5.class 2KB
JavaElementCategoryLookup$_collectAllMethods_closure2.class 2KB
JavaElementCategoryLookup$_createJavaTypeHiearchy_closure3.class 2KB
JavaElementCategoryLookup$_createGroovyTypeHiearchy_closure4.class 2KB
JavaElementCategoryLookup$_createGroovyTypeHiearchy_closure5.class 2KB
MemberLookupRegistry$__clinit__closure1.class 2KB
ContextUtil$__clinit__closure1.class 2KB
CategoryLookup$_createLookupsForClassNames_closure3.class 2KB
internal-testRunTabs.exsd 3KB
testng_blur.gif 1KB
report.gif 1005B
relaunchf.gif 1003B
relaunchf.gif 994B
testng1.gif 957B
testng5.gif 937B
testng.GIF 929B
testng4.GIF 927B
testng2.gif 926B
testng.gif 923B
testng6.gif 909B
testng_noshadow.gif 902B
testng3.gif 888B
testng-old.gif 877B
failureOnPercentage.gif 844B
lock.gif 626B
relaunchf.gif 609B
runjunit.gif 596B
testrun.gif 594B
testrun.gif 594B
relaunch.gif 590B
relaunch.gif 590B
suiterun.gif 589B
tsuiterun.gif 589B
lock.gif 588B
new_testcase.gif 587B
history_list.gif 586B
relaunchf.gif 585B
relaunch.gif 580B
relaunch.gif 580B
groovy_file.gif 580B
debugjunit.gif 550B
new_testsuite.gif 387B
suiteok.gif 382B
tsuiteok.gif 382B
testok.gif 380B
testok.gif 380B
suiteskip.gif 376B
suitefail.gif 376B
tsuitefail.gif 376B
tsuiteerror.gif 376B
testfail.gif 374B
testskip.gif 374B
th_horizontal.gif 374B
th_horizontal.gif 374B
testerr.gif 374B
testfail.gif 374B
testignored.gif 365B
test.gif 362B
test.gif 362B
new_testsuite.gif 361B
th_automatic.gif 358B
suite.gif 358B
testhier.gif 358B
testhier.gif 358B
tsuite.gif 358B
th_automatic.gif 358B
new_testcase.gif 355B
th_horizontal.gif 354B
th_horizontal.gif 354B
runjunit.gif 353B
th_vertical.gif 352B
th_vertical.gif 352B
junitsuccq.gif 345B
debug.gif 341B
th_automatic.gif 338B
th_automatic.gif 338B
select_next.gif 332B
select_next.gif 332B
select_prev.gif 323B
select_prev.gif 323B
debug.gif 317B
juniterrq.gif 234B
compare.gif 229B
compare.gif 229B
junitsucc.gif 226B
junitsucc.gif 226B
history_list.gif 225B
共 237 条
- 1
- 2
- 3
资源评论
- qq_332854402017-11-02找了好久了
- 传奇大虾2018-04-24可以啊可以
GZ-豆浆油条
- 粉丝: 70
- 资源: 3
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- VSc++编程助手1.0 - 1
- 基于matlab的说话人语音识别源码+PPT+报告(优质项目).zip
- 语音识别基于matlab说话人识别系统源码+报告PPT(高分优质项目).zip
- 毕业设计: 校园失物招领小程序的设计与实现论文(源码 + 数据库 + 说明文档)
- 美易ME-DUI自绘模块3.3-易语言模块
- 毕业设计:小程序消防知识每天学(源码 + 数据库 + 说明文档)
- 2024-NEW.zip
- 软件.zip
- 华为FPGA设计技巧FPGA设计规范设计经验设计流程指南华为面经硬件工程师手册等资料(15个).zip
- 毕业设计:基于微信小程序大学校园二手教材与书籍拍卖系统(源码 + 数据库 + 说明文档)
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功