Java Code Examples for com.sun.tools.javac.comp.Attr#instance()

The following examples show how to use com.sun.tools.javac.comp.Attr#instance() . 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: 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 2
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 3
Source File: VanillaPartialReparser.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public BlockTree reattrMethodBody(Context context, Scope scope, MethodTree methodToReparse, BlockTree block) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException {
        Attr attr = Attr.instance(context);
//        assert ((JCTree.JCMethodDecl)methodToReparse).localEnv != null;
        JCTree.JCMethodDecl tree = (JCTree.JCMethodDecl) methodToReparse;
        final Names names = Names.instance(context);
        final Symtab syms = Symtab.instance(context);
        final TypeEnter typeEnter = TypeEnter.instance(context);
        final Log log = Log.instance(context);
        final TreeMaker make = TreeMaker.instance(context);
        final Env<AttrContext> env = ((JavacScope) scope).getEnv();//this is a copy anyway...
        final Symbol.ClassSymbol owner = env.enclClass.sym;
        if (tree.name == names.init && !owner.type.isErroneous() && owner.type != syms.objectType) {
            JCTree.JCBlock body = tree.body;
            if (body.stats.isEmpty() || !TreeInfo.isSelfCall(body.stats.head)) {
                body.stats = body.stats.
                prepend(make.at(body.pos).Exec(make.Apply(com.sun.tools.javac.util.List.nil(), make.Ident(names._super), com.sun.tools.javac.util.List.nil())));
            } else if ((env.enclClass.sym.flags() & Flags.ENUM) != 0 &&
                (tree.mods.flags & Flags.GENERATEDCONSTR) == 0 &&
                TreeInfo.isSuperCall(body.stats.head)) {
                // enum constructors are not allowed to call super
                // directly, so make sure there aren't any super calls
                // in enum constructors, except in the compiler
                // generated one.
                log.error(tree.body.stats.head.pos(),
                          new JCDiagnostic.Error("compiler",
                                    "call.to.super.not.allowed.in.enum.ctor",
                                    env.enclClass.sym));
                    }
        }
        attr.attribStat((JCTree.JCBlock)block, env);
        return block;
    }
 
Example 4
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 5
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 6
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 7
Source File: JavacTrees.java    From openjdk-jdk8u-backup 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 8
Source File: Utilities.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private static TypeMirror attributeTree(JavacTaskImpl jti, Tree tree, Scope scope, 
            final List<Diagnostic<? extends JavaFileObject>> errors, @NullAllowed final Diagnostic.Kind filter) {
        Log log = Log.instance(jti.getContext());
        JavaFileObject prev = log.useSource(new DummyJFO());
        Enter enter = Enter.instance(jti.getContext());
        
        Log.DiagnosticHandler discardHandler = new Log.DiscardDiagnosticHandler(log) {
            private Diagnostic.Kind f = filter == null ? Diagnostic.Kind.ERROR : filter;
            @Override
            public void report(JCDiagnostic diag) {
                if (diag.getKind().compareTo(f) >= 0) {
                    errors.add(diag);
                }
            }            
        };
//        ArgumentAttr argumentAttr = ArgumentAttr.instance(jti.getContext());
//        ArgumentAttr.LocalCacheContext cacheContext = argumentAttr.withLocalCacheContext();
        try {
//            enter.shadowTypeEnvs(true);
            Attr attr = Attr.instance(jti.getContext());
            Env<AttrContext> env = ((JavacScope) scope).getEnv();
            if (tree instanceof JCTree.JCExpression) {
                return attr.attribExpr((JCTree) tree,env, Type.noType);
            }
            return attr.attribStat((JCTree) tree,env);
        } finally {
//            cacheContext.leave();
            log.useSource(prev);
            log.popDiagnosticHandler(discardHandler);
//            enter.shadowTypeEnvs(false);
        }
    }
 
Example 9
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 10
Source File: TreeUtilities.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private static TypeMirror attributeTree(JavacTaskImpl jti, Tree tree, Scope scope, final List<Diagnostic<? extends JavaFileObject>> errors) {
        Log log = Log.instance(jti.getContext());
        JavaFileObject prev = log.useSource(new DummyJFO());
        Log.DiagnosticHandler discardHandler = new Log.DiscardDiagnosticHandler(log) {
            @Override
            public void report(JCDiagnostic diag) {
                errors.add(diag);
            }            
        };
        NBResolve resolve = NBResolve.instance(jti.getContext());
        resolve.disableAccessibilityChecks();
//        Enter enter = Enter.instance(jti.getContext());
//        enter.shadowTypeEnvs(true);
//        ArgumentAttr argumentAttr = ArgumentAttr.instance(jti.getContext());
//        ArgumentAttr.LocalCacheContext cacheContext = argumentAttr.withLocalCacheContext();
        try {
            Attr attr = Attr.instance(jti.getContext());
            Env<AttrContext> env = getEnv(scope);
            if (tree instanceof JCExpression)
                return attr.attribExpr((JCTree) tree,env, Type.noType);
            if (env.tree != null && env.tree.getKind() == Kind.VARIABLE && !VARIABLE_CAN_OWN_VARIABLES) {
                env = env.next;
            }
            return attr.attribStat((JCTree) tree,env);
        } finally {
//            cacheContext.leave();
            log.useSource(prev);
            log.popDiagnosticHandler(discardHandler);
            resolve.restoreAccessbilityChecks();
//            enter.shadowTypeEnvs(false);
        }
    }
 
Example 11
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 12
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 13
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 14
Source File: JavacTrees.java    From openjdk-jdk8u 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 15
Source File: JavacTrees.java    From java-n-IDE-for-Android with Apache License 2.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 16
Source File: TypeAnnotations.java    From openjdk-8-source 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 17
Source File: JavacTrees.java    From jdk8u60 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 18
Source File: TypeAnnotations.java    From TencentKona-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 19
Source File: JavacResolution.java    From EasyMPermission with MIT License 4 votes vote down vote up
public JavacResolution(Context context) {
	attr = Attr.instance(context);
	messageSuppressor = new CompilerMessageSuppressor(context);
}
 
Example 20
Source File: JavaCompiler.java    From javaide with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Construct a new compiler using a shared context.
 */
public JavaCompiler(Context context) {
    this.context = context;
    context.put(compilerKey, this);

    // if fileManager not already set, register the JavacFileManager to be used
    if (context.get(JavaFileManager.class) == null)
        JavacFileManager.preRegister(context);

    names = Names.instance(context);
    log = Log.instance(context);
    diagFactory = JCDiagnostic.Factory.instance(context);
    reader = ClassReader.instance(context);
    make = TreeMaker.instance(context);
    writer = ClassWriter.instance(context);
    enter = Enter.instance(context);
    todo = Todo.instance(context);

    fileManager = context.get(JavaFileManager.class);
    parserFactory = ParserFactory.instance(context);

    try {
        // catch completion problems with predefineds
        syms = Symtab.instance(context);
    } catch (CompletionFailure ex) {
        // inlined Check.completionError as it is not initialized yet
        log.error("cant.access", ex.sym, ex.getDetailValue());
        if (ex instanceof ClassReader.BadClassFile)
            throw new Abort();
    }
    source = Source.instance(context);
    attr = Attr.instance(context);
    chk = Check.instance(context);
    gen = Gen.instance(context);
    flow = Flow.instance(context);
    transTypes = TransTypes.instance(context);
    lower = Lower.instance(context);
    annotate = Annotate.instance(context);
    types = Types.instance(context);
    taskListener = context.get(TaskListener.class);

    reader.sourceCompleter = this;

    options = Options.instance(context);

    verbose = options.isSet(VERBOSE);
    sourceOutput = options.isSet(PRINTSOURCE); // used to be -s
    stubOutput = options.isSet("-stubs");
    relax = options.isSet("-relax");
    printFlat = options.isSet("-printflat");
    attrParseOnly = options.isSet("-attrparseonly");
    encoding = options.get(ENCODING);
    lineDebugInfo = options.isUnset(G_CUSTOM) ||
            options.isSet(G_CUSTOM, "lines");
    genEndPos = options.isSet(XJCOV) ||
            context.get(DiagnosticListener.class) != null;
    devVerbose = options.isSet("dev");
    processPcks = options.isSet("process.packages");
    werror = options.isSet(WERROR);

    if (source.compareTo(Source.DEFAULT) < 0) {
        if (options.isUnset(XLINT_CUSTOM, "-" + LintCategory.OPTIONS.option)) {
            if (fileManager instanceof BaseFileManager) {
                if (((BaseFileManager) fileManager).isDefaultBootClassPath())
                    log.warning(LintCategory.OPTIONS, "source.no.bootclasspath", source.name);
            }
        }
    }

    verboseCompilePolicy = options.isSet("verboseCompilePolicy");

    if (attrParseOnly)
        compilePolicy = CompilePolicy.ATTR_ONLY;
    else
        compilePolicy = CompilePolicy.decode(options.get("compilePolicy"));

    implicitSourcePolicy = ImplicitSourcePolicy.decode(options.get("-implicit"));

    completionFailureName =
            options.isSet("failcomplete")
                    ? names.fromString(options.get("failcomplete"))
                    : null;

    shouldStopPolicy =
            options.isSet("shouldStopPolicy")
                    ? CompileState.valueOf(options.get("shouldStopPolicy"))
                    : null;
    if (options.isUnset("oldDiags"))
        log.setDiagnosticFormatter(RichDiagnosticFormatter.instance(context));
}