Wed, 20 Jun 2012 13:23:26 -0700
7174143: encapsulate doc comment table
Reviewed-by: ksrini, mcimadamore
duke@1 | 1 | /* |
ohair@554 | 2 | * Copyright (c) 2005, 2008, Oracle and/or its affiliates. All rights reserved. |
duke@1 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
duke@1 | 4 | * |
duke@1 | 5 | * This code is free software; you can redistribute it and/or modify it |
duke@1 | 6 | * under the terms of the GNU General Public License version 2 only, as |
ohair@554 | 7 | * published by the Free Software Foundation. Oracle designates this |
duke@1 | 8 | * particular file as subject to the "Classpath" exception as provided |
ohair@554 | 9 | * by Oracle in the LICENSE file that accompanied this code. |
duke@1 | 10 | * |
duke@1 | 11 | * This code is distributed in the hope that it will be useful, but WITHOUT |
duke@1 | 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
duke@1 | 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
duke@1 | 14 | * version 2 for more details (a copy is included in the LICENSE file that |
duke@1 | 15 | * accompanied this code). |
duke@1 | 16 | * |
duke@1 | 17 | * You should have received a copy of the GNU General Public License version |
duke@1 | 18 | * 2 along with this work; if not, write to the Free Software Foundation, |
duke@1 | 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
duke@1 | 20 | * |
ohair@554 | 21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
ohair@554 | 22 | * or visit www.oracle.com if you need additional information or have any |
ohair@554 | 23 | * questions. |
duke@1 | 24 | */ |
duke@1 | 25 | |
duke@1 | 26 | package com.sun.tools.javac.model; |
duke@1 | 27 | |
duke@1 | 28 | import java.util.AbstractList; |
duke@1 | 29 | import java.util.Iterator; |
duke@1 | 30 | import java.util.NoSuchElementException; |
duke@1 | 31 | import com.sun.tools.javac.code.Scope; |
duke@1 | 32 | import com.sun.tools.javac.code.Symbol; |
duke@1 | 33 | |
duke@1 | 34 | import static com.sun.tools.javac.code.Flags.*; |
duke@1 | 35 | |
duke@1 | 36 | /** |
duke@1 | 37 | * Utility to construct a view of a symbol's members, |
duke@1 | 38 | * filtering out unwanted elements such as synthetic ones. |
duke@1 | 39 | * This view is most efficiently accessed through its iterator() method. |
duke@1 | 40 | * |
jjg@581 | 41 | * <p><b>This is NOT part of any supported API. |
jjg@581 | 42 | * If you write code that depends on this, you do so at your own risk. |
duke@1 | 43 | * This code and its internal interfaces are subject to change or |
duke@1 | 44 | * deletion without notice.</b> |
duke@1 | 45 | */ |
duke@1 | 46 | public class FilteredMemberList extends AbstractList<Symbol> { |
duke@1 | 47 | |
duke@1 | 48 | private final Scope scope; |
duke@1 | 49 | |
duke@1 | 50 | public FilteredMemberList(Scope scope) { |
duke@1 | 51 | this.scope = scope; |
duke@1 | 52 | } |
duke@1 | 53 | |
duke@1 | 54 | public int size() { |
duke@1 | 55 | int cnt = 0; |
duke@1 | 56 | for (Scope.Entry e = scope.elems; e != null; e = e.sibling) { |
duke@1 | 57 | if (!unwanted(e.sym)) |
duke@1 | 58 | cnt++; |
duke@1 | 59 | } |
duke@1 | 60 | return cnt; |
duke@1 | 61 | } |
duke@1 | 62 | |
duke@1 | 63 | public Symbol get(int index) { |
duke@1 | 64 | for (Scope.Entry e = scope.elems; e != null; e = e.sibling) { |
duke@1 | 65 | if (!unwanted(e.sym) && (index-- == 0)) |
duke@1 | 66 | return e.sym; |
duke@1 | 67 | } |
duke@1 | 68 | throw new IndexOutOfBoundsException(); |
duke@1 | 69 | } |
duke@1 | 70 | |
duke@1 | 71 | // A more efficient implementation than AbstractList's. |
duke@1 | 72 | public Iterator<Symbol> iterator() { |
duke@1 | 73 | return new Iterator<Symbol>() { |
duke@1 | 74 | |
duke@1 | 75 | /** The next entry to examine, or null if none. */ |
duke@1 | 76 | private Scope.Entry nextEntry = scope.elems; |
duke@1 | 77 | |
duke@1 | 78 | private boolean hasNextForSure = false; |
duke@1 | 79 | |
duke@1 | 80 | public boolean hasNext() { |
duke@1 | 81 | if (hasNextForSure) { |
duke@1 | 82 | return true; |
duke@1 | 83 | } |
duke@1 | 84 | while (nextEntry != null && unwanted(nextEntry.sym)) { |
duke@1 | 85 | nextEntry = nextEntry.sibling; |
duke@1 | 86 | } |
duke@1 | 87 | hasNextForSure = (nextEntry != null); |
duke@1 | 88 | return hasNextForSure; |
duke@1 | 89 | } |
duke@1 | 90 | |
duke@1 | 91 | public Symbol next() { |
duke@1 | 92 | if (hasNext()) { |
duke@1 | 93 | Symbol result = nextEntry.sym; |
duke@1 | 94 | nextEntry = nextEntry.sibling; |
duke@1 | 95 | hasNextForSure = false; |
duke@1 | 96 | return result; |
duke@1 | 97 | } else { |
duke@1 | 98 | throw new NoSuchElementException(); |
duke@1 | 99 | } |
duke@1 | 100 | } |
duke@1 | 101 | |
duke@1 | 102 | public void remove() { |
duke@1 | 103 | throw new UnsupportedOperationException(); |
duke@1 | 104 | } |
duke@1 | 105 | }; |
duke@1 | 106 | } |
duke@1 | 107 | |
duke@1 | 108 | /** |
duke@1 | 109 | * Tests whether this is a symbol that should never be seen by |
duke@1 | 110 | * clients, such as a synthetic class. Returns true for null. |
duke@1 | 111 | */ |
duke@1 | 112 | private static boolean unwanted(Symbol s) { |
duke@1 | 113 | return s == null || (s.flags() & SYNTHETIC) != 0; |
duke@1 | 114 | } |
duke@1 | 115 | } |