private void handleVarDef(final JCVariableDecl node, final boolean endStatement) { final TreePath path = trees.getPath(compilationUnit, node); final TypeMirror typeMirror = trees.getElement(path).asType(); printExpr(node.mods); print(substitutionInventory.applyTypeSubstitution(typeMirror)); print(" "); print(node.name); // variable name if (node.init != null) { print(" = "); printExpr(node.init); } if (endStatement) { print(";"); } }
private static boolean createField(LoggingFramework framework, JavacNode typeNode, JCFieldAccess loggingType, JCTree source, String logFieldName, boolean useStatic, String loggerTopic) { JavacTreeMaker maker = typeNode.getTreeMaker(); // private static final <loggerType> log = <factoryMethod>(<parameter>); JCExpression loggerType = chainDotsString(typeNode, framework.getLoggerTypeName()); JCExpression factoryMethod = chainDotsString(typeNode, framework.getLoggerFactoryMethodName()); JCExpression loggerName; if (loggerTopic == null || loggerTopic.trim().length() == 0) { loggerName = framework.createFactoryParameter(typeNode, loggingType); } else { loggerName = maker.Literal(loggerTopic); } JCMethodInvocation factoryMethodCall = maker.Apply(List.<JCExpression>nil(), factoryMethod, List.<JCExpression>of(loggerName)); JCVariableDecl fieldDecl = recursiveSetGeneratedBy(maker.VarDef( maker.Modifiers(Flags.PRIVATE | Flags.FINAL | (useStatic ? Flags.STATIC : 0)), typeNode.toName(logFieldName), loggerType, factoryMethodCall), source, typeNode.getContext()); injectFieldAndMarkGenerated(typeNode, fieldDecl); return true; }
@Override public void visitVarDef(JCVariableDecl tree) { boolean isJavacPack = tree.sym.outermostClass().fullname.toString() .contains(packageToCheck); if (isJavacPack && (tree.sym.flags() & SYNTHETIC) == 0 && tree.sym.owner.kind == TYP) { if (!ignoreField(tree.sym.owner.flatName().toString(), tree.getName().toString())) { boolean enumClass = (tree.sym.owner.flags() & ENUM) != 0; boolean nonFinalStaticEnumField = (tree.sym.flags() & (ENUM | FINAL)) == 0; boolean nonFinalStaticField = (tree.sym.flags() & STATIC) != 0 && (tree.sym.flags() & FINAL) == 0; if (enumClass ? nonFinalStaticEnumField : nonFinalStaticField) { messages.error(tree, "crules.err.var.must.be.final", tree); } } } super.visitVarDef(tree); }
String applySubstitutions(final VariableElement element) { final JCVariableDecl tree = (JCVariableDecl)trees.getTree(element); if (tree.init != null) { final StringWriter writer = new StringWriter(); final SubstitutingPretty visitor = new SubstitutingPretty( writer, ImmutableSet.of(), trees.getPath(element).getCompilationUnit(), false); visitor.printExpr(tree.init); return writer.toString(); } return ""; }
@Override public void visitVarDef(final JCVariableDecl node) { // Note: The behavior here is to break out list definitions such as: // // int x = 0, y = 1; // // to separate statements: // // int x = 0; // int y = 1; // // Places where this can't be done, // e.g. for loops, will call handleVarDef directly so that this // visitor method does not get invoked. handleVarDef(node, true); }
@Override public void visitForLoop(final JCForLoop node) { print("for ("); if (node.init.nonEmpty()) { if (node.init.head instanceof JCVariableDecl) { handleVarDef((JCVariableDecl)node.init.head, false); for (List<JCStatement> l = node.init.tail; l.nonEmpty(); l = l.tail) { final JCVariableDecl decl = (JCVariableDecl)l.head; print(", " + decl.name + " = "); printExpr(decl.init); } } else { printExprs(node.init); } } print("; "); if (node.cond != null) { printExpr(node.cond); } print("; "); printExprs(node.step); print(") "); printStat(node.body); }
/** {@inheritDoc} */ @Override protected JavacNode buildTree(JCTree node, Kind kind) { switch (kind) { case COMPILATION_UNIT: return buildCompilationUnit((JCCompilationUnit) node); case TYPE: return buildType((JCClassDecl) node); case FIELD: return buildField((JCVariableDecl) node); case INITIALIZER: return buildInitializer((JCBlock) node); case METHOD: return buildMethod((JCMethodDecl) node); case ARGUMENT: return buildLocalVar((JCVariableDecl) node, kind); case LOCAL: return buildLocalVar((JCVariableDecl) node, kind); case STATEMENT: return buildStatementOrExpression(node); case ANNOTATION: return buildAnnotation((JCAnnotation) node, false); default: throw new AssertionError("Did not expect: " + kind); } }
private JavacNode buildType(JCClassDecl type) { if (setAndGetAsHandled(type)) return null; List<JavacNode> childNodes = new ArrayList<JavacNode>(); for (JCAnnotation annotation : type.mods.annotations) addIfNotNull(childNodes, buildAnnotation(annotation, false)); for (JCTree def : type.defs) { /* A def can be: * JCClassDecl for inner types * JCMethodDecl for constructors and methods * JCVariableDecl for fields * JCBlock for (static) initializers */ if (def instanceof JCMethodDecl) addIfNotNull(childNodes, buildMethod((JCMethodDecl)def)); else if (def instanceof JCClassDecl) addIfNotNull(childNodes, buildType((JCClassDecl)def)); else if (def instanceof JCVariableDecl) addIfNotNull(childNodes, buildField((JCVariableDecl)def)); else if (def instanceof JCBlock) addIfNotNull(childNodes, buildInitializer((JCBlock)def)); } return putInMap(new JavacNode(this, type, childNodes, Kind.TYPE)); }
public static List<JavacNode> findFields(JavacNode typeNode, boolean nullMarked) { ListBuffer<JavacNode> fields = new ListBuffer<JavacNode>(); for (JavacNode child : typeNode.down()) { if (child.getKind() != Kind.FIELD) continue; JCVariableDecl fieldDecl = (JCVariableDecl) child.get(); //Skip fields that start with $ if (fieldDecl.name.toString().startsWith("$")) continue; long fieldFlags = fieldDecl.mods.flags; //Skip static fields. if ((fieldFlags & Flags.STATIC) != 0) continue; boolean isFinal = (fieldFlags & Flags.FINAL) != 0; boolean isNonNull = nullMarked && !findAnnotations(child, NON_NULL_PATTERN).isEmpty(); if ((isFinal || isNonNull) && fieldDecl.init == null) fields.append(child); } return fields.toList(); }
public static List<JavacNode> findAllFields(JavacNode typeNode) { ListBuffer<JavacNode> fields = new ListBuffer<JavacNode>(); for (JavacNode child : typeNode.down()) { if (child.getKind() != Kind.FIELD) continue; JCVariableDecl fieldDecl = (JCVariableDecl) child.get(); //Skip fields that start with $ if (fieldDecl.name.toString().startsWith("$")) continue; long fieldFlags = fieldDecl.mods.flags; //Skip static fields. if ((fieldFlags & Flags.STATIC) != 0) continue; //Skip initialized final fields boolean isFinal = (fieldFlags & Flags.FINAL) != 0; if (!isFinal || fieldDecl.init == null) fields.append(child); } return fields.toList(); }
public void setFieldDefaultsForField(JavacNode fieldNode, AccessLevel level, boolean makeFinal) { JCVariableDecl field = (JCVariableDecl) fieldNode.get(); if (level != null && level != AccessLevel.NONE) { if ((field.mods.flags & (Flags.PUBLIC | Flags.PRIVATE | Flags.PROTECTED)) == 0) { if (!hasAnnotationAndDeleteIfNeccessary(PackagePrivate.class, fieldNode)) { field.mods.flags |= toJavacModifier(level); } } } if (makeFinal && (field.mods.flags & Flags.FINAL) == 0) { if (!hasAnnotationAndDeleteIfNeccessary(NonFinal.class, fieldNode)) { if ((field.mods.flags & Flags.STATIC) == 0 || field.init != null) { field.mods.flags |= Flags.FINAL; } } } fieldNode.rebuild(); }
/** * Checks if there is a field with the provided name. * * @param fieldName the field name to check for. * @param node Any node that represents the Type (JCClassDecl) to look in, or any child node thereof. */ public static MemberExistsResult fieldExists(String fieldName, JavacNode node) { node = upToTypeNode(node); if (node != null && node.get() instanceof JCClassDecl) { for (JCTree def : ((JCClassDecl)node.get()).defs) { if (def instanceof JCVariableDecl) { if (((JCVariableDecl)def).name.contentEquals(fieldName)) { return getGeneratedBy(def) == null ? MemberExistsResult.EXISTS_BY_USER : MemberExistsResult.EXISTS_BY_LOMBOK; } } } } return MemberExistsResult.NOT_EXISTS; }
/** * Given a list of field names and a node referring to a type, finds each name in the list that does not match a field within the type. */ public static List<Integer> createListOfNonExistentFields(List<String> list, JavacNode type, boolean excludeStandard, boolean excludeTransient) { boolean[] matched = new boolean[list.size()]; for (JavacNode child : type.down()) { if (list.isEmpty()) break; if (child.getKind() != Kind.FIELD) continue; JCVariableDecl field = (JCVariableDecl)child.get(); if (excludeStandard) { if ((field.mods.flags & Flags.STATIC) != 0) continue; if (field.name.toString().startsWith("$")) continue; } if (excludeTransient && (field.mods.flags & Flags.TRANSIENT) != 0) continue; int idx = list.indexOf(child.getName()); if (idx > -1) matched[idx] = true; } ListBuffer<Integer> problematic = new ListBuffer<Integer>(); for (int i = 0 ; i < list.size() ; i++) { if (!matched[i]) problematic.append(i); } return problematic.toList(); }
private JCMethodDecl generateCleanMethod(java.util.List<BuilderFieldData> builderFields, JavacNode type, JCTree source) { JavacTreeMaker maker = type.getTreeMaker(); ListBuffer<JCStatement> statements = new ListBuffer<JCStatement>(); for (BuilderFieldData bfd : builderFields) { if (bfd.singularData != null && bfd.singularData.getSingularizer() != null) { bfd.singularData.getSingularizer().appendCleaningCode(bfd.singularData, type, source, statements); } } statements.append(maker.Exec(maker.Assign(maker.Select(maker.Ident(type.toName("this")), type.toName("$lombokUnclean")), maker.Literal(CTC_BOOLEAN, false)))); JCBlock body = maker.Block(0, statements.toList()); return maker.MethodDef(maker.Modifiers(Flags.PUBLIC), type.toName("$lombokClean"), maker.Type(Javac.createVoidType(maker, CTC_VOID)), List.<JCTypeParameter>nil(), List.<JCVariableDecl>nil(), List.<JCExpression>nil(), body, null); /* * if (shouldReturnThis) { methodType = cloneSelfType(field); } if (methodType == null) { //WARNING: Do not use field.getSymbolTable().voidType - that field has gone through non-backwards compatible API changes within javac1.6. methodType = treeMaker.Type(Javac.createVoidType(treeMaker, CTC_VOID)); shouldReturnThis = false; } */ }
public JCMethodDecl generateBuilderMethod(boolean isStatic, String builderMethodName, String builderClassName, JavacNode type, List<JCTypeParameter> typeParams) { JavacTreeMaker maker = type.getTreeMaker(); ListBuffer<JCExpression> typeArgs = new ListBuffer<JCExpression>(); for (JCTypeParameter typeParam : typeParams) { typeArgs.append(maker.Ident(typeParam.name)); } JCExpression call = maker.NewClass(null, List.<JCExpression>nil(), namePlusTypeParamsToTypeReference(maker, type.toName(builderClassName), typeParams), List.<JCExpression>nil(), null); JCStatement statement = maker.Return(call); JCBlock body = maker.Block(0, List.<JCStatement>of(statement)); int modifiers = Flags.PUBLIC; if (isStatic) modifiers |= Flags.STATIC; return maker.MethodDef(maker.Modifiers(modifiers), type.toName(builderMethodName), namePlusTypeParamsToTypeReference(maker, type.toName(builderClassName), typeParams), copyTypeParams(maker, typeParams), List.<JCVariableDecl>nil(), List.<JCExpression>nil(), body, null); }
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()); }
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); }
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); }
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); }
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); }
public <R, D> R accept(TreeVisitor<R, D> arg0, D arg1) { R ret = null; for (JCVariableDecl v : vars) { ret = v.accept(arg0, arg1); } return ret; }
protected int diffVarDef(JCVariableDecl oldT, JCVariableDecl newT, int pos) { int localPointer = oldT.pos; copyTo(pos, localPointer); if (nameChanged(oldT.name, newT.name)) { copyTo(localPointer, oldT.pos); printer.print(newT.name); diffInfo.put(oldT.pos, NbBundle.getMessage(CasualDiff.class,"TXT_RenameVariable",oldT.name)); localPointer = oldT.pos + oldT.name.length(); } if (newT.init != null && oldT.init != null) { copyTo(localPointer, localPointer = getOldPos(oldT.init)); localPointer = diffTree(oldT.init, newT.init, new int[] { localPointer, endPos(oldT.init) }); } else { if (oldT.init != null && newT.init == null) { // remove initial value pos = getOldPos(oldT.init); tokenSequence.move(pos); moveToSrcRelevant(tokenSequence, Direction.BACKWARD); moveToSrcRelevant(tokenSequence, Direction.BACKWARD); tokenSequence.moveNext(); int to = tokenSequence.offset(); copyTo(localPointer, to); localPointer = endPos(oldT.init); } if (oldT.init == null && newT.init != null) { int end = endPos(oldT); tokenSequence.move(end); moveToSrcRelevant(tokenSequence, Direction.BACKWARD); copyTo(localPointer, localPointer = tokenSequence.offset()); printer.printVarInit(newT); } } copyTo(localPointer, localPointer = endPos(oldT)); return localPointer; }
private DocCommentTree getDocComment(JCTree t, boolean old) { if (t instanceof FieldGroupTree) { FieldGroupTree fgt = (FieldGroupTree)t; List<JCVariableDecl> vars = fgt.getVariables(); t = vars.get(0); } return old ? oldTopLevel.docComments.getCommentTree(t) : tree2Doc.get(t); }
private boolean isCommaSeparated(JCVariableDecl oldT) { if (getOldPos(oldT) <= 0 || oldT.pos <= 0) { return false; } tokenSequence.move(oldT.pos); moveToSrcRelevant(tokenSequence, Direction.BACKWARD); if (tokenSequence.token() == null) { return false; } if (JavaTokenId.COMMA == tokenSequence.token().id()) { return true; } if (oldT.getInitializer() != null && (oldT.mods.flags & Flags.ENUM) == 0) { tokenSequence.move(endPos(oldT.getInitializer())); } else { tokenSequence.move(oldT.pos); tokenSequence.moveNext(); } moveToSrcRelevant(tokenSequence, Direction.FORWARD); if (tokenSequence.token() == null) { return false; } if (JavaTokenId.COMMA == tokenSequence.token().id()) { return true; } return false; }
@Override public Void visitVariable(VariableTree node, Void p) { JCVariableDecl varDecl = (JCVariableDecl) node; if (varDecl.sym != null && active && varDecl.sym.pos >= 0) { varDecl.sym.pos += delta; } return super.visitVariable(node, p); }
@Override public void visitVarDef(JCVariableDecl tree) { cancelService.abortIfCanceled(); JCExpression init = tree.init; try { super.visitVarDef(tree); } finally { //reinstall init: tree.init = init; } }
public void visitLambda(JCLambda tree) { JCLambda prevLambda = currentLambda; try { currentLambda = tree; int i = 0; for (JCVariableDecl param : tree.params) { if (!param.mods.annotations.isEmpty()) { // Nothing to do for separateAnnotationsKinds if // there are no annotations of either kind. TypeAnnotationPosition pos = new TypeAnnotationPosition(); pos.type = TargetType.METHOD_FORMAL_PARAMETER; pos.parameter_index = i; pos.pos = param.vartype.pos; pos.onLambda = tree; separateAnnotationsKinds(param.vartype, param.sym.type, param.sym, pos); } ++i; } push(tree); scan(tree.body); scan(tree.params); pop(); } finally { currentLambda = prevLambda; } }
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); } }); }
/** * field definitions: replace initializers with 0, 0.0, false etc * when possible -- i.e. leave public, protected initializers alone */ @Override public void visitVarDef(JCVariableDecl tree) { tree.mods = translate(tree.mods); tree.vartype = translate(tree.vartype); if (tree.init != null) { if ((tree.mods.flags & (Flags.PUBLIC | Flags.PROTECTED)) != 0) tree.init = translate(tree.init); else { String t = tree.vartype.toString(); if (t.equals("boolean")) tree.init = new JCLiteral(TypeTag.BOOLEAN, 0) { }; else if (t.equals("byte")) tree.init = new JCLiteral(TypeTag.BYTE, 0) { }; else if (t.equals("char")) tree.init = new JCLiteral(TypeTag.CHAR, 0) { }; else if (t.equals("double")) tree.init = new JCLiteral(TypeTag.DOUBLE, 0.d) { }; else if (t.equals("float")) tree.init = new JCLiteral(TypeTag.FLOAT, 0.f) { }; else if (t.equals("int")) tree.init = new JCLiteral(TypeTag.INT, 0) { }; else if (t.equals("long")) tree.init = new JCLiteral(TypeTag.LONG, 0) { }; else if (t.equals("short")) tree.init = new JCLiteral(TypeTag.SHORT, 0) { }; else tree.init = new JCLiteral(TypeTag.BOT, null) { }; } } result = tree; }
@Override @DefinedBy(Api.COMPILER_TREE) public TypeMirror getLub(CatchTree tree) { JCCatch ct = (JCCatch) tree; JCVariableDecl v = ct.param; if (v.type != null && v.type.getKind() == TypeKind.UNION) { UnionClassType ut = (UnionClassType) v.type; return ut.getLub(); } else { return v.type; } }
public void visitLambda(JCLambda tree) { JCLambda prevLambda = currentLambda; try { currentLambda = tree; int i = 0; for (JCVariableDecl param : tree.params) { if (!param.mods.annotations.isEmpty()) { // Nothing to do for separateAnnotationsKinds if // there are no annotations of either kind. final TypeAnnotationPosition pos = TypeAnnotationPosition .methodParameter(tree, i, param.vartype.pos); push(param); try { separateAnnotationsKinds(param.vartype, param.sym.type, param.sym, pos); } finally { pop(); } } ++i; } scan(tree.body); scan(tree.params); } finally { currentLambda = prevLambda; } }
@Override JCLambda map (JCNewClass oldTree, JCNewClass newTree){ JCMethodDecl md = (JCMethodDecl)decls(newTree.def).head; List<JCVariableDecl> params = md.params; JCBlock body = md.body; return make.Lambda(params, body); }
AnalysisContext(JCTree tree, Env<AttrContext> env) { this.tree = tree; this.env = attr.copyEnv(env); /* this is a temporary workaround that should be removed once we have a truly independent * clone operation */ if (tree.hasTag(VARDEF)) { // avoid redefinition clashes this.env.info.scope.remove(((JCVariableDecl)tree).sym); } }