|
Java example source code file (ReferenceFinder.java)
The ReferenceFinder.java Java example source code
/*
* Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.tools.classfile;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Objects;
import java.util.Set;
import com.sun.tools.classfile.Instruction.TypeKind;
import static com.sun.tools.classfile.ConstantPool.*;
/**
* A utility class to find where in a ClassFile references
* a {@link CONSTANT_Methodref_info method},
* a {@link CONSTANT_InterfaceMethodref_info interface method,
* or a {@link CONSTANT_Fieldref_info field}.
*/
public final class ReferenceFinder {
/**
* Filter for ReferenceFinder of what constant pool entries for reference lookup.
*/
public interface Filter {
/**
* Decides if the given CPRefInfo entry should be accepted or filtered.
*
* @param cpool ConstantPool of the ClassFile being parsed
* @param cpref constant pool entry representing a reference to
* a fields method, and interface method.
* @return {@code true} if accepted; otherwise {@code false}
*/
boolean accept(ConstantPool cpool, CPRefInfo cpref);
}
/**
* Visitor of individual method of a ClassFile that references the
* accepted field, method, or interface method references.
*/
public interface Visitor {
/**
* Invoked for a method containing one or more accepted CPRefInfo entries
*
* @param cf ClassFile
* @param method Method that does the references the accepted references
* @param refs Accepted constant pool method/field reference
*/
void visit(ClassFile cf, Method method, List<CPRefInfo> refConstantPool);
}
private final Filter filter;
private final Visitor visitor;
/**
* Constructor.
*/
public ReferenceFinder(Filter filter, Visitor visitor) {
this.filter = Objects.requireNonNull(filter);
this.visitor = Objects.requireNonNull(visitor);
}
/**
* Parses a given ClassFile and invoke the visitor if there is any reference
* to the constant pool entries referencing field, method, or
* interface method that are accepted. This method will return
* {@code true} if there is one or more accepted constant pool entries
* to lookup; otherwise, it will return {@code false}.
*
* @param cf ClassFile
* @return {@code true} if the given class file is processed to lookup
* references
* @throws ConstantPoolException if an error of the constant pool
*/
public boolean parse(ClassFile cf) throws ConstantPoolException {
List<Integer> cprefs = new ArrayList
Other Java examples (source code examples)Here is a short list of links related to this Java ReferenceFinder.java source code file: |
| ... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2024 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.