本文整理汇总了Java中com.sun.tools.javac.tree.JCTree.JCModifiers类的典型用法代码示例。如果您正苦于以下问题:Java JCModifiers类的具体用法?Java JCModifiers怎么用?Java JCModifiers使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
JCModifiers类属于com.sun.tools.javac.tree.JCTree包,在下文中一共展示了JCModifiers类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: rewriteChildren
import com.sun.tools.javac.tree.JCTree.JCModifiers; //导入依赖的package包/类
protected final MethodTree rewriteChildren(MethodTree tree) {
ModifiersTree mods = (ModifiersTree)translate(tree.getModifiers());
ExpressionTree restype = (ExpressionTree)translateClassRef(tree.getReturnType());
List<? extends TypeParameterTree> typarams = translateStable(tree.getTypeParameters());
List<? extends VariableTree> params = translateStable(tree.getParameters());
List<? extends ExpressionTree> thrown = translate(tree.getThrows());
ExpressionTree defaultValue = (ExpressionTree)translate(tree.getDefaultValue());
BlockTree body = (BlockTree)translate(tree.getBody());
if (restype!=tree.getReturnType() || !typarams.equals(tree.getTypeParameters()) ||
!params.equals(tree.getParameters()) || !thrown.equals(tree.getThrows()) ||
mods!=tree.getModifiers() || defaultValue!=tree.getDefaultValue() ||
body!=tree.getBody()) {
if ((((JCModifiers) mods).flags & Flags.GENERATEDCONSTR) != 0) {
mods = make.Modifiers(((JCModifiers) mods).flags & ~Flags.GENERATEDCONSTR, mods.getAnnotations());
}
MethodTree n = make.Method(mods, tree.getName().toString(), restype, typarams,
params, thrown, body, defaultValue);
copyCommentTo(tree,n);
copyPosTo(tree,n);
tree = n;
}
return tree;
}
示例2: addModifiersModifier
import com.sun.tools.javac.tree.JCTree.JCModifiers; //导入依赖的package包/类
public ModifiersTree addModifiersModifier(ModifiersTree modifiers, Modifier modifier) {
long c = ((JCModifiers) modifiers).flags & ~Flags.GENERATEDCONSTR;
switch (modifier) {
case ABSTRACT: c = c | Flags.ABSTRACT; break;
case FINAL: c = c | Flags.FINAL; break;
case NATIVE: c = c | Flags.NATIVE; break;
case PRIVATE: c = c | Flags.PRIVATE; break;
case PROTECTED: c = c | Flags.PROTECTED; break;
case PUBLIC: c = c | Flags.PUBLIC; break;
case STATIC: c = c | Flags.STATIC; break;
case STRICTFP: c = c | Flags.STRICTFP; break;
case SYNCHRONIZED: c = c | Flags.SYNCHRONIZED; break;
case TRANSIENT: c = c | Flags.TRANSIENT; break;
case VOLATILE: c = c | Flags.VOLATILE; break;
case DEFAULT: c = c | Flags.DEFAULT; break;
default:
break;
}
return Modifiers(c, modifiers.getAnnotations());
}
示例3: removeModifiersModifier
import com.sun.tools.javac.tree.JCTree.JCModifiers; //导入依赖的package包/类
public ModifiersTree removeModifiersModifier(ModifiersTree modifiers, Modifier modifier) {
long c = ((JCModifiers) modifiers).flags & ~Flags.GENERATEDCONSTR;
switch (modifier) {
case ABSTRACT: c = c & ~Flags.ABSTRACT; break;
case FINAL: c = c & ~Flags.FINAL; break;
case NATIVE: c = c & ~Flags.NATIVE; break;
case PRIVATE: c = c & ~Flags.PRIVATE; break;
case PROTECTED: c = c & ~Flags.PROTECTED; break;
case PUBLIC: c = c & ~Flags.PUBLIC; break;
case STATIC: c = c & ~Flags.STATIC; break;
case STRICTFP: c = c & ~Flags.STRICTFP; break;
case SYNCHRONIZED: c = c & ~Flags.SYNCHRONIZED; break;
case TRANSIENT: c = c & ~Flags.TRANSIENT; break;
case VOLATILE: c = c & ~Flags.VOLATILE; break;
case DEFAULT: c = c & ~Flags.DEFAULT; break;
default:
break;
}
return Modifiers(c, modifiers.getAnnotations());
}
示例4: printModifierKeywords
import com.sun.tools.javac.tree.JCTree.JCModifiers; //导入依赖的package包/类
private void printModifierKeywords(JCModifiers tree) {
long v = flagMod & tree.flags;
flagMod = -1L;
if ((v & SYNTHETIC) != 0) print("/* synthetic */ ");
if ((v & PUBLIC) != 0) print("public ");
if ((v & PRIVATE) != 0) print("private ");
if ((v & PROTECTED) != 0) print("protected ");
if ((v & STATIC) != 0) print("static ");
if ((v & FINAL) != 0) print("final ");
if ((v & SYNCHRONIZED) != 0) print("synchronized ");
if ((v & VOLATILE) != 0) print("volatile ");
if ((v & TRANSIENT) != 0) print("transient ");
if ((v & NATIVE) != 0) print("native ");
if ((v & ABSTRACT) != 0) print("abstract ");
if ((v & STRICTFP) != 0) print("strictfp ");
if ((v & DEFAULT) != 0 && (v & INTERFACE) == 0) print("default ");
}
示例5: createCanEqual
import com.sun.tools.javac.tree.JCTree.JCModifiers; //导入依赖的package包/类
public JCMethodDecl createCanEqual(JavacNode typeNode, JCTree source, List<JCAnnotation> onParam) {
/* protected boolean canEqual(final java.lang.Object other) {
* return other instanceof Outer.Inner.MyType;
* }
*/
JavacTreeMaker maker = typeNode.getTreeMaker();
JCModifiers mods = maker.Modifiers(Flags.PROTECTED, List.<JCAnnotation>nil());
JCExpression returnType = maker.TypeIdent(CTC_BOOLEAN);
Name canEqualName = typeNode.toName("canEqual");
JCExpression objectType = genJavaLangTypeRef(typeNode, "Object");
Name otherName = typeNode.toName("other");
long flags = JavacHandlerUtil.addFinalIfNeeded(Flags.PARAMETER, typeNode.getContext());
List<JCVariableDecl> params = List.of(maker.VarDef(maker.Modifiers(flags, onParam), otherName, objectType, null));
JCBlock body = maker.Block(0, List.<JCStatement>of(
maker.Return(maker.TypeTest(maker.Ident(otherName), createTypeReference(typeNode)))));
return recursiveSetGeneratedBy(maker.MethodDef(mods, canEqualName, returnType, List.<JCTypeParameter>nil(), params, List.<JCExpression>nil(), body, null), source, typeNode.getContext());
}
示例6: generateClearMethod
import com.sun.tools.javac.tree.JCTree.JCModifiers; //导入依赖的package包/类
private void generateClearMethod(JavacTreeMaker maker, JCExpression returnType, JCStatement returnStatement, SingularData data, JavacNode builderType, JCTree source) {
JCModifiers mods = maker.Modifiers(Flags.PUBLIC);
List<JCTypeParameter> typeParams = List.nil();
List<JCExpression> thrown = List.nil();
List<JCVariableDecl> params = List.nil();
List<JCExpression> jceBlank = List.nil();
JCExpression thisDotKeyField = chainDots(builderType, "this", data.getPluralName() + "$key");
JCExpression thisDotKeyFieldDotClear = chainDots(builderType, "this", data.getPluralName() + "$key", "clear");
JCExpression thisDotValueFieldDotClear = chainDots(builderType, "this", data.getPluralName() + "$value", "clear");
JCStatement clearKeyCall = maker.Exec(maker.Apply(jceBlank, thisDotKeyFieldDotClear, jceBlank));
JCStatement clearValueCall = maker.Exec(maker.Apply(jceBlank, thisDotValueFieldDotClear, jceBlank));
JCExpression cond = maker.Binary(CTC_NOT_EQUAL, thisDotKeyField, maker.Literal(CTC_BOT, null));
JCBlock clearCalls = maker.Block(0, List.of(clearKeyCall, clearValueCall));
JCStatement ifSetCallClear = maker.If(cond, clearCalls, null);
List<JCStatement> statements = returnStatement != null ? List.of(ifSetCallClear, returnStatement) : List.of(ifSetCallClear);
JCBlock body = maker.Block(0, statements);
Name methodName = builderType.toName(HandlerUtil.buildAccessorName("clear", data.getPluralName().toString()));
JCMethodDecl method = maker.MethodDef(mods, methodName, returnType, typeParams, params, thrown, body, null);
injectMethod(builderType, method);
}
示例7: generateClearMethod
import com.sun.tools.javac.tree.JCTree.JCModifiers; //导入依赖的package包/类
private void generateClearMethod(JavacTreeMaker maker, JCExpression returnType, JCStatement returnStatement, SingularData data, JavacNode builderType, JCTree source) {
JCModifiers mods = maker.Modifiers(Flags.PUBLIC);
List<JCTypeParameter> typeParams = List.nil();
List<JCExpression> thrown = List.nil();
List<JCVariableDecl> params = List.nil();
List<JCExpression> jceBlank = List.nil();
JCExpression thisDotField = maker.Select(maker.Ident(builderType.toName("this")), data.getPluralName());
JCExpression thisDotFieldDotClear = maker.Select(maker.Select(maker.Ident(builderType.toName("this")), data.getPluralName()), builderType.toName("clear"));
JCStatement clearCall = maker.Exec(maker.Apply(jceBlank, thisDotFieldDotClear, jceBlank));
JCExpression cond = maker.Binary(CTC_NOT_EQUAL, thisDotField, maker.Literal(CTC_BOT, null));
JCStatement ifSetCallClear = maker.If(cond, clearCall, null);
List<JCStatement> statements = returnStatement != null ? List.of(ifSetCallClear, returnStatement) : List.of(ifSetCallClear);
JCBlock body = maker.Block(0, statements);
Name methodName = builderType.toName(HandlerUtil.buildAccessorName("clear", data.getPluralName().toString()));
JCMethodDecl method = maker.MethodDef(mods, methodName, returnType, typeParams, params, thrown, body, null);
injectMethod(builderType, method);
}
示例8: generateSingularMethod
import com.sun.tools.javac.tree.JCTree.JCModifiers; //导入依赖的package包/类
void generateSingularMethod(JavacTreeMaker maker, JCExpression returnType, JCStatement returnStatement, SingularData data, JavacNode builderType, JCTree source, boolean fluent) {
List<JCTypeParameter> typeParams = List.nil();
List<JCExpression> thrown = List.nil();
JCModifiers mods = maker.Modifiers(Flags.PUBLIC);
ListBuffer<JCStatement> statements = new ListBuffer<JCStatement>();
statements.append(createConstructBuilderVarIfNeeded(maker, data, builderType, false, source));
JCExpression thisDotFieldDotAdd = chainDots(builderType, "this", data.getPluralName().toString(), "add");
JCExpression invokeAdd = maker.Apply(List.<JCExpression>nil(), thisDotFieldDotAdd, List.<JCExpression>of(maker.Ident(data.getSingularName())));
statements.append(maker.Exec(invokeAdd));
if (returnStatement != null) statements.append(returnStatement);
JCBlock body = maker.Block(0, statements.toList());
Name name = data.getSingularName();
long paramFlags = JavacHandlerUtil.addFinalIfNeeded(Flags.PARAMETER, builderType.getContext());
if (!fluent) name = builderType.toName(HandlerUtil.buildAccessorName("add", name.toString()));
JCExpression paramType = cloneParamType(0, maker, data.getTypeArgs(), builderType, source);
JCVariableDecl param = maker.VarDef(maker.Modifiers(paramFlags), data.getSingularName(), paramType, null);
JCMethodDecl method = maker.MethodDef(mods, name, returnType, typeParams, List.of(param), thrown, body, null);
injectMethod(builderType, method);
}
示例9: generatePluralMethod
import com.sun.tools.javac.tree.JCTree.JCModifiers; //导入依赖的package包/类
void generatePluralMethod(JavacTreeMaker maker, JCExpression returnType, JCStatement returnStatement, SingularData data, JavacNode builderType, JCTree source, boolean fluent) {
List<JCTypeParameter> typeParams = List.nil();
List<JCExpression> thrown = List.nil();
JCModifiers mods = maker.Modifiers(Flags.PUBLIC);
ListBuffer<JCStatement> statements = new ListBuffer<JCStatement>();
statements.append(createConstructBuilderVarIfNeeded(maker, data, builderType, false, source));
JCExpression thisDotFieldDotAdd = chainDots(builderType, "this", data.getPluralName().toString(), "addAll");
JCExpression invokeAdd = maker.Apply(List.<JCExpression>nil(), thisDotFieldDotAdd, List.<JCExpression>of(maker.Ident(data.getPluralName())));
statements.append(maker.Exec(invokeAdd));
if (returnStatement != null) statements.append(returnStatement);
JCBlock body = maker.Block(0, statements.toList());
Name name = data.getPluralName();
long paramFlags = JavacHandlerUtil.addFinalIfNeeded(Flags.PARAMETER, builderType.getContext());
if (!fluent) name = builderType.toName(HandlerUtil.buildAccessorName("addAll", name.toString()));
JCExpression paramType = chainDots(builderType, "java", "util", "Collection");
paramType = addTypeArgs(1, true, builderType, paramType, data.getTypeArgs(), source);
JCVariableDecl param = maker.VarDef(maker.Modifiers(paramFlags), data.getPluralName(), paramType, null);
JCMethodDecl method = maker.MethodDef(mods, name, returnType, typeParams, List.of(param), thrown, body, null);
injectMethod(builderType, method);
}
示例10: createCanEqual
import com.sun.tools.javac.tree.JCTree.JCModifiers; //导入依赖的package包/类
public JCMethodDecl createCanEqual(JavacNode typeNode, JCTree source, List<JCAnnotation> onParam) {
/* public boolean canEqual(final java.lang.Object other) {
* return other instanceof Outer.Inner.MyType;
* }
*/
JavacTreeMaker maker = typeNode.getTreeMaker();
JCModifiers mods = maker.Modifiers(Flags.PROTECTED, List.<JCAnnotation>nil());
JCExpression returnType = maker.TypeIdent(CTC_BOOLEAN);
Name canEqualName = typeNode.toName("canEqual");
JCExpression objectType = genJavaLangTypeRef(typeNode, "Object");
Name otherName = typeNode.toName("other");
long flags = JavacHandlerUtil.addFinalIfNeeded(Flags.PARAMETER, typeNode.getContext());
List<JCVariableDecl> params = List.of(maker.VarDef(maker.Modifiers(flags, onParam), otherName, objectType, null));
JCBlock body = maker.Block(0, List.<JCStatement>of(
maker.Return(maker.TypeTest(maker.Ident(otherName), createTypeReference(typeNode)))));
return recursiveSetGeneratedBy(maker.MethodDef(mods, canEqualName, returnType, List.<JCTypeParameter>nil(), params, List.<JCExpression>nil(), body, null), source, typeNode.getContext());
}
示例11: visitAnnotationDeclaration
import com.sun.tools.javac.tree.JCTree.JCModifiers; //导入依赖的package包/类
@Override
public boolean visitAnnotationDeclaration(AnnotationDeclaration node) {
JCModifiers modifiers = (JCModifiers) toTree(node.astModifiers());
modifiers.flags |= Flags.INTERFACE | Flags.ANNOTATION;
int start = posOfStructure(node, "interface", true);
int end = node.getPosition().getEnd();
if (hasSourceStructures()) {
if (modifiers.pos == -1) modifiers.pos = posOfStructure(node, "@", true);
endPosTable.put(modifiers, posOfStructure(node, "@", false));
}
return set(node, setPos(start, end, treeMaker.ClassDef(
modifiers,
toName(node.astName()),
List.<JCTypeParameter>nil(),
null,
List.<JCExpression>nil(),
node.astBody() == null ? List.<JCTree>nil() : toList(JCTree.class, node.astBody().astMembers())
)));
}
示例12: visitAnnotationMethodDeclaration
import com.sun.tools.javac.tree.JCTree.JCModifiers; //导入依赖的package包/类
@Override
public boolean visitAnnotationMethodDeclaration(AnnotationMethodDeclaration node) {
JCMethodDecl methodDef = treeMaker.MethodDef(
(JCModifiers)toTree(node.astModifiers()),
toName(node.astMethodName()),
toExpression(node.astReturnTypeReference()),
List.<JCTypeParameter>nil(),
List.<JCVariableDecl>nil(),
List.<JCExpression>nil(),
null,
toExpression(node.astDefaultValue())
);
int start = node.astMethodName().getPosition().getStart();
int end = node.getPosition().getEnd();
return set(node, setPos(start, end, methodDef));
}
示例13: visitMethodDeclaration
import com.sun.tools.javac.tree.JCTree.JCModifiers; //导入依赖的package包/类
@Override
public boolean visitMethodDeclaration(MethodDeclaration node) {
JCMethodDecl methodDef = treeMaker.MethodDef(
(JCModifiers)toTree(node.astModifiers()),
toName(node.astMethodName()),
toExpression(node.astReturnTypeReference()),
toList(JCTypeParameter.class, node.astTypeVariables()),
toList(JCVariableDecl.class, node.astParameters()),
toList(JCExpression.class, node.astThrownTypeReferences()),
(JCBlock)toTree(node.astBody()),
null
);
for (JCVariableDecl decl : methodDef.params) {
decl.mods.flags |= Flags.PARAMETER;
}
int start = node.astMethodName().getPosition().getStart();
int end = node.getPosition().getEnd();
return set(node, setPos(start, end, methodDef));
}
示例14: visitConstructorDeclaration
import com.sun.tools.javac.tree.JCTree.JCModifiers; //导入依赖的package包/类
@Override
public boolean visitConstructorDeclaration(ConstructorDeclaration node) {
JCMethodDecl constrDef = treeMaker.MethodDef(
(JCModifiers)toTree(node.astModifiers()),
table.init, null,
toList(JCTypeParameter.class, node.astTypeVariables()),
toList(JCVariableDecl.class, node.astParameters()),
toList(JCExpression.class, node.astThrownTypeReferences()),
(JCBlock)toTree(node.astBody()),
null
);
for (JCVariableDecl decl : constrDef.params) {
decl.mods.flags |= Flags.PARAMETER;
}
int start = node.astTypeName().getPosition().getStart();
int end = node.getPosition().getEnd();
return set(node, setPos(start, end, constrDef));
}
示例15: fixByModifyingMethod
import com.sun.tools.javac.tree.JCTree.JCModifiers; //导入依赖的package包/类
private Description fixByModifyingMethod(
VisitorState state, JCClassDecl enclosingClass, MethodTree method) {
JCModifiers methodModifiers = ((JCMethodDecl) method).getModifiers();
String replacementModifiersString = createReplacementMethodModifiers(state, methodModifiers);
JCModifiers enclosingClassModifiers = enclosingClass.getModifiers();
String enclosingClassReplacementModifiersString =
createReplacementClassModifiers(state, enclosingClassModifiers);
SuggestedFix.Builder fixBuilder =
SuggestedFix.builder()
.addImport("dagger.multibindings.Multibinds")
.replace(methodModifiers, replacementModifiersString)
.replace(method.getBody(), ";");
fixBuilder =
(enclosingClassModifiers.pos == -1)
? fixBuilder.prefixWith(enclosingClass, enclosingClassReplacementModifiersString)
: fixBuilder.replace(enclosingClassModifiers, enclosingClassReplacementModifiersString);
return describeMatch(method, fixBuilder.build());
}