< prev index next >

src/jdk.compiler/share/classes/com/sun/tools/javac/model/JavacElements.java

Print this page




  28 import java.util.Collections;
  29 import java.util.HashMap;
  30 import java.util.HashSet;
  31 import java.util.LinkedHashSet;
  32 import java.util.Map;
  33 import java.util.Optional;
  34 import java.util.Set;
  35 import java.util.stream.Collectors;
  36 
  37 import javax.lang.model.AnnotatedConstruct;
  38 import javax.lang.model.SourceVersion;
  39 import javax.lang.model.element.*;
  40 import javax.lang.model.type.DeclaredType;
  41 import javax.lang.model.util.Elements;
  42 import javax.tools.JavaFileObject;
  43 import static javax.lang.model.util.ElementFilter.methodsIn;
  44 
  45 import com.sun.source.util.JavacTask;
  46 import com.sun.tools.javac.api.JavacTaskImpl;
  47 import com.sun.tools.javac.code.*;

  48 import com.sun.tools.javac.code.Attribute.Compound;
  49 import com.sun.tools.javac.code.Directive.ExportsDirective;
  50 import com.sun.tools.javac.code.Directive.ExportsFlag;
  51 import com.sun.tools.javac.code.Directive.OpensDirective;
  52 import com.sun.tools.javac.code.Directive.OpensFlag;
  53 import com.sun.tools.javac.code.Directive.RequiresDirective;
  54 import com.sun.tools.javac.code.Directive.RequiresFlag;
  55 import com.sun.tools.javac.code.Scope.WriteableScope;
  56 import com.sun.tools.javac.code.Source.Feature;
  57 import com.sun.tools.javac.code.Symbol.*;
  58 import com.sun.tools.javac.comp.AttrContext;
  59 import com.sun.tools.javac.comp.Enter;
  60 import com.sun.tools.javac.comp.Env;
  61 import com.sun.tools.javac.main.JavaCompiler;
  62 import com.sun.tools.javac.processing.PrintingProcessor;
  63 import com.sun.tools.javac.tree.JCTree;
  64 import com.sun.tools.javac.tree.JCTree.*;
  65 import com.sun.tools.javac.tree.TreeInfo;
  66 import com.sun.tools.javac.tree.TreeScanner;
  67 import com.sun.tools.javac.util.*;


 782             javacTaskImpl.ensureEntered();
 783         }
 784         if (!javaCompiler.isEnterDone()) {
 785             throw new IllegalStateException("Cannot use Elements." + methodName + " before the TaskEvent.Kind.ENTER finished event.");
 786         }
 787     }
 788 
 789     /**
 790      * Returns an object cast to the specified type.
 791      * @throws NullPointerException if the object is {@code null}
 792      * @throws IllegalArgumentException if the object is of the wrong type
 793      */
 794     private static <T> T cast(Class<T> clazz, Object o) {
 795         if (! clazz.isInstance(o))
 796             throw new IllegalArgumentException(o.toString());
 797         return clazz.cast(o);
 798     }
 799 
 800     public void newRound() {
 801         resultCache.clear();



















 802     }
 803 }


  28 import java.util.Collections;
  29 import java.util.HashMap;
  30 import java.util.HashSet;
  31 import java.util.LinkedHashSet;
  32 import java.util.Map;
  33 import java.util.Optional;
  34 import java.util.Set;
  35 import java.util.stream.Collectors;
  36 
  37 import javax.lang.model.AnnotatedConstruct;
  38 import javax.lang.model.SourceVersion;
  39 import javax.lang.model.element.*;
  40 import javax.lang.model.type.DeclaredType;
  41 import javax.lang.model.util.Elements;
  42 import javax.tools.JavaFileObject;
  43 import static javax.lang.model.util.ElementFilter.methodsIn;
  44 
  45 import com.sun.source.util.JavacTask;
  46 import com.sun.tools.javac.api.JavacTaskImpl;
  47 import com.sun.tools.javac.code.*;
  48 import com.sun.tools.javac.code.Accessors.Kind;
  49 import com.sun.tools.javac.code.Attribute.Compound;
  50 import com.sun.tools.javac.code.Directive.ExportsDirective;
  51 import com.sun.tools.javac.code.Directive.ExportsFlag;
  52 import com.sun.tools.javac.code.Directive.OpensDirective;
  53 import com.sun.tools.javac.code.Directive.OpensFlag;
  54 import com.sun.tools.javac.code.Directive.RequiresDirective;
  55 import com.sun.tools.javac.code.Directive.RequiresFlag;
  56 import com.sun.tools.javac.code.Scope.WriteableScope;
  57 import com.sun.tools.javac.code.Source.Feature;
  58 import com.sun.tools.javac.code.Symbol.*;
  59 import com.sun.tools.javac.comp.AttrContext;
  60 import com.sun.tools.javac.comp.Enter;
  61 import com.sun.tools.javac.comp.Env;
  62 import com.sun.tools.javac.main.JavaCompiler;
  63 import com.sun.tools.javac.processing.PrintingProcessor;
  64 import com.sun.tools.javac.tree.JCTree;
  65 import com.sun.tools.javac.tree.JCTree.*;
  66 import com.sun.tools.javac.tree.TreeInfo;
  67 import com.sun.tools.javac.tree.TreeScanner;
  68 import com.sun.tools.javac.util.*;


 783             javacTaskImpl.ensureEntered();
 784         }
 785         if (!javaCompiler.isEnterDone()) {
 786             throw new IllegalStateException("Cannot use Elements." + methodName + " before the TaskEvent.Kind.ENTER finished event.");
 787         }
 788     }
 789 
 790     /**
 791      * Returns an object cast to the specified type.
 792      * @throws NullPointerException if the object is {@code null}
 793      * @throws IllegalArgumentException if the object is of the wrong type
 794      */
 795     private static <T> T cast(Class<T> clazz, Object o) {
 796         if (! clazz.isInstance(o))
 797             throw new IllegalArgumentException(o.toString());
 798         return clazz.cast(o);
 799     }
 800 
 801     public void newRound() {
 802         resultCache.clear();
 803     }
 804 
 805     @Override
 806     public ExecutableElement getterFor(VariableElement variableElement) {
 807         return accessorFor(Kind.GET, variableElement);
 808     }
 809 
 810     @Override
 811     public ExecutableElement setterFor(VariableElement variableElement) {
 812         return accessorFor(Kind.SET, variableElement);
 813     }
 814 
 815     private ExecutableElement accessorFor(Accessors.Kind kind, VariableElement variableElement) {
 816         for (Pair<Accessors.Kind, MethodSymbol> accessor : ((VarSymbol)variableElement).accessors) {
 817             if (accessor.fst == kind) {
 818                 return accessor.snd;
 819             }
 820         }
 821         return null;
 822     }
 823 }
< prev index next >