当前位置: 首页>>代码示例>>Java>>正文


Java TypeParameter.typeBounds方法代码示例

本文整理汇总了Java中org.eclipse.jdt.core.dom.TypeParameter.typeBounds方法的典型用法代码示例。如果您正苦于以下问题:Java TypeParameter.typeBounds方法的具体用法?Java TypeParameter.typeBounds怎么用?Java TypeParameter.typeBounds使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.eclipse.jdt.core.dom.TypeParameter的用法示例。


在下文中一共展示了TypeParameter.typeBounds方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: createTypeParameters

import org.eclipse.jdt.core.dom.TypeParameter; //导入方法依赖的package包/类
private static void createTypeParameters(
    ImportRewrite imports,
    ImportRewriteContext context,
    AST ast,
    IMethodBinding binding,
    MethodDeclaration decl) {
  ITypeBinding[] typeParams = binding.getTypeParameters();
  List<TypeParameter> typeParameters = decl.typeParameters();
  for (int i = 0; i < typeParams.length; i++) {
    ITypeBinding curr = typeParams[i];
    TypeParameter newTypeParam = ast.newTypeParameter();
    newTypeParam.setName(ast.newSimpleName(curr.getName()));
    ITypeBinding[] typeBounds = curr.getTypeBounds();
    if (typeBounds.length != 1
        || !"java.lang.Object".equals(typeBounds[0].getQualifiedName())) { // $NON-NLS-1$
      List<Type> newTypeBounds = newTypeParam.typeBounds();
      for (int k = 0; k < typeBounds.length; k++) {
        newTypeBounds.add(imports.addImport(typeBounds[k], ast, context));
      }
    }
    typeParameters.add(newTypeParam);
  }
}
 
开发者ID:eclipse,项目名称:che,代码行数:24,代码来源:StubUtility2.java

示例2: createTypeParameters

import org.eclipse.jdt.core.dom.TypeParameter; //导入方法依赖的package包/类
private static void createTypeParameters(ImportRewrite imports, ImportRewriteContext context, AST ast, IMethodBinding binding, MethodDeclaration decl) {
	ITypeBinding[] typeParams= binding.getTypeParameters();
	List<TypeParameter> typeParameters= decl.typeParameters();
	for (int i= 0; i < typeParams.length; i++) {
		ITypeBinding curr= typeParams[i];
		TypeParameter newTypeParam= ast.newTypeParameter();
		newTypeParam.setName(ast.newSimpleName(curr.getName()));
		ITypeBinding[] typeBounds= curr.getTypeBounds();
		if (typeBounds.length != 1 || !"java.lang.Object".equals(typeBounds[0].getQualifiedName())) {//$NON-NLS-1$
			List<Type> newTypeBounds= newTypeParam.typeBounds();
			for (int k= 0; k < typeBounds.length; k++) {
				newTypeBounds.add(imports.addImport(typeBounds[k], ast, context, TypeLocation.TYPE_BOUND));
			}
		}
		typeParameters.add(newTypeParam);
	}
}
 
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:18,代码来源:StubUtility2.java

示例3: copyTypeParameters

import org.eclipse.jdt.core.dom.TypeParameter; //导入方法依赖的package包/类
/**
 * Copies the constructor's parent type's type parameters, if any, as method type parameters of
 * the new static factory method. (Recall that static methods can't refer to type arguments of the
 * enclosing class, since they have no instance to serve as a context.)<br>
 * Makes sure to copy the bounds from the owning type, to ensure that the return type of the
 * factory method satisfies the bounds of the type being instantiated.<br>
 * E.g., for ctor Foo() in the type Foo<T extends Number>, be sure that the factory method is
 * declared as<br>
 * <code>static <T extends Number> Foo<T> createFoo()</code><br>
 * and not simply<br>
 * <code>static <T> Foo<T> createFoo()</code><br>
 * or the compiler will bark.
 *
 * @param ast utility object needed to create ASTNode's for the new method
 * @param newMethod the method onto which to copy the type parameters
 */
private void copyTypeParameters(AST ast, MethodDeclaration newMethod) {
  ITypeBinding[] ctorOwnerTypeParms = fCtorBinding.getDeclaringClass().getTypeParameters();
  List<TypeParameter> factoryMethodTypeParms = newMethod.typeParameters();
  for (int i = 0; i < ctorOwnerTypeParms.length; i++) {
    TypeParameter newParm = ast.newTypeParameter();
    ITypeBinding[] parmTypeBounds = ctorOwnerTypeParms[i].getTypeBounds();
    List<Type> newParmBounds = newParm.typeBounds();

    newParm.setName(ast.newSimpleName(ctorOwnerTypeParms[i].getName()));
    for (int b = 0; b < parmTypeBounds.length; b++) {
      if (parmTypeBounds[b].isClass() && parmTypeBounds[b].getSuperclass() == null) continue;

      Type newBound = fImportRewriter.addImport(parmTypeBounds[b], ast);

      newParmBounds.add(newBound);
    }
    factoryMethodTypeParms.add(newParm);
  }
}
 
开发者ID:eclipse,项目名称:che,代码行数:36,代码来源:IntroduceFactoryRefactoring.java

示例4: copyTypeParameters

import org.eclipse.jdt.core.dom.TypeParameter; //导入方法依赖的package包/类
/**
 * Copies the constructor's parent type's type parameters, if any, as
 * method type parameters of the new static factory method. (Recall
 * that static methods can't refer to type arguments of the enclosing
 * class, since they have no instance to serve as a context.)<br>
 * Makes sure to copy the bounds from the owning type, to ensure that the
 * return type of the factory method satisfies the bounds of the type
 * being instantiated.<br>
 * E.g., for ctor Foo() in the type Foo<T extends Number>, be sure that
 * the factory method is declared as<br>
 * <code>static <T extends Number> Foo<T> createFoo()</code><br>
 * and not simply<br>
 * <code>static <T> Foo<T> createFoo()</code><br>
 * or the compiler will bark.
 * @param ast utility object needed to create ASTNode's for the new method
 * @param newMethod the method onto which to copy the type parameters
 */
private void copyTypeParameters(AST ast, MethodDeclaration newMethod) {
	ITypeBinding[] ctorOwnerTypeParms= fCtorBinding.getDeclaringClass().getTypeParameters();
	List<TypeParameter> factoryMethodTypeParms= newMethod.typeParameters();
	for(int i= 0; i < ctorOwnerTypeParms.length; i++) {
           TypeParameter newParm= ast.newTypeParameter();
           ITypeBinding[] parmTypeBounds= ctorOwnerTypeParms[i].getTypeBounds();
           List<Type> newParmBounds= newParm.typeBounds();

           newParm.setName(ast.newSimpleName(ctorOwnerTypeParms[i].getName()));
           for(int b=0; b < parmTypeBounds.length; b++) {
           	if (parmTypeBounds[b].isClass() && parmTypeBounds[b].getSuperclass() == null)
           		continue;

           	Type newBound= fImportRewriter.addImport(parmTypeBounds[b], ast);

               newParmBounds.add(newBound);
           }
		factoryMethodTypeParms.add(newParm);
	}
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:38,代码来源:IntroduceFactoryRefactoring.java

示例5: createTypeParameters

import org.eclipse.jdt.core.dom.TypeParameter; //导入方法依赖的package包/类
private static void createTypeParameters(ImportRewrite imports, ImportRewriteContext context, AST ast, IMethodBinding binding, MethodDeclaration decl) {
	ITypeBinding[] typeParams= binding.getTypeParameters();
	List<TypeParameter> typeParameters= decl.typeParameters();
	for (int i= 0; i < typeParams.length; i++) {
		ITypeBinding curr= typeParams[i];
		TypeParameter newTypeParam= ast.newTypeParameter();
		newTypeParam.setName(ast.newSimpleName(curr.getName()));
		ITypeBinding[] typeBounds= curr.getTypeBounds();
		if (typeBounds.length != 1 || !"java.lang.Object".equals(typeBounds[0].getQualifiedName())) {//$NON-NLS-1$
			List<Type> newTypeBounds= newTypeParam.typeBounds();
			for (int k= 0; k < typeBounds.length; k++) {
				newTypeBounds.add(imports.addImport(typeBounds[k], ast, context));
			}
		}
		typeParameters.add(newTypeParam);
	}
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:18,代码来源:StubUtility2.java

示例6: visit

import org.eclipse.jdt.core.dom.TypeParameter; //导入方法依赖的package包/类
@Override
public boolean visit(TypeParameter node) {
	//System.out.println("Found: " + node.getClass());
	node.getName().accept(this);
	if (node.typeBounds().size() == 1) {
		print(" : ");
		((Type)node.typeBounds().get(0)).accept(this);
	} else if (node.typeBounds().size() > 1) {
		StringWriter sw = new StringWriter();
		pushWriter(sw);
		int printed = 0;
		for (Object o : node.typeBounds()) {
			Type t = (Type)o;
			if (printed > 0) {
				print(" && ");
			}
			print("is(");
			node.getName().accept(this);
			print(" : ");
			t.accept(this);
			print(")");
			printed++;
		}
		popWriter();
		if (constraints.length() > 0) {
			constraints += " && " + sw.toString();
		} else {
			constraints = sw.toString();
		}
	}
	return false;
}
 
开发者ID:mrmonday,项目名称:j2d,代码行数:33,代码来源:J2dVisitor.java

示例7: createConstructorStub

import org.eclipse.jdt.core.dom.TypeParameter; //导入方法依赖的package包/类
public static MethodDeclaration createConstructorStub(ICompilationUnit unit, ASTRewrite rewrite, ImportRewrite imports, ImportRewriteContext context, IMethodBinding binding, String type, int modifiers, boolean omitSuperForDefConst, boolean todo, CodeGenerationSettings settings) throws CoreException {
	AST ast= rewrite.getAST();
	MethodDeclaration decl= ast.newMethodDeclaration();
	decl.modifiers().addAll(ASTNodeFactory.newModifiers(ast, modifiers & ~Modifier.ABSTRACT & ~Modifier.NATIVE));
	decl.setName(ast.newSimpleName(type));
	decl.setConstructor(true);

	ITypeBinding[] typeParams= binding.getTypeParameters();
	List<TypeParameter> typeParameters= decl.typeParameters();
	for (int i= 0; i < typeParams.length; i++) {
		ITypeBinding curr= typeParams[i];
		TypeParameter newTypeParam= ast.newTypeParameter();
		newTypeParam.setName(ast.newSimpleName(curr.getName()));
		ITypeBinding[] typeBounds= curr.getTypeBounds();
		if (typeBounds.length != 1 || !"java.lang.Object".equals(typeBounds[0].getQualifiedName())) {//$NON-NLS-1$
			List<Type> newTypeBounds= newTypeParam.typeBounds();
			for (int k= 0; k < typeBounds.length; k++) {
				newTypeBounds.add(imports.addImport(typeBounds[k], ast, context));
			}
		}
		typeParameters.add(newTypeParam);
	}

	List<SingleVariableDeclaration> parameters= createParameters(unit.getJavaProject(), imports, context, ast, binding, decl);

	List<Name> thrownExceptions= decl.thrownExceptions();
	ITypeBinding[] excTypes= binding.getExceptionTypes();
	for (int i= 0; i < excTypes.length; i++) {
		String excTypeName= imports.addImport(excTypes[i], context);
		thrownExceptions.add(ASTNodeFactory.newName(ast, excTypeName));
	}

	Block body= ast.newBlock();
	decl.setBody(body);

	String delimiter= StubUtility.getLineDelimiterUsed(unit);
	String bodyStatement= ""; //$NON-NLS-1$
	if (!omitSuperForDefConst || !parameters.isEmpty()) {
		SuperConstructorInvocation invocation= ast.newSuperConstructorInvocation();
		SingleVariableDeclaration varDecl= null;
		for (Iterator<SingleVariableDeclaration> iterator= parameters.iterator(); iterator.hasNext();) {
			varDecl= iterator.next();
			invocation.arguments().add(ast.newSimpleName(varDecl.getName().getIdentifier()));
		}
		bodyStatement= ASTNodes.asFormattedString(invocation, 0, delimiter, unit.getJavaProject().getOptions(true));
	}

	if (todo) {
		String placeHolder= CodeGeneration.getMethodBodyContent(unit, type, binding.getName(), true, bodyStatement, delimiter);
		if (placeHolder != null) {
			ReturnStatement todoNode= (ReturnStatement) rewrite.createStringPlaceholder(placeHolder, ASTNode.RETURN_STATEMENT);
			body.statements().add(todoNode);
		}
	} else {
		ReturnStatement statementNode= (ReturnStatement) rewrite.createStringPlaceholder(bodyStatement, ASTNode.RETURN_STATEMENT);
		body.statements().add(statementNode);
	}

	if (settings != null && settings.createComments) {
		String string= CodeGeneration.getMethodComment(unit, type, decl, binding, delimiter);
		if (string != null) {
			Javadoc javadoc= (Javadoc) rewrite.createStringPlaceholder(string, ASTNode.JAVADOC);
			decl.setJavadoc(javadoc);
		}
	}
	return decl;
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion-Juno38,代码行数:68,代码来源:StubUtility2.java


注:本文中的org.eclipse.jdt.core.dom.TypeParameter.typeBounds方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。