All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.apache.commons.javaflow.providers.asm3.SharedContinuableClassInfos Maven / Gradle / Ivy

There is a newer version: 2.7.8
Show newest version
/**
 * Copyright 2013-2022 Valery Silaev (http://vsilaev.com)
 *
 * 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.apache.commons.javaflow.providers.asm3;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;

import org.apache.commons.javaflow.spi.ClassMatcher;

import org.objectweb.asm.Type;

class SharedContinuableClassInfos {
    private final Map visitedClasses;
    private final Map processedAnnotations;
    private final Map continuableAnnotations;

    private final ClassHierarchy hierarhcy;
    private final ClassMatcher veto;
    
    SharedContinuableClassInfos(ClassHierarchy hierarchy, ClassMatcher veto) {
        this.hierarhcy = hierarchy;
        this.veto = veto;
        
        visitedClasses         = new ConcurrentHashMap();
        /*
        /* Collections.newSetFromMap(new ConcurrentHashMap())
         * is not ok for the task -- addAll is not atomic 
         */
        processedAnnotations   = new ConcurrentHashMap();
        continuableAnnotations = new ConcurrentHashMap();
        
        processedAnnotations.put(CONTINUABLE_ANNOTATION_TYPE.getDescriptor(), Boolean.TRUE);
        continuableAnnotations.put(CONTINUABLE_ANNOTATION_TYPE.getDescriptor(), Boolean.TRUE);
    }
 
    IContinuableClassInfo getResolved(String classInternalName) {
        return visitedClasses.get(classInternalName);
    }
    
    boolean isProcessedAnnotation(String annotationClassDescriptor) {
        return processedAnnotations.containsKey(annotationClassDescriptor);
    }
    
    boolean isContinuableAnnotation(String annotationClassDescriptor) {
        return continuableAnnotations.containsKey(annotationClassDescriptor);
    }
    
    ClassHierarchy hierarchy() {
        return hierarhcy;
    }
    
    ClassMatcher veto() {
        return veto;
    }

    /* synchronized */
    void mergeWith(Map newVisitedClasses, 
                   Set newProcessedAnnotations,
                   Set newContinuableAnnotations) {
        
        visitedClasses.putAll(newVisitedClasses);
        continuableAnnotations.putAll(toMap(newContinuableAnnotations));
        processedAnnotations.putAll(toMap(newProcessedAnnotations));
    }
    
    private static Map toMap(Set keys) {
        Map result = new HashMap();
        for (String key : keys) {
            result.put(key, Boolean.TRUE);
        }
        return result;
    }
    
    private static final Type CONTINUABLE_ANNOTATION_TYPE = 
        Type.getObjectType("org/apache/commons/javaflow/api/ContinuableAnnotation");

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy