@@ -0,0 +1,3949 @@
+/*%0A * Copyright 2015 Michael Rozumyanskiy%0A *%0A * Licensed under the Apache License, Version 2.0 (the %22License%22);%0A * you may not use this file except in compliance with the License.%0A * You may obtain a copy of the License at%0A *%0A *     http://www.apache.org/licenses/LICENSE-2.0%0A *%0A * Unless required by applicable law or agreed to in writing, software%0A * distributed under the License is distributed on an %22AS IS%22 BASIS,%0A * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.%0A * See the License for the specific language governing permissions and%0A * limitations under the License.%0A */%0A%0Apackage io.michaelrocks.lightsaber.processor.signature;%0A%0Aimport io.michaelrocks.lightsaber.processor.ProcessorContext;%0Aimport org.objectweb.asm.Type;%0Aimport org.objectweb.asm.signature.SignatureReader;%0Aimport org.objectweb.asm.signature.SignatureVisitor;%0A%0Aimport java.util.ArrayList;%0Aimport java.util.List;%0A%0Aimport static org.objectweb.asm.Opcodes.ASM5;%0A%0Apublic class MethodSignatureParser extends SignatureVisitor %7B%0A    private final ProcessorContext processorContext;%0A%0A    private final List%3CTypeSignatureParser%3E argumentTypeParsers = new ArrayList%3C%3E();%0A    private TypeSignatureParser returnTypeParser;%0A    private boolean isValid = true;%0A%0A    private MethodSignature methodSignature;%0A%0A    public MethodSignatureParser(final ProcessorContext processorContext) %7B%0A        super(ASM5);%0A        this.processorContext = processorContext;%0A    %7D%0A%0A    public static MethodSignature parseMethodSignature(final ProcessorContext processorContext, final String signature,%0A            final Type methodType) %7B%0A        final MethodSignature methodSignature;%0A        if (signature == null) %7B%0A            methodSignature = null;%0A        %7D else %7B%0A            final SignatureReader signatureReader = new SignatureReader(signature);%0A            final MethodSignatureParser signatureParser = new MethodSignatureParser(processorContext);%0A            signatureReader.accept(signatureParser);%0A            methodSignature = signatureParser.getMethodSignature();%0A        %7D%0A        return methodSignature != null ? methodSignature : new MethodSignature(methodType);%0A    %7D%0A%0A    public MethodSignature getMethodSignature() %7B%0A        if (isValid && methodSignature == null) %7B%0A            methodSignature = createMethodSignature();%0A            isValid = methodSignature != null;%0A        %7D%0A        return methodSignature;%0A    %7D%0A%0A    private MethodSignature createMethodSignature() %7B%0A        if (returnTypeParser == null) %7B%0A            return null;%0A        %7D%0A%0A        final TypeSignature returnType = returnTypeParser.getTypeSignature();%0A%0A        final List%3CTypeSignature%3E argumentTypes = new ArrayList%3C%3E(argumentTypeParsers.size());%0A        for (final TypeSignatureParser argumentTypeParser : argumentTypeParsers) %7B%0A            final TypeSignature argumentType = argumentTypeParser.getTypeSignature();%0A            if (argumentType == null) %7B%0A                return null;%0A            %7D%0A            argumentTypes.add(argumentType);%0A        %7D%0A%0A        return new MethodSignature(returnType, argumentTypes);%0A    %7D%0A%0A    @Override%0A    public SignatureVisitor visitParameterType() %7B%0A        final TypeSignatureParser argumentTypeParser = new TypeSignatureParser(processorContext);%0A        argumentTypeParsers.add(argumentTypeParser);%0A        return argumentTypeParser;%0A    %7D%0A%0A    @Override%0A    public SignatureVisitor visitReturnType() %7B%0A        if (returnTypeParser != null) %7B%0A            reportError(%22Return type has already been parsed%22);%0A        %7D%0A        returnTypeParser = new TypeSignatureParser(processorContext);%0A        return returnTypeParser;%0A    %7D%0A%0A    // Prohibited callbacks.%0A%0A    @Override%0A    public void visitFormalTypeParameter(final String name) %7B%0A        reportError(%22Injectable methods cannot have type parameters%22);%0A    %7D%0A%0A    private void reportError(final String message) %7B%0A        processorContext.reportError(message);%0A        isValid = false;%0A    %7D%0A%7D%0A

Implement a parser for method signatures