本文整理了Java中com.sun.tools.javac.util.List.of()
方法的一些代码示例,展示了List.of()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。List.of()
方法的具体详情如下:
包路径:com.sun.tools.javac.util.List
类名称:List
方法名:of
[英]Construct a list consisting of given element.
[中]构造一个由给定元素组成的列表。
代码示例来源:origin: google/error-prone
@Override
public List<JCStatement> inlineStatements(Inliner inliner) throws CouldNotResolveImportException {
return List.of(inline(inliner));
}
代码示例来源:origin: google/error-prone
private static Function<Unifier, Choice<Unifier>> unifyUStatementWithSingleStatement(
@Nullable final UStatement toUnify, @Nullable final StatementTree target) {
return (Unifier unifier) -> {
if (toUnify == null) {
return (target == null) ? Choice.of(unifier) : Choice.<Unifier>none();
}
List<StatementTree> list = (target == null) ? List.<StatementTree>nil() : List.of(target);
return toUnify
.apply(UnifierWithUnconsumedStatements.create(unifier, list))
.condition(s -> s.unconsumedStatements().isEmpty())
.transform(UnifierWithUnconsumedStatements::unifier);
};
}
代码示例来源:origin: google/error-prone
@Override
public List<JCStatement> inlineStatements(Inliner inliner) throws CouldNotResolveImportException {
return List.<JCStatement>of(
inliner
.maker()
.If(
getCondition().inline(inliner),
Iterables.getOnlyElement(getThenStatement().inlineStatements(inliner)),
(getElseStatement() == null)
? null
: Iterables.getOnlyElement(getElseStatement().inlineStatements(inliner))));
}
}
代码示例来源:origin: google/error-prone
@Override
public List<JCStatement> inlineStatements(final Inliner inliner)
throws CouldNotResolveImportException {
try {
Optional<List<JCStatement>> binding = inliner.getOptionalBinding(placeholder().blockKey());
// If a placeholder was used as an expression binding in the @BeforeTemplate,
// and as a bare statement or as a return in the @AfterTemplate, we may need to convert.
Optional<JCExpression> exprBinding = inliner.getOptionalBinding(placeholder().exprKey());
binding =
binding.or(
exprBinding.transform(
(JCExpression expr) -> {
switch (implementationFlow()) {
case NEVER_EXITS:
return List.of((JCStatement) inliner.maker().Exec(expr));
case ALWAYS_RETURNS:
return List.of((JCStatement) inliner.maker().Return(expr));
default:
throw new AssertionError();
}
}));
return UPlaceholderExpression.copier(arguments(), inliner).copy(binding.get(), inliner);
} catch (UncheckedCouldNotResolveImportException e) {
throw e.getCause();
}
}
}
代码示例来源:origin: robolectric/robolectric
private static JCMethodInvocation createSyntheticShadowAccess(
MethodInvocationTree shadowOfCall,
String newFieldName,
Symbol originalSymbol,
VisitorState state) {
TreeMaker treeMaker = state.getTreeMaker();
Symbol newSymbol = createSymbol(originalSymbol, state.getName(newFieldName),
((JCExpression) shadowOfCall.getArguments().get(0)).type);
JCExpression methodSelect = (JCExpression) shadowOfCall.getMethodSelect();
if (methodSelect instanceof JCIdent) {
// clone so start pos can be changed...
methodSelect = treeMaker.Ident(((JCIdent) shadowOfCall.getMethodSelect()).sym);
}
JCMethodInvocation callShadowOf =
treeMaker.Apply(
null,
methodSelect,
com.sun.tools.javac.util.List.of(createIdent(treeMaker, newSymbol)));
callShadowOf.type = ((JCMethodInvocation) shadowOfCall).type;
return callShadowOf;
}
代码示例来源:origin: robolectric/robolectric
private JCMethodInvocation createSyntheticShadowAccess(VisitorState state) {
TreeMaker treeMaker = state.getTreeMaker();
JCExpression application =
treeMaker.Select(
treeMaker.Ident(findSymbol(state, "org.robolectric.RuntimeEnvironment")),
findSymbol(state, "org.robolectric.RuntimeEnvironment", "application"));
JCExpression shadowOfApp =
treeMaker.Select(
treeMaker.Ident(findSymbol(state, "org.robolectric.Shadows")),
findSymbol(state, "org.robolectric.Shadows", "shadowOf(android.app.Application)"));
JCMethodInvocation callShadowOf =
treeMaker.Apply(null, shadowOfApp, com.sun.tools.javac.util.List.of(application));
callShadowOf.type = callShadowOf.meth.type;
return callShadowOf;
}
代码示例来源:origin: google/error-prone
.apply(
UnifierWithUnconsumedStatements.create(
unifierAfterCond, List.of(ifTree.getThenStatement())))
.thenOption(
(UnifierWithUnconsumedStatements stateAfterThen) ->
代码示例来源:origin: org.jvnet.sorcerer/sorcerer-javac
/** Construct a list consisting of given elements.
*/
public static <A> List<A> of(A x1, A x2) {
return new List<A>(x1, of(x2));
}
代码示例来源:origin: org.kohsuke.sorcerer/sorcerer-javac
/** Append given element at length, forming and returning
* a new list.
*/
public List<A> append(A x) {
return of(x).prependList(this);
}
代码示例来源:origin: org.kohsuke.sorcerer/sorcerer-javac
List<Comment> addComment(List<Comment> comments, Comment comment) {
return comments == null ?
List.of(comment) :
comments.prepend(comment);
}
代码示例来源:origin: org.jvnet.sorcerer/sorcerer-javac
/**
* A convenience wrapper for {@link #makeCompoundType(List)}; the
* arguments are converted to a list and passed to the other
* method. Note that this might cause a symbol completion.
* Hence, this version of makeCompoundType may not be called
* during a classfile read.
*/
public Type makeCompoundType(Type bound1, Type bound2) {
return makeCompoundType(List.of(bound1, bound2));
}
// </editor-fold>
代码示例来源:origin: org.jvnet.sorcerer/sorcerer-javac
/**
* Gets a localized string from the compiler's default bundle.
*/
// used to support legacy Log.getLocalizedString
static String getDefaultLocalizedString(String key, Object... args) {
return getLocalizedString(List.of(getDefaultBundle()), key, args);
}
代码示例来源:origin: com.android.tools.external.lombok/lombok-ast
private boolean set(Node node, JCTree value) {
if (result != null) throw new IllegalStateException("result is already set");
JCTree actualValue = value;
if (node instanceof Expression) {
for (int i = 0; i < ((Expression)node).getIntendedParens(); i++) {
actualValue = treeMaker.Parens((JCExpression)actualValue);
posParen(node, i, ((Expression)node).astParensPositions(), actualValue);
}
}
result = List.of(actualValue);
return true;
}
代码示例来源:origin: org.jvnet.sorcerer/sorcerer-javac
public Iterable<? extends File> getLocation(Location location) {
nullCheck(location);
paths.lazy();
if (location == CLASS_OUTPUT) {
return (getClassOutDir() == null ? null : List.of(getClassOutDir()));
} else if (location == SOURCE_OUTPUT) {
return (getSourceOutDir() == null ? null : List.of(getSourceOutDir()));
} else
return paths.getPathForLocation(location);
}
代码示例来源:origin: org.jvnet.sorcerer/sorcerer-javac
@Override
public List<Type> visitTypeVar(TypeVar t, Void ignored) {
if (t.bound.isCompound())
return interfaces(t.bound);
if (t.bound.isInterface())
return List.of(t.bound);
return List.nil();
}
};
代码示例来源:origin: org.kohsuke.sorcerer/sorcerer-javac
/** Generate a base clause for an enum type.
* @param pos The position for trees and diagnostics, if any
* @param c The class symbol of the enum
*/
private JCExpression enumBase(int pos, ClassSymbol c) {
JCExpression result = make.at(pos).
TypeApply(make.QualIdent(syms.enumSym),
List.<JCExpression>of(make.Type(c.type)));
return result;
}
代码示例来源:origin: org.jvnet.sorcerer/sorcerer-javac
/** Generate a base clause for an enum type.
* @param pos The position for trees and diagnostics, if any
* @param c The class symbol of the enum
*/
private JCExpression enumBase(int pos, ClassSymbol c) {
JCExpression result = make.at(pos).
TypeApply(make.QualIdent(syms.enumSym),
List.<JCExpression>of(make.Type(c.type)));
return result;
}
代码示例来源:origin: org.jvnet.sorcerer/sorcerer-javac
static Type makeClassType(Types types, Type type) {
Type arg = type.isPrimitive()
? types.boxedClass(type).type
: types.erasure(type);
return new Type.ClassType(types.syms.classType.getEnclosingType(),
List.of(arg),
types.syms.classType.tsym);
}
public String toString() {
代码示例来源:origin: org.kohsuke.sorcerer/sorcerer-javac
@Override
protected Symbol lookup(Env<AttrContext> env, MethodResolutionPhase phase) {
Scope sc = new Scope(syms.arrayClass);
MethodSymbol arrayConstr = new MethodSymbol(PUBLIC, name, null, site.tsym);
arrayConstr.type = new MethodType(List.<Type>of(syms.intType), site, List.<Type>nil(), syms.methodClass);
sc.enter(arrayConstr);
return findMethodInScope(env, site, name, argtypes, typeargtypes, sc, methodNotFound, phase.isBoxingRequired(), phase.isVarargsRequired(), false, false);
}
代码示例来源:origin: systems.manifold/manifold-ext
private Symbol.MethodSymbol findReflectUtilConstructor( JCTree.JCNewClass tree )
{
Symtab symtab = _tp.getSymtab();
Type.ArrayType classArrayType = new Type.ArrayType( symtab.classType, symtab.arrayClass );
Type.ArrayType objectArrayType = new Type.ArrayType( symtab.objectType, symtab.arrayClass );
List<Type> paramTypes = List.of( symtab.classType, classArrayType, objectArrayType );
Symbol.ClassSymbol reflectMethodClassSym =
IDynamicJdk.instance().getTypeElement( _tp.getContext(), _tp.getCompilationUnit(), ReflectionRuntimeMethods.class.getName() );
Names names = Names.instance( _tp.getContext() );
return resolveMethod( tree.pos(), names.fromString( "construct" ), reflectMethodClassSym.type, paramTypes );
}
内容来源于网络,如有侵权,请联系作者删除!