001/**
002 * Copyright 2013 John Ericksen
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *    http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016package org.androidtransfuse.analysis.astAnalyzer;
017
018import com.google.common.base.Function;
019import com.google.common.collect.FluentIterable;
020import com.google.common.collect.ImmutableList;
021import org.androidtransfuse.adapter.ASTMethod;
022import org.androidtransfuse.adapter.ASTParameter;
023import org.androidtransfuse.adapter.ASTType;
024import org.apache.commons.lang.builder.EqualsBuilder;
025import org.apache.commons.lang.builder.HashCodeBuilder;
026
027import java.util.HashSet;
028import java.util.Set;
029
030/**
031 * @author John Ericksen
032 */
033public class ManualSuperAspect {
034
035    private Set<Method> methods = new HashSet<Method>();
036
037    public void add(String name, ImmutableList<ASTType> parameters) {
038        methods.add(new Method(name, parameters));
039    }
040
041    public Set<Method> getMethods() {
042        return methods;
043    }
044
045    public void add(ASTMethod eventMethod) {
046        add(eventMethod.getName(), FluentIterable.from(eventMethod.getParameters())
047                .transform(new Function<ASTParameter, ASTType>() {
048                    public ASTType apply(ASTParameter parameter) {
049                        return parameter.getASTType();
050                    }
051                }).toList());
052    }
053
054    public class Method{
055
056        private final String name;
057        private final ImmutableList<ASTType> parameters;
058
059        public Method(String name, ImmutableList<ASTType> parameters) {
060            this.name = name;
061            this.parameters = parameters;
062        }
063
064        @Override
065        public boolean equals(Object obj) {
066            if (!(obj instanceof Method)) {
067            return false;
068        }
069            if (this == obj) {
070                return true;
071            }
072            Method that = (Method) obj;
073            return new EqualsBuilder().append(name, that.name).append(parameters, that.parameters).isEquals();
074        }
075
076        @Override
077        public int hashCode() {
078            return new HashCodeBuilder().append(name).append(parameters).hashCode();
079        }
080
081        public ImmutableList<ASTType> getParameters() {
082            return parameters;
083        }
084
085        public String getName() {
086            return name;
087        }
088    }
089}