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


Java ParameterizedType类代码示例

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


ParameterizedType类属于org.eclipse.jdt.core.dom包,在下文中一共展示了ParameterizedType类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: rewriteAST

import org.eclipse.jdt.core.dom.ParameterizedType; //导入依赖的package包/类
@Override
public void rewriteAST(CompilationUnitRewrite cuRewrite, LinkedProposalModel positionGroups) throws CoreException {
	final ASTRewrite rewrite = cuRewrite.getASTRewrite();
	VariableDeclarationFragment fragment = null;
	for (int i = 0; i < fNodes.length; i++) {
		final ASTNode node = fNodes[i];

		final AST ast = node.getAST();

		fragment = ast.newVariableDeclarationFragment();
		fragment.setName(ast.newSimpleName(NAME_FIELD));

		final FieldDeclaration declaration = ast.newFieldDeclaration(fragment);
		declaration.setType(ast.newPrimitiveType(PrimitiveType.LONG));
		declaration.modifiers().addAll(ASTNodeFactory.newModifiers(ast, Modifier.PRIVATE | Modifier.STATIC | Modifier.FINAL));

		if (!addInitializer(fragment, node)) {
			continue;
		}

		if (fragment.getInitializer() != null) {

			final TextEditGroup editGroup = createTextEditGroup(FixMessages.SerialVersion_group_description, cuRewrite);
			if (node instanceof AbstractTypeDeclaration) {
				rewrite.getListRewrite(node, ((AbstractTypeDeclaration) node).getBodyDeclarationsProperty()).insertAt(declaration, 0, editGroup);
			} else if (node instanceof AnonymousClassDeclaration) {
				rewrite.getListRewrite(node, AnonymousClassDeclaration.BODY_DECLARATIONS_PROPERTY).insertAt(declaration, 0, editGroup);
			} else if (node instanceof ParameterizedType) {
				final ParameterizedType type = (ParameterizedType) node;
				final ASTNode parent = type.getParent();
				if (parent instanceof ClassInstanceCreation) {
					final ClassInstanceCreation creation = (ClassInstanceCreation) parent;
					final AnonymousClassDeclaration anonymous = creation.getAnonymousClassDeclaration();
					if (anonymous != null) {
						rewrite.getListRewrite(anonymous, AnonymousClassDeclaration.BODY_DECLARATIONS_PROPERTY).insertAt(declaration, 0, editGroup);
					}
				}
			} else {
				Assert.isTrue(false);
			}

			addLinkedPositions(rewrite, fragment, positionGroups);
		}

		final String comment = CodeGeneration.getFieldComment(fUnit, declaration.getType().toString(), NAME_FIELD, "\n" /* StubUtility.getLineDelimiterUsed(fUnit) */);
		if (comment != null && comment.length() > 0 && !"/**\n *\n */\n".equals(comment)) {
			final Javadoc doc = (Javadoc) rewrite.createStringPlaceholder(comment, ASTNode.JAVADOC);
			declaration.setJavadoc(doc);
		}
	}
	if (fragment == null) {
		return;
	}

	positionGroups.setEndPosition(rewrite.track(fragment));
}
 
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:57,代码来源:AbstractSerialVersionOperation.java

示例2: createPrivilegedActionType

import org.eclipse.jdt.core.dom.ParameterizedType; //导入依赖的package包/类
private ParameterizedType createPrivilegedActionType(ASTRewrite rewrite, ClassInstanceCreation classLoaderCreation) {
    AST ast = rewrite.getAST();

    Name privilegedActionName;
    if (isUpdateImports()) {
        privilegedActionName = ast.newSimpleName(PrivilegedAction.class.getSimpleName());
    } else {
        privilegedActionName = ast.newName(PrivilegedAction.class.getName());
    }
    SimpleType rawPrivilegedActionType = ast.newSimpleType(privilegedActionName);
    ParameterizedType privilegedActionType = ast.newParameterizedType(rawPrivilegedActionType);
    Type typeArgument = (Type) rewrite.createCopyTarget(classLoaderCreation.getType());
    List<Type> typeArguments = checkedList(privilegedActionType.typeArguments());

    typeArguments.add(typeArgument);

    return privilegedActionType;
}
 
开发者ID:OpenNTF,项目名称:FindBug-for-Domino-Designer,代码行数:19,代码来源:CreateDoPrivilegedBlockResolution.java

示例3: isInvariant

import org.eclipse.jdt.core.dom.ParameterizedType; //导入依赖的package包/类
public boolean isInvariant(Type type) {
    if (this.C() != type.C())
        return false;
    if (t == null || ! t.isParameterizedType()) // this type is not yet concretized or not parametric
        return true;
    if (! type.T().isParameterizedType())
        return false;

    // sanity check
    ParameterizedType pt1 = (ParameterizedType) T();
    ParameterizedType pt2 = (ParameterizedType) type.T();
    int n1 = pt1.typeArguments().size();
    int n2 = pt2.typeArguments().size();
    if (n1 != n2)
        throw new SynthesisException(SynthesisException.GenericTypeVariableMismatch);

    for (int i = 0; i < n1; i++) {
        Type t1 = new Type((org.eclipse.jdt.core.dom.Type) pt1.typeArguments().get(i));
        Type t2 = new Type((org.eclipse.jdt.core.dom.Type) pt2.typeArguments().get(i));

        if (! t1.isInvariant(t2))
            return false;
    }
    return true;
}
 
开发者ID:capergroup,项目名称:bayou,代码行数:26,代码来源:Type.java

示例4: autoConcretize

import org.eclipse.jdt.core.dom.ParameterizedType; //导入依赖的package包/类
private void autoConcretize() {
    concretization = new HashMap<>();

    // check sanity of types
    if (! t.isParameterizedType()) {
        if (c.getTypeParameters().length > 0)
            throw new SynthesisException(SynthesisException.GenericTypeVariableMismatch);
        if (t.isArrayType() && !c.isArray())
            throw new SynthesisException(SynthesisException.InvalidKindOfType);
        return;
    }
    ParameterizedType pType = (ParameterizedType) t;
    int n1 = pType.typeArguments().size();
    int n2 = c.getTypeParameters().length;
    if (n1 != n2)
        throw new SynthesisException(SynthesisException.GenericTypeVariableMismatch);

    // unify generic names with their actual types
    for (int i = 0; i < n1; i++) {
        String name = c.getTypeParameters()[i].getName();
        Type type = new Type((org.eclipse.jdt.core.dom.Type) pType.typeArguments().get(i));
        concretization.put(name, type);
    }
}
 
开发者ID:capergroup,项目名称:bayou,代码行数:25,代码来源:Type.java

示例5: provideAnswer

import org.eclipse.jdt.core.dom.ParameterizedType; //导入依赖的package包/类
public static Object provideAnswer(InvocationOnMock inv) {
    Type type = ((BuilderField) inv.getArguments()[0]).getFieldType();
    if (type instanceof ParameterizedType) {
        Type baseType = ((ParameterizedType) type).getType();
        if (baseType instanceof SimpleType) {
            String name = ((SimpleType) baseType).getName().getFullyQualifiedName();

            // if name is fully qualified
            if (recognisedClasses.contains(name)) {
                return Optional.ofNullable(name);
            }

            Optional<String> found = recognisedClasses.stream()
                    .filter(fqn -> fqn.endsWith("." + name))
                    .findFirst();
            if (found.isPresent()) {
                return found;
            }
        }
    }
    return Optional.of("some.other.value");
}
 
开发者ID:helospark,项目名称:SparkBuilderGenerator,代码行数:23,代码来源:FieldDeclarationAnswerProvider.java

示例6: getNormalizedNode

import org.eclipse.jdt.core.dom.ParameterizedType; //导入依赖的package包/类
/**
 * For {@link Name} or {@link Type} nodes, returns the topmost {@link Type} node
 * that shares the same type binding as the given node.
 *
 * @param node an ASTNode
 * @return the normalized {@link Type} node or the original node
 */
public static ASTNode getNormalizedNode(ASTNode node) {
	ASTNode current= node;
	// normalize name
	if (QualifiedName.NAME_PROPERTY.equals(current.getLocationInParent())) {
		current= current.getParent();
	}
	// normalize type
	if (QualifiedType.NAME_PROPERTY.equals(current.getLocationInParent())
			|| SimpleType.NAME_PROPERTY.equals(current.getLocationInParent())
			|| NameQualifiedType.NAME_PROPERTY.equals(current.getLocationInParent())) {
		current= current.getParent();
	}
	// normalize parameterized types
	if (ParameterizedType.TYPE_PROPERTY.equals(current.getLocationInParent())) {
		current= current.getParent();
	}
	return current;
}
 
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:26,代码来源:ASTNodes.java

示例7: newCreationType

import org.eclipse.jdt.core.dom.ParameterizedType; //导入依赖的package包/类
/**
 * Create a Type suitable as the creationType in a ClassInstanceCreation expression.
 * @param ast The AST to create the nodes for.
 * @param typeBinding binding representing the given class type
 * @param importRewrite the import rewrite to use
 * @param importContext the import context used to determine which (null) annotations to consider
 * @return a Type suitable as the creationType in a ClassInstanceCreation expression.
 */
public static Type newCreationType(AST ast, ITypeBinding typeBinding, ImportRewrite importRewrite, ImportRewriteContext importContext) {
	if (typeBinding.isParameterizedType()) {
		Type baseType= newCreationType(ast, typeBinding.getTypeDeclaration(), importRewrite, importContext);
		IAnnotationBinding[] typeAnnotations= importContext.removeRedundantTypeAnnotations(typeBinding.getTypeAnnotations(), TypeLocation.NEW, typeBinding);
		for (IAnnotationBinding typeAnnotation : typeAnnotations) {
			((AnnotatableType)baseType).annotations().add(importRewrite.addAnnotation(typeAnnotation, ast, importContext));
		}
		ParameterizedType parameterizedType= ast.newParameterizedType(baseType);
		for (ITypeBinding typeArgument : typeBinding.getTypeArguments()) {
			typeArgument= StubUtility2.replaceWildcardsAndCaptures(typeArgument);
			parameterizedType.typeArguments().add(importRewrite.addImport(typeArgument, ast, importContext, TypeLocation.TYPE_ARGUMENT));
		}
		return parameterizedType;
	} else {
		return importRewrite.addImport(typeBinding, ast, importContext, TypeLocation.NEW);
	}
}
 
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:26,代码来源:ASTNodeFactory.java

示例8: getVariableNameSuggestions

import org.eclipse.jdt.core.dom.ParameterizedType; //导入依赖的package包/类
private static String[] getVariableNameSuggestions(int variableKind, IJavaProject project, Type expectedType, Collection<String> excluded, boolean evaluateDefault) {
	int dim= 0;
	if (expectedType.isArrayType()) {
		ArrayType arrayType= (ArrayType)expectedType;
		dim= arrayType.getDimensions();
		expectedType= arrayType.getElementType();
	}
	if (expectedType.isParameterizedType()) {
		expectedType= ((ParameterizedType)expectedType).getType();
	}
	String typeName= ASTNodes.getTypeName(expectedType);

	if (typeName.length() > 0) {
		return getVariableNameSuggestions(variableKind, project, typeName, dim, excluded, evaluateDefault);
	}
	return EMPTY;
}
 
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:18,代码来源:StubUtility.java

示例9: getDeclarationNode

import org.eclipse.jdt.core.dom.ParameterizedType; //导入依赖的package包/类
/**
 * Returns the declaration node for the originally selected node.
 *
 * @param name
 *            the name of the node
 *
 * @return the declaration node
 */
private static ASTNode getDeclarationNode(SimpleName name) {
	ASTNode parent = name.getParent();
	if (!(parent instanceof AbstractTypeDeclaration)) {

		parent = parent.getParent();
		if (parent instanceof ParameterizedType || parent instanceof Type) {
			parent = parent.getParent();
		}
		if (parent instanceof ClassInstanceCreation) {

			final ClassInstanceCreation creation = (ClassInstanceCreation) parent;
			parent = creation.getAnonymousClassDeclaration();
		}
	}
	return parent;
}
 
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:25,代码来源:PotentialProgrammingProblemsFix.java

示例10: getVariableNameSuggestions

import org.eclipse.jdt.core.dom.ParameterizedType; //导入依赖的package包/类
private static String[] getVariableNameSuggestions(
    int variableKind,
    IJavaProject project,
    Type expectedType,
    Collection<String> excluded,
    boolean evaluateDefault) {
  int dim = 0;
  if (expectedType.isArrayType()) {
    ArrayType arrayType = (ArrayType) expectedType;
    dim = arrayType.getDimensions();
    expectedType = arrayType.getElementType();
  }
  if (expectedType.isParameterizedType()) {
    expectedType = ((ParameterizedType) expectedType).getType();
  }
  String typeName = ASTNodes.getTypeName(expectedType);

  if (typeName.length() > 0) {
    return getVariableNameSuggestions(
        variableKind, project, typeName, dim, excluded, evaluateDefault);
  }
  return EMPTY;
}
 
开发者ID:eclipse,项目名称:che,代码行数:24,代码来源:StubUtility.java

示例11: getDeclarationNode

import org.eclipse.jdt.core.dom.ParameterizedType; //导入依赖的package包/类
/**
 * Returns the declaration node for the originally selected node.
 *
 * @param name the name of the node
 * @return the declaration node
 */
private static ASTNode getDeclarationNode(SimpleName name) {
  ASTNode parent = name.getParent();
  if (!(parent instanceof AbstractTypeDeclaration)) {

    parent = parent.getParent();
    if (parent instanceof ParameterizedType || parent instanceof Type)
      parent = parent.getParent();
    if (parent instanceof ClassInstanceCreation) {

      final ClassInstanceCreation creation = (ClassInstanceCreation) parent;
      parent = creation.getAnonymousClassDeclaration();
    }
  }
  return parent;
}
 
开发者ID:eclipse,项目名称:che,代码行数:22,代码来源:PotentialProgrammingProblemsFix.java

示例12: rewriteAST

import org.eclipse.jdt.core.dom.ParameterizedType; //导入依赖的package包/类
/** {@inheritDoc} */
@Override
public void rewriteAST(CompilationUnitRewrite cuRewrite, LinkedProposalModel model)
    throws CoreException {
  TextEditGroup group =
      createTextEditGroup(
          FixMessages.TypeParametersFix_remove_redundant_type_arguments_description, cuRewrite);

  ASTRewrite rewrite = cuRewrite.getASTRewrite();
  rewrite.setTargetSourceRangeComputer(new NoCommentSourceRangeComputer());

  ListRewrite listRewrite =
      rewrite.getListRewrite(fParameterizedType, ParameterizedType.TYPE_ARGUMENTS_PROPERTY);

  List<Type> typeArguments = fParameterizedType.typeArguments();
  for (Iterator<Type> iterator = typeArguments.iterator(); iterator.hasNext(); ) {
    listRewrite.remove(iterator.next(), group);
  }
}
 
开发者ID:eclipse,项目名称:che,代码行数:20,代码来源:TypeParametersFix.java

示例13: createInsertInferredTypeArgumentsFix

import org.eclipse.jdt.core.dom.ParameterizedType; //导入依赖的package包/类
public static TypeParametersFix createInsertInferredTypeArgumentsFix(
    CompilationUnit compilationUnit, ParameterizedType node) {
  if (node == null) return null;

  final ArrayList<ASTNode> changedNodes = new ArrayList<ASTNode>();
  node.accept(new InsertTypeArgumentsVisitor(changedNodes));

  if (changedNodes.isEmpty()) return null;

  CompilationUnitRewriteOperation op =
      new InsertTypeArgumentsOperation(new ParameterizedType[] {node});
  return new TypeParametersFix(
      FixMessages.TypeParametersFix_insert_inferred_type_arguments_name,
      compilationUnit,
      new CompilationUnitRewriteOperation[] {op});
}
 
开发者ID:eclipse,项目名称:che,代码行数:17,代码来源:TypeParametersFix.java

示例14: rewriteAST

import org.eclipse.jdt.core.dom.ParameterizedType; //导入依赖的package包/类
/** {@inheritDoc} */
@Override
public void rewriteAST(CompilationUnitRewrite cuRewrite, LinkedProposalModel positionGroups)
    throws CoreException {
  final ASTRewrite rewrite = cuRewrite.getASTRewrite();
  VariableDeclarationFragment fragment = null;
  for (int i = 0; i < fNodes.length; i++) {
    final ASTNode node = fNodes[i];

    final AST ast = node.getAST();

    fragment = ast.newVariableDeclarationFragment();
    fragment.setName(ast.newSimpleName(NAME_FIELD));

    final FieldDeclaration declaration = ast.newFieldDeclaration(fragment);
    declaration.setType(ast.newPrimitiveType(PrimitiveType.LONG));
    declaration
        .modifiers()
        .addAll(
            ASTNodeFactory.newModifiers(
                ast, Modifier.PRIVATE | Modifier.STATIC | Modifier.FINAL));

    if (!addInitializer(fragment, node)) continue;

    if (fragment.getInitializer() != null) {

      final TextEditGroup editGroup =
          createTextEditGroup(FixMessages.SerialVersion_group_description, cuRewrite);
      if (node instanceof AbstractTypeDeclaration)
        rewrite
            .getListRewrite(node, ((AbstractTypeDeclaration) node).getBodyDeclarationsProperty())
            .insertAt(declaration, 0, editGroup);
      else if (node instanceof AnonymousClassDeclaration)
        rewrite
            .getListRewrite(node, AnonymousClassDeclaration.BODY_DECLARATIONS_PROPERTY)
            .insertAt(declaration, 0, editGroup);
      else if (node instanceof ParameterizedType) {
        final ParameterizedType type = (ParameterizedType) node;
        final ASTNode parent = type.getParent();
        if (parent instanceof ClassInstanceCreation) {
          final ClassInstanceCreation creation = (ClassInstanceCreation) parent;
          final AnonymousClassDeclaration anonymous = creation.getAnonymousClassDeclaration();
          if (anonymous != null)
            rewrite
                .getListRewrite(anonymous, AnonymousClassDeclaration.BODY_DECLARATIONS_PROPERTY)
                .insertAt(declaration, 0, editGroup);
        }
      } else Assert.isTrue(false);

      addLinkedPositions(rewrite, fragment, positionGroups);
    }

    final String comment =
        CodeGeneration.getFieldComment(
            fUnit,
            declaration.getType().toString(),
            NAME_FIELD,
            StubUtility.getLineDelimiterUsed(fUnit));
    if (comment != null && comment.length() > 0) {
      final Javadoc doc = (Javadoc) rewrite.createStringPlaceholder(comment, ASTNode.JAVADOC);
      declaration.setJavadoc(doc);
    }
  }
  if (fragment == null) return;

  positionGroups.setEndPosition(rewrite.track(fragment));
}
 
开发者ID:eclipse,项目名称:che,代码行数:68,代码来源:AbstractSerialVersionOperation.java

示例15: rewriteConstraintVariable

import org.eclipse.jdt.core.dom.ParameterizedType; //导入依赖的package包/类
private static ParameterizedType rewriteConstraintVariable(
    ConstraintVariable2 cv,
    CompilationUnitRewrite rewrite,
    InferTypeArgumentsTCModel tCModel,
    boolean leaveUnconstraindRaw,
    SimpleType[] types) {
  if (cv instanceof CollectionElementVariable2) {
    ConstraintVariable2 parentElement =
        ((CollectionElementVariable2) cv).getParentConstraintVariable();
    if (parentElement instanceof TypeVariable2) {
      TypeVariable2 typeCv = (TypeVariable2) parentElement;
      return rewriteTypeVariable(typeCv, rewrite, tCModel, leaveUnconstraindRaw, types);
    } else {
      // only rewrite type variables
    }
  }
  return null;
}
 
开发者ID:eclipse,项目名称:che,代码行数:19,代码来源:InferTypeArgumentsRefactoring.java


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