热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

org.eclipse.jdt.core.dom.AST.newTypeParameter()方法的使用及代码示例

本文整理了Java中org.eclipse.jdt.core.dom.AST.newTypeParameter()方法的一些代码示例,展示了AST.newT

本文整理了Java中org.eclipse.jdt.core.dom.AST.newTypeParameter()方法的一些代码示例,展示了AST.newTypeParameter()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。AST.newTypeParameter()方法的具体详情如下:
包路径:org.eclipse.jdt.core.dom.AST
类名称:AST
方法名:newTypeParameter

AST.newTypeParameter介绍

[英]Creates and returns a new unparented type parameter type node with an unspecified type variable name and an empty list of type bounds.
[中]创建并返回一个新的未命名类型参数类型节点,该节点具有未指定的类型变量名和类型边界的空列表。

代码示例

代码示例来源:origin: stackoverflow.com

TypeParameter tp = ast.newTypeParameter();
tp.setName(ast.newSimpleName("X"));
td.typeParameters().add(tp);

代码示例来源:origin: forge/roaster

@SuppressWarnings("unchecked")
@Override
public TypeVariableSource addTypeVariable()
{
TypeParameter tp2 = method.getAST().newTypeParameter();
method.typeParameters().add(tp2);
return new TypeVariableImpl(parent, tp2);
}

代码示例来源:origin: forge/roaster

@Override
public TypeVariableSource addTypeVariable()
{
TypeDeclaration type = (TypeDeclaration) body;
TypeParameter tp2 = unit.getAST().newTypeParameter();
type.typeParameters().add(tp2);
return new TypeVariableImpl((O) this, tp2);
}

代码示例来源:origin: org.jboss.forge/roaster-jdt

@Override
public TypeVariableSource addTypeVariable()
{
TypeDeclaration type = (TypeDeclaration) body;
TypeParameter tp2 = unit.getAST().newTypeParameter();
type.typeParameters().add(tp2);
return new TypeVariableImpl((O) this, tp2);
}

代码示例来源:origin: org.jboss.forge/roaster-jdt

@SuppressWarnings("unchecked")
@Override
public TypeVariableSource addTypeVariable()
{
TypeParameter tp2 = method.getAST().newTypeParameter();
method.typeParameters().add(tp2);
return new TypeVariableImpl(parent, tp2);
}

代码示例来源:origin: org.eclipse.jdt/org.eclipse.jdt.ui

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 existing= type.typeParameters();
final Set names= new HashSet<>();
TypeParameter parameter= null;
for (final Iterator 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 name= parameters[index].getName();
if (!names.contains(name)) {
parameter= type.getAST().newTypeParameter();
parameter.setName(type.getAST().newSimpleName(name));
rewriter.insertLast(parameter, null);
}
}
}
}

代码示例来源:origin: org.eclipse/org.eclipse.jdt.ui

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 existing= type.typeParameters();
final Set names= new HashSet();
TypeParameter parameter= null;
for (final Iterator iterator= existing.iterator(); iterator.hasNext();) {
parameter= (TypeParameter) 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 name= parameters[index].getName();
if (!names.contains(name)) {
parameter= type.getAST().newTypeParameter();
parameter.setName(type.getAST().newSimpleName(name));
rewriter.insertLast(parameter, null);
}
}
}
}

代码示例来源:origin: org.eclipse.scout.sdk.deps/org.eclipse.jdt.ui

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 existing= type.typeParameters();
final Set names= new HashSet<>();
TypeParameter parameter= null;
for (final Iterator 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 name= parameters[index].getName();
if (!names.contains(name)) {
parameter= type.getAST().newTypeParameter();
parameter.setName(type.getAST().newSimpleName(name));
rewriter.insertLast(parameter, null);
}
}
}
}

代码示例来源:origin: org.eclipse.jdt/org.eclipse.jdt.core.manipulation

public static void createTypeParameters(ImportRewrite imports, ImportRewriteContext context, AST ast, IMethodBinding binding, MethodDeclaration decl) {
ITypeBinding[] typeParams= binding.getTypeParameters();
List typeParameters= decl.typeParameters();
for (int i= 0; 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 newTypeBounds= newTypeParam.typeBounds();
for (int k= 0; k newTypeBounds.add(imports.addImport(typeBounds[k], ast, context, TypeLocation.TYPE_BOUND));
}
}
typeParameters.add(newTypeParam);
}
}

代码示例来源:origin: org.eclipse.scout.sdk.deps/org.eclipse.jdt.ui

private static void createTypeParameters(ImportRewrite imports, ImportRewriteContext context, AST ast, IMethodBinding binding, MethodDeclaration decl) {
ITypeBinding[] typeParams= binding.getTypeParameters();
List typeParameters= decl.typeParameters();
for (int i= 0; 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 newTypeBounds= newTypeParam.typeBounds();
for (int k= 0; k newTypeBounds.add(imports.addImport(typeBounds[k], ast, context));
}
}
typeParameters.add(newTypeParam);
}
}

代码示例来源:origin: org.eclipse.scout.sdk.deps/org.eclipse.jdt.ui

private void copyTypeParameters(MethodDeclaration intermediary, CompilationUnitRewrite rew, ImportRewriteContext context) {
ITypeBinding[] typeParameters= fTargetMethodBinding.getTypeParameters();
for (int i= 0; i ITypeBinding current= typeParameters[i];
TypeParameter parameter= rew.getAST().newTypeParameter();
parameter.setName(rew.getAST().newSimpleName(current.getName()));
ITypeBinding[] bounds= current.getTypeBounds();
for (int j= 0; j if (!"java.lang.Object".equals(bounds[j].getQualifiedName())) //$NON-NLS-1$
parameter.typeBounds().add(rew.getImportRewrite().addImport(bounds[j], rew.getAST(), context));
intermediary.typeParameters().add(parameter);
}
}

代码示例来源:origin: org.eclipse/org.eclipse.jdt.ui

private void copyTypeParameters(MethodDeclaration intermediary, CompilationUnitRewrite rew) {
ITypeBinding[] typeParameters= fTargetMethodBinding.getTypeParameters();
for (int i= 0; i ITypeBinding current= typeParameters[i];
TypeParameter parameter= rew.getAST().newTypeParameter();
parameter.setName(rew.getAST().newSimpleName(current.getName()));
ITypeBinding[] bounds= current.getTypeBounds();
for (int j= 0; j if (!"java.lang.Object".equals(bounds[j].getQualifiedName())) //$NON-NLS-1$
parameter.typeBounds().add(rew.getImportRewrite().addImport(bounds[j], rew.getAST()));
intermediary.typeParameters().add(parameter);
}
}

代码示例来源:origin: org.eclipse.jdt/org.eclipse.jdt.ui

private void copyTypeParameters(MethodDeclaration intermediary, CompilationUnitRewrite rew, ImportRewriteContext context) {
ITypeBinding[] typeParameters= fTargetMethodBinding.getTypeParameters();
for (int i= 0; i ITypeBinding current= typeParameters[i];
TypeParameter parameter= rew.getAST().newTypeParameter();
parameter.setName(rew.getAST().newSimpleName(current.getName()));
ITypeBinding[] bounds= current.getTypeBounds();
for (int j= 0; j if (!"java.lang.Object".equals(bounds[j].getQualifiedName())) //$NON-NLS-1$
parameter.typeBounds().add(rew.getImportRewrite().addImport(bounds[j], rew.getAST(), context, TypeLocation.TYPE_BOUND));
intermediary.typeParameters().add(parameter);
}
}

代码示例来源:origin: org.eclipse/org.eclipse.jdt.ui

private void addTypeParameters(CompilationUnitRewrite imRewrite, List newTypeParameters, ITypeBinding parent) {
ITypeBinding enclosing= parent.getDeclaringClass();
if (enclosing != null)
addTypeParameters(imRewrite, newTypeParameters, enclosing);
ITypeBinding[] typeParameters= parent.getTypeParameters();
for (int i= 0; i TypeParameter ntp= imRewrite.getAST().newTypeParameter();
ntp.setName(imRewrite.getAST().newSimpleName(typeParameters[i].getName()));
ITypeBinding[] bounds= typeParameters[i].getTypeBounds();
for (int j= 0; j if (!"java.lang.Object".equals(bounds[j].getQualifiedName())) //$NON-NLS-1$
ntp.typeBounds().add(imRewrite.getImportRewrite().addImport(bounds[j], imRewrite.getAST()));
newTypeParameters.add(ntp);
}
}

代码示例来源:origin: org.eclipse.scout.sdk.deps/org.eclipse.jdt.ui

private void addTypeParameters(CompilationUnitRewrite imRewrite, List list, ITypeBinding parent, ImportRewriteContext context) {
ITypeBinding enclosing= parent.getDeclaringClass();
if (enclosing != null)
addTypeParameters(imRewrite, list, enclosing, context);
ITypeBinding[] typeParameters= parent.getTypeParameters();
for (int i= 0; i TypeParameter ntp= imRewrite.getAST().newTypeParameter();
ntp.setName(imRewrite.getAST().newSimpleName(typeParameters[i].getName()));
ITypeBinding[] bounds= typeParameters[i].getTypeBounds();
for (int j= 0; j if (!"java.lang.Object".equals(bounds[j].getQualifiedName())) //$NON-NLS-1$
ntp.typeBounds().add(imRewrite.getImportRewrite().addImport(bounds[j], imRewrite.getAST(), context));
list.add(ntp);
}
}

代码示例来源:origin: org.eclipse.jdt/org.eclipse.jdt.ui

private void addTypeParameters(CompilationUnitRewrite imRewrite, List list, ITypeBinding parent, ImportRewriteContext context) {
ITypeBinding enclosing= parent.getDeclaringClass();
if (enclosing != null)
addTypeParameters(imRewrite, list, enclosing, context);
ITypeBinding[] typeParameters= parent.getTypeParameters();
for (int i= 0; i TypeParameter ntp= imRewrite.getAST().newTypeParameter();
ntp.setName(imRewrite.getAST().newSimpleName(typeParameters[i].getName()));
ITypeBinding[] bounds= typeParameters[i].getTypeBounds();
for (int j= 0; j if (!"java.lang.Object".equals(bounds[j].getQualifiedName())) //$NON-NLS-1$
ntp.typeBounds().add(imRewrite.getImportRewrite().addImport(bounds[j], imRewrite.getAST(), context, TypeLocation.TYPE_BOUND));
list.add(ntp);
}
}

代码示例来源:origin: org.eclipse.jdt/org.eclipse.jdt.ui

private void updateConstructorReference(ITypeBinding[] parameters, ParameterizedType type, CompilationUnitRewrite targetRewrite, ICompilationUnit cu, TextEditGroup group) throws CoreException {
final ListRewrite rewrite= targetRewrite.getASTRewrite().getListRewrite(type, ParameterizedType.TYPE_ARGUMENTS_PROPERTY);
TypeParameter parameter= null;
for (int index= type.typeArguments().size(); index parameter= targetRewrite.getRoot().getAST().newTypeParameter();
parameter.setName(targetRewrite.getRoot().getAST().newSimpleName(parameters[index].getName()));
rewrite.insertLast(parameter, group);
}
if (type.getParent() instanceof ClassInstanceCreation)
updateConstructorReference((ClassInstanceCreation) type.getParent(), targetRewrite, cu, group);
}

代码示例来源:origin: org.eclipse/org.eclipse.jdt.ui

private void updateConstructorReference(ITypeBinding[] parameters, ParameterizedType type, CompilationUnitRewrite targetRewrite, ICompilationUnit cu, TextEditGroup group) throws CoreException {
final ListRewrite rewrite= targetRewrite.getASTRewrite().getListRewrite(type, ParameterizedType.TYPE_ARGUMENTS_PROPERTY);
TypeParameter parameter= null;
for (int index= type.typeArguments().size(); index parameter= targetRewrite.getRoot().getAST().newTypeParameter();
parameter.setName(targetRewrite.getRoot().getAST().newSimpleName(parameters[index].getName()));
rewrite.insertLast(parameter, group);
}
if (type.getParent() instanceof ClassInstanceCreation)
updateConstructorReference((ClassInstanceCreation) type.getParent(), targetRewrite, cu, group);
}

代码示例来源:origin: org.eclipse.scout.sdk.deps/org.eclipse.jdt.ui

private void updateConstructorReference(ITypeBinding[] parameters, ParameterizedType type, CompilationUnitRewrite targetRewrite, ICompilationUnit cu, TextEditGroup group) throws CoreException {
final ListRewrite rewrite= targetRewrite.getASTRewrite().getListRewrite(type, ParameterizedType.TYPE_ARGUMENTS_PROPERTY);
TypeParameter parameter= null;
for (int index= type.typeArguments().size(); index parameter= targetRewrite.getRoot().getAST().newTypeParameter();
parameter.setName(targetRewrite.getRoot().getAST().newSimpleName(parameters[index].getName()));
rewrite.insertLast(parameter, group);
}
if (type.getParent() instanceof ClassInstanceCreation)
updateConstructorReference((ClassInstanceCreation) type.getParent(), targetRewrite, cu, group);
}

代码示例来源:origin: forge/roaster

@SuppressWarnings("rawtypes")
@Override
public O setName(final String name)
{
AbstractTypeDeclaration typeDeclaration = getDeclaration();
TypeImpl type = new TypeImpl(this, null, name);
typeDeclaration.setName(unit.getAST().newSimpleName(type.getName()));
if (typeDeclaration instanceof TypeDeclaration)
{
TypeDeclaration td = (TypeDeclaration) typeDeclaration;
for (Type arg : type.getTypeArguments())
{
TypeParameter typeParameter = unit.getAST().newTypeParameter();
typeParameter.setName(unit.getAST().newSimpleName(arg.getName()));
td.typeParameters().add(typeParameter);
}
}
return updateTypeNames(name);
}

推荐阅读
author-avatar
多米音乐_34058991
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有