Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* Copyright 2003-2009 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 groovy.grape;
import groovy.lang.Grab;
import groovy.lang.Grapes;
import org.codehaus.groovy.ast.*;
import org.codehaus.groovy.ast.expr.*;
import org.codehaus.groovy.ast.stmt.ExpressionStatement;
import org.codehaus.groovy.control.CompilePhase;
import org.codehaus.groovy.control.SourceUnit;
import org.codehaus.groovy.transform.ASTTransformation;
import org.codehaus.groovy.transform.GroovyASTTransformation;
import java.util.*;
/**
* Created by IntelliJ IDEA.
* User: Danno
* Date: Jan 18, 2008
* Time: 9:48:57 PM
*/
@GroovyASTTransformation(phase=CompilePhase.CONVERSION)
public class GrabAnnotationTransformation extends ClassCodeVisitorSupport implements ASTTransformation {
private static final String GRAB_CLASS_NAME = Grab.class.getName();
private static final String GRAB_DOT_NAME = GRAB_CLASS_NAME.substring(GRAB_CLASS_NAME.lastIndexOf("."));
private static final String GRAB_SHORT_NAME = GRAB_DOT_NAME.substring(1);
private static final String GRAPES_CLASS_NAME = Grapes.class.getName();
private static final String GRAPES_DOT_NAME = GRAPES_CLASS_NAME.substring(GRAPES_CLASS_NAME.lastIndexOf("."));
private static final String GRAPES_SHORT_NAME = GRAPES_DOT_NAME.substring(1);
boolean allowShortGrab;
Set grabAliases;
List grabAnnotations;
boolean allowShortGrapes;
Set grapesAliases;
List grapesAnnotations;
SourceUnit sourceUnit;
public SourceUnit getSourceUnit() {
return sourceUnit;
}
public void visit(ASTNode[] nodes, SourceUnit source) {
sourceUnit = source;
ModuleNode mn = (ModuleNode) nodes[0];
allowShortGrab = true;
allowShortGrapes = true;
grabAliases = new HashSet();
grapesAliases = new HashSet();
for (ImportNode im : (Collection) mn.getImports()) {
String alias = im.getAlias();
String className = im.getClassName();
if ((className.endsWith(GRAB_DOT_NAME) && ((alias == null) || (alias.length() == 0)))
|| (GRAB_CLASS_NAME.equals(alias)))
{
allowShortGrab = false;
} else if (GRAB_CLASS_NAME.equals(className)) {
grabAliases.add(im.getAlias());
}
if ((className.endsWith(GRAPES_DOT_NAME) && ((alias == null) || (alias.length() == 0)))
|| (GRAPES_CLASS_NAME.equals(alias)))
{
allowShortGrapes = false;
} else if (GRAPES_CLASS_NAME.equals(className)) {
grapesAliases.add(im.getAlias());
}
}
List