langtools/src/share/classes/com/sun/tools/javac/code/SymbolMetadata.java
changeset 23814 06ab27895804
parent 22702 1297fbaf34fa
--- a/langtools/src/share/classes/com/sun/tools/javac/code/SymbolMetadata.java	Wed Apr 09 17:18:22 2014 -0700
+++ b/langtools/src/share/classes/com/sun/tools/javac/code/SymbolMetadata.java	Thu Apr 03 20:28:23 2014 -0400
@@ -25,19 +25,9 @@
 
 package com.sun.tools.javac.code;
 
-import java.util.Map;
 
-import javax.tools.JavaFileObject;
-
-import com.sun.tools.javac.comp.Annotate;
-import com.sun.tools.javac.comp.AttrContext;
-import com.sun.tools.javac.comp.Env;
-import com.sun.tools.javac.util.*;
 import com.sun.tools.javac.util.Assert;
 import com.sun.tools.javac.util.List;
-import com.sun.tools.javac.util.Log;
-import com.sun.tools.javac.util.Pair;
-import static com.sun.tools.javac.code.Kinds.PCK;
 
 /**
  * Container for all annotations (attributes in javac) on a Symbol.
@@ -157,70 +147,6 @@
         setClassInitTypeAttributes(other.getClassInitTypeAttributes());
     }
 
-    public void setDeclarationAttributesWithCompletion(final Annotate.AnnotateRepeatedContext<Attribute.Compound> ctx) {
-        Assert.check(pendingCompletion() || (!isStarted() && sym.kind == PCK));
-        this.setDeclarationAttributes(getAttributesForCompletion(ctx));
-    }
-
-    public void appendTypeAttributesWithCompletion(final Annotate.AnnotateRepeatedContext<Attribute.TypeCompound> ctx) {
-        this.appendUniqueTypes(getAttributesForCompletion(ctx));
-    }
-
-    private <T extends Attribute.Compound> List<T> getAttributesForCompletion(
-            final Annotate.AnnotateRepeatedContext<T> ctx) {
-
-        Map<Symbol.TypeSymbol, ListBuffer<T>> annotated = ctx.annotated;
-        boolean atLeastOneRepeated = false;
-        List<T> buf = List.<T>nil();
-        for (ListBuffer<T> lb : annotated.values()) {
-            if (lb.size() == 1) {
-                buf = buf.prepend(lb.first());
-            } else { // repeated
-                // This will break when other subtypes of Attributs.Compound
-                // are introduced, because PlaceHolder is a subtype of TypeCompound.
-                T res;
-                @SuppressWarnings("unchecked")
-                T ph = (T) new Placeholder<>(ctx, lb.toList(), sym);
-                res = ph;
-                buf = buf.prepend(res);
-                atLeastOneRepeated = true;
-            }
-        }
-
-        if (atLeastOneRepeated) {
-            // The Symbol s is now annotated with a combination of
-            // finished non-repeating annotations and placeholders for
-            // repeating annotations.
-            //
-            // We need to do this in two passes because when creating
-            // a container for a repeating annotation we must
-            // guarantee that the @Repeatable on the
-            // contained annotation is fully annotated
-            //
-            // The way we force this order is to do all repeating
-            // annotations in a pass after all non-repeating are
-            // finished. This will work because @Repeatable
-            // is non-repeating and therefore will be annotated in the
-            // fist pass.
-
-            // Queue a pass that will replace Attribute.Placeholders
-            // with Attribute.Compound (made from synthesized containers).
-            ctx.annotateRepeated(new Annotate.Worker() {
-                @Override
-                public String toString() {
-                    return "repeated annotation pass of: " + sym + " in: " + sym.owner;
-                }
-
-                @Override
-                public void run() {
-                    complete(ctx);
-                }
-            });
-        }
-        // Add non-repeating attributes
-        return buf.reverse();
-    }
-
     public SymbolMetadata reset() {
         attributes = DECL_IN_PROGRESS;
         return this;
@@ -313,143 +239,4 @@
     private boolean isStarted() {
         return attributes != DECL_NOT_STARTED;
     }
-
-    private List<Attribute.Compound> getPlaceholders() {
-        List<Attribute.Compound> res = List.<Attribute.Compound>nil();
-        for (Attribute.Compound a : filterDeclSentinels(attributes)) {
-            if (a instanceof Placeholder) {
-                res = res.prepend(a);
-            }
-        }
-        return res.reverse();
-    }
-
-    private List<Attribute.TypeCompound> getTypePlaceholders() {
-        List<Attribute.TypeCompound> res = List.<Attribute.TypeCompound>nil();
-        for (Attribute.TypeCompound a : type_attributes) {
-            if (a instanceof Placeholder) {
-                res = res.prepend(a);
-            }
-        }
-        return res.reverse();
-    }
-
-    /*
-     * Replace Placeholders for repeating annotations with their containers
-     */
-    private <T extends Attribute.Compound> void complete(Annotate.AnnotateRepeatedContext<T> ctx) {
-        Log log = ctx.log;
-        Env<AttrContext> env = ctx.env;
-        JavaFileObject oldSource = log.useSource(env.toplevel.sourcefile);
-        try {
-            // TODO: can we reduce duplication in the following branches?
-            if (ctx.isTypeCompound) {
-                Assert.check(!isTypesEmpty());
-
-                if (isTypesEmpty()) {
-                    return;
-                }
-
-                List<Attribute.TypeCompound> result = List.nil();
-                for (Attribute.TypeCompound a : getTypeAttributes()) {
-                    if (a instanceof Placeholder) {
-                        @SuppressWarnings("unchecked")
-                        Placeholder<Attribute.TypeCompound> ph = (Placeholder<Attribute.TypeCompound>) a;
-                        Attribute.TypeCompound replacement = replaceOne(ph, ph.getRepeatedContext());
-
-                        if (null != replacement) {
-                            result = result.prepend(replacement);
-                        }
-                    } else {
-                        result = result.prepend(a);
-                    }
-                }
-
-                type_attributes = result.reverse();
-
-                Assert.check(SymbolMetadata.this.getTypePlaceholders().isEmpty());
-            } else {
-                Assert.check(!pendingCompletion());
-
-                if (isEmpty()) {
-                    return;
-                }
-
-                List<Attribute.Compound> result = List.nil();
-                for (Attribute.Compound a : getDeclarationAttributes()) {
-                    if (a instanceof Placeholder) {
-                        @SuppressWarnings("unchecked")
-                        Attribute.Compound replacement = replaceOne((Placeholder<T>) a, ctx);
-
-                        if (null != replacement) {
-                            result = result.prepend(replacement);
-                        }
-                    } else {
-                        result = result.prepend(a);
-                    }
-                }
-
-                attributes = result.reverse();
-
-                Assert.check(SymbolMetadata.this.getPlaceholders().isEmpty());
-            }
-        } finally {
-            log.useSource(oldSource);
-        }
-    }
-
-    private <T extends Attribute.Compound> T replaceOne(Placeholder<T> placeholder, Annotate.AnnotateRepeatedContext<T> ctx) {
-        Log log = ctx.log;
-
-        // Process repeated annotations
-        T validRepeated = ctx.processRepeatedAnnotations(placeholder.getPlaceholderFor(), sym);
-
-        if (validRepeated != null) {
-            // Check that the container isn't manually
-            // present along with repeated instances of
-            // its contained annotation.
-            ListBuffer<T> manualContainer = ctx.annotated.get(validRepeated.type.tsym);
-            if (manualContainer != null) {
-                log.error(ctx.pos.get(manualContainer.first()), "invalid.repeatable.annotation.repeated.and.container.present",
-                        manualContainer.first().type.tsym);
-            }
-        }
-
-        // A null return will delete the Placeholder
-        return validRepeated;
-    }
-
-    private static class Placeholder<T extends Attribute.Compound> extends Attribute.TypeCompound {
-
-        private final Annotate.AnnotateRepeatedContext<T> ctx;
-        private final List<T> placeholderFor;
-        private final Symbol on;
-
-        public Placeholder(Annotate.AnnotateRepeatedContext<T> ctx,
-                           List<T> placeholderFor, Symbol on) {
-            super(on.type, List.<Pair<Symbol.MethodSymbol, Attribute>>nil(),
-                  ctx.isTypeCompound ?
-                  ((Attribute.TypeCompound)placeholderFor.head).position :
-                  // TODO: Eventually, we will need to get rid of this
-                  // use of unknown, either by using null, or by
-                  // throwing an assertion failure here.
-                  TypeAnnotationPosition.unknown);
-            this.ctx = ctx;
-            this.placeholderFor = placeholderFor;
-            this.on = on;
-        }
-
-        @Override
-        public String toString() {
-            return "<placeholder: " + placeholderFor + " on: " + on + ">";
-        }
-
-        public List<T> getPlaceholderFor() {
-            return placeholderFor;
-        }
-
-        public Annotate.AnnotateRepeatedContext<T> getRepeatedContext() {
-            return ctx;
-        }
-    }
 }