本文整理汇总了Java中org.eclipse.jdt.core.dom.TypeParameter类的典型用法代码示例。如果您正苦于以下问题:Java TypeParameter类的具体用法?Java TypeParameter怎么用?Java TypeParameter使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
TypeParameter类属于org.eclipse.jdt.core.dom包,在下文中一共展示了TypeParameter类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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);
}
}
示例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);
}
}
示例3: insertAllMissingTypeTags
import org.eclipse.jdt.core.dom.TypeParameter; //导入依赖的package包/类
private void insertAllMissingTypeTags(ASTRewrite rewriter, TypeDeclaration typeDecl) {
AST ast= typeDecl.getAST();
Javadoc javadoc= typeDecl.getJavadoc();
ListRewrite tagsRewriter= rewriter.getListRewrite(javadoc, Javadoc.TAGS_PROPERTY);
List<TypeParameter> typeParams= typeDecl.typeParameters();
for (int i= typeParams.size() - 1; i >= 0; i--) {
TypeParameter decl= typeParams.get(i);
String name= '<' + decl.getName().getIdentifier() + '>';
if (findTag(javadoc, TagElement.TAG_PARAM, name) == null) {
TagElement newTag= ast.newTagElement();
newTag.setTagName(TagElement.TAG_PARAM);
TextElement text= ast.newTextElement();
text.setText(name);
newTag.fragments().add(text);
insertTabStop(rewriter, newTag.fragments(), "typeParam" + i); //$NON-NLS-1$
insertTag(tagsRewriter, newTag, getPreviousTypeParamNames(typeParams, decl));
}
}
}
示例4: addTypeParameters
import org.eclipse.jdt.core.dom.TypeParameter; //导入依赖的package包/类
private void addTypeParameters(
CompilationUnitRewrite imRewrite, List<TypeParameter> list, ITypeBinding parent) {
ITypeBinding enclosing = parent.getDeclaringClass();
if (enclosing != null) addTypeParameters(imRewrite, list, enclosing);
ITypeBinding[] typeParameters = parent.getTypeParameters();
for (int i = 0; i < typeParameters.length; i++) {
TypeParameter ntp = imRewrite.getAST().newTypeParameter();
ntp.setName(imRewrite.getAST().newSimpleName(typeParameters[i].getName()));
ITypeBinding[] bounds = typeParameters[i].getTypeBounds();
for (int j = 0; j < bounds.length; j++)
if (!"java.lang.Object".equals(bounds[j].getQualifiedName())) // $NON-NLS-1$
ntp.typeBounds().add(imRewrite.getImportRewrite().addImport(bounds[j], imRewrite.getAST()));
list.add(ntp);
}
}
示例5: 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);
}
}
示例6: insertAllMissingTypeTags
import org.eclipse.jdt.core.dom.TypeParameter; //导入依赖的package包/类
private void insertAllMissingTypeTags(ASTRewrite rewriter, TypeDeclaration typeDecl) {
AST ast = typeDecl.getAST();
Javadoc javadoc = typeDecl.getJavadoc();
ListRewrite tagsRewriter = rewriter.getListRewrite(javadoc, Javadoc.TAGS_PROPERTY);
List<TypeParameter> typeParams = typeDecl.typeParameters();
for (int i = typeParams.size() - 1; i >= 0; i--) {
TypeParameter decl = typeParams.get(i);
String name = '<' + decl.getName().getIdentifier() + '>';
if (findTag(javadoc, TagElement.TAG_PARAM, name) == null) {
TagElement newTag = ast.newTagElement();
newTag.setTagName(TagElement.TAG_PARAM);
TextElement text = ast.newTextElement();
text.setText(name);
newTag.fragments().add(text);
insertTabStop(rewriter, newTag.fragments(), "typeParam" + i); // $NON-NLS-1$
insertTag(tagsRewriter, newTag, getPreviousTypeParamNames(typeParams, decl));
}
}
}
示例7: addTypeParameters
import org.eclipse.jdt.core.dom.TypeParameter; //导入依赖的package包/类
private static void addTypeParameters(final CompilationUnit unit, final IType type, final Map<String, ITypeBinding> map) throws JavaModelException {
Assert.isNotNull(unit);
Assert.isNotNull(type);
Assert.isNotNull(map);
final AbstractTypeDeclaration declaration= ASTNodeSearchUtil.getAbstractTypeDeclarationNode(type, unit);
if (declaration instanceof TypeDeclaration) {
ITypeBinding binding= null;
TypeParameter parameter= null;
for (final Iterator<TypeParameter> iterator= ((TypeDeclaration) declaration).typeParameters().iterator(); iterator.hasNext();) {
parameter= iterator.next();
binding= parameter.resolveBinding();
if (binding != null && !map.containsKey(binding.getKey()))
map.put(binding.getKey(), binding);
}
final IType declaring= type.getDeclaringType();
if (declaring != null && !JdtFlags.isStatic(type))
addTypeParameters(unit, declaring, map);
}
}
示例8: addEnclosingInstanceTypeParameters
import org.eclipse.jdt.core.dom.TypeParameter; //导入依赖的package包/类
private void addEnclosingInstanceTypeParameters(final ITypeBinding[] parameters, final AbstractTypeDeclaration declaration, final ASTRewrite rewrite) {
Assert.isNotNull(parameters);
Assert.isNotNull(declaration);
Assert.isNotNull(rewrite);
if (declaration instanceof TypeDeclaration) {
final TypeDeclaration type= (TypeDeclaration) declaration;
final List<TypeParameter> existing= type.typeParameters();
final Set<String> names= new HashSet<String>();
TypeParameter parameter= null;
for (final Iterator<TypeParameter> iterator= existing.iterator(); iterator.hasNext();) {
parameter= iterator.next();
names.add(parameter.getName().getIdentifier());
}
final ListRewrite rewriter= rewrite.getListRewrite(type, TypeDeclaration.TYPE_PARAMETERS_PROPERTY);
String name= null;
for (int index= 0; index < parameters.length; index++) {
name= parameters[index].getName();
if (!names.contains(name)) {
parameter= type.getAST().newTypeParameter();
parameter.setName(type.getAST().newSimpleName(name));
rewriter.insertLast(parameter, null);
}
}
}
}
示例9: addTypeParameters
import org.eclipse.jdt.core.dom.TypeParameter; //导入依赖的package包/类
private void addTypeParameters(CompilationUnitRewrite imRewrite, List<TypeParameter> list, ITypeBinding parent) {
ITypeBinding enclosing= parent.getDeclaringClass();
if (enclosing != null)
addTypeParameters(imRewrite, list, enclosing);
ITypeBinding[] typeParameters= parent.getTypeParameters();
for (int i= 0; i < typeParameters.length; i++) {
TypeParameter ntp= imRewrite.getAST().newTypeParameter();
ntp.setName(imRewrite.getAST().newSimpleName(typeParameters[i].getName()));
ITypeBinding[] bounds= typeParameters[i].getTypeBounds();
for (int j= 0; j < bounds.length; j++)
if (!"java.lang.Object".equals(bounds[j].getQualifiedName())) //$NON-NLS-1$
ntp.typeBounds().add(imRewrite.getImportRewrite().addImport(bounds[j], imRewrite.getAST()));
list.add(ntp);
}
}
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:18,代码来源:IntroduceIndirectionRefactoring.java
示例10: 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);
}
}
示例11: 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);
}
}
示例12: addTypeParameters
import org.eclipse.jdt.core.dom.TypeParameter; //导入依赖的package包/类
private static void addTypeParameters(final CompilationUnit unit, final IType type, final Map<String, ITypeBinding> map) throws JavaModelException {
Assert.isNotNull(unit);
Assert.isNotNull(type);
Assert.isNotNull(map);
final AbstractTypeDeclaration declaration= ASTNodeSearchUtil.getAbstractTypeDeclarationNode(type, unit);
if (declaration instanceof TypeDeclaration) {
ITypeBinding binding= null;
TypeParameter parameter= null;
for (final Iterator<TypeParameter> iterator= ((TypeDeclaration) declaration).typeParameters().iterator(); iterator.hasNext();) {
parameter= iterator.next();
binding= parameter.resolveBinding();
if (binding != null && !map.containsKey(binding.getKey()))
map.put(binding.getKey(), binding);
}
final IType declaring= type.getDeclaringType();
if (declaring != null && !Flags.isStatic(type.getFlags()))
addTypeParameters(unit, declaring, map);
}
}
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion-Juno38,代码行数:20,代码来源:MoveInnerToTopRefactoring.java
示例13: writeTypeParameters
import org.eclipse.jdt.core.dom.TypeParameter; //导入依赖的package包/类
/**
* Write out the type parameters in the specified list, surrounded by "<" and ">".
*
* @param typeParameters list of TypeParameter objects
* @param includeClassKeyword if true, each parameter is prefixed with "class "
*/
public void writeTypeParameters(List typeParameters, boolean includeClassKeyword) {
// If we're writing the implementation of a generic method, include the "template<...>" prefix
write("<");
forEach(typeParameters, (TypeParameter typeParameter, boolean first) -> {
if (!first)
write(", ");
if (includeClassKeyword)
write("class ");
write(typeParameter.getName().getIdentifier());
});
write(">");
}
示例14: passOnTypes
import org.eclipse.jdt.core.dom.TypeParameter; //导入依赖的package包/类
/**
* Replaces a name of the parametric type in the superclass.
*/
protected void passOnTypes(List<TypeDeclaration> list) {
// this list has no superclasses
if (list.size() < 2) {
return;
}
Type superType = list.get(0).getSuperclassType();
if (!superType.isParameterizedType()) {
return;
}
ParameterizedType superT = (ParameterizedType)superType;
TypeDeclaration parentTD = list.get(1);
for (int i = 0; i < superT.typeArguments().size(); i++) {
// get a new type
Type newType = (Type)superT.typeArguments().get(i);
// get an old type
SimpleName oldTypeName = ((TypeParameter)parentTD.typeParameters().get(i)).getName();
String oldType = oldTypeName.getFullyQualifiedName();
// replace the old type with a new type
ReplaceTypeVisitor visitor = new ReplaceTypeVisitor(newType, oldType);
parentTD.accept(visitor);
}
}
示例15: initializeReplacements
import org.eclipse.jdt.core.dom.TypeParameter; //导入依赖的package包/类
/**
* Initialise the replacements for this type
*
* For example:
* T -> JavaObject
* U extends Foo -> Foo
* V extends U -> Foo
* X extends Foo<K> -> Foo<K>
* Y extends Foo<Y> -> _j2d_Foo
* @param node
*/
private void initializeReplacements(TypeDeclaration node) {
for (Object o : node.typeParameters()) {
TypeParameter t = (TypeParameter)o;
if (t.typeBounds().size() == 0) {
getTypeState().typeReplacements.put(t.resolveBinding(), null);
} else {
// TODO This won't work for U extends T, T extends IFoobar
// The first type in the list is the class, if any
Type firstType = (Type)t.typeBounds().get(0);
ITypeBinding itb = firstType.resolveBinding();
while (itb.isTypeVariable()) {
itb = itb.getSuperclass();
}
/*if (itb.isParameterizedType() && hasTypeVariableArgument(itb)) {
itb = itb.getErasure();
}*/
getTypeState().typeReplacements.put(t.resolveBinding(), itb);
}
}
}