Skip to content

Commit

Permalink
Update plugin with new layout; Add Lombok support
Browse files Browse the repository at this point in the history
  • Loading branch information
aalmiray committed Dec 3, 2012
1 parent 9abdd3f commit dcce687
Show file tree
Hide file tree
Showing 26 changed files with 1,268 additions and 136 deletions.
4 changes: 4 additions & 0 deletions .gitignore
@@ -1,2 +1,6 @@
target
release_notes.md
.idea
rest-griffonPluginFixes.iml
rest-griffonPlugins.iml
rest.iml
4 changes: 3 additions & 1 deletion RestGriffonAddon.groovy
Expand Up @@ -16,6 +16,7 @@

import griffon.core.GriffonClass
import griffon.plugins.rest.RestEnhancer
import griffon.plugins.rest.RestContributionHandler

/**
* @author Andres Almiray
Expand All @@ -25,8 +26,9 @@ class RestGriffonAddon {
def types = app.config.griffon?.rest?.injectInto ?: ['controller']
for(String type : types) {
for(GriffonClass gc : app.artifactManager.getClassesOfType(type)) {
if (RestContributionHandler.isAssignableFrom(gc.clazz)) continue
RestEnhancer.enhance(gc.metaClass)
}
}
}
}
}
265 changes: 223 additions & 42 deletions RestGriffonPlugin.groovy

Large diffs are not rendered by default.

5 changes: 4 additions & 1 deletion application.properties
@@ -1,2 +1,5 @@
app.griffon.version=0.9.5-rc2
#Griffon Metadata file
#Mon Dec 03 11:16:52 CET 2012
app.griffon.version=1.2.0-SNAPSHOT
app.name=rest
plugins.lombok=0.4
22 changes: 22 additions & 0 deletions griffon-app/conf/BuildConfig.groovy
Expand Up @@ -21,6 +21,28 @@ griffon.project.dependency.resolution = {
'xerces:xercesImpl:2.9.1') {
excludes 'commons-logging'
}

build('org.eclipse.jdt:org.eclipse.jdt.core:3.6.0.v_A58') {
export = false
}
String lombokIdea = '0.5'
build("de.plushnikov.lombok-intellij-plugin:processor-api:$lombokIdea",
"de.plushnikov.lombok-intellij-plugin:processor-core:$lombokIdea",
"de.plushnikov.lombok-intellij-plugin:intellij-facade-factory:$lombokIdea",
"de.plushnikov.lombok-intellij-plugin:intellij-facade-api:$lombokIdea",
"de.plushnikov.lombok-intellij-plugin:intellij-facade-9:$lombokIdea",
"de.plushnikov.lombok-intellij-plugin:intellij-facade-10:$lombokIdea",
"de.plushnikov.lombok-intellij-plugin:intellij-facade-11:$lombokIdea") {
export = false
transitive = false
}
String ideaVersion = '11.1.4'
build("org.jetbrains.idea:idea-openapi:$ideaVersion",
"org.jetbrains.idea:extensions:$ideaVersion",
"org.jetbrains.idea:util:$ideaVersion",
"org.jetbrains.idea:annotations:$ideaVersion") {
export = false
}
}
}

Expand Down
@@ -0,0 +1 @@
lombok.intellij.processor.clazz.RestAwareProcessor
@@ -0,0 +1 @@
lombok.intellij.processor.clazz.RestAwareProcessor
@@ -0,0 +1 @@
lombok.eclipse.handlers.HandleRestAware
@@ -0,0 +1 @@
lombok.javac.handlers.HandleRestAware
26 changes: 26 additions & 0 deletions src/cli/dsld/rest.dsld
@@ -0,0 +1,26 @@
/*
* Copyright 2012 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package dsld

/**
* @author Andres Almiray
*/

contribute(enclosingClass(annotatedBy('griffon.plugins.rest.RestAware'))) {
provider = "Rest DSL"
delegatesTo "griffon.plugins.rest.RestContributionHandler"
}
26 changes: 26 additions & 0 deletions src/cli/gdsl/rest.gdsl
@@ -0,0 +1,26 @@
/*
* Copyright 2012 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package gdsl

/**
* @author Andres Almiray
*/

contributor(scope: annotatedScope(ctype: 'griffon.plugins.rest.RestAware')) {
delegatesTo(findClass('griffon.plugins.rest.RestContributionHandler'))
}

36 changes: 36 additions & 0 deletions src/cli/griffon/plugins/rest/RestAware.java
@@ -0,0 +1,36 @@
/*
* Copyright 2012 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License")
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package griffon.plugins.rest;

import org.codehaus.groovy.transform.GroovyASTTransformationClass;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

/**
* <p>Annotates a class.</p>
*
* @author Andres Almiray
* @see org.codehaus.griffon.ast.RestAwareASTTransformation
*/
@Retention(RetentionPolicy.SOURCE)
@Target(ElementType.TYPE)
@GroovyASTTransformationClass("org.codehaus.griffon.ast.RestAwareASTTransformation")
public @interface RestAware {
}
91 changes: 91 additions & 0 deletions src/cli/lombok/core/handlers/RestAwareConstants.java
@@ -0,0 +1,91 @@
/*
* Copyright 2012 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package lombok.core.handlers;

import lombok.core.BaseConstants;
import lombok.core.util.MethodDescriptor;

import static lombok.core.util.MethodDescriptor.args;
import static lombok.core.util.MethodDescriptor.type;
import static lombok.core.util.MethodDescriptor.typeParams;

/**
* @author Andres Almiray
*/
public interface RestAwareConstants extends BaseConstants {
String REST_PROVIDER_TYPE = "griffon.plugins.rest.RestProvider";
String DEFAULT_REST_PROVIDER_TYPE = "griffon.plugins.rest.DefaultRestProvider";
String REST_CONTRIBUTION_HANDLER_TYPE = "griffon.plugins.rest.RestContributionHandler";
String REST_PROVIDER_FIELD_NAME = "this$restProvider";
String METHOD_GET_REST_PROVIDER = "getRestProvider";
String METHOD_SET_REST_PROVIDER = "setRestProvider";
String METHOD_WITH_ASYNC_HTTP = "withAsyncHttp";
String METHOD_WITH_REST = "withRest";
String METHOD_WITH_HTTP = "withHttp";
String PROVIDER = "provider";

MethodDescriptor[] METHODS = new MethodDescriptor[]{
MethodDescriptor.method(
type(R),
typeParams(R),
METHOD_WITH_HTTP,
args(
type(JAVA_UTIL_MAP, JAVA_LANG_STRING, JAVA_LANG_OBJECT),
type(GROOVY_LANG_CLOSURE, R))
),
MethodDescriptor.method(
type(R),
typeParams(R),
METHOD_WITH_REST,
args(
type(JAVA_UTIL_MAP, JAVA_LANG_STRING, JAVA_LANG_OBJECT),
type(GROOVY_LANG_CLOSURE, R))
),
MethodDescriptor.method(
type(R),
typeParams(R),
METHOD_WITH_ASYNC_HTTP,
args(
type(JAVA_UTIL_MAP, JAVA_LANG_STRING, JAVA_LANG_OBJECT),
type(GROOVY_LANG_CLOSURE, R))
),
MethodDescriptor.method(
type(R),
typeParams(R),
METHOD_WITH_HTTP,
args(
type(JAVA_UTIL_MAP, JAVA_LANG_STRING, JAVA_LANG_OBJECT),
type(GRIFFON_UTIL_CALLABLEWITHARGS, R))
),
MethodDescriptor.method(
type(R),
typeParams(R),
METHOD_WITH_REST,
args(
type(JAVA_UTIL_MAP, JAVA_LANG_STRING, JAVA_LANG_OBJECT),
type(GRIFFON_UTIL_CALLABLEWITHARGS, R))
),
MethodDescriptor.method(
type(R),
typeParams(R),
METHOD_WITH_ASYNC_HTTP,
args(
type(JAVA_UTIL_MAP, JAVA_LANG_STRING, JAVA_LANG_OBJECT),
type(GRIFFON_UTIL_CALLABLEWITHARGS, R))
)
};
}
60 changes: 60 additions & 0 deletions src/cli/lombok/core/handlers/RestAwareHandler.java
@@ -0,0 +1,60 @@
/*
* Copyright 2012 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package lombok.core.handlers;

import lombok.ast.Expression;
import lombok.ast.IMethod;
import lombok.ast.IType;

import static lombok.ast.AST.*;

/**
* @author Andres Almiray
*/
public abstract class RestAwareHandler<TYPE_TYPE extends IType<? extends IMethod<?, ?, ?, ?>, ?, ?, ?, ?, ?>> extends AbstractHandler<TYPE_TYPE> implements RestAwareConstants {
private Expression<?> defaultRestProviderInstance() {
return Call(Name(DEFAULT_REST_PROVIDER_TYPE), "getInstance");
}

public void addRestProviderField(final TYPE_TYPE type) {
addField(type, REST_PROVIDER_TYPE, REST_PROVIDER_FIELD_NAME, defaultRestProviderInstance());
}

public void addRestProviderAccessors(final TYPE_TYPE type) {
type.editor().injectMethod(
MethodDecl(Type(VOID), METHOD_SET_REST_PROVIDER)
.makePublic()
.withArgument(Arg(Type(REST_PROVIDER_TYPE), PROVIDER))
.withStatement(
If(Equal(Name(PROVIDER), Null()))
.Then(Block()
.withStatement(Assign(Field(REST_PROVIDER_FIELD_NAME), defaultRestProviderInstance())))
.Else(Block()
.withStatement(Assign(Field(REST_PROVIDER_FIELD_NAME), Name(PROVIDER)))))
);

type.editor().injectMethod(
MethodDecl(Type(REST_PROVIDER_TYPE), METHOD_GET_REST_PROVIDER)
.makePublic()
.withStatement(Return(Field(REST_PROVIDER_FIELD_NAME)))
);
}

public void addRestContributionMethods(final TYPE_TYPE type) {
delegateMethodsTo(type, METHODS, Field(REST_PROVIDER_FIELD_NAME));
}
}
53 changes: 53 additions & 0 deletions src/cli/lombok/eclipse/handlers/HandleRestAware.java
@@ -0,0 +1,53 @@
/*
* Copyright 2012 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package lombok.eclipse.handlers;

import griffon.plugins.rest.RestAware;
import lombok.core.AnnotationValues;
import lombok.core.handlers.RestAwareConstants;
import lombok.core.handlers.RestAwareHandler;
import lombok.eclipse.EclipseAnnotationHandler;
import lombok.eclipse.EclipseNode;
import lombok.eclipse.handlers.ast.EclipseType;
import org.eclipse.jdt.internal.compiler.ast.Annotation;

import static lombok.core.util.ErrorMessages.canBeUsedOnClassAndEnumOnly;

/**
* @author Andres Almiray
*/
public class HandleRestAware extends EclipseAnnotationHandler<RestAware> {
private final EclipseRestAwareHandler handler = new EclipseRestAwareHandler();

@Override
public void handle(AnnotationValues<RestAware> annotation, Annotation source, EclipseNode annotationNode) {
EclipseType type = EclipseType.typeOf(annotationNode, source);
if (type.isAnnotation() || type.isInterface()) {
annotationNode.addError(canBeUsedOnClassAndEnumOnly(RestAware.class));
return;
}

EclipseUtil.addInterface(type.get(), RestAwareConstants.REST_CONTRIBUTION_HANDLER_TYPE, source);
handler.addRestProviderField(type);
handler.addRestProviderAccessors(type);
handler.addRestContributionMethods(type);
type.editor().rebuild();
}

private static class EclipseRestAwareHandler extends RestAwareHandler<EclipseType> {
}
}

0 comments on commit dcce687

Please sign in to comment.