com.sun.tools.javac.comp.Attr Java Examples

The following examples show how to use com.sun.tools.javac.comp.Attr. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CodeTranslator.java    From vertx-codetrans with Apache License 2.0 6 votes vote down vote up
public CodeTranslator(ProcessingEnvironment processingEnv) {
  this.trees = Trees.instance(processingEnv);
  this.SystemType = (DeclaredType) processingEnv.getElementUtils().getTypeElement(System.class.getName()).asType();
  this.ThrowableType = (DeclaredType) processingEnv.getElementUtils().getTypeElement(Throwable.class.getName()).asType();
  Context context = ((JavacProcessingEnvironment)processingEnv).getContext();
  this.attr = Attr.instance(context);
  this.typeUtils = processingEnv.getTypeUtils();
  this.factory = new TypeMirrorFactory(processingEnv.getElementUtils(), processingEnv.getTypeUtils()) {
    @Override
    public TypeInfo create(TypeUse use, TypeMirror type) {
      if (type.getKind() == TypeKind.WILDCARD) {
        WildcardType wildcardType = (WildcardType) type;
        if (wildcardType.getExtendsBound() != null) {
          return super.create(wildcardType.getExtendsBound());
        } else if (wildcardType.getSuperBound() != null) {
          return super.create(use, wildcardType.getSuperBound());
        }
      }
      return super.create(use, type);
    }
  };
}
 
Example #2
Source File: ManTypes.java    From manifold with Apache License 2.0 6 votes vote down vote up
private void reassignEarlyHolders8( Context context )
{
  ReflectUtil.field( Annotate.instance( context ), TYPES_FIELD ).set( this );
  ReflectUtil.field( Attr.instance( context ), TYPES_FIELD ).set( this );
  ReflectUtil.field( Check.instance( context ), TYPES_FIELD ).set( this );
  ReflectUtil.field( DeferredAttr.instance( context ), TYPES_FIELD ).set( this );
  ReflectUtil.field( Flow.instance( context ), TYPES_FIELD ).set( this );
  ReflectUtil.field( Gen.instance( context ), TYPES_FIELD ).set( this );
  ReflectUtil.field( Infer.instance( context ), TYPES_FIELD ).set( this );
  ReflectUtil.field( JavaCompiler.instance( context ), TYPES_FIELD ).set( this );
  ReflectUtil.field( JavacTrees.instance( context ), TYPES_FIELD ).set( this );
  ReflectUtil.field( JavacTypes.instance( context ), TYPES_FIELD ).set( this );
  ReflectUtil.field( JavacElements.instance( context ), TYPES_FIELD ).set( this );
  ReflectUtil.field( LambdaToMethod.instance( context ), TYPES_FIELD ).set( this );
  ReflectUtil.field( Lower.instance( context ), TYPES_FIELD ).set( this );
  ReflectUtil.field( ManResolve.instance( context ), TYPES_FIELD ).set( this );
  ReflectUtil.field( MemberEnter.instance( context ), TYPES_FIELD ).set( this );
  ReflectUtil.field( RichDiagnosticFormatter.instance( context ), TYPES_FIELD ).set( this );
  ReflectUtil.field( TransTypes.instance( context ), TYPES_FIELD ).set( this );
}
 
Example #3
Source File: ManTypes.java    From manifold with Apache License 2.0 6 votes vote down vote up
private ManTypes( Context ctx )
{
  super( ctx );

  _attr = Attr.instance( ctx );
  _syms = Symtab.instance( ctx );
  _transTypes = (ManTransTypes)TransTypes.instance( ctx );
  if( JavacPlugin.IS_JAVA_8 )
  {
    reassignEarlyHolders8( ctx );
  }
  else
  {
    reassignEarlyHolders( ctx );
  }
}
 
Example #4
Source File: JavacTrees.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private void init(Context context) {
    modules = Modules.instance(context);
    attr = Attr.instance(context);
    enter = Enter.instance(context);
    elements = JavacElements.instance(context);
    log = Log.instance(context);
    resolve = Resolve.instance(context);
    treeMaker = TreeMaker.instance(context);
    memberEnter = MemberEnter.instance(context);
    names = Names.instance(context);
    types = Types.instance(context);
    docTreeMaker = DocTreeMaker.instance(context);
    parser = ParserFactory.instance(context);
    syms = Symtab.instance(context);
    fileManager = context.get(JavaFileManager.class);
    JavacTask t = context.get(JavacTask.class);
    if (t instanceof JavacTaskImpl)
        javacTaskImpl = (JavacTaskImpl) t;
}
 
Example #5
Source File: ManResolve.java    From manifold with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("ConstantConditions")
private ManResolve( Context context )
{
  super( context );
  _attr = Attr.instance( context );
  ReflectUtil.field( this, "log" ).set( ReflectUtil.field( _attr, "log" ).get() );

  if( JavacPlugin.IS_JAVA_8 )
  {
    reassignEarlyHolders8( context );
  }
  else
  {
    reassignEarlyHolders( context );
  }
}
 
Example #6
Source File: JavacTrees.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
private void init(Context context) {
    modules = Modules.instance(context);
    attr = Attr.instance(context);
    enter = Enter.instance(context);
    elements = JavacElements.instance(context);
    log = Log.instance(context);
    resolve = Resolve.instance(context);
    treeMaker = TreeMaker.instance(context);
    memberEnter = MemberEnter.instance(context);
    names = Names.instance(context);
    types = Types.instance(context);
    docTreeMaker = DocTreeMaker.instance(context);
    parser = ParserFactory.instance(context);
    syms = Symtab.instance(context);
    fileManager = context.get(JavaFileManager.class);
    JavacTask t = context.get(JavacTask.class);
    if (t instanceof JavacTaskImpl)
        javacTaskImpl = (JavacTaskImpl) t;
}
 
Example #7
Source File: TypeAnnotations.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
protected TypeAnnotations(Context context) {
    context.put(typeAnnosKey, this);
    names = Names.instance(context);
    log = Log.instance(context);
    syms = Symtab.instance(context);
    annotate = Annotate.instance(context);
    attr = Attr.instance(context);
    Options options = Options.instance(context);
}
 
Example #8
Source File: Symbol.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
public void setLazyConstValue(final Env<AttrContext> env,
                              final Attr attr,
                              final JCVariableDecl variable)
{
    setData(new Callable<Object>() {
        public Object call() {
            return attr.attribLazyConstantValue(env, variable, type);
        }
    });
}
 
Example #9
Source File: T7021650.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
    round++;

    Context context = ((JavacProcessingEnvironment) processingEnv).getContext();

    // verify items in context as expected
    check("Demo", Demo.instance(context), Demo.class);
    check("Attr", Attr.instance(context), MyAttr.class);

    // For a few rounds, generate new source files, so that we can check whether
    // values in the context are correctly handled in subsequent processing rounds
    if (round <= MAX_ROUNDS) {
        String pkg = "p";
        String currClass = "Gen" + round;
        String curr = pkg + "." + currClass;
        String next = (pkg + ".Gen" + (round + 1));
        StringBuilder text = new StringBuilder();
        text.append("package ").append(pkg).append(";\n");
        text.append("public class ").append(currClass).append(" {\n");
        if (round < MAX_ROUNDS)
            text.append("    ").append(next).append(" x;\n");
        text.append("}\n");

        try {
            JavaFileObject fo = filer.createSourceFile(curr);
            Writer out = fo.openWriter();
            try {
                out.write(text.toString());
            } finally {
                out.close();
            }
        } catch (IOException e) {
            throw new Error(e);
        }
    }

    return true;
}
 
Example #10
Source File: T7021650.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
static void preRegister(Context context, final Counter counter) {
    context.put(attrKey, new Context.Factory<Attr>() {
        public Attr make(Context c) {
            counter.count++;
            return new MyAttr(c);
        }
    });
}
 
Example #11
Source File: T7021650.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
static void preRegister(Context context, final Counter counter) {
    context.put(attrKey, new Context.Factory<Attr>() {
        public Attr make(Context c) {
            counter.count++;
            return new MyAttr(c);
        }
    });
}
 
Example #12
Source File: T7021650.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
    round++;

    Context context = ((JavacProcessingEnvironment) processingEnv).getContext();

    // verify items in context as expected
    check("Demo", Demo.instance(context), Demo.class);
    check("Attr", Attr.instance(context), MyAttr.class);

    // For a few rounds, generate new source files, so that we can check whether
    // values in the context are correctly handled in subsequent processing rounds
    if (round <= MAX_ROUNDS) {
        String pkg = "p";
        String currClass = "Gen" + round;
        String curr = pkg + "." + currClass;
        String next = (pkg + ".Gen" + (round + 1));
        StringBuilder text = new StringBuilder();
        text.append("package ").append(pkg).append(";\n");
        text.append("public class ").append(currClass).append(" {\n");
        if (round < MAX_ROUNDS)
            text.append("    ").append(next).append(" x;\n");
        text.append("}\n");

        try {
            JavaFileObject fo = filer.createSourceFile(curr);
            Writer out = fo.openWriter();
            try {
                out.write(text.toString());
            } finally {
                out.close();
            }
        } catch (IOException e) {
            throw new Error(e);
        }
    }

    return true;
}
 
Example #13
Source File: JavacTrees.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
private void init(Context context) {
    attr = Attr.instance(context);
    enter = Enter.instance(context);
    elements = JavacElements.instance(context);
    log = Log.instance(context);
    resolve = Resolve.instance(context);
    treeMaker = TreeMaker.instance(context);
    memberEnter = MemberEnter.instance(context);
    names = Names.instance(context);
    types = Types.instance(context);

    JavacTask t = context.get(JavacTask.class);
    if (t instanceof JavacTaskImpl)
        javacTaskImpl = (JavacTaskImpl) t;
}
 
Example #14
Source File: Symbol.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
public void setLazyConstValue(final Env<AttrContext> env,
                              final Attr attr,
                              final JCVariableDecl variable)
{
    setData(new Callable<Object>() {
        public Object call() {
            return attr.attribLazyConstantValue(env, variable, type);
        }
    });
}
 
Example #15
Source File: JavacTrees.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
private void init(Context context) {
    attr = Attr.instance(context);
    enter = Enter.instance(context);
    elements = JavacElements.instance(context);
    log = Log.instance(context);
    resolve = Resolve.instance(context);
    treeMaker = TreeMaker.instance(context);
    memberEnter = MemberEnter.instance(context);
    names = Names.instance(context);
    types = Types.instance(context);

    JavacTask t = context.get(JavacTask.class);
    if (t instanceof JavacTaskImpl)
        javacTaskImpl = (JavacTaskImpl) t;
}
 
Example #16
Source File: JavacTrees.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
private void init(Context context) {
    attr = Attr.instance(context);
    enter = Enter.instance(context);
    elements = JavacElements.instance(context);
    log = Log.instance(context);
    resolve = Resolve.instance(context);
    treeMaker = TreeMaker.instance(context);
    memberEnter = MemberEnter.instance(context);
    names = Names.instance(context);
    types = Types.instance(context);

    JavacTask t = context.get(JavacTask.class);
    if (t instanceof JavacTaskImpl)
        javacTaskImpl = (JavacTaskImpl) t;
}
 
Example #17
Source File: TypeAnnotations.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
protected TypeAnnotations(Context context) {
    context.put(typeAnnosKey, this);
    names = Names.instance(context);
    log = Log.instance(context);
    syms = Symtab.instance(context);
    annotate = Annotate.instance(context);
    attr = Attr.instance(context);
    Options options = Options.instance(context);
}
 
Example #18
Source File: Symbol.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
public void setLazyConstValue(final Env<AttrContext> env,
                              final Attr attr,
                              final JCVariableDecl variable)
{
    setData(new Callable<Object>() {
        public Object call() {
            return attr.attribLazyConstantValue(env, variable, type);
        }
    });
}
 
Example #19
Source File: T7021650.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
static void preRegister(Context context, final Counter counter) {
    context.put(attrKey, new Context.Factory<Attr>() {
        public Attr make(Context c) {
            counter.count++;
            return new MyAttr(c);
        }
    });
}
 
Example #20
Source File: T7021650.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
    round++;

    Context context = ((JavacProcessingEnvironment) processingEnv).getContext();

    // verify items in context as expected
    check("Demo", Demo.instance(context), Demo.class);
    check("Attr", Attr.instance(context), MyAttr.class);

    // For a few rounds, generate new source files, so that we can check whether
    // values in the context are correctly handled in subsequent processing rounds
    if (round <= MAX_ROUNDS) {
        String pkg = "p";
        String currClass = "Gen" + round;
        String curr = pkg + "." + currClass;
        String next = (pkg + ".Gen" + (round + 1));
        StringBuilder text = new StringBuilder();
        text.append("package ").append(pkg).append(";\n");
        text.append("public class ").append(currClass).append(" {\n");
        if (round < MAX_ROUNDS)
            text.append("    ").append(next).append(" x;\n");
        text.append("}\n");

        try {
            JavaFileObject fo = filer.createSourceFile(curr);
            Writer out = fo.openWriter();
            try {
                out.write(text.toString());
            } finally {
                out.close();
            }
        } catch (IOException e) {
            throw new Error(e);
        }
    }

    return true;
}
 
Example #21
Source File: Symbol.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
public void setLazyConstValue(final Env<AttrContext> env,
                              final Attr attr,
                              final JCVariableDecl variable)
{
    setData(new Callable<Object>() {
        public Object call() {
            return attr.attribLazyConstantValue(env, variable, type);
        }
    });
}
 
Example #22
Source File: ManTypes.java    From manifold with Apache License 2.0 5 votes vote down vote up
private void reassignEarlyHolders( Context context )
{
  ReflectUtil.field(
    ReflectUtil.method( ReflectUtil.type( "com.sun.tools.javac.comp.Analyzer" ), "instance", Context.class )
      .invokeStatic( context ), TYPES_FIELD ).set( this );
  ReflectUtil.field( Annotate.instance( context ), TYPES_FIELD ).set( this );
  ReflectUtil.field( Attr.instance( context ), TYPES_FIELD ).set( this );
  ReflectUtil.field( Check.instance( context ), TYPES_FIELD ).set( this );
  ReflectUtil.field( DeferredAttr.instance( context ), TYPES_FIELD ).set( this );
  ReflectUtil.field( Flow.instance( context ), TYPES_FIELD ).set( this );
  ReflectUtil.field( Gen.instance( context ), TYPES_FIELD ).set( this );
  ReflectUtil.field( Infer.instance( context ), TYPES_FIELD ).set( this );
  ReflectUtil.field( JavaCompiler.instance( context ), TYPES_FIELD ).set( this );
  ReflectUtil.field( JavacElements.instance( context ), TYPES_FIELD ).set( this );
  ReflectUtil.field( JavacProcessingEnvironment.instance( context ), TYPES_FIELD ).set( this );
  ReflectUtil.field( JavacTrees.instance( context ), TYPES_FIELD ).set( this );
  ReflectUtil.field( JavacTypes.instance( context ), TYPES_FIELD ).set( this );
  ReflectUtil.field( LambdaToMethod.instance( context ), TYPES_FIELD ).set( this );
  ReflectUtil.field( Lower.instance( context ), TYPES_FIELD ).set( this );
  ReflectUtil.field( ManResolve.instance( context ), TYPES_FIELD ).set( this );
  ReflectUtil.field( MemberEnter.instance( context ), TYPES_FIELD ).set( this );
  ReflectUtil.field(
    ReflectUtil.method( ReflectUtil.type( "com.sun.tools.javac.comp.Modules" ), "instance", Context.class )
      .invokeStatic( context ), TYPES_FIELD ).set( this );
  ReflectUtil.field(
    ReflectUtil.method( ReflectUtil.type( "com.sun.tools.javac.comp.Operators" ), "instance", Context.class )
      .invokeStatic( context ), TYPES_FIELD ).set( this );
  //noinspection ConstantConditions
  ReflectUtil.field(
    ReflectUtil.method( ReflectUtil.type( "com.sun.tools.javac.jvm.StringConcat" ), "instance", Context.class )
      .invokeStatic( context ), TYPES_FIELD ).set( this );
  ReflectUtil.field( RichDiagnosticFormatter.instance( context ), TYPES_FIELD ).set( this );
  ReflectUtil.field( TransTypes.instance( context ), TYPES_FIELD ).set( this );
  ReflectUtil.field(
    ReflectUtil.method( ReflectUtil.type( "com.sun.tools.javac.comp.TypeEnter" ), "instance", Context.class )
      .invokeStatic( context ), TYPES_FIELD ).set( this );
  ReflectUtil.field( TreeMaker.instance( context ), TYPES_FIELD ).set( this );
}
 
Example #23
Source File: ManAttr_8.java    From manifold with Apache License 2.0 5 votes vote down vote up
public static ManAttr_8 instance( Context ctx )
{
  Attr attr = ctx.get( attrKey );
  if( !(attr instanceof ManAttr_8) )
  {
    ctx.put( attrKey, (Attr)null );
    attr = new ManAttr_8( ctx );
  }

  return (ManAttr_8)attr;
}
 
Example #24
Source File: ManResolve.java    From manifold with Apache License 2.0 5 votes vote down vote up
private void reassignEarlyHolders8( Context context )
{
  ReflectUtil.field( Attr.instance( context ), RESOLVE_FIELD ).set( this );
  ReflectUtil.field( DeferredAttr.instance( context ), RESOLVE_FIELD ).set( this );
  ReflectUtil.field( Check.instance( context ), RESOLVE_FIELD ).set( this );
  ReflectUtil.field( Infer.instance( context ), RESOLVE_FIELD ).set( this );
  ReflectUtil.field( Flow.instance( context ), RESOLVE_FIELD ).set( this );
  ReflectUtil.field( Lower.instance( context ), RESOLVE_FIELD ).set( this );
  ReflectUtil.field( Gen.instance( context ), RESOLVE_FIELD ).set( this );
  ReflectUtil.field( Annotate.instance( context ), RESOLVE_FIELD ).set( this );
  ReflectUtil.field( JavacTrees.instance( context ), "resolve" ).set( this );
  ReflectUtil.field( TransTypes.instance( context ), "resolve" ).set( this );
}
 
Example #25
Source File: TypeAnnotations.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
protected TypeAnnotations(Context context) {
    context.put(typeAnnosKey, this);
    names = Names.instance(context);
    log = Log.instance(context);
    syms = Symtab.instance(context);
    annotate = Annotate.instance(context);
    attr = Attr.instance(context);
}
 
Example #26
Source File: Symbol.java    From javaide with GNU General Public License v3.0 5 votes vote down vote up
public void setLazyConstValue(final Env<AttrContext> env,
                              final Attr attr,
                              final JCTree.JCExpression initializer)
{
    setData(new Callable<Object>() {
        public Object call() {
            return attr.attribLazyConstantValue(env, initializer, type);
        }
    });
}
 
Example #27
Source File: JavacTrees.java    From javaide with GNU General Public License v3.0 5 votes vote down vote up
private void init(Context context) {
    attr = Attr.instance(context);
    enter = Enter.instance(context);
    elements = JavacElements.instance(context);
    log = Log.instance(context);
    resolve = Resolve.instance(context);
    treeMaker = TreeMaker.instance(context);
    memberEnter = MemberEnter.instance(context);
    javacTaskImpl = context.get(JavacTaskImpl.class);
}
 
Example #28
Source File: T7021650.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
    round++;

    Context context = ((JavacProcessingEnvironment) processingEnv).getContext();

    // verify items in context as expected
    check("Demo", Demo.instance(context), Demo.class);
    check("Attr", Attr.instance(context), MyAttr.class);

    // For a few rounds, generate new source files, so that we can check whether
    // values in the context are correctly handled in subsequent processing rounds
    if (round <= MAX_ROUNDS) {
        String pkg = "p";
        String currClass = "Gen" + round;
        String curr = pkg + "." + currClass;
        String next = (pkg + ".Gen" + (round + 1));
        StringBuilder text = new StringBuilder();
        text.append("package ").append(pkg).append(";\n");
        text.append("public class ").append(currClass).append(" {\n");
        if (round < MAX_ROUNDS)
            text.append("    ").append(next).append(" x;\n");
        text.append("}\n");

        try {
            JavaFileObject fo = filer.createSourceFile(curr);
            Writer out = fo.openWriter();
            try {
                out.write(text.toString());
            } finally {
                out.close();
            }
        } catch (IOException e) {
            throw new Error(e);
        }
    }

    return true;
}
 
Example #29
Source File: JavacTrees.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
private void init(Context context) {
    attr = Attr.instance(context);
    enter = Enter.instance(context);
    elements = JavacElements.instance(context);
    log = Log.instance(context);
    resolve = Resolve.instance(context);
    treeMaker = TreeMaker.instance(context);
    memberEnter = MemberEnter.instance(context);
    names = Names.instance(context);
    types = Types.instance(context);

    JavacTask t = context.get(JavacTask.class);
    if (t instanceof JavacTaskImpl)
        javacTaskImpl = (JavacTaskImpl) t;
}
 
Example #30
Source File: T7021650.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
static void preRegister(Context context, final Counter counter) {
    context.put(attrKey, new Context.Factory<Attr>() {
        public Attr make(Context c) {
            counter.count++;
            return new MyAttr(c);
        }
    });
}