You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by su...@apache.org on 2017/12/20 00:56:43 UTC
[46/49] groovy git commit: Move source files to proper packages
http://git-wip-us.apache.org/repos/asf/groovy/blob/10110145/src/main/groovy/beans/PropertyAccessor.java
----------------------------------------------------------------------
diff --git a/src/main/groovy/beans/PropertyAccessor.java b/src/main/groovy/beans/PropertyAccessor.java
deleted file mode 100644
index 822ab10..0000000
--- a/src/main/groovy/beans/PropertyAccessor.java
+++ /dev/null
@@ -1,25 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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.beans;
-
-/**
- * @author Andres Almiray
- */
-public interface PropertyAccessor extends PropertyReader, PropertyWriter {
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/groovy/blob/10110145/src/main/groovy/beans/PropertyReader.java
----------------------------------------------------------------------
diff --git a/src/main/groovy/beans/PropertyReader.java b/src/main/groovy/beans/PropertyReader.java
deleted file mode 100644
index 4ef13af..0000000
--- a/src/main/groovy/beans/PropertyReader.java
+++ /dev/null
@@ -1,26 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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.beans;
-
-/**
- * @author Andres Almiray
- */
-public interface PropertyReader {
- Object read(Object owner, String propertyName);
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/groovy/blob/10110145/src/main/groovy/beans/PropertyWriter.java
----------------------------------------------------------------------
diff --git a/src/main/groovy/beans/PropertyWriter.java b/src/main/groovy/beans/PropertyWriter.java
deleted file mode 100644
index 5b9e1ce..0000000
--- a/src/main/groovy/beans/PropertyWriter.java
+++ /dev/null
@@ -1,26 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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.beans;
-
-/**
- * @author Andres Almiray
- */
-public interface PropertyWriter {
- void write(Object owner, String propertyName, Object value);
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/groovy/blob/10110145/src/main/groovy/beans/Vetoable.java
----------------------------------------------------------------------
diff --git a/src/main/groovy/beans/Vetoable.java b/src/main/groovy/beans/Vetoable.java
deleted file mode 100644
index 5b40e1a..0000000
--- a/src/main/groovy/beans/Vetoable.java
+++ /dev/null
@@ -1,113 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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.beans;
-
-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;
-
-/**
- * Annotates a groovy property or a class.
- * <p>
- * When annotating a property it indicates that the property should be a
- * constrained property according to the JavaBeans spec, subject to
- * listeners vetoing the property change.
- * <p>
- * When annotating a class it indicates that all groovy properties in that
- * class should be bound as though each property had the annotation (even
- * if it already has it explicitly).
- * <p>
- * It is a compilation error to place this annotation on a field (that is
- * not a property, i.e. has scope visibility modifiers).
- * <p>
- * If a property with a user defined setter method is annotated the code
- * block is wrapped with the needed code to fire off the event.
- * <p>
- * Here is a simple example of how to annotate a class with Vetoable:
- * <pre>
- * @groovy.beans.Vetoable
- * class Person {
- * String firstName
- * def zipCode
- * }
- * </pre>
- * This code is transformed by the compiler into something resembling the following
- * snippet. Notice the difference between a String and a def/Object property:
- * <pre>
- * public class Person implements groovy.lang.GroovyObject {
- * private java.lang.String firstName
- * private java.lang.Object zipCode
- * final private java.beans.VetoableChangeSupport this$vetoableChangeSupport
- *
- * public Person() {
- * this$vetoableChangeSupport = new java.beans.VetoableChangeSupport(this)
- * }
- *
- * public void addVetoableChangeListener(java.beans.VetoableChangeListener listener) {
- * this$vetoableChangeSupport.addVetoableChangeListener(listener)
- * }
- *
- * public void addVetoableChangeListener(java.lang.String name, java.beans.VetoableChangeListener listener) {
- * this$vetoableChangeSupport.addVetoableChangeListener(name, listener)
- * }
- *
- * public void removeVetoableChangeListener(java.beans.VetoableChangeListener listener) {
- * this$vetoableChangeSupport.removeVetoableChangeListener(listener)
- * }
- *
- * public void removeVetoableChangeListener(java.lang.String name, java.beans.VetoableChangeListener listener) {
- * this$vetoableChangeSupport.removeVetoableChangeListener(name, listener)
- * }
- *
- * public void fireVetoableChange(java.lang.String name, java.lang.Object oldValue, java.lang.Object newValue) throws java.beans.PropertyVetoException {
- * this$vetoableChangeSupport.fireVetoableChange(name, oldValue, newValue)
- * }
- *
- * public java.beans.VetoableChangeListener[] getVetoableChangeListeners() {
- * return this$vetoableChangeSupport.getVetoableChangeListeners()
- * }
- *
- * public java.beans.VetoableChangeListener[] getVetoableChangeListeners(java.lang.String name) {
- * return this$vetoableChangeSupport.getVetoableChangeListeners(name)
- * }
- *
- * public void setFirstName(java.lang.String value) throws java.beans.PropertyVetoException {
- * this.fireVetoableChange('firstName', firstName, value)
- * firstName = value
- * }
- *
- * public void setZipCode(java.lang.Object value) throws java.beans.PropertyVetoException {
- * this.fireVetoableChange('zipCode', zipCode, value)
- * zipCode = value
- * }
- * }
- * </pre>
- *
- * @see VetoableASTTransformation
- * @author Danno Ferrin (shemnon)
- */
-@java.lang.annotation.Documented
-@Retention(RetentionPolicy.SOURCE)
-@Target({ElementType.FIELD, ElementType.TYPE})
-@GroovyASTTransformationClass("groovy.beans.VetoableASTTransformation")
-public @interface Vetoable {
-}
http://git-wip-us.apache.org/repos/asf/groovy/blob/10110145/src/main/groovy/beans/VetoableASTTransformation.java
----------------------------------------------------------------------
diff --git a/src/main/groovy/beans/VetoableASTTransformation.java b/src/main/groovy/beans/VetoableASTTransformation.java
deleted file mode 100644
index 17535ca..0000000
--- a/src/main/groovy/beans/VetoableASTTransformation.java
+++ /dev/null
@@ -1,444 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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.beans;
-
-import org.codehaus.groovy.ast.ASTNode;
-import org.codehaus.groovy.ast.AnnotatedNode;
-import org.codehaus.groovy.ast.AnnotationNode;
-import org.codehaus.groovy.ast.ClassHelper;
-import org.codehaus.groovy.ast.ClassNode;
-import org.codehaus.groovy.ast.FieldNode;
-import org.codehaus.groovy.ast.MethodNode;
-import org.codehaus.groovy.ast.Parameter;
-import org.codehaus.groovy.ast.PropertyNode;
-import org.codehaus.groovy.ast.expr.Expression;
-import org.codehaus.groovy.ast.stmt.BlockStatement;
-import org.codehaus.groovy.ast.stmt.Statement;
-import org.codehaus.groovy.ast.tools.PropertyNodeUtils;
-import org.codehaus.groovy.control.CompilePhase;
-import org.codehaus.groovy.control.SourceUnit;
-import org.codehaus.groovy.control.messages.SimpleMessage;
-import org.codehaus.groovy.control.messages.SyntaxErrorMessage;
-import org.codehaus.groovy.runtime.MetaClassHelper;
-import org.codehaus.groovy.syntax.SyntaxException;
-import org.codehaus.groovy.transform.GroovyASTTransformation;
-import org.objectweb.asm.Opcodes;
-
-import java.beans.PropertyVetoException;
-import java.beans.VetoableChangeListener;
-import java.beans.VetoableChangeSupport;
-
-import static org.codehaus.groovy.ast.tools.GeneralUtils.args;
-import static org.codehaus.groovy.ast.tools.GeneralUtils.assignS;
-import static org.codehaus.groovy.ast.tools.GeneralUtils.callThisX;
-import static org.codehaus.groovy.ast.tools.GeneralUtils.callX;
-import static org.codehaus.groovy.ast.tools.GeneralUtils.constX;
-import static org.codehaus.groovy.ast.tools.GeneralUtils.ctorX;
-import static org.codehaus.groovy.ast.tools.GeneralUtils.declS;
-import static org.codehaus.groovy.ast.tools.GeneralUtils.fieldX;
-import static org.codehaus.groovy.ast.tools.GeneralUtils.param;
-import static org.codehaus.groovy.ast.tools.GeneralUtils.params;
-import static org.codehaus.groovy.ast.tools.GeneralUtils.returnS;
-import static org.codehaus.groovy.ast.tools.GeneralUtils.stmt;
-import static org.codehaus.groovy.ast.tools.GeneralUtils.varX;
-
-/**
- * Handles generation of code for the {@code @Vetoable} annotation, and {@code @Bindable}
- * if also present.
- * <p>
- * Generally, it adds (if needed) a VetoableChangeSupport field and
- * the needed add/removeVetoableChangeListener methods to support the
- * listeners.
- * <p>
- * It also generates the setter and wires the setter through the
- * VetoableChangeSupport.
- * <p>
- * If a {@link Bindable} annotation is detected it also adds support similar
- * to what {@link BindableASTTransformation} would do.
- *
- * @author Danno Ferrin (shemnon)
- * @author Chris Reeves
- */
-@GroovyASTTransformation(phase = CompilePhase.CANONICALIZATION)
-public class VetoableASTTransformation extends BindableASTTransformation {
-
- protected static final ClassNode constrainedClassNode = ClassHelper.make(Vetoable.class);
-
- /**
- * Convenience method to see if an annotated node is {@code @Vetoable}.
- *
- * @param node the node to check
- * @return true if the node is constrained
- */
- public static boolean hasVetoableAnnotation(AnnotatedNode node) {
- for (AnnotationNode annotation : node.getAnnotations()) {
- if (constrainedClassNode.equals(annotation.getClassNode())) {
- return true;
- }
- }
- return false;
- }
-
- /**
- * Handles the bulk of the processing, mostly delegating to other methods.
- *
- * @param nodes the AST nodes
- * @param source the source unit for the nodes
- */
- public void visit(ASTNode[] nodes, SourceUnit source) {
- if (!(nodes[0] instanceof AnnotationNode) || !(nodes[1] instanceof AnnotatedNode)) {
- throw new RuntimeException("Internal error: wrong types: $node.class / $parent.class");
- }
- AnnotationNode node = (AnnotationNode) nodes[0];
-
- if (nodes[1] instanceof ClassNode) {
- addListenerToClass(source, (ClassNode) nodes[1]);
- } else {
- if ((((FieldNode)nodes[1]).getModifiers() & Opcodes.ACC_FINAL) != 0) {
- source.getErrorCollector().addErrorAndContinue(new SyntaxErrorMessage(
- new SyntaxException("@groovy.beans.Vetoable cannot annotate a final property.",
- node.getLineNumber(), node.getColumnNumber(), node.getLastLineNumber(), node.getLastColumnNumber()),
- source));
- }
-
- addListenerToProperty(source, node, (AnnotatedNode) nodes[1]);
- }
- }
-
- private void addListenerToProperty(SourceUnit source, AnnotationNode node, AnnotatedNode parent) {
- ClassNode declaringClass = parent.getDeclaringClass();
- FieldNode field = ((FieldNode) parent);
- String fieldName = field.getName();
- for (PropertyNode propertyNode : declaringClass.getProperties()) {
- boolean bindable = BindableASTTransformation.hasBindableAnnotation(parent)
- || BindableASTTransformation.hasBindableAnnotation(parent.getDeclaringClass());
-
- if (propertyNode.getName().equals(fieldName)) {
- if (field.isStatic()) {
- //noinspection ThrowableInstanceNeverThrown
- source.getErrorCollector().addErrorAndContinue(new SyntaxErrorMessage(
- new SyntaxException("@groovy.beans.Vetoable cannot annotate a static property.",
- node.getLineNumber(), node.getColumnNumber(), node.getLastLineNumber(), node.getLastColumnNumber()),
- source));
- } else {
- createListenerSetter(source, bindable, declaringClass, propertyNode);
- }
- return;
- }
- }
- //noinspection ThrowableInstanceNeverThrown
- source.getErrorCollector().addErrorAndContinue(new SyntaxErrorMessage(
- new SyntaxException("@groovy.beans.Vetoable must be on a property, not a field. Try removing the private, protected, or public modifier.",
- node.getLineNumber(), node.getColumnNumber(), node.getLastLineNumber(), node.getLastColumnNumber()),
- source));
- }
-
-
- private void addListenerToClass(SourceUnit source, ClassNode classNode) {
- boolean bindable = BindableASTTransformation.hasBindableAnnotation(classNode);
- for (PropertyNode propertyNode : classNode.getProperties()) {
- if (!hasVetoableAnnotation(propertyNode.getField())
- && !propertyNode.getField().isFinal()
- && !propertyNode.getField().isStatic())
- {
- createListenerSetter(source,
- bindable || BindableASTTransformation.hasBindableAnnotation(propertyNode.getField()),
- classNode, propertyNode);
- }
- }
- }
-
- /**
- * Wrap an existing setter.
- */
- private static void wrapSetterMethod(ClassNode classNode, boolean bindable, String propertyName) {
- String getterName = "get" + MetaClassHelper.capitalize(propertyName);
- MethodNode setter = classNode.getSetterMethod("set" + MetaClassHelper.capitalize(propertyName));
-
- if (setter != null) {
- // Get the existing code block
- Statement code = setter.getCode();
-
- Expression oldValue = varX("$oldValue");
- Expression newValue = varX("$newValue");
- Expression proposedValue = varX(setter.getParameters()[0].getName());
- BlockStatement block = new BlockStatement();
-
- // create a local variable to hold the old value from the getter
- block.addStatement(declS(oldValue, callThisX(getterName)));
-
- // add the fireVetoableChange method call
- block.addStatement(stmt(callThisX("fireVetoableChange", args(
- constX(propertyName), oldValue, proposedValue))));
-
- // call the existing block, which will presumably set the value properly
- block.addStatement(code);
-
- if (bindable) {
- // get the new value to emit in the event
- block.addStatement(declS(newValue, callThisX(getterName)));
-
- // add the firePropertyChange method call
- block.addStatement(stmt(callThisX("firePropertyChange", args(constX(propertyName), oldValue, newValue))));
- }
-
- // replace the existing code block with our new one
- setter.setCode(block);
- }
- }
-
- private void createListenerSetter(SourceUnit source, boolean bindable, ClassNode declaringClass, PropertyNode propertyNode) {
- if (bindable && needsPropertyChangeSupport(declaringClass, source)) {
- addPropertyChangeSupport(declaringClass);
- }
- if (needsVetoableChangeSupport(declaringClass, source)) {
- addVetoableChangeSupport(declaringClass);
- }
- String setterName = "set" + MetaClassHelper.capitalize(propertyNode.getName());
- if (declaringClass.getMethods(setterName).isEmpty()) {
- Expression fieldExpression = fieldX(propertyNode.getField());
- BlockStatement setterBlock = new BlockStatement();
- setterBlock.addStatement(createConstrainedStatement(propertyNode, fieldExpression));
- if (bindable) {
- setterBlock.addStatement(createBindableStatement(propertyNode, fieldExpression));
- } else {
- setterBlock.addStatement(createSetStatement(fieldExpression));
- }
-
- // create method void <setter>(<type> fieldName)
- createSetterMethod(declaringClass, propertyNode, setterName, setterBlock);
- } else {
- wrapSetterMethod(declaringClass, bindable, propertyNode.getName());
- }
- }
-
- /**
- * Creates a statement body similar to:
- * <code>this.fireVetoableChange("field", field, field = value)</code>
- *
- * @param propertyNode the field node for the property
- * @param fieldExpression a field expression for setting the property value
- * @return the created statement
- */
- protected Statement createConstrainedStatement(PropertyNode propertyNode, Expression fieldExpression) {
- return stmt(callThisX("fireVetoableChange", args(constX(propertyNode.getName()), fieldExpression, varX("value"))));
- }
-
- /**
- * Creates a statement body similar to:
- * <code>field = value</code>.
- * <p>
- * Used when the field is not also {@code @Bindable}.
- *
- * @param fieldExpression a field expression for setting the property value
- * @return the created statement
- */
- protected Statement createSetStatement(Expression fieldExpression) {
- return assignS(fieldExpression, varX("value"));
- }
-
- /**
- * Snoops through the declaring class and all parents looking for a field
- * of type VetoableChangeSupport. Remembers the field and returns false
- * if found otherwise returns true to indicate that such support should
- * be added.
- *
- * @param declaringClass the class to search
- * @return true if vetoable change support should be added
- */
- protected boolean needsVetoableChangeSupport(ClassNode declaringClass, SourceUnit sourceUnit) {
- boolean foundAdd = false, foundRemove = false, foundFire = false;
- ClassNode consideredClass = declaringClass;
- while (consideredClass!= null) {
- for (MethodNode method : consideredClass.getMethods()) {
- // just check length, MOP will match it up
- foundAdd = foundAdd || method.getName().equals("addVetoableChangeListener") && method.getParameters().length == 1;
- foundRemove = foundRemove || method.getName().equals("removeVetoableChangeListener") && method.getParameters().length == 1;
- foundFire = foundFire || method.getName().equals("fireVetoableChange") && method.getParameters().length == 3;
- if (foundAdd && foundRemove && foundFire) {
- return false;
- }
- }
- consideredClass = consideredClass.getSuperClass();
- }
- // check if a super class has @Vetoable annotations
- consideredClass = declaringClass.getSuperClass();
- while (consideredClass!=null) {
- if (hasVetoableAnnotation(consideredClass)) return false;
- for (FieldNode field : consideredClass.getFields()) {
- if (hasVetoableAnnotation(field)) return false;
- }
- consideredClass = consideredClass.getSuperClass();
- }
- if (foundAdd || foundRemove || foundFire) {
- sourceUnit.getErrorCollector().addErrorAndContinue(
- new SimpleMessage("@Vetoable cannot be processed on "
- + declaringClass.getName()
- + " because some but not all of addVetoableChangeListener, removeVetoableChange, and fireVetoableChange were declared in the current or super classes.",
- sourceUnit)
- );
- return false;
- }
- return true;
- }
-
- /**
- * Creates a setter method with the given body.
- * <p>
- * This differs from normal setters in that we need to add a declared
- * exception java.beans.PropertyVetoException
- *
- * @param declaringClass the class to which we will add the setter
- * @param propertyNode the field to back the setter
- * @param setterName the name of the setter
- * @param setterBlock the statement representing the setter block
- */
- protected void createSetterMethod(ClassNode declaringClass, PropertyNode propertyNode, String setterName, Statement setterBlock) {
- ClassNode[] exceptions = {ClassHelper.make(PropertyVetoException.class)};
- MethodNode setter = new MethodNode(
- setterName,
- PropertyNodeUtils.adjustPropertyModifiersForMethod(propertyNode),
- ClassHelper.VOID_TYPE,
- params(param(propertyNode.getType(), "value")),
- exceptions,
- setterBlock);
- setter.setSynthetic(true);
- // add it to the class
- declaringClass.addMethod(setter);
- }
-
- /**
- * Adds the necessary field and methods to support vetoable change support.
- * <p>
- * Adds a new field:
- * <code>"protected final java.beans.VetoableChangeSupport this$vetoableChangeSupport = new java.beans.VetoableChangeSupport(this)"</code>
- * <p>
- * Also adds support methods:
- * <code>public void addVetoableChangeListener(java.beans.VetoableChangeListener)</code>
- * <code>public void addVetoableChangeListener(String, java.beans.VetoableChangeListener)</code>
- * <code>public void removeVetoableChangeListener(java.beans.VetoableChangeListener)</code>
- * <code>public void removeVetoableChangeListener(String, java.beans.VetoableChangeListener)</code>
- * <code>public java.beans.VetoableChangeListener[] getVetoableChangeListeners()</code>
- *
- * @param declaringClass the class to which we add the support field and methods
- */
- protected void addVetoableChangeSupport(ClassNode declaringClass) {
- ClassNode vcsClassNode = ClassHelper.make(VetoableChangeSupport.class);
- ClassNode vclClassNode = ClassHelper.make(VetoableChangeListener.class);
-
- // add field:
- // protected static VetoableChangeSupport this$vetoableChangeSupport = new java.beans.VetoableChangeSupport(this)
- FieldNode vcsField = declaringClass.addField(
- "this$vetoableChangeSupport",
- ACC_FINAL | ACC_PRIVATE | ACC_SYNTHETIC,
- vcsClassNode,
- ctorX(vcsClassNode, args(varX("this"))));
-
- // add method:
- // void addVetoableChangeListener(listener) {
- // this$vetoableChangeSupport.addVetoableChangeListener(listener)
- // }
- declaringClass.addMethod(
- new MethodNode(
- "addVetoableChangeListener",
- ACC_PUBLIC,
- ClassHelper.VOID_TYPE,
- params(param(vclClassNode, "listener")),
- ClassNode.EMPTY_ARRAY,
- stmt(callX(fieldX(vcsField), "addVetoableChangeListener", args(varX("listener", vclClassNode))))));
-
- // add method:
- // void addVetoableChangeListener(name, listener) {
- // this$vetoableChangeSupport.addVetoableChangeListener(name, listener)
- // }
- declaringClass.addMethod(
- new MethodNode(
- "addVetoableChangeListener",
- ACC_PUBLIC,
- ClassHelper.VOID_TYPE,
- params(param(ClassHelper.STRING_TYPE, "name"), param(vclClassNode, "listener")),
- ClassNode.EMPTY_ARRAY,
- stmt(callX(fieldX(vcsField), "addVetoableChangeListener", args(varX("name", ClassHelper.STRING_TYPE), varX("listener", vclClassNode))))));
-
- // add method:
- // boolean removeVetoableChangeListener(listener) {
- // return this$vetoableChangeSupport.removeVetoableChangeListener(listener);
- // }
- declaringClass.addMethod(
- new MethodNode(
- "removeVetoableChangeListener",
- ACC_PUBLIC,
- ClassHelper.VOID_TYPE,
- params(param(vclClassNode, "listener")),
- ClassNode.EMPTY_ARRAY,
- stmt(callX(fieldX(vcsField), "removeVetoableChangeListener", args(varX("listener", vclClassNode))))));
-
- // add method: void removeVetoableChangeListener(name, listener)
- declaringClass.addMethod(
- new MethodNode(
- "removeVetoableChangeListener",
- ACC_PUBLIC,
- ClassHelper.VOID_TYPE,
- params(param(ClassHelper.STRING_TYPE, "name"), param(vclClassNode, "listener")),
- ClassNode.EMPTY_ARRAY,
- stmt(callX(fieldX(vcsField), "removeVetoableChangeListener", args(varX("name", ClassHelper.STRING_TYPE), varX("listener", vclClassNode))))));
-
- // add method:
- // void fireVetoableChange(String name, Object oldValue, Object newValue)
- // throws PropertyVetoException
- // {
- // this$vetoableChangeSupport.fireVetoableChange(name, oldValue, newValue)
- // }
- declaringClass.addMethod(
- new MethodNode(
- "fireVetoableChange",
- ACC_PUBLIC,
- ClassHelper.VOID_TYPE,
- params(param(ClassHelper.STRING_TYPE, "name"), param(ClassHelper.OBJECT_TYPE, "oldValue"), param(ClassHelper.OBJECT_TYPE, "newValue")),
- new ClassNode[] {ClassHelper.make(PropertyVetoException.class)},
- stmt(callX(fieldX(vcsField), "fireVetoableChange", args(varX("name", ClassHelper.STRING_TYPE), varX("oldValue"), varX("newValue"))))));
-
- // add method:
- // VetoableChangeListener[] getVetoableChangeListeners() {
- // return this$vetoableChangeSupport.getVetoableChangeListeners
- // }
- declaringClass.addMethod(
- new MethodNode(
- "getVetoableChangeListeners",
- ACC_PUBLIC,
- vclClassNode.makeArray(),
- Parameter.EMPTY_ARRAY,
- ClassNode.EMPTY_ARRAY,
- returnS(callX(fieldX(vcsField), "getVetoableChangeListeners"))));
-
- // add method:
- // VetoableChangeListener[] getVetoableChangeListeners(String name) {
- // return this$vetoableChangeSupport.getVetoableChangeListeners(name)
- // }
- declaringClass.addMethod(
- new MethodNode(
- "getVetoableChangeListeners",
- ACC_PUBLIC,
- vclClassNode.makeArray(),
- params(param(ClassHelper.STRING_TYPE, "name")),
- ClassNode.EMPTY_ARRAY,
- returnS(callX(fieldX(vcsField), "getVetoableChangeListeners", args(varX("name", ClassHelper.STRING_TYPE))))));
- }
-
-}
http://git-wip-us.apache.org/repos/asf/groovy/blob/10110145/src/main/groovy/cli/CliBuilderException.groovy
----------------------------------------------------------------------
diff --git a/src/main/groovy/cli/CliBuilderException.groovy b/src/main/groovy/cli/CliBuilderException.groovy
deleted file mode 100644
index 84a9438..0000000
--- a/src/main/groovy/cli/CliBuilderException.groovy
+++ /dev/null
@@ -1,24 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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.cli
-
-import groovy.transform.InheritConstructors
-
-@InheritConstructors
-class CliBuilderException extends RuntimeException { }
http://git-wip-us.apache.org/repos/asf/groovy/blob/10110145/src/main/groovy/cli/Option.java
----------------------------------------------------------------------
diff --git a/src/main/groovy/cli/Option.java b/src/main/groovy/cli/Option.java
deleted file mode 100644
index 9b48861..0000000
--- a/src/main/groovy/cli/Option.java
+++ /dev/null
@@ -1,105 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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.cli;
-
-import groovy.transform.Undefined;
-
-import java.lang.annotation.ElementType;
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-import java.lang.annotation.Target;
-
-/**
- * Indicates that a method or property can be used to set a CLI option.
- */
-@java.lang.annotation.Documented
-@Retention(RetentionPolicy.RUNTIME)
-@Target({ElementType.METHOD, ElementType.FIELD})
-public @interface Option {
- /**
- * The description of this option
- *
- * @return the description of this option
- */
- String description() default "";
-
- /**
- * The short name of this option. Defaults to the name of member being annotated if the longName is empty.
- *
- * @return the short name of this option
- */
- String shortName() default "";
-
- /**
- * The long name of this option. Defaults to the name of member being annotated.
- *
- * @return the long name of this option
- */
- String longName() default "";
-
- /**
- * The value separator for this multi-valued option. Only allowed for array-typed arguments.
- *
- * @return the value separator for this multi-valued option
- */
- String valueSeparator() default "";
-
- /**
- * Whether this option can have an optional argument.
- * Only supported for array-typed arguments to indicate that the array may be empty.
- *
- * @return true if this array-typed option can have an optional argument (i.e. could be empty)
- */
- boolean optionalArg() default false;
-
- /**
- * How many arguments this option has.
- * A value greater than 1 is only allowed for array-typed arguments.
- * Ignored for boolean options which are assumed to have a default of 0
- * or if {@code numberOfArgumentsString} is set.
- *
- * @return the number of arguments
- */
- int numberOfArguments() default 1;
-
- /**
- * How many arguments this option has represented as a String.
- * Only allowed for array-typed arguments.
- * Overrides {@code numberOfArguments} if set.
- * The special values of '+' means one or more and '*' as 0 or more.
- *
- * @return the number of arguments (as a String)
- */
- String numberOfArgumentsString() default "";
-
- /**
- * The default value for this option as a String; subject to type conversion and 'convert'.
- * Ignored for Boolean options.
- *
- * @return the default value for this option
- */
- String defaultValue() default "";
-
- /**
- * A conversion closure to convert the incoming String into the desired object
- *
- * @return the closure to convert this option's argument(s)
- */
- Class convert() default Undefined.CLASS.class;
-}
http://git-wip-us.apache.org/repos/asf/groovy/blob/10110145/src/main/groovy/cli/OptionField.groovy
----------------------------------------------------------------------
diff --git a/src/main/groovy/cli/OptionField.groovy b/src/main/groovy/cli/OptionField.groovy
deleted file mode 100644
index 69cc1f5..0000000
--- a/src/main/groovy/cli/OptionField.groovy
+++ /dev/null
@@ -1,27 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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.cli
-
-import groovy.transform.AnnotationCollector
-import groovy.transform.Field
-
-@Option
-@Field
-@AnnotationCollector
-@interface OptionField { }
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/groovy/blob/10110145/src/main/groovy/cli/TypedOption.java
----------------------------------------------------------------------
diff --git a/src/main/groovy/cli/TypedOption.java b/src/main/groovy/cli/TypedOption.java
deleted file mode 100644
index e669324..0000000
--- a/src/main/groovy/cli/TypedOption.java
+++ /dev/null
@@ -1,27 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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.cli;
-
-import java.util.HashMap;
-
-public class TypedOption<T> extends HashMap<String, T> {
- public T defaultValue() {
- return (T) super.get("defaultValue");
- }
-}
http://git-wip-us.apache.org/repos/asf/groovy/blob/10110145/src/main/groovy/cli/Unparsed.java
----------------------------------------------------------------------
diff --git a/src/main/groovy/cli/Unparsed.java b/src/main/groovy/cli/Unparsed.java
deleted file mode 100644
index a741413..0000000
--- a/src/main/groovy/cli/Unparsed.java
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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.cli;
-
-import java.lang.annotation.ElementType;
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-import java.lang.annotation.Target;
-
-/**
- * Indicates that a method or property will contain the remaining arguments.
- */
-@java.lang.annotation.Documented
-@Retention(RetentionPolicy.RUNTIME)
-@Target({ElementType.METHOD, ElementType.FIELD})
-public @interface Unparsed {
- /**
- * The description for the remaining non-option arguments
- *
- * @return the description for the remaining non-option arguments
- */
- String description() default "ARGUMENTS";
-}
http://git-wip-us.apache.org/repos/asf/groovy/blob/10110145/src/main/groovy/cli/UnparsedField.groovy
----------------------------------------------------------------------
diff --git a/src/main/groovy/cli/UnparsedField.groovy b/src/main/groovy/cli/UnparsedField.groovy
deleted file mode 100644
index b185431..0000000
--- a/src/main/groovy/cli/UnparsedField.groovy
+++ /dev/null
@@ -1,27 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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.cli
-
-import groovy.transform.AnnotationCollector
-import groovy.transform.Field
-
-@Unparsed
-@Field
-@AnnotationCollector
-@interface UnparsedField { }
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/groovy/blob/10110145/src/main/groovy/genArrayAccess.groovy
----------------------------------------------------------------------
diff --git a/src/main/groovy/genArrayAccess.groovy b/src/main/groovy/genArrayAccess.groovy
deleted file mode 100644
index 08cb68a..0000000
--- a/src/main/groovy/genArrayAccess.groovy
+++ /dev/null
@@ -1,146 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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.classgen
-
-println """
-package org.codehaus.groovy.runtime.dgmimpl;
-
-import groovy.lang.MetaClassImpl;
-import groovy.lang.MetaMethod;
-import org.codehaus.groovy.runtime.callsite.CallSite;
-import org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite;
-import org.codehaus.groovy.reflection.CachedClass;
-import org.codehaus.groovy.reflection.ReflectionCache;
-
-public class ArrayOperations {
- ${genInners()}
-}
-"""
-
-def genInners () {
- def res = ""
-
- final Map primitives = [
- "boolean": "Boolean",
- "byte": "Byte",
- "char": "Character",
- "short": "Short",
- "int": "Integer",
- "long": "Long",
- "float": "Float",
- "double": "Double"
- ]
-
- primitives.each {primName, clsName ->
- res += """
- public static class ${clsName}ArrayGetAtMetaMethod extends ArrayGetAtMetaMethod {
- private static final CachedClass ARR_CLASS = ReflectionCache.getCachedClass(${primName}[].class);
-
- public Class getReturnType() {
- return ${clsName}.class;
- }
-
- public final CachedClass getDeclaringClass() {
- return ARR_CLASS;
- }
-
- public Object invoke(Object object, Object[] args) {
- final ${primName}[] objects = (${primName}[]) object;
- return objects[normaliseIndex(((Integer) args[0]).intValue(), objects.length)];
- }
-
- public CallSite createPojoCallSite(CallSite site, MetaClassImpl metaClass, MetaMethod metaMethod, Class[] params, Object receiver, Object[] args) {
- if (!(args [0] instanceof Integer))
- return PojoMetaMethodSite.createNonAwareCallSite(site, metaClass, metaMethod, params, args);
- else
- return new PojoMetaMethodSite(site, metaClass, metaMethod, params) {
- public Object invoke(Object receiver, Object[] args) {
- final ${primName}[] objects = (${primName}[]) receiver;
- return objects[normaliseIndex(((Integer) args[0]).intValue(), objects.length)];
- }
-
- public Object callBinop(Object receiver, Object arg) {
- if ((receiver instanceof ${primName}[] && arg instanceof Integer)
- && checkMetaClass()) {
- final ${primName}[] objects = (${primName}[]) receiver;
- return objects[normaliseIndex(((Integer) arg).intValue(), objects.length)];
- }
- else
- return super.callBinop(receiver,arg);
- }
-
- public Object invokeBinop(Object receiver, Object arg) {
- final ${primName}[] objects = (${primName}[]) receiver;
- return objects[normaliseIndex(((Integer) arg).intValue(), objects.length)];
- }
- };
- }
- }
-
-
- public static class ${clsName}ArrayPutAtMetaMethod extends ArrayPutAtMetaMethod {
- private static final CachedClass OBJECT_CLASS = ReflectionCache.OBJECT_CLASS;
- private static final CachedClass ARR_CLASS = ReflectionCache.getCachedClass(${primName}[].class);
- private static final CachedClass [] PARAM_CLASS_ARR = new CachedClass[] {INTEGER_CLASS, OBJECT_CLASS};
-
- public ${clsName}ArrayPutAtMetaMethod() {
- parameterTypes = PARAM_CLASS_ARR;
- }
-
- public final CachedClass getDeclaringClass() {
- return ARR_CLASS;
- }
-
- public Object invoke(Object object, Object[] args) {
- final ${primName}[] objects = (${primName}[]) object;
- final int index = normaliseIndex(((Integer) args[0]).intValue(), objects.length);
- Object newValue = args[1];
- if (!(newValue instanceof ${clsName})) {
- Number n = (Number) newValue;
- objects[index] = ((Number)newValue).${primName}Value();
- }
- else
- objects[index] = ((${clsName})args[1]).${primName}Value();
- return null;
- }
-
- public CallSite createPojoCallSite(CallSite site, MetaClassImpl metaClass, MetaMethod metaMethod, Class[] params, Object receiver, Object[] args) {
- if (!(args [0] instanceof Integer) || !(args [1] instanceof ${clsName}))
- return PojoMetaMethodSite.createNonAwareCallSite(site, metaClass, metaMethod, params, args);
- else
- return new PojoMetaMethodSite(site, metaClass, metaMethod, params) {
- public Object call(Object receiver, Object[] args) {
- if ((receiver instanceof ${primName}[] && args[0] instanceof Integer && args[1] instanceof ${clsName} )
- && checkMetaClass()) {
- final ${primName}[] objects = (${primName}[]) receiver;
- objects[normaliseIndex(((Integer) args[0]).intValue(), objects.length)] = ((${clsName})args[1]).${primName}Value();
- return null;
- }
- else
- return super.call(receiver,args);
- }
- };
- }
- }
-
- """
- }
-
- res
-}
http://git-wip-us.apache.org/repos/asf/groovy/blob/10110145/src/main/groovy/genArrays.groovy
----------------------------------------------------------------------
diff --git a/src/main/groovy/genArrays.groovy b/src/main/groovy/genArrays.groovy
deleted file mode 100644
index 9bbe3cf..0000000
--- a/src/main/groovy/genArrays.groovy
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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.classgen
-
-print """
-
-public class ArrayUtil {
- ${genMethods()}
-}
-
-"""
-
-def genMethods () {
- def res = ""
- for (i in 1..250)
- res += "\n\n" + genMethod (i)
- res
-}
-
-def genMethod (int paramNum) {
- def res = "public static Object [] createArray ("
- for (k in 0..<paramNum) {
- res += "Object arg" + k
- if (k != paramNum-1)
- res += ", "
- }
- res += ") {\n"
- res += "return new Object [] {\n"
- for (k in 0..<paramNum) {
- res += "arg" + k
- if (k != paramNum-1)
- res += ", "
- }
- res += "};\n"
- res += "}"
- res
-}
http://git-wip-us.apache.org/repos/asf/groovy/blob/10110145/src/main/groovy/genDgmMath.groovy
----------------------------------------------------------------------
diff --git a/src/main/groovy/genDgmMath.groovy b/src/main/groovy/genDgmMath.groovy
deleted file mode 100644
index 71bdd5f..0000000
--- a/src/main/groovy/genDgmMath.groovy
+++ /dev/null
@@ -1,87 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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.classgen
-
-def types = ["Integer", "Long", "Float", "Double"]
-
-def getMath (a,b) {
- if (a == "Double" || b == "Double" || a == "Float" || b == "Float")
- return "FloatingPointMath"
-
- if (a == "Long" || b == "Long")
- return "LongMath"
-
- "IntegerMath"
-}
-
-println """
-public CallSite createPojoCallSite(CallSite site, MetaClassImpl metaClass, MetaMethod metaMethod, Class[] params, Object receiver, Object[] args) {
- NumberMath m = NumberMath.getMath((Number)receiver, (Number)args[0]);
-"""
-
-types.each {
- a ->
- print """
- if (receiver instanceof $a) {"""
- types.each {
- b ->
- print """
- if (args[0] instanceof $b)
- return new NumberNumberCallSite (site, metaClass, metaMethod, params, (Number)receiver, (Number)args[0]){
- public final Object invoke(Object receiver, Object[] args) {
- return ${getMath(a,b)}.INSTANCE.addImpl(($a)receiver,($b)args[0]);
- }
-
- public final Object invokeBinop(Object receiver, Object arg) {
- return ${getMath(a,b)}.INSTANCE.addImpl(($a)receiver,($b)arg);
- }
- };
- """
- }
- println "}"
-}
-
-println """
- return new NumberNumberCallSite (site, metaClass, metaMethod, params, (Number)receiver, (Number)args[0]){
- public final Object invoke(Object receiver, Object[] args) {
- return math.addImpl((Number)receiver,(Number)args[0]);
- }
-
- public final Object invokeBinop(Object receiver, Object arg) {
- return math.addImpl((Number)receiver,(Number)arg);
- }
-}
-"""
-
-for (i in 2..256) {
- print "public Object invoke$i (Object receiver, "
- for (j in 1..(i-1)) {
- print "Object a$j, "
- }
- println "Object a$i) {"
-
- print " return invoke (receiver, new Object[] {"
-
- for (j in 1..(i-1)) {
- print "a$j, "
- }
- println "a$i} );"
-
- println "}"
-}
http://git-wip-us.apache.org/repos/asf/groovy/blob/10110145/src/main/groovy/genMathModification.groovy
----------------------------------------------------------------------
diff --git a/src/main/groovy/genMathModification.groovy b/src/main/groovy/genMathModification.groovy
deleted file mode 100644
index 10cc7eb..0000000
--- a/src/main/groovy/genMathModification.groovy
+++ /dev/null
@@ -1,133 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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.classgen
-
-def ops = [
- "plus",
- "minus",
- "multiply",
- "div",
- "or",
- "and",
- "xor",
- "intdiv",
- "mod",
- "leftShift",
- "rightShift",
- "rightShiftUnsigned"
-]
-
-def numbers = ["Byte":"byte", "Short":"short", "Integer":"int", "Long":"long", "Float":"float", "Double":"double"]
-
-ops.each { op ->
- numbers.each { wrappedType, type ->
- println "public boolean ${type}_${op};";
- }
-}
-
-ops.each { op ->
- println "if (\"${op}\".equals(name)) {"
- numbers.each { wrappedType, type ->
- println """if (klazz==${wrappedType}.class) {
- ${type}_${op} = true;
- }"""
- }
- println "if (klazz==Object.class) {"
- numbers.each { wrappedType, type ->
- println "${type}_${op} = true;"
- }
- println "}"
- println "}"
-}
-
-ops.each { op ->
- numbers.each { wrappedType1, type1 ->
- numbers.each { wrappedType2, type2 ->
- def math = getMath(wrappedType1, wrappedType2)
- if (math [op]) {
- println """public static ${math.resType} ${op}(${type1} op1, ${type2} op2) {
- if (instance.${type1}_${op}) {
- return ${op}Slow(op1, op2);
- }
- else {
- return ${math.resType != type1 ? "((" + math.resType+ ")op1)" : "op1"} ${math[op]} ${math.resType != type2 ? "((" + math.resType+ ")op2)" : "op2"};
- }
- }"""
- println """private static ${math.resType} ${op}Slow(${type1} op1,${type2} op2) {
- return ((Number)InvokerHelper.invokeMethod(op1, "${op}", op2)).${math.resType}Value();
- }"""
- }
- }
- }
-}
-
-def isFloatingPoint(number) {
- return number == "Double" || number == "Float";
-}
-
-def isLong(number) {
- return number == "Long";
-}
-
-def getMath (left, right) {
- if (isFloatingPoint(left) || isFloatingPoint(right)) {
- return [
- resType : "double",
-
- plus : "+",
- minus : "-",
- multiply : "*",
- div : "/",
- ];
- }
- if (isLong(left) || isLong(right)){
- return [
- resType : "long",
-
- plus : "+",
- minus : "-",
- multiply : "*",
- div : "/",
- or : "|",
- and : "&",
- xor : "^",
- intdiv : "/",
- mod : "%",
- leftShift : "<<",
- rightShift : ">>",
- rightShiftUnsigned : ">>>"
- ]
- }
- return [
- resType : "int",
-
- plus : "+",
- minus : "-",
- multiply : "*",
- div : "/",
- or : "|",
- and : "&",
- xor : "^",
- intdiv : "/",
- mod : "%",
- leftShift : "<<",
- rightShift : ">>",
- rightShiftUnsigned : ">>>"
- ]
-}