• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java JavacScope类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中com.sun.tools.javac.api.JavacScope的典型用法代码示例。如果您正苦于以下问题:Java JavacScope类的具体用法?Java JavacScope怎么用?Java JavacScope使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



JavacScope类属于com.sun.tools.javac.api包,在下文中一共展示了JavacScope类的17个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: findField

import com.sun.tools.javac.api.JavacScope; //导入依赖的package包/类
/**
 * Finds the field with name {@code name} in a given type.
 *
 * <p>
 * The method adheres to all the rules of Java's scoping (while also
 * considering the imports) for name resolution.
 *
 * @param name
 *            The name of the field.
 * @param type
 *            The type of the receiver (i.e., the type in which to look for
 *            the field).
 * @param path
 *            The tree path to the local scope.
 * @return The element for the field.
 */
public VariableElement findField(String name, TypeMirror type, TreePath path) {
    Log.DiagnosticHandler discardDiagnosticHandler =
        new Log.DiscardDiagnosticHandler(log);
    try {
        JavacScope scope = (JavacScope) trees.getScope(path);
        Env<AttrContext> env = scope.getEnv();
        Element res = wrapInvocation(FIND_IDENT_IN_TYPE, env, type,
                names.fromString(name), VAR);
        if (res.getKind() == ElementKind.FIELD) {
            return (VariableElement) res;
        } else {
            // Most likely didn't find the field and the Element is a SymbolNotFoundError
            return null;
        }
    } finally {
        log.popDiagnosticHandler(discardDiagnosticHandler);
    }
}
 
开发者ID:reprogrammer,项目名称:checker-framework,代码行数:35,代码来源:Resolver.java


示例2: findVariable

import com.sun.tools.javac.api.JavacScope; //导入依赖的package包/类
/**
 * Finds the variable referenced in the passed {@code String}.
 *
 * This method may only operate on variable references, e.g. local
 * variables, parameters, fields.
 *
 * The reference string may be either an single Java identifier (e.g. "field")
 * or dot-separated identifiers (e.g. "Collections.EMPTY_LIST").
 *
 * The method adheres to all the rules of Java's scoping (while also
 * considering the imports) for name resolution.
 *
 * @param reference     the variable reference string
 * @param path          the tree path to the local scope
 * @return  the variable reference
 */
public Element findVariable(String reference, TreePath path) {
    JavacScope scope = (JavacScope) trees.getScope(path);
    Env<AttrContext> env = scope.getEnv();

    if (!reference.contains(".")) {
        // Simple variable
        return wrapInvocation(
                FIND_IDENT,
                env, names.fromString(reference), Kinds.VAR);
    } else {
        int lastDot = reference.lastIndexOf('.');
        String expr = reference.substring(0, lastDot);
        String name = reference.substring(lastDot + 1);

        Element site = findType(expr, env);
        Name ident = names.fromString(name);

        return wrapInvocation(
                FIND_IDENT_IN_TYPE,
                env, site.asType(), ident, VAR);
    }

}
 
开发者ID:reprogrammer,项目名称:checker-framework,代码行数:40,代码来源:Resolver2.java


示例3: getInvocationTargetType

import com.sun.tools.javac.api.JavacScope; //导入依赖的package包/类
@Override
public IsType getInvocationTargetType(CompilationUnitTree cup, MethodInvocationTree node) {
  if (node instanceof JCMethodInvocation) {
    final TreePath path = trees.getPath(cup, node);
    final TreePath parent = path.getParentPath();
    final Tree target = parent.getLeaf();
    switch (target.getKind()) {
      case VARIABLE:
        JCVariableDecl var = (JCVariableDecl) target;
        final JCTree type = var.getType();
        final JavacScope scope = trees.getScope(path);
        final IsType cls = getTypeOf(cup, scope, type);
        return cls;
      default:
        X_Log.error(getClass(), "Unhandled invocation target type: ", target.getKind(), target);
    }
  } else {
    X_Log.warn(getClass(), "Does not support MethodInvocationTree ", node);
  }
  return null;
}
 
开发者ID:WeTheInternet,项目名称:xapi,代码行数:22,代码来源:JavacServiceImpl.java


示例4: getEnv

import com.sun.tools.javac.api.JavacScope; //导入依赖的package包/类
private static Env<AttrContext> getEnv(Scope scope) {
    if (scope instanceof NBScope) {
        scope = ((NBScope) scope).delegate;
    }
    
    return ((JavacScope) scope).getEnv();
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:8,代码来源:TreeUtilities.java


示例5: attributeTreeTo

import com.sun.tools.javac.api.JavacScope; //导入依赖的package包/类
private static Scope attributeTreeTo(JavacTaskImpl jti, Tree tree, Scope scope, Tree to, 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);
            Env<AttrContext> result = tree instanceof JCExpression ?
                attr.attribExprToTree((JCExpression) tree, env, (JCTree) to) :
                attr.attribStatToTree((JCTree) tree, env, (JCTree) to);
            try {
                Constructor<JavacScope> c = JavacScope.class.getDeclaredConstructor(Env.class);
                c.setAccessible(true);
                return c.newInstance(result);
            } catch (NoSuchMethodException | SecurityException | InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException ex) {
                throw new IllegalStateException(ex);
            }
        } finally {
//            cacheContext.leave();
            log.useSource(prev);
            log.popDiagnosticHandler(discardHandler);
            resolve.restoreAccessbilityChecks();
//            enter.shadowTypeEnvs(false);
        }
    }
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:37,代码来源:TreeUtilities.java


示例6: attributeTree

import com.sun.tools.javac.api.JavacScope; //导入依赖的package包/类
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 = ((JavacScope) scope).getEnv();
            if (tree instanceof JCExpression)
                return attr.attribExpr((JCTree) tree,env, Type.noType);
            return attr.attribStat((JCTree) tree,env);
        } finally {
//            cacheContext.leave();
            log.useSource(prev);
            log.popDiagnosticHandler(discardHandler);
            resolve.restoreAccessbilityChecks();
//            enter.shadowTypeEnvs(false);
        }
    }
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:30,代码来源:Utilities.java


示例7: attributeTree

import com.sun.tools.javac.api.JavacScope; //导入依赖的package包/类
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);
        }
    }
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:33,代码来源:Utilities.java


示例8: findMethod

import com.sun.tools.javac.api.JavacScope; //导入依赖的package包/类
/**
 * Finds the method element for a given name and list of expected parameter
 * types.
 *
 * <p>
 * The method adheres to all the rules of Java's scoping (while also
 * considering the imports) for name resolution.
 *
 * @param methodName
 *            Name of the method to find.
 * @param receiverType
 *            Type of the receiver of the method
 * @param path
 *            Tree path.
 * @return The method element (if found).
 */
public Element findMethod(String methodName, TypeMirror receiverType,
        TreePath path, java.util.List<TypeMirror> argumentTypes) {
    Log.DiagnosticHandler discardDiagnosticHandler =
        new Log.DiscardDiagnosticHandler(log);
    try {
        JavacScope scope = (JavacScope) trees.getScope(path);
        Env<AttrContext> env = scope.getEnv();

        Type site = (Type) receiverType;
        Name name = names.fromString(methodName);
        List<Type> argtypes = List.nil();
        for (TypeMirror a : argumentTypes) {
            argtypes = argtypes.append((Type) a);
        }
        List<Type> typeargtypes = List.nil();
        boolean allowBoxing = true;
        boolean useVarargs = false;
        boolean operator = true;

        try {
            // For some reason we have to set our own method context, which is rather ugly.
            // TODO: find a nicer way to do this.
            Object methodContext = buildMethodContext();
            Object oldContext = getField(resolve, "currentResolutionContext");
            setField(resolve, "currentResolutionContext", methodContext);
            Element result = wrapInvocation(FIND_METHOD, env, site, name, argtypes,
                typeargtypes, allowBoxing, useVarargs, operator);
            setField(resolve, "currentResolutionContext", oldContext);
            return result;
        } catch (Throwable t) {
            Error err = new AssertionError("Unexpected Reflection error");
            err.initCause(t);
            throw err;
        }
    } finally {
        log.popDiagnosticHandler(discardDiagnosticHandler);
    }
}
 
开发者ID:reprogrammer,项目名称:checker-framework,代码行数:55,代码来源:Resolver.java


示例9: getName

import com.sun.tools.javac.api.JavacScope; //导入依赖的package包/类
@Override
public IsNamedType getName(CompilationUnitTree cup, MethodInvocationTree node) {
  if (node instanceof JCMethodInvocation) {
    final String simpleName = TreeInfo.name(((JCMethodInvocation) node).meth).toString();
    String fullName = TreeInfo.fullName(((JCMethodInvocation) node).meth).toString();
    String className = fullName.indexOf('.') == -1 ? fullName : fullName.replaceFirst("[.](?:[^.]+)$", "");
    if (fullName.equals(className)) {
      // This is a local method reference.  Find the enclosing class type
      ClassTree cls = getEnclosingClass(cup, node);
      className = getNameOf(cls);
      return IsNamedType.namedType(className, simpleName);
    }
    final TreePath path = trees.getPath(cup, node);
    final JavacScope scope = trees.getScope(path);
    if (scope.isStarImportScope()) {
      // need to do lookup on the simple name of the method
    } else {
      // need to do lookup on the class of the imported method
    }
    final Optional<? extends ImportTree> match = cup.getImports().stream()
        .filter(importName -> {
          final Name n = TreeInfo.name((JCTree) importName.getQualifiedIdentifier());
          return n.contentEquals(simpleName);
        })
        .findFirst();
    return IsNamedType.namedType(className, simpleName);
  } else {
    X_Log.warn(getClass(), "Does not support MethodInvocationTree ", node);
  }
  return null;
}
 
开发者ID:WeTheInternet,项目名称:xapi,代码行数:32,代码来源:JavacServiceImpl.java


示例10: attributeTree

import com.sun.tools.javac.api.JavacScope; //导入依赖的package包/类
public TypeMirror attributeTree(Tree tree, Scope scope) {
//        if (scope instanceof NBScope && ((NBScope)scope).areAccessibilityChecksDisabled()) {
//            NBResolve.instance(info.impl.getJavacTask().getContext()).disableAccessibilityChecks();
//        }
//        try {
            return info.getJavacTask().attributeTree((JCTree) tree, ((JavacScope) scope).getEnv());
//        } finally {
//            NBResolve.instance(info.impl.getJavacTask().getContext()).restoreAccessbilityChecks();
//        }
    }
 
开发者ID:jtulach,项目名称:dew,代码行数:11,代码来源:TreeUtilities.java


示例11: attributeTreeTo

import com.sun.tools.javac.api.JavacScope; //导入依赖的package包/类
/**Attribute the given tree until the given <code>to</code> tree is reached.
     * Returns scope valid at point when <code>to</code> is reached.
     */
    public Scope attributeTreeTo(Tree tree, Scope scope, Tree to) {
//        if (scope instanceof NBScope && ((NBScope)scope).areAccessibilityChecksDisabled()) {
//            NBResolve.instance(info.impl.getJavacTask().getContext()).disableAccessibilityChecks();
//        }
//        try {
            return info.getJavacTask().attributeTreeTo((JCTree)tree, ((JavacScope)scope).getEnv(), (JCTree)to);
//        } finally {
//            NBResolve.instance(info.impl.getJavacTask().getContext()).restoreAccessbilityChecks();
//        }
    }
 
开发者ID:jtulach,项目名称:dew,代码行数:14,代码来源:TreeUtilities.java


示例12: reattributeTree

import com.sun.tools.javac.api.JavacScope; //导入依赖的package包/类
public TypeMirror reattributeTree(Tree tree, Scope scope) {
        Env<AttrContext> env = ((JavacScope)scope).getEnv();
        copyInnerClassIndexes(env.tree, tree);
//        if (scope instanceof NBScope && ((NBScope)scope).areAccessibilityChecksDisabled()) {
//            NBResolve.instance(info.impl.getJavacTask().getContext()).disableAccessibilityChecks();
//        }
//        try {
            return info.getJavacTask().attributeTree((JCTree)tree, env);
//        } finally {
//            NBResolve.instance(info.impl.getJavacTask().getContext()).restoreAccessbilityChecks();
//        }
    }
 
开发者ID:jtulach,项目名称:dew,代码行数:13,代码来源:TreeUtilities.java


示例13: reattributeTreeTo

import com.sun.tools.javac.api.JavacScope; //导入依赖的package包/类
public Scope reattributeTreeTo(Tree tree, Scope scope, Tree to) {
        Env<AttrContext> env = ((JavacScope)scope).getEnv();
        copyInnerClassIndexes(env.tree, tree);
//        if (scope instanceof NBScope && ((NBScope)scope).areAccessibilityChecksDisabled()) {
//            NBResolve.instance(info.impl.getJavacTask().getContext()).disableAccessibilityChecks();
//        }
//        try {
            return info.getJavacTask().attributeTreeTo((JCTree)tree, env, (JCTree)to);
//        } finally {
//            NBResolve.instance(info.impl.getJavacTask().getContext()).restoreAccessbilityChecks();
//        }
    }
 
开发者ID:jtulach,项目名称:dew,代码行数:13,代码来源:TreeUtilities.java


示例14: NBScope

import com.sun.tools.javac.api.JavacScope; //导入依赖的package包/类
private NBScope(JavacScope delegate) {
    this.delegate = delegate;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:4,代码来源:TreeUtilities.java


示例15: isStaticContext

import com.sun.tools.javac.api.JavacScope; //导入依赖的package包/类
/**Checks whether the given scope is in "static" context.
 */
public boolean isStaticContext(Scope scope) {
    return Resolve.instance(info.getJavacTask().getContext()).isStatic(((JavacScope)scope).getEnv());
}
 
开发者ID:jtulach,项目名称:dew,代码行数:6,代码来源:TreeUtilities.java


示例16: findClass

import com.sun.tools.javac.api.JavacScope; //导入依赖的package包/类
/**
 * Finds the class literal with name {@code name}.
 *
 * <p>
 * The method adheres to all the rules of Java's scoping (while also
 * considering the imports) for name resolution.
 *
 * @param name
 *            The name of the class.
 * @param path
 *            The tree path to the local scope.
 * @return The element for the class.
 */
public Element findClass(String name, TreePath path) {
    Log.DiagnosticHandler discardDiagnosticHandler =
        new Log.DiscardDiagnosticHandler(log);
    try {
        JavacScope scope = (JavacScope) trees.getScope(path);
        Env<AttrContext> env = scope.getEnv();
        return wrapInvocation(FIND_TYPE, env, names.fromString(name));
    } finally {
        log.popDiagnosticHandler(discardDiagnosticHandler);
    }
}
 
开发者ID:reprogrammer,项目名称:checker-framework,代码行数:25,代码来源:Resolver.java


示例17: toScopeWithDisabledAccessibilityChecks

import com.sun.tools.javac.api.JavacScope; //导入依赖的package包/类
/**
 * Creates {@link Scope} capable to access all private methods and fields when
 * parsing and evaluating expressions. When using this Scope, the accessibility
 * checks would not be enforced during a tree attribution.
 * @param scope an existing scope
 * @return scope with disabled accessibility checks
 * @since 0.129
 */
public Scope toScopeWithDisabledAccessibilityChecks(Scope scope) {
    return new NBScope((JavacScope)scope);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:12,代码来源:TreeUtilities.java



注:本文中的com.sun.tools.javac.api.JavacScope类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java XFormParseException类代码示例发布时间:2022-05-23
下一篇:
Java RemotePayloadChangeEvent类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap