org.teavm.callgraph.DefaultCallGraph Maven / Gradle / Ivy
/*
* Copyright 2014 Alexey Andreev.
*
* 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.teavm.callgraph;
import java.util.*;
import org.teavm.model.FieldReference;
import org.teavm.model.MethodReference;
/**
*
* @author Alexey Andreev
*/
public class DefaultCallGraph implements CallGraph {
private Map nodes = new HashMap<>();
private Map> fieldAccessSites = new HashMap<>();
private Map> classAccessSites = new HashMap<>();
@Override
public DefaultCallGraphNode getNode(MethodReference method) {
DefaultCallGraphNode node = nodes.get(method);
if (node == null) {
node = new DefaultCallGraphNode(this, method);
nodes.put(method, node);
}
return nodes.get(method);
}
@Override
public Collection getFieldAccess(FieldReference reference) {
Set resultSet = fieldAccessSites.get(reference);
return resultSet != null ? Collections.unmodifiableSet(resultSet) :
Collections.emptySet();
}
void addFieldAccess(DefaultFieldAccessSite accessSite) {
Set sites = fieldAccessSites.get(accessSite.getField());
if (sites == null) {
sites = new HashSet<>();
fieldAccessSites.put(accessSite.getField(), sites);
}
sites.add(accessSite);
}
@Override
public Collection getClassAccess(String className) {
Set resultSet = classAccessSites.get(className);
return resultSet != null ? Collections.unmodifiableSet(resultSet) :
Collections.emptySet();
}
void addClassAccess(DefaultClassAccessSite accessSite) {
Set sites = classAccessSites.get(accessSite.getClassName());
if (sites == null) {
sites = new HashSet<>();
classAccessSites.put(accessSite.getClassName(), sites);
}
sites.add(accessSite);
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy