langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/model/JavacElements.java
changeset 42826 563b42fc70ba
parent 42824 89b14017e8d6
child 43142 e72c3d9b0a0b
equal deleted inserted replaced
42825:c22877f68145 42826:563b42fc70ba
    27 
    27 
    28 import java.util.LinkedHashSet;
    28 import java.util.LinkedHashSet;
    29 import java.util.Map;
    29 import java.util.Map;
    30 import java.util.Set;
    30 import java.util.Set;
    31 
    31 
       
    32 import javax.lang.model.AnnotatedConstruct;
    32 import javax.lang.model.SourceVersion;
    33 import javax.lang.model.SourceVersion;
    33 import javax.lang.model.element.*;
    34 import javax.lang.model.element.*;
    34 import javax.lang.model.type.DeclaredType;
    35 import javax.lang.model.type.DeclaredType;
    35 import javax.lang.model.util.Elements;
    36 import javax.lang.model.util.Elements;
    36 import javax.tools.JavaFileObject;
    37 import javax.tools.JavaFileObject;
    37 import static javax.lang.model.util.ElementFilter.methodsIn;
    38 import static javax.lang.model.util.ElementFilter.methodsIn;
    38 
    39 
    39 import com.sun.source.util.JavacTask;
    40 import com.sun.source.util.JavacTask;
    40 import com.sun.tools.javac.api.JavacTaskImpl;
    41 import com.sun.tools.javac.api.JavacTaskImpl;
    41 import com.sun.tools.javac.code.*;
    42 import com.sun.tools.javac.code.*;
       
    43 import com.sun.tools.javac.code.Attribute.Compound;
       
    44 import com.sun.tools.javac.code.Directive.ExportsDirective;
       
    45 import com.sun.tools.javac.code.Directive.ExportsFlag;
       
    46 import com.sun.tools.javac.code.Directive.OpensDirective;
       
    47 import com.sun.tools.javac.code.Directive.OpensFlag;
       
    48 import com.sun.tools.javac.code.Directive.RequiresDirective;
       
    49 import com.sun.tools.javac.code.Directive.RequiresFlag;
    42 import com.sun.tools.javac.code.Scope.WriteableScope;
    50 import com.sun.tools.javac.code.Scope.WriteableScope;
    43 import com.sun.tools.javac.code.Symbol.*;
    51 import com.sun.tools.javac.code.Symbol.*;
    44 import com.sun.tools.javac.comp.AttrContext;
    52 import com.sun.tools.javac.comp.AttrContext;
    45 import com.sun.tools.javac.comp.Enter;
    53 import com.sun.tools.javac.comp.Enter;
    46 import com.sun.tools.javac.comp.Env;
    54 import com.sun.tools.javac.comp.Env;
   428         Symbol sym = cast(Symbol.class, e);
   436         Symbol sym = cast(Symbol.class, e);
   429         sym.complete();
   437         sym.complete();
   430         return sym.isDeprecated();
   438         return sym.isDeprecated();
   431     }
   439     }
   432 
   440 
       
   441     @Override @DefinedBy(Api.LANGUAGE_MODEL)
       
   442     public Origin getOrigin(Element e) {
       
   443         Symbol sym = cast(Symbol.class, e);
       
   444         if ((sym.flags() & Flags.GENERATEDCONSTR) != 0)
       
   445             return Origin.MANDATED;
       
   446         //TypeElement.getEnclosedElements does not return synthetic elements,
       
   447         //and most synthetic elements are not read from the classfile anyway:
       
   448         return Origin.EXPLICIT;
       
   449     }
       
   450 
       
   451     @Override @DefinedBy(Api.LANGUAGE_MODEL)
       
   452     public Origin getOrigin(AnnotatedConstruct c, AnnotationMirror a) {
       
   453         Compound ac = cast(Compound.class, a);
       
   454         if (ac.isSynthesized())
       
   455             return Origin.MANDATED;
       
   456         return Origin.EXPLICIT;
       
   457     }
       
   458 
       
   459     @Override @DefinedBy(Api.LANGUAGE_MODEL)
       
   460     public Origin getOrigin(ModuleElement m, ModuleElement.Directive directive) {
       
   461         switch (directive.getKind()) {
       
   462             case REQUIRES:
       
   463                 RequiresDirective rd = cast(RequiresDirective.class, directive);
       
   464                 if (rd.flags.contains(RequiresFlag.MANDATED))
       
   465                     return Origin.MANDATED;
       
   466                 if (rd.flags.contains(RequiresFlag.SYNTHETIC))
       
   467                     return Origin.SYNTHETIC;
       
   468                 return Origin.EXPLICIT;
       
   469             case EXPORTS:
       
   470                 ExportsDirective ed = cast(ExportsDirective.class, directive);
       
   471                 if (ed.flags.contains(ExportsFlag.MANDATED))
       
   472                     return Origin.MANDATED;
       
   473                 if (ed.flags.contains(ExportsFlag.SYNTHETIC))
       
   474                     return Origin.SYNTHETIC;
       
   475                 return Origin.EXPLICIT;
       
   476             case OPENS:
       
   477                 OpensDirective od = cast(OpensDirective.class, directive);
       
   478                 if (od.flags.contains(OpensFlag.MANDATED))
       
   479                     return Origin.MANDATED;
       
   480                 if (od.flags.contains(OpensFlag.SYNTHETIC))
       
   481                     return Origin.SYNTHETIC;
       
   482                 return Origin.EXPLICIT;
       
   483         }
       
   484         return Origin.EXPLICIT;
       
   485     }
       
   486 
   433     @DefinedBy(Api.LANGUAGE_MODEL)
   487     @DefinedBy(Api.LANGUAGE_MODEL)
   434     public Name getBinaryName(TypeElement type) {
   488     public Name getBinaryName(TypeElement type) {
   435         return cast(TypeSymbol.class, type).flatName();
   489         return cast(TypeSymbol.class, type).flatName();
   436     }
   490     }
   437 
   491