org.codehaus.groovy.antlr.java.Groovifier Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of groovy-all-minimal Show documentation
Show all versions of groovy-all-minimal Show documentation
Groovy: A powerful, dynamic language for the JVM
/*
* Copyright 2003-2007 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 org.codehaus.groovy.antlr.java;
import org.codehaus.groovy.antlr.GroovySourceAST;
import org.codehaus.groovy.antlr.parser.GroovyTokenTypes;
import org.codehaus.groovy.antlr.treewalker.VisitorAdapter;
public class Groovifier extends VisitorAdapter implements GroovyTokenTypes {
private String[] tokenNames;
public Groovifier(String[] tokenNames) {
this.tokenNames = tokenNames;
}
public void visitDefault(GroovySourceAST t,int visit) {
if (visit == OPENING_VISIT) {
// only want to do this once per node...
// remove 'public' when implied already
if (t.getType() == LITERAL_public) {
t.setType(EXPR);
}
// constructors are not distinguished from methods in java ast
if (t.getType() == METHOD_DEF) {
String methodName = t.childOfType(IDENT).getText();
if (methodName != null && methodName.length() > 0) {
if (Character.isUpperCase(methodName.charAt(0))) { // todo - replace naive uppercase check for constructors with check for current classname
t.setType(CTOR_IDENT);
}
}
}
/* if (t.getType() == MODIFIERS) {
GroovySourceAST publicNode = t.childOfType(LITERAL_public);
if (t.getNumberOfChildren() > 1 && publicNode != null) {
// has more than one modifier, and one of them is public
// delete 'public' node
publicNode.setType(EXPR); // near enough the same as delete for now...
}
}*/
// ----
}
}
}