org.apache.commons.weaver.model.WeavableExecutable Maven / Gradle / Ivy
Show all versions of commons-weaver-processor Show documentation
/*
* 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.apache.commons.weaver.model;
import java.lang.reflect.Member;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import org.apache.commons.weaver.utils.Args;
/**
* Represents a {@link Weavable} "executable".
*
* @param own type
* @param target executable type
* @param owning type
* @param parameter type
*/
public abstract class WeavableExecutable
,
TARGET extends Member,
T,
P extends WeavableParameter>
extends NestedWeavable, Class> {
private final List parameters;
/**
* Create a new {@link WeavableExecutable} instance.
* @param target executable
* @param parent enclosing {@link WeavableClass}
*/
protected WeavableExecutable(final TARGET target, final WeavableClass parent) {
super(target, parent);
final List params = new ArrayList<>();
final int paramCount = getParameterTypes().length;
for (int i = 0; i < paramCount; i++) {
params.add(createParameter(i));
}
parameters = Collections.unmodifiableList(params);
}
/**
* Create an appropriate {@link WeavableParameter} object.
* @param index of parameter
* @return {@code P}
*/
protected abstract P createParameter(int index);
/**
* Get the parameter types of {@link #getTarget()}.
* @return {@link Class}[]
*/
protected abstract Class>[] getParameterTypes();
/**
* {@inheritDoc}
*/
@Override
protected int localCompareTo(final SELF obj) {
return Args.compare(getParameterTypes(), obj.getParameterTypes());
}
/**
* Get the parameter at the specified index.
* @param index {@code int}
* @return {@code P}
*/
public P getWeavableParameter(final int index) {
return parameters.get(index);
}
/**
* Get the parameters declared by this {@link WeavableExecutable}.
* @return {@link Iterable} of {@code P}
*/
public Iterable
getParameters() {
return parameters;
}
}