com.sun.tools.javac.tree.JCTree.JCTypeParameter Java Examples

The following examples show how to use com.sun.tools.javac.tree.JCTree.JCTypeParameter. 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 File: JavacJavaUtilListSetSingularizer.java    From EasyMPermission with MIT License 6 votes vote down vote up
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);
}
 
Example #2
Source File: JavacJavaUtilListSetSingularizer.java    From EasyMPermission with MIT License 6 votes vote down vote up
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);
}
 
Example #3
Source File: HandleEqualsAndHashCode.java    From EasyMPermission with MIT License 6 votes vote down vote up
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());
}
 
Example #4
Source File: HandleBuilder.java    From EasyMPermission with MIT License 6 votes vote down vote up
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;
	}

	 */
}
 
Example #5
Source File: JavacHandlerUtil.java    From EasyMPermission with MIT License 6 votes vote down vote up
public static JCExpression cloneSelfType(JavacNode childOfType) {
	JavacNode typeNode = childOfType;
	JavacTreeMaker maker = childOfType.getTreeMaker();
	while (typeNode != null && typeNode.getKind() != Kind.TYPE) typeNode = typeNode.up();
	if (typeNode != null && typeNode.get() instanceof JCClassDecl) {
		JCClassDecl type = (JCClassDecl) typeNode.get();
		ListBuffer<JCExpression> typeArgs = new ListBuffer<JCExpression>();
		if (!type.typarams.isEmpty()) {
			for (JCTypeParameter tp : type.typarams) {
				typeArgs.append(maker.Ident(tp.name));
			}
			return maker.TypeApply(maker.Ident(type.name), typeArgs.toList());
		} else {
			return maker.Ident(type.name);
		}
	} else {
		return null;
	}
}
 
Example #6
Source File: HandleUtilityClass.java    From EasyMPermission with MIT License 5 votes vote down vote up
private void createPrivateDefaultConstructor(JavacNode typeNode) {
	JavacTreeMaker maker = typeNode.getTreeMaker();
	JCModifiers mods = maker.Modifiers(Flags.PRIVATE, List.<JCAnnotation>nil());
	
	Name name = typeNode.toName("<init>");
	JCBlock block = maker.Block(0L, createThrowStatement(typeNode, maker));
	JCMethodDecl methodDef = maker.MethodDef(mods, name, null, List.<JCTypeParameter>nil(), List.<JCVariableDecl>nil(), List.<JCExpression>nil(), block, null);
	JCMethodDecl constructor = recursiveSetGeneratedBy(methodDef, typeNode.get(), typeNode.getContext());
	JavacHandlerUtil.injectMethod(typeNode, constructor);
}
 
Example #7
Source File: UMethodDecl.java    From Refaster with Apache License 2.0 5 votes vote down vote up
@Override
public JCMethodDecl inline(Inliner inliner) throws CouldNotResolveImportException {
  return inliner.maker().MethodDef(
      getModifiers().inline(inliner),
      inliner.asName(name()),
      getReturnType().inline(inliner),
      List.<JCTypeParameter>nil(),
      List.convert(JCVariableDecl.class, inliner.inlineList(getParameters())),
      inliner.inlineList(getThrows()),
      getBody().inline(inliner),
      null);
}
 
Example #8
Source File: JavacGuavaSingularizer.java    From EasyMPermission with MIT License 5 votes vote down vote up
protected 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();
	boolean mapMode = isMap();
	
	JCModifiers mods = maker.Modifiers(Flags.PUBLIC);
	ListBuffer<JCStatement> statements = new ListBuffer<JCStatement>();
	statements.append(createConstructBuilderVarIfNeeded(maker, data, builderType, mapMode, source));
	JCExpression thisDotFieldDotAddAll = chainDots(builderType, "this", data.getPluralName().toString(), mapMode ? "putAll" : "addAll");
	JCExpression invokeAddAll = maker.Apply(List.<JCExpression>nil(), thisDotFieldDotAddAll, List.<JCExpression>of(maker.Ident(data.getPluralName())));
	statements.append(maker.Exec(invokeAddAll));
	if (returnStatement != null) statements.append(returnStatement);
	JCBlock body = maker.Block(0, statements.toList());
	Name methodName = data.getPluralName();
	long paramFlags = JavacHandlerUtil.addFinalIfNeeded(Flags.PARAMETER, builderType.getContext());
	if (!fluent) methodName = builderType.toName(HandlerUtil.buildAccessorName(mapMode ? "putAll" : "addAll", methodName.toString()));
	JCExpression paramType;
	if (mapMode) {
		paramType = chainDots(builderType, "java", "util", "Map");
	} else {
		paramType = genJavaLangTypeRef(builderType, "Iterable");
	}
	paramType = addTypeArgs(mapMode ? 2 : 1, true, builderType, paramType, data.getTypeArgs(), source);
	JCVariableDecl param = maker.VarDef(maker.Modifiers(paramFlags), data.getPluralName(), paramType, null);
	JCMethodDecl method = maker.MethodDef(mods, methodName, returnType, typeParams, List.of(param), thrown, body, null);
	injectMethod(builderType, method);
}
 
Example #9
Source File: JavacGuavaSingularizer.java    From EasyMPermission with MIT License 5 votes vote down vote up
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();
	boolean mapMode = isMap();
	
	Name keyName = !mapMode ? data.getSingularName() : builderType.toName(data.getSingularName() + "$key");
	Name valueName = !mapMode ? null : builderType.toName(data.getSingularName() + "$value");
	
	JCModifiers mods = maker.Modifiers(Flags.PUBLIC);
	ListBuffer<JCStatement> statements = new ListBuffer<JCStatement>();
	statements.append(createConstructBuilderVarIfNeeded(maker, data, builderType, mapMode, source));
	JCExpression thisDotFieldDotAdd = chainDots(builderType, "this", data.getPluralName().toString(), mapMode ? "put" : "add");
	List<JCExpression> invokeAddExpr;
	if (mapMode) {
		invokeAddExpr = List.<JCExpression>of(maker.Ident(keyName), maker.Ident(valueName));
	} else {
		invokeAddExpr = List.<JCExpression>of(maker.Ident(keyName));
	}
	JCExpression invokeAdd = maker.Apply(List.<JCExpression>nil(), thisDotFieldDotAdd, invokeAddExpr);
	statements.append(maker.Exec(invokeAdd));
	if (returnStatement != null) statements.append(returnStatement);
	JCBlock body = maker.Block(0, statements.toList());
	Name methodName = data.getSingularName();
	long paramFlags = JavacHandlerUtil.addFinalIfNeeded(Flags.PARAMETER, builderType.getContext());
	if (!fluent) methodName = builderType.toName(HandlerUtil.buildAccessorName(mapMode ? "put" : "add", methodName.toString()));
	List<JCVariableDecl> params;
	if (mapMode) {
		JCExpression keyType = cloneParamType(0, maker, data.getTypeArgs(), builderType, source);
		JCExpression valueType = cloneParamType(1, maker, data.getTypeArgs(), builderType, source);
		JCVariableDecl paramKey = maker.VarDef(maker.Modifiers(paramFlags), keyName, keyType, null);
		JCVariableDecl paramValue = maker.VarDef(maker.Modifiers(paramFlags), valueName, valueType, null);
		params = List.of(paramKey, paramValue);
	} else {
		JCExpression paramType = cloneParamType(0, maker, data.getTypeArgs(), builderType, source);
		params = List.of(maker.VarDef(maker.Modifiers(paramFlags), data.getSingularName(), paramType, null));
	}
	JCMethodDecl method = maker.MethodDef(mods, methodName, returnType, typeParams, params, thrown, body, null);
	injectMethod(builderType, method);
}
 
Example #10
Source File: JavacJavaUtilMapSingularizer.java    From EasyMPermission with MIT License 5 votes vote down vote up
private void generatePluralMethod(JavacTreeMaker maker, JCExpression returnType, JCStatement returnStatement, SingularData data, JavacNode builderType, JCTree source, boolean fluent) {
	List<JCTypeParameter> typeParams = List.nil();
	List<JCExpression> jceBlank = List.nil();
	JCModifiers mods = maker.Modifiers(Flags.PUBLIC);
	ListBuffer<JCStatement> statements = new ListBuffer<JCStatement>();
	statements.append(createConstructBuilderVarIfNeeded(maker, data, builderType, true, source));
	long paramFlags = JavacHandlerUtil.addFinalIfNeeded(Flags.PARAMETER, builderType.getContext());
	long baseFlags = JavacHandlerUtil.addFinalIfNeeded(0, builderType.getContext());
	Name entryName = builderType.toName("$lombokEntry");
	
	JCExpression forEachType = chainDots(builderType, "java", "util", "Map", "Entry");
	forEachType = addTypeArgs(2, true, builderType, forEachType, data.getTypeArgs(), source);
	JCExpression keyArg = maker.Apply(List.<JCExpression>nil(), maker.Select(maker.Ident(entryName), builderType.toName("getKey")), List.<JCExpression>nil());
	JCExpression valueArg = maker.Apply(List.<JCExpression>nil(), maker.Select(maker.Ident(entryName), builderType.toName("getValue")), List.<JCExpression>nil());
	JCExpression addKey = maker.Apply(List.<JCExpression>nil(), chainDots(builderType, "this", data.getPluralName() + "$key", "add"), List.of(keyArg));
	JCExpression addValue = maker.Apply(List.<JCExpression>nil(), chainDots(builderType, "this", data.getPluralName() + "$value", "add"), List.of(valueArg));
	JCBlock forEachBody = maker.Block(0, List.<JCStatement>of(maker.Exec(addKey), maker.Exec(addValue)));
	JCExpression entrySetInvocation = maker.Apply(jceBlank, maker.Select(maker.Ident(data.getPluralName()), builderType.toName("entrySet")), jceBlank);
	JCStatement forEach = maker.ForeachLoop(maker.VarDef(maker.Modifiers(baseFlags), entryName, forEachType, null), entrySetInvocation, forEachBody);
	statements.append(forEach);
	
	if (returnStatement != null) statements.append(returnStatement);
	JCBlock body = maker.Block(0, statements.toList());
	Name name = data.getPluralName();
	if (!fluent) name = builderType.toName(HandlerUtil.buildAccessorName("putAll", name.toString()));
	JCExpression paramType = chainDots(builderType, "java", "util", "Map");
	paramType = addTypeArgs(2, 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), jceBlank, body, null);
	injectMethod(builderType, method);
}
 
Example #11
Source File: HandleBuilder.java    From EasyMPermission with MIT License 5 votes vote down vote up
public JCMethodDecl generateBuilderMethod(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));
	return maker.MethodDef(maker.Modifiers(Flags.STATIC | Flags.PUBLIC), type.toName(builderMethodName), namePlusTypeParamsToTypeReference(maker, type.toName(builderClassName), typeParams), copyTypeParams(maker, typeParams), List.<JCVariableDecl>nil(), List.<JCExpression>nil(), body, null);
}
 
Example #12
Source File: JavacHandlerUtil.java    From EasyMPermission with MIT License 5 votes vote down vote up
public static JCExpression namePlusTypeParamsToTypeReference(JavacTreeMaker maker, Name typeName, List<JCTypeParameter> params) {
	ListBuffer<JCExpression> typeArgs = new ListBuffer<JCExpression>();
	
	if (!params.isEmpty()) {
		for (JCTypeParameter param : params) {
			typeArgs.append(maker.Ident(param.name));
		}
		
		return maker.TypeApply(maker.Ident(typeName), typeArgs.toList());
	}
	
	return maker.Ident(typeName);
}
 
Example #13
Source File: Enter.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
/** Class enter visitor method for type parameters.
 *  Enter a symbol for type parameter in local scope, after checking that it
 *  is unique.
 */
@Override
public void visitTypeParameter(JCTypeParameter tree) {
    TypeVar a = (tree.type != null)
        ? (TypeVar)tree.type
        : new TypeVar(tree.name, env.info.scope.owner, syms.botType);
    tree.type = a;
    if (chk.checkUnique(tree.pos(), a.tsym, env.info.scope)) {
        env.info.scope.enter(a.tsym);
    }
    result = a;
}
 
Example #14
Source File: PrettyCommentsPrinter.java    From EasyMPermission with MIT License 5 votes vote down vote up
public void visitTypeParameter(JCTypeParameter tree) {
	try {
		print(tree.name);
		if (tree.bounds.nonEmpty()) {
			print(" extends ");
			printExprs(tree.bounds, " & ");
		}
	} catch (IOException e) {
		throw new UncheckedIOException(e);
	}
}
 
Example #15
Source File: PrettyCommentsPrinter.java    From EasyMPermission with MIT License 5 votes vote down vote up
/** If type parameter list is non-empty, print it enclosed in "<...>" brackets.
 */
public void printTypeParameters(List<JCTypeParameter> trees) throws IOException {
	if (trees.nonEmpty()) {
		print("<");
		printExprs(trees);
		print(">");
	}
}
 
Example #16
Source File: Enter.java    From javaide with GNU General Public License v3.0 5 votes vote down vote up
/** Class enter visitor method for type parameters.
 *  Enter a symbol for type parameter in local scope, after checking that it
 *  is unique.
 */
@Override
public void visitTypeParameter(JCTypeParameter tree) {
    TypeVar a = (tree.type != null)
        ? (TypeVar)tree.type
        : new TypeVar(tree.name, env.info.scope.owner, syms.botType);
    tree.type = a;
    if (chk.checkUnique(tree.pos(), a.tsym, env.info.scope)) {
        env.info.scope.enter(a.tsym);
    }
    result = a;
}
 
Example #17
Source File: Enter.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/** Class enter visitor method for type parameters.
 *  Enter a symbol for type parameter in local scope, after checking that it
 *  is unique.
 */
@Override
public void visitTypeParameter(JCTypeParameter tree) {
    TypeVar a = (tree.type != null)
        ? (TypeVar)tree.type
        : new TypeVar(tree.name, env.info.scope.owner, syms.botType);
    tree.type = a;
    if (chk.checkUnique(tree.pos(), a.tsym, env.info.scope)) {
        env.info.scope.enter(a.tsym);
    }
    result = a;
}
 
Example #18
Source File: NBParserFactory.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
protected JCTree methodDeclaratorRest(int pos, JCModifiers mods, JCExpression type, Name name, List<JCTypeParameter> typarams, boolean isInterface, boolean isVoid, Comment dc) {
    if (cancelService != null) {
        cancelService.abortIfCanceled();
    }
    return super.methodDeclaratorRest(pos, mods, type, name, typarams, isInterface, isVoid, dc);
}
 
Example #19
Source File: NBTreeMaker.java    From netbeans with Apache License 2.0 5 votes vote down vote up
protected IndexedClassDecl(JCModifiers mods,
                           Name name,
                           List<JCTypeParameter> typarams,
                           JCExpression extending,
                           List<JCExpression> implementing,
                           List<JCTree> defs,
                           ClassSymbol sym) {
    super(mods, name, typarams, extending, implementing, defs, sym);
    this.index = -1;
}
 
Example #20
Source File: NBTreeMaker.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public JCClassDecl ClassDef(JCModifiers mods, Name name, List<JCTypeParameter> typarams, JCExpression extending, List<JCExpression> implementing, List<JCTree> defs) {
    try {
        IndexedClassDecl result = new IndexedClassDecl(mods, name, typarams, extending, implementing, defs, null);

        result.pos = pos;

        return result;
    } catch (NoSuchMethodError err) {
        return super.ClassDef(mods, name, typarams, extending, implementing, defs);
    }
}
 
Example #21
Source File: MemberEnter.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public Env<AttrContext> getMethodEnv(JCMethodDecl tree, Env<AttrContext> env) {
    Env<AttrContext> mEnv = methodEnv(tree, env);
    mEnv.info.lint = mEnv.info.lint.augment(tree.sym);
    for (List<JCTypeParameter> l = tree.typarams; l.nonEmpty(); l = l.tail)
        mEnv.info.scope.enterIfAbsent(l.head.type.tsym);
    for (List<JCVariableDecl> l = tree.params; l.nonEmpty(); l = l.tail)
        mEnv.info.scope.enterIfAbsent(l.head.sym);
    return mEnv;
}
 
Example #22
Source File: CRTable.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public void visitTypeParameter(JCTypeParameter tree) {
    SourceRange sr = new SourceRange(startPos(tree), endPos(tree));
    sr.mergeWith(csp(tree.bounds));
    result = sr;
}
 
Example #23
Source File: JavacTreeMaker.java    From EasyMPermission with MIT License 4 votes vote down vote up
public JCMethodDecl MethodDef(JCModifiers mods, Name name, JCExpression resType, List<JCTypeParameter> typarams, JCVariableDecl recvparam, List<JCVariableDecl> params, List<JCExpression> thrown, JCBlock body, JCExpression defaultValue) {
	return invoke(MethodDefWithRecvParam, mods, name, resType, recvparam, typarams, params, thrown, body, defaultValue);
}
 
Example #24
Source File: TreeFinder.java    From annotation-tools with MIT License 4 votes vote down vote up
@Override
public Pair<ASTRecord, Integer> visitTypeParameter(TypeParameterTree node, Insertion ins) {
  JCTypeParameter tp = (JCTypeParameter) node;
  return Pair.of(astRecord(node), tp.getStartPosition());
}
 
Example #25
Source File: Method.java    From EasyMPermission with MIT License 4 votes vote down vote up
@Override
public IParameter paramType() {
    this.typeList = List.<JCTypeParameter>nil();
    return this;
}
 
Example #26
Source File: Method.java    From EasyMPermission with MIT License 4 votes vote down vote up
@Override
public IParameter paramType(List<JCTypeParameter> typeList) {
    this.typeList = typeList;
    return this;
}
 
Example #27
Source File: TypeAnnotations.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public void visitTypeParameter(JCTypeParameter tree) {
    findPosition(tree, peek2(), tree.annotations);
    super.visitTypeParameter(tree);
}
 
Example #28
Source File: Check.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public void visitTypeParameter(JCTypeParameter tree) {
    validateTrees(tree.bounds, true, isOuter);
    checkClassBounds(tree.pos(), tree.type);
}
 
Example #29
Source File: Annotate.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public void visitTypeParameter(JCTypeParameter tree) {
    enterTypeAnnotations(tree.annotations, env, sym, deferPos, true);
    scan(tree.bounds);
}
 
Example #30
Source File: MemberEnter.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
/** Construct method type from method signature.
 *  @param typarams    The method's type parameters.
 *  @param params      The method's value parameters.
 *  @param res             The method's result type,
 *                 null if it is a constructor.
 *  @param recvparam       The method's receiver parameter,
 *                 null if none given; TODO: or already set here?
 *  @param thrown      The method's thrown exceptions.
 *  @param env             The method's (local) environment.
 */
Type signature(MethodSymbol msym,
               List<JCTypeParameter> typarams,
               List<JCVariableDecl> params,
               JCTree res,
               JCVariableDecl recvparam,
               List<JCExpression> thrown,
               Env<AttrContext> env) {

    // Enter and attribute type parameters.
    List<Type> tvars = enter.classEnter(typarams, env);
    attr.attribTypeVariables(typarams, env);

    // Enter and attribute value parameters.
    ListBuffer<Type> argbuf = new ListBuffer<>();
    for (List<JCVariableDecl> l = params; l.nonEmpty(); l = l.tail) {
        memberEnter(l.head, env);
        argbuf.append(l.head.vartype.type);
    }

    // Attribute result type, if one is given.
    Type restype = res == null ? syms.voidType : attr.attribType(res, env);

    // Attribute receiver type, if one is given.
    Type recvtype;
    if (recvparam!=null) {
        memberEnter(recvparam, env);
        recvtype = recvparam.vartype.type;
    } else {
        recvtype = null;
    }

    // Attribute thrown exceptions.
    ListBuffer<Type> thrownbuf = new ListBuffer<>();
    for (List<JCExpression> l = thrown; l.nonEmpty(); l = l.tail) {
        Type exc = attr.attribType(l.head, env);
        if (!exc.hasTag(TYPEVAR)) {
            exc = chk.checkClassType(l.head.pos(), exc);
        } else if (exc.tsym.owner == msym) {
            //mark inference variables in 'throws' clause
            exc.tsym.flags_field |= THROWS;
        }
        thrownbuf.append(exc);
    }
    MethodType mtype = new MethodType(argbuf.toList(),
                                restype,
                                thrownbuf.toList(),
                                syms.methodClass);
    mtype.recvtype = recvtype;

    return tvars.isEmpty() ? mtype : new ForAll(tvars, mtype);
}