Java Code Examples for com.sun.tools.javac.tree.JCTree.JCVariableDecl

The following examples show how to use com.sun.tools.javac.tree.JCTree.JCVariableDecl. These examples are extracted from open source projects. 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 Project: EasyMPermission   Source File: JavacAST.java    License: MIT License 6 votes vote down vote up
/** {@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);
	}
}
 
Example 2
@Override
public boolean process(final Set<? extends TypeElement> annotations, final RoundEnvironment roundEnv) {
	Set<? extends Element> fields = roundEnv.getElementsAnnotatedWith(Multiline.class);
	for (Element field : fields) {
		String docComment = elementUtils.getDocComment(field);
		if (null != docComment) {
			Multiline annotation = field.getAnnotation(Multiline.class);
			if(annotation.trim()){
				docComment=comments.matcher(docComment).replaceAll(" ");
				docComment=docComment.replaceAll("\\s+"," ");
				docComment=docComment.replaceAll(" ?([={}<>;,+\\-]) ?","$1");
			}

			JCVariableDecl fieldNode = (JCVariableDecl) elementUtils.getTree(field);
			fieldNode.init = maker.Literal(docComment);
		}
	}
	return true;
}
 
Example 3
Source Project: EasyMPermission   Source File: JavacHandlerUtil.java    License: MIT License 6 votes vote down vote up
/**
 * 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;
}
 
Example 4
Source Project: lua-for-android   Source File: Flow.java    License: BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/** Complain that pending exceptions are not caught.
 */
void errorUncaught() {
    for (FlowPendingExit exit = pendingExits.next();
         exit != null;
         exit = pendingExits.next()) {
        if (classDef != null &&
            classDef.pos == exit.tree.pos) {
            log.error(exit.tree.pos(),
                      Errors.UnreportedExceptionDefaultConstructor(exit.thrown));
        } else if (exit.tree.hasTag(VARDEF) &&
                ((JCVariableDecl)exit.tree).sym.isResourceVariable()) {
            log.error(exit.tree.pos(),
                      Errors.UnreportedExceptionImplicitClose(exit.thrown,
                                                              ((JCVariableDecl)exit.tree).sym.name));
        } else {
            log.error(exit.tree.pos(),
                      Errors.UnreportedExceptionNeedToCatchOrThrow(exit.thrown));
        }
    }
}
 
Example 5
Source Project: EasyMPermission   Source File: HandleSneakyThrows.java    License: MIT License 6 votes vote down vote up
public JCStatement buildTryCatchBlock(JavacNode node, List<JCStatement> contents, String exception, JCTree source) {
	JavacTreeMaker maker = node.getTreeMaker();
	
	Context context = node.getContext();
	JCBlock tryBlock = setGeneratedBy(maker.Block(0, contents), source, context);
	JCExpression varType = chainDots(node, exception.split("\\."));
	
	JCVariableDecl catchParam = maker.VarDef(maker.Modifiers(Flags.FINAL | Flags.PARAMETER), node.toName("$ex"), varType, null);
	JCExpression lombokLombokSneakyThrowNameRef = chainDots(node, "lombok", "Lombok", "sneakyThrow");
	JCBlock catchBody = maker.Block(0, List.<JCStatement>of(maker.Throw(maker.Apply(
			List.<JCExpression>nil(), lombokLombokSneakyThrowNameRef,
			List.<JCExpression>of(maker.Ident(node.toName("$ex")))))));
	JCTry tryStatement = maker.Try(tryBlock, List.of(recursiveSetGeneratedBy(maker.Catch(catchParam, catchBody), source, context)), null);
	if (JavacHandlerUtil.inNetbeansEditor(node)) {
		//set span (start and end position) of the try statement and the main block
		//this allows NetBeans to dive into the statement correctly:
		JCCompilationUnit top = (JCCompilationUnit) node.top().get();
		int startPos = contents.head.pos;
		int endPos = Javac.getEndPosition(contents.last().pos(), top);
		tryBlock.pos = startPos;
		tryStatement.pos = startPos;
		Javac.storeEnd(tryBlock, endPos, top);
		Javac.storeEnd(tryStatement, endPos, top);
	}
	return setGeneratedBy(tryStatement, source, context);
}
 
Example 6
List<JCVariableDecl> freevarDefs(int pos, List<VarSymbol> freevars, Symbol owner,
        long additionalFlags) {
    long flags = FINAL | SYNTHETIC | additionalFlags;
    List<JCVariableDecl> defs = List.nil();
    Set<Name> proxyNames = new HashSet<>();
    for (List<VarSymbol> l = freevars; l.nonEmpty(); l = l.tail) {
        VarSymbol v = l.head;
        int index = 0;
        Name proxyName;
        do {
            proxyName = proxyName(v.name, index++);
        } while (!proxyNames.add(proxyName));
        VarSymbol proxy = new VarSymbol(
            flags, proxyName, v.erasure(types), owner);
        proxies.put(v, proxy);
        JCVariableDecl vd = make.at(pos).VarDef(proxy, null);
        vd.vartype = access(vd.vartype);
        defs = defs.prepend(vd);
    }
    return defs;
}
 
Example 7
RewritingContext(
        JCTree originalTree,
        JCTree oldTree,
        JCTree replacement,
        StatementAnalyzer<JCTree, JCTree> analyzer,
        Env<AttrContext> env) {
    this.originalTree = originalTree;
    this.oldTree = oldTree;
    this.replacement = replacement;
    this.analyzer = analyzer;
    this.env = attr.copyEnv(env);
    /*  this is a temporary workaround that should be removed once we have a truly independent
     *  clone operation
     */
    if (originalTree.hasTag(VARDEF)) {
        // avoid redefinition clashes
        this.env.info.scope.remove(((JCVariableDecl)originalTree).sym);
    }
}
 
Example 8
void checkReceiver(JCVariableDecl tree, Env<AttrContext> localEnv) {
    attr.attribExpr(tree.nameexpr, localEnv);
    MethodSymbol m = localEnv.enclMethod.sym;
    if (m.isConstructor()) {
        Type outertype = m.owner.owner.type;
        if (outertype.hasTag(TypeTag.METHOD)) {
            // we have a local inner class
            outertype = m.owner.owner.owner.type;
        }
        if (outertype.hasTag(TypeTag.CLASS)) {
            checkType(tree.vartype, outertype, "incorrect.constructor.receiver.type");
            checkType(tree.nameexpr, outertype, "incorrect.constructor.receiver.name");
        } else {
            log.error(tree, Errors.ReceiverParameterNotApplicableConstructorToplevelClass);
        }
    } else {
        checkType(tree.vartype, m.owner.type, "incorrect.receiver.type");
        checkType(tree.nameexpr, m.owner.type, "incorrect.receiver.name");
    }
}
 
Example 9
Source Project: EasyMPermission   Source File: HandleFieldDefaults.java    License: MIT License 6 votes vote down vote up
public void setFieldDefaultsForField(JavacNode fieldNode, DiagnosticPosition pos, 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)) {
			field.mods.flags |= Flags.FINAL;
		}
	}
	
	fieldNode.rebuild();
}
 
Example 10
Source Project: openjdk-8-source   Source File: Symbol.java    License: GNU General Public License v2.0 5 votes vote down vote up
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);
        }
    });
}
 
Example 11
Source Project: openjdk-jdk8u   Source File: GenStubs.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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;
}
 
Example 12
Source Project: j2cl   Source File: CompilationUnitBuilder.java    License: Apache License 2.0 5 votes vote down vote up
private VariableDeclarationFragment createVariableDeclarationFragment(
    JCVariableDecl variableDeclaration) {
  Variable variable = createVariable(variableDeclaration, false);
  return VariableDeclarationFragment.newBuilder()
      .setVariable(variable)
      .setInitializer(convertExpressionOrNull(variableDeclaration.getInitializer()))
      .build();
}
 
Example 13
Source Project: j2cl   Source File: CompilationUnitBuilder.java    License: Apache License 2.0 5 votes vote down vote up
private VariableDeclarationExpression toResource(JCTree resourceTree) {
  if (resourceTree.getTag() == Tag.VARDEF) {
    return createVariableDeclarationExpression((JCVariableDecl) resourceTree);
  }
  checkArgument(resourceTree.getTag() == Tag.IDENT);
  return toResource((JCIdent) resourceTree);
}
 
Example 14
Source Project: EasyMPermission   Source File: JavacAST.java    License: MIT License 5 votes vote down vote up
private JavacNode buildField(JCVariableDecl field) {
	if (setAndGetAsHandled(field)) return null;
	List<JavacNode> childNodes = new ArrayList<JavacNode>();
	for (JCAnnotation annotation : field.mods.annotations) addIfNotNull(childNodes, buildAnnotation(annotation, true));
	addIfNotNull(childNodes, buildExpression(field.init));
	return putInMap(new JavacNode(this, field, childNodes, Kind.FIELD));
}
 
Example 15
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;
    }
}
 
Example 16
Source Project: j2cl   Source File: CompilationUnitBuilder.java    License: Apache License 2.0 5 votes vote down vote up
private List<Expression> convertVariableDeclarations(List<JCStatement> statements) {
  return ImmutableList.of(
      VariableDeclarationExpression.newBuilder()
          .addVariableDeclarationFragments(
              statements.stream()
                  .map(s -> createVariableDeclarationFragment((JCVariableDecl) s))
                  .collect(toImmutableList()))
          .build());
}
 
Example 17
Source Project: EasyMPermission   Source File: HandleBuilder.java    License: MIT License 5 votes vote down vote up
private void makeSimpleSetterMethodForBuilder(JavacNode builderType, JavacNode fieldNode, JavacNode source, boolean fluent, boolean chain) {
	Name fieldName = ((JCVariableDecl) fieldNode.get()).name;
	
	for (JavacNode child : builderType.down()) {
		if (child.getKind() != Kind.METHOD) continue;
		Name existingName = ((JCMethodDecl) child.get()).name;
		if (existingName.equals(fieldName)) return;
	}
	
	String setterName = fluent ? fieldNode.getName() : HandlerUtil.buildAccessorName("set", fieldNode.getName());
	
	JavacTreeMaker maker = fieldNode.getTreeMaker();
	JCMethodDecl newMethod = HandleSetter.createSetter(Flags.PUBLIC, fieldNode, maker, setterName, chain, source, List.<JCAnnotation>nil(), List.<JCAnnotation>nil());
	injectMethod(builderType, newMethod);
}
 
Example 18
Source Project: EasyMPermission   Source File: HandleBuilder.java    License: MIT License 5 votes vote down vote up
public void generateBuilderFields(JavacNode builderType, java.util.List<BuilderFieldData> builderFields, JCTree source) {
	int len = builderFields.size();
	java.util.List<JavacNode> existing = new ArrayList<JavacNode>();
	for (JavacNode child : builderType.down()) {
		if (child.getKind() == Kind.FIELD) existing.add(child);
	}
	
	top:
	for (int i = len - 1; i >= 0; i--) {
		BuilderFieldData bfd = builderFields.get(i);
		if (bfd.singularData != null && bfd.singularData.getSingularizer() != null) {
			bfd.createdFields.addAll(bfd.singularData.getSingularizer().generateFields(bfd.singularData, builderType, source));
		} else {
			for (JavacNode exists : existing) {
				Name n = ((JCVariableDecl) exists.get()).name;
				if (n.equals(bfd.name)) {
					bfd.createdFields.add(exists);
					continue top;
				}
			}
			JavacTreeMaker maker = builderType.getTreeMaker();
			JCModifiers mods = maker.Modifiers(Flags.PRIVATE);
			JCVariableDecl newField = maker.VarDef(mods, bfd.name, cloneType(maker, bfd.type, source, builderType.getContext()), null);
			bfd.createdFields.add(injectFieldAndMarkGenerated(builderType, newField));
		}
	}
}
 
Example 19
Source Project: EasyMPermission   Source File: PrettyCommentsPrinter.java    License: MIT License 5 votes vote down vote up
public void visitVarDef(JCVariableDecl tree) {
	try {
		boolean suppressSemi = suppressFinalAndSemicolonsInTry;
		if (getJavadocFor(tree) != null) {
			println(); align();
		}
		printDocComment(tree);
		if ((tree.mods.flags & ENUM) != 0) {
			printEnumMember(tree);
		} else {
			printExpr(tree.mods);
			if ((tree.mods.flags & VARARGS) != 0) {
				printExpr(((JCArrayTypeTree) tree.vartype).elemtype);
				print("... " + tree.name);
			} else {
				printExpr(tree.vartype);
				print(" " + tree.name);
			}
			if (tree.init != null) {
				print(" = ");
				printExpr(tree.init);
			}
			if (prec == TreeInfo.notExpression && !suppressSemi) print(";");
		}
	} catch (IOException e) {
		throw new UncheckedIOException(e);
	}
}
 
Example 20
Source Project: EasyMPermission   Source File: JavacAST.java    License: MIT License 5 votes vote down vote up
private JavacNode buildLocalVar(JCVariableDecl local, Kind kind) {
	if (setAndGetAsHandled(local)) return null;
	List<JavacNode> childNodes = new ArrayList<JavacNode>();
	for (JCAnnotation annotation : local.mods.annotations) addIfNotNull(childNodes, buildAnnotation(annotation, true));
	addIfNotNull(childNodes, buildExpression(local.init));
	return putInMap(new JavacNode(this, local, childNodes, kind));
}
 
Example 21
Source Project: lua-for-android   Source File: Flow.java    License: BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void visitLambda(JCLambda tree) {
    final Bits prevUninits = new Bits(uninits);
    final Bits prevInits = new Bits(inits);
    int returnadrPrev = returnadr;
    int nextadrPrev = nextadr;
    ListBuffer<AssignPendingExit> prevPending = pendingExits;
    try {
        returnadr = nextadr;
        pendingExits = new ListBuffer<>();
        for (List<JCVariableDecl> l = tree.params; l.nonEmpty(); l = l.tail) {
            JCVariableDecl def = l.head;
            scan(def);
            inits.incl(def.sym.adr);
            uninits.excl(def.sym.adr);
        }
        if (tree.getBodyKind() == JCLambda.BodyKind.EXPRESSION) {
            scanExpr(tree.body);
        } else {
            scan(tree.body);
        }
    }
    finally {
        returnadr = returnadrPrev;
        uninits.assign(prevUninits);
        inits.assign(prevInits);
        pendingExits = prevPending;
        nextadr = nextadrPrev;
    }
}
 
Example 22
/** Definition for this$n field.
 *  @param pos        The source code position of the definition.
 *  @param owner      The method in which the definition goes.
 */
JCVariableDecl outerThisDef(int pos, MethodSymbol owner) {
    ClassSymbol c = owner.enclClass();
    boolean isMandated =
        // Anonymous constructors
        (owner.isConstructor() && owner.isAnonymous()) ||
        // Constructors of non-private inner member classes
        (owner.isConstructor() && c.isInner() &&
         !c.isPrivate() && !c.isStatic());
    long flags =
        FINAL | (isMandated ? MANDATED : SYNTHETIC) | PARAMETER;
    VarSymbol outerThis = makeOuterThisVarSymbol(owner, flags);
    owner.extraParams = owner.extraParams.prepend(outerThis);
    return makeOuterThisVarDecl(pos, outerThis);
}
 
Example 23
private JCStatement makeTwrCloseStatement(Symbol primaryException, JCExpression resource) {
    // primaryException.addSuppressed(catchException);
    VarSymbol catchException =
        new VarSymbol(SYNTHETIC, make.paramName(2),
                      syms.throwableType,
                      currentMethodSym);
    JCStatement addSuppressionStatement =
        make.Exec(makeCall(make.Ident(primaryException),
                           names.addSuppressed,
                           List.of(make.Ident(catchException))));

    // try { resource.close(); } catch (e) { primaryException.addSuppressed(e); }
    JCBlock tryBlock =
        make.Block(0L, List.of(makeResourceCloseInvocation(resource)));
    JCVariableDecl catchExceptionDecl = make.VarDef(catchException, null);
    JCBlock catchBlock = make.Block(0L, List.of(addSuppressionStatement));
    List<JCCatch> catchClauses = List.of(make.Catch(catchExceptionDecl, catchBlock));
    JCTry tryTree = make.Try(tryBlock, catchClauses, null);
    tryTree.finallyCanCompleteNormally = true;

    // if (primaryException != null) {try...} else resourceClose;
    JCIf closeIfStatement = make.If(makeNonNullCheck(make.Ident(primaryException)),
                                    tryTree,
                                    makeResourceCloseInvocation(resource));

    return closeIfStatement;
}
 
Example 24
/** Construct an expression using the builder, with the given rval
 *  expression as an argument to the builder.  However, the rval
 *  expression must be computed only once, even if used multiple
 *  times in the result of the builder.  We do that by
 *  constructing a "let" expression that saves the rvalue into a
 *  temporary variable and then uses the temporary variable in
 *  place of the expression built by the builder.  The complete
 *  resulting expression is of the form
 *  <pre>
 *    (let <b>TYPE</b> <b>TEMP</b> = <b>RVAL</b>;
 *     in (<b>BUILDER</b>(<b>TEMP</b>)))
 *  </pre>
 *  where <code><b>TEMP</b></code> is a newly declared variable
 *  in the let expression.
 */
JCExpression abstractRval(JCExpression rval, Type type, TreeBuilder builder) {
    rval = TreeInfo.skipParens(rval);
    switch (rval.getTag()) {
    case LITERAL:
        return builder.build(rval);
    case IDENT:
        JCIdent id = (JCIdent) rval;
        if ((id.sym.flags() & FINAL) != 0 && id.sym.owner.kind == MTH)
            return builder.build(rval);
    }
    Name name = TreeInfo.name(rval);
    if (name == names._super || name == names._this)
        return builder.build(rval);
    VarSymbol var =
        new VarSymbol(FINAL|SYNTHETIC,
                      names.fromString(
                                      target.syntheticNameChar()
                                      + "" + rval.hashCode()),
                                  type,
                                  currentMethodSym);
    rval = convert(rval,type);
    JCVariableDecl def = make.VarDef(var, rval); // XXX cast
    JCExpression built = builder.build(make.Ident(var));
    JCExpression res = make.LetExpr(def, built);
    res.type = built.type;
    return res;
}
 
Example 25
Source Project: EasyMPermission   Source File: JavacHandlerUtil.java    License: MIT License 5 votes vote down vote up
/**
 * Returns if a field is marked deprecated, either by {@code @Deprecated} or in javadoc
 * @param field the field to check
 * @return {@code true} if a field is marked deprecated, either by {@code @Deprecated} or in javadoc, otherwise {@code false}
 */
public static boolean isFieldDeprecated(JavacNode field) {
	JCVariableDecl fieldNode = (JCVariableDecl) field.get();
	if ((fieldNode.mods.flags & Flags.DEPRECATED) != 0) {
		return true;
	}
	for (JavacNode child : field.down()) {
		if (annotationTypeMatches(Deprecated.class, child)) {
			return true;
		}
	}
	return false;
}
 
Example 26
Source Project: EasyMPermission   Source File: JavacGuavaSingularizer.java    License: MIT License 5 votes vote down vote up
@Override public java.util.List<JavacNode> generateFields(SingularData data, JavacNode builderType, JCTree source) {
	JavacTreeMaker maker = builderType.getTreeMaker();
	JCExpression type = JavacHandlerUtil.chainDots(builderType, "com", "google", "common", "collect", getSimpleTargetTypeName(data), "Builder");
	type = addTypeArgs(isMap() ? 2 : 1, false, builderType, type, data.getTypeArgs(), source);
	
	JCVariableDecl buildField = maker.VarDef(maker.Modifiers(Flags.PRIVATE), data.getPluralName(), type, null);
	return Collections.singletonList(injectFieldAndMarkGenerated(builderType, buildField));
}
 
Example 27
boolean canLambdaBodyCompleteNormally(JCLambda tree) {
    List<JCVariableDecl> oldParams = tree.params;
    LocalCacheContext localCacheContext = argumentAttr.withLocalCacheContext();
    try {
        tree.params = StreamSupport.stream(tree.params)
                .map(vd -> make.VarDef(vd.mods, vd.name, make.Erroneous(), null))
                .collect(List.collector());
        return attribSpeculativeLambda(tree, env, attr.unknownExprInfo).canCompleteNormally;
    } finally {
        localCacheContext.leave();
        tree.params = oldParams;
    }
}
 
Example 28
/**
 * Analyze results of local variable inference.
 */
void processVar(JCVariableDecl oldTree, JCVariableDecl newTree, boolean hasErrors) {
    if (!hasErrors) {
        if (types.isSameType(oldTree.type, newTree.type)) {
            log.warning(oldTree, Warnings.LocalRedundantType);
        }
    }
}
 
Example 29
Source Project: EasyMPermission   Source File: JavacAST.java    License: MIT License 5 votes vote down vote up
private JavacNode buildMethod(JCMethodDecl method) {
	if (setAndGetAsHandled(method)) return null;
	List<JavacNode> childNodes = new ArrayList<JavacNode>();
	for (JCAnnotation annotation : method.mods.annotations) addIfNotNull(childNodes, buildAnnotation(annotation, false));
	for (JCVariableDecl param : method.params) addIfNotNull(childNodes, buildLocalVar(param, Kind.ARGUMENT));
	if (method.body != null && method.body.stats != null) {
		for (JCStatement statement : method.body.stats) addIfNotNull(childNodes, buildStatement(statement));
	}
	return putInMap(new JavacNode(this, method, childNodes, Kind.METHOD));
}
 
Example 30
Source Project: bazel   Source File: TreePruner.java    License: Apache License 2.0 5 votes vote down vote up
private static boolean isFinal(JCClassDecl enclClass, JCVariableDecl tree) {
  if ((tree.mods.flags & Flags.FINAL) == Flags.FINAL) {
    return true;
  }
  if (enclClass != null && (enclClass.mods.flags & (Flags.ANNOTATION | Flags.INTERFACE)) != 0) {
    // Fields in annotation declarations and interfaces are implicitly final
    return true;
  }
  return false;
}