JavaFileObjectWithLocation.java revision 3170:dc017a37aac5
1139825Simp/*
21541Srgrimes * Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
31541Srgrimes * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
41541Srgrimes *
51541Srgrimes * This code is free software; you can redistribute it and/or modify it
61541Srgrimes * under the terms of the GNU General Public License version 2 only, as
71541Srgrimes * published by the Free Software Foundation.  Oracle designates this
81541Srgrimes * particular file as subject to the "Classpath" exception as provided
91541Srgrimes * by Oracle in the LICENSE file that accompanied this code.
101541Srgrimes *
111541Srgrimes * This code is distributed in the hope that it will be useful, but WITHOUT
121541Srgrimes * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
131541Srgrimes * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
141541Srgrimes * version 2 for more details (a copy is included in the LICENSE file that
151541Srgrimes * accompanied this code).
161541Srgrimes *
171541Srgrimes * You should have received a copy of the GNU General Public License version
181541Srgrimes * 2 along with this work; if not, write to the Free Software Foundation,
191541Srgrimes * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
201541Srgrimes *
211541Srgrimes * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
221541Srgrimes * or visit www.oracle.com if you need additional information or have any
231541Srgrimes * questions.
241541Srgrimes */
251541Srgrimes
261541Srgrimespackage com.sun.tools.sjavac.comp;
271541Srgrimes
281541Srgrimesimport javax.tools.ForwardingJavaFileObject;
291541Srgrimesimport javax.tools.JavaFileManager.Location;
301541Srgrimesimport javax.tools.JavaFileObject;
311541Srgrimes
3214495Shsuimport com.sun.tools.javac.api.ClientCodeWrapper.Trusted;
3350477Speter
341541Srgrimes@Trusted
351541Srgrimespublic class JavaFileObjectWithLocation<F extends JavaFileObject> extends ForwardingJavaFileObject<F> {
362165Spaul
372165Spaul    private final Location loc;
381541Srgrimes
391541Srgrimes    public JavaFileObjectWithLocation(F delegate, Location loc) {
401541Srgrimes        super(delegate);
4136449Sdt        this.loc = loc;
421541Srgrimes    }
431541Srgrimes
441541Srgrimes    public Location getLocation() {
451541Srgrimes        return loc;
461541Srgrimes    }
471541Srgrimes
48143063Sjoerg    public F getDelegate() {
49143063Sjoerg        return fileObject;
50143063Sjoerg    }
51143063Sjoerg
52143063Sjoerg    public String toString() {
53143063Sjoerg        return "JavaFileObjectWithLocation[loc: " + loc + ", " + fileObject + "]";
54143063Sjoerg    }
55143063Sjoerg
56143063Sjoerg    @Override
57143063Sjoerg    public int hashCode() {
58143063Sjoerg        return loc.hashCode() ^ fileObject.hashCode();
59143063Sjoerg    }
60143063Sjoerg
61143063Sjoerg    @Override
62143063Sjoerg    public boolean equals(Object obj) {
63143063Sjoerg        if (!(obj instanceof JavaFileObjectWithLocation))
64143063Sjoerg            return false;
65143063Sjoerg        JavaFileObjectWithLocation<?> other = (JavaFileObjectWithLocation<?>) obj;
66143063Sjoerg        return loc.equals(other.loc) && fileObject.equals(other.fileObject);
67143063Sjoerg    }
68143063Sjoerg}
69143063Sjoerg