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


Java ParameterizedType.typeArguments方法代码示例

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


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

示例1: setCtorTypeArguments

import org.eclipse.jdt.core.dom.ParameterizedType; //导入方法依赖的package包/类
/**
 * Sets the type being instantiated in the given constructor call, including specifying any
 * necessary type arguments.
 *
 * @param newCtorCall the constructor call to modify
 * @param ctorTypeName the simple name of the type being instantiated
 * @param ctorOwnerTypeParameters the formal type parameters of the type being instantiated
 * @param ast utility object used to create AST nodes
 */
private void setCtorTypeArguments(
    ClassInstanceCreation newCtorCall,
    String ctorTypeName,
    ITypeBinding[] ctorOwnerTypeParameters,
    AST ast) {
  if (ctorOwnerTypeParameters.length == 0) // easy, just a simple type
  newCtorCall.setType(ASTNodeFactory.newType(ast, ctorTypeName));
  else {
    Type baseType = ast.newSimpleType(ast.newSimpleName(ctorTypeName));
    ParameterizedType newInstantiatedType = ast.newParameterizedType(baseType);
    List<Type> newInstTypeArgs = newInstantiatedType.typeArguments();

    for (int i = 0; i < ctorOwnerTypeParameters.length; i++) {
      Type typeArg = ASTNodeFactory.newType(ast, ctorOwnerTypeParameters[i].getName());

      newInstTypeArgs.add(typeArg);
    }
    newCtorCall.setType(newInstantiatedType);
  }
}
 
开发者ID:eclipse,项目名称:che,代码行数:30,代码来源:IntroduceFactoryRefactoring.java

示例2: setMethodReturnType

import org.eclipse.jdt.core.dom.ParameterizedType; //导入方法依赖的package包/类
/**
 * Sets the return type of the factory method, including any necessary type arguments. E.g., for
 * constructor <code>Foo()</code> in <code>Foo&lt;T&gt;</code>, the factory method defines a
 * method type parameter <code>&lt;T&gt;</code> and returns a <code>Foo&lt;T&gt;</code>.
 *
 * @param newMethod the method whose return type is to be set
 * @param retTypeName the simple name of the return type (without type parameters)
 * @param ctorOwnerTypeParameters the formal type parameters of the type that the factory method
 *     instantiates (whose constructor is being encapsulated)
 * @param ast utility object used to create AST nodes
 */
private void setMethodReturnType(
    MethodDeclaration newMethod,
    String retTypeName,
    ITypeBinding[] ctorOwnerTypeParameters,
    AST ast) {
  if (ctorOwnerTypeParameters.length == 0)
    newMethod.setReturnType2(ast.newSimpleType(ast.newSimpleName(retTypeName)));
  else {
    Type baseType = ast.newSimpleType(ast.newSimpleName(retTypeName));
    ParameterizedType newRetType = ast.newParameterizedType(baseType);
    List<Type> newRetTypeArgs = newRetType.typeArguments();

    for (int i = 0; i < ctorOwnerTypeParameters.length; i++) {
      Type retTypeArg = ASTNodeFactory.newType(ast, ctorOwnerTypeParameters[i].getName());

      newRetTypeArgs.add(retTypeArg);
    }
    newMethod.setReturnType2(newRetType);
  }
}
 
开发者ID:eclipse,项目名称:che,代码行数:32,代码来源:IntroduceFactoryRefactoring.java

示例3: getOwnerTypeBinding

import org.eclipse.jdt.core.dom.ParameterizedType; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
private static ITypeBinding getOwnerTypeBinding(
    TypeDeclaration uiBinderSubtype) {
  List<Type> superInterfaces = uiBinderSubtype.superInterfaceTypes();
  for (Type superInterface : superInterfaces) {
    ITypeBinding binding = superInterface.resolveBinding();
    if (binding != null) {
      if (binding.getErasure().getQualifiedName().equals(
          UiBinderConstants.UI_BINDER_TYPE_NAME)) {
        if (superInterface instanceof ParameterizedType) {
          ParameterizedType uiBinderType = (ParameterizedType) superInterface;
          List<Type> typeArgs = uiBinderType.typeArguments();
          if (typeArgs.size() == 2) {
            Type ownerType = typeArgs.get(1);
            return ownerType.resolveBinding();
          }
        }
      }
    }
  }
  return null;
}
 
开发者ID:gwt-plugins,项目名称:gwt-eclipse-plugin,代码行数:23,代码来源:UiBinderJavaValidator.java

示例4: setCtorTypeArguments

import org.eclipse.jdt.core.dom.ParameterizedType; //导入方法依赖的package包/类
/**
 * Sets the type being instantiated in the given constructor call, including
    * specifying any necessary type arguments.
 * @param newCtorCall the constructor call to modify
 * @param ctorTypeName the simple name of the type being instantiated
 * @param ctorOwnerTypeParameters the formal type parameters of the type being
 * instantiated
 * @param ast utility object used to create AST nodes
 */
private void setCtorTypeArguments(ClassInstanceCreation newCtorCall, String ctorTypeName, ITypeBinding[] ctorOwnerTypeParameters, AST ast) {
       if (ctorOwnerTypeParameters.length == 0) // easy, just a simple type
           newCtorCall.setType(ASTNodeFactory.newType(ast, ctorTypeName));
       else {
           Type baseType= ast.newSimpleType(ast.newSimpleName(ctorTypeName));
           ParameterizedType newInstantiatedType= ast.newParameterizedType(baseType);
           List<Type> newInstTypeArgs= newInstantiatedType.typeArguments();

           for(int i= 0; i < ctorOwnerTypeParameters.length; i++) {
               Type typeArg= ASTNodeFactory.newType(ast, ctorOwnerTypeParameters[i].getName());

               newInstTypeArgs.add(typeArg);
           }
           newCtorCall.setType(newInstantiatedType);
       }
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:26,代码来源:IntroduceFactoryRefactoring.java

示例5: setMethodReturnType

import org.eclipse.jdt.core.dom.ParameterizedType; //导入方法依赖的package包/类
/**
 * Sets the return type of the factory method, including any necessary type
 * arguments. E.g., for constructor <code>Foo()</code> in <code>Foo&lt;T&gt;</code>,
 * the factory method defines a method type parameter <code>&lt;T&gt;</code> and
 * returns a <code>Foo&lt;T&gt;</code>.
 * @param newMethod the method whose return type is to be set
 * @param retTypeName the simple name of the return type (without type parameters)
 * @param ctorOwnerTypeParameters the formal type parameters of the type that the
 * factory method instantiates (whose constructor is being encapsulated)
 * @param ast utility object used to create AST nodes
 */
private void setMethodReturnType(MethodDeclaration newMethod, String retTypeName, ITypeBinding[] ctorOwnerTypeParameters, AST ast) {
       if (ctorOwnerTypeParameters.length == 0)
           newMethod.setReturnType2(ast.newSimpleType(ast.newSimpleName(retTypeName)));
       else {
           Type baseType= ast.newSimpleType(ast.newSimpleName(retTypeName));
           ParameterizedType newRetType= ast.newParameterizedType(baseType);
           List<Type> newRetTypeArgs= newRetType.typeArguments();

           for(int i= 0; i < ctorOwnerTypeParameters.length; i++) {
               Type retTypeArg= ASTNodeFactory.newType(ast, ctorOwnerTypeParameters[i].getName());

               newRetTypeArgs.add(retTypeArg);
           }
           newMethod.setReturnType2(newRetType);
       }
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:28,代码来源:IntroduceFactoryRefactoring.java

示例6: transferTypeArguments

import org.eclipse.jdt.core.dom.ParameterizedType; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
private void transferTypeArguments(ParameterizedType existingType, ParameterizedType newType) {
    List<Type> oldTypeArgs = existingType.typeArguments();

    int i = 0;
    while (!oldTypeArgs.isEmpty()) {
        // This is the only way I could find to copy the Types. rewrite.createCopyTarget didn't help
        // because the types seemed to be in a limbo between attached and not attached.
        // If I try to copy w/o deleting them from the original list, some sort of infinite loop happens
        // on clone
        Type oldType = oldTypeArgs.get(0);
        oldType.delete();
        if (i == 0) {
            this.keyType = copy(oldType);
        } else if (i == 1) {
            this.valueType = copy(oldType);
        }
        // oldType is okay to add now w/o a clone, because it is detached.
        newType.typeArguments().add(oldType);
        i++;
    }
}
 
开发者ID:kjlubick,项目名称:fb-contrib-eclipse-quick-fixes,代码行数:23,代码来源:EntrySetResolution.java

示例7: rewriteAST

import org.eclipse.jdt.core.dom.ParameterizedType; //导入方法依赖的package包/类
/** {@inheritDoc} */
@Override
public void rewriteAST(CompilationUnitRewrite cuRewrite, LinkedProposalModel positionGroups)
    throws CoreException {
  InferTypeArgumentsTCModel model = new InferTypeArgumentsTCModel();
  InferTypeArgumentsConstraintCreator creator =
      new InferTypeArgumentsConstraintCreator(model, true);

  CompilationUnit root = cuRewrite.getRoot();
  root.accept(creator);

  InferTypeArgumentsConstraintsSolver solver = new InferTypeArgumentsConstraintsSolver(model);
  InferTypeArgumentsUpdate update = solver.solveConstraints(new NullProgressMonitor());
  solver = null; // free caches

  ParameterizedType[] nodes =
      InferTypeArgumentsRefactoring.inferArguments(fTypes, update, model, cuRewrite);
  if (nodes.length == 0) return;

  ASTRewrite astRewrite = cuRewrite.getASTRewrite();
  for (int i = 0; i < nodes.length; i++) {
    ParameterizedType type = nodes[i];
    List<Type> args = type.typeArguments();
    int j = 0;
    for (Iterator<Type> iter = args.iterator(); iter.hasNext(); ) {
      LinkedProposalPositionGroup group =
          new LinkedProposalPositionGroup("G" + i + "_" + j); // $NON-NLS-1$ //$NON-NLS-2$
      Type argType = iter.next();
      if (!positionGroups.hasLinkedPositions()) {
        group.addPosition(astRewrite.track(argType), true);
      } else {
        group.addPosition(astRewrite.track(argType), false);
      }
      positionGroups.addPositionGroup(group);
      j++;
    }
  }
  positionGroups.setEndPosition(astRewrite.track(nodes[0]));
}
 
开发者ID:eclipse,项目名称:che,代码行数:40,代码来源:Java50Fix.java

示例8: doValidateReturnTypes

import org.eclipse.jdt.core.dom.ParameterizedType; //导入方法依赖的package包/类
/**
 * Validate that the AsyncCallback's parameterization and the sync method's
 * return type are assignment compatible.
 */
@SuppressWarnings("unchecked")
private List<CategorizedProblem> doValidateReturnTypes(
    MethodDeclaration node, SingleVariableDeclaration lastParameter,
    ITypeBinding[] parameterTypes, IMethodBinding dependentMethod) {
  ITypeBinding asyncCallbackParam = parameterTypes[parameterTypes.length - 1];
  if (asyncCallbackParam.isParameterizedType()) {
    ITypeBinding[] typeArguments = asyncCallbackParam.getTypeArguments();
    ITypeBinding syncReturnTypeBinding = dependentMethod.getReturnType();

    ITypeBinding typeBinding = syncReturnTypeBinding;
    if (syncReturnTypeBinding.isPrimitive()) {
      String qualifiedWrapperTypeName = JavaASTUtils.getWrapperTypeName(syncReturnTypeBinding.getQualifiedName());
      typeBinding = node.getAST().resolveWellKnownType(
          qualifiedWrapperTypeName);
    }

    boolean compatible = false;
    if (typeBinding != null) {
      compatible = canAssign(typeArguments[0], typeBinding);
    }

    if (!compatible) {
      ParameterizedType parameterizedType = (ParameterizedType) lastParameter.getType();
      List<Type> types = parameterizedType.typeArguments();
      CategorizedProblem problem = RemoteServiceProblemFactory.newAsyncCallbackTypeArgumentMismatchOnAsync(
          types.get(0), typeArguments[0], syncReturnTypeBinding);
      if (problem != null) {
        return Collections.singletonList(problem);
      }
    }
  }

  return Collections.emptyList();
}
 
开发者ID:gwt-plugins,项目名称:gwt-eclipse-plugin,代码行数:39,代码来源:AsynchronousInterfaceValidator.java

示例9: createAsyncCallbackParameter

import org.eclipse.jdt.core.dom.ParameterizedType; //导入方法依赖的package包/类
/**
 * Creates a GWT RPC async callback parameter declaration based on the sync
 * method return type.
 *
 * @param ast {@link AST} associated with the destination compilation unit
 * @param syncReturnType the sync method return type
 * @param callbackParameterName name of the callback parameter
 * @param imports {@link ImportsRewrite} for the destination compilation unit
 * @return callback paramter declaration
 */
@SuppressWarnings("unchecked")
public static SingleVariableDeclaration createAsyncCallbackParameter(AST ast,
    Type syncReturnType, String callbackParameterName, ImportRewrite imports) {
  ITypeBinding syncReturnTypeBinding = syncReturnType.resolveBinding();

  SingleVariableDeclaration parameter = ast.newSingleVariableDeclaration();

  String gwtCallbackTypeSig = Signature.createTypeSignature(
      RemoteServiceUtilities.ASYNCCALLBACK_QUALIFIED_NAME, true);
  Type gwtCallbackType = imports.addImportFromSignature(gwtCallbackTypeSig,
      ast);

  if (syncReturnTypeBinding.isPrimitive()) {
    String wrapperName = JavaASTUtils.getWrapperTypeName(syncReturnTypeBinding.getName());
    String wrapperTypeSig = Signature.createTypeSignature(wrapperName, true);
    syncReturnType = imports.addImportFromSignature(wrapperTypeSig, ast);
  } else {
    syncReturnType = JavaASTUtils.normalizeTypeAndAddImport(ast,
        syncReturnType, imports);
  }

  ParameterizedType type = ast.newParameterizedType(gwtCallbackType);
  List<Type> typeArgs = type.typeArguments();
  typeArgs.add(syncReturnType);

  parameter.setType(type);
  parameter.setName(ast.newSimpleName(callbackParameterName));

  return parameter;
}
 
开发者ID:gwt-plugins,项目名称:gwt-eclipse-plugin,代码行数:41,代码来源:Util.java

示例10: rewriteAST

import org.eclipse.jdt.core.dom.ParameterizedType; //导入方法依赖的package包/类
/**
 * {@inheritDoc}
 */
@Override
public void rewriteAST(CompilationUnitRewrite cuRewrite, LinkedProposalModel positionGroups) throws CoreException {
	InferTypeArgumentsTCModel model= new InferTypeArgumentsTCModel();
	InferTypeArgumentsConstraintCreator creator= new InferTypeArgumentsConstraintCreator(model, true);

	CompilationUnit root= cuRewrite.getRoot();
	root.accept(creator);

	InferTypeArgumentsConstraintsSolver solver= new InferTypeArgumentsConstraintsSolver(model);
	InferTypeArgumentsUpdate update= solver.solveConstraints(new NullProgressMonitor());
	solver= null; //free caches

	ParameterizedType[] nodes= InferTypeArgumentsRefactoring.inferArguments(fTypes, update, model, cuRewrite);
	if (nodes.length == 0)
		return;

	ASTRewrite astRewrite= cuRewrite.getASTRewrite();
	for (int i= 0; i < nodes.length; i++) {
		ParameterizedType type= nodes[i];
		List<Type> args= type.typeArguments();
		int j= 0;
		for (Iterator<Type> iter= args.iterator(); iter.hasNext();) {
			LinkedProposalPositionGroup group= new LinkedProposalPositionGroup("G" + i + "_" + j); //$NON-NLS-1$ //$NON-NLS-2$
			Type argType= iter.next();
			if (!positionGroups.hasLinkedPositions()) {
				group.addPosition(astRewrite.track(argType), true);
			} else {
				group.addPosition(astRewrite.track(argType), false);
			}
			positionGroups.addPositionGroup(group);
			j++;
		}
	}
	positionGroups.setEndPosition(astRewrite.track(nodes[0]));
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:39,代码来源:Java50Fix.java

示例11: addRemoveRedundantTypeArgumentsProposals

import org.eclipse.jdt.core.dom.ParameterizedType; //导入方法依赖的package包/类
public static void addRemoveRedundantTypeArgumentsProposals(IInvocationContext context, IProblemLocation problem, Collection<ICommandAccess> proposals) {
	CompilationUnit astRoot= context.getASTRoot();
	ASTNode selectedNode= problem.getCoveringNode(astRoot);
	if (selectedNode == null)
		return;

	while (!(selectedNode instanceof ParameterizedType) && !(selectedNode instanceof Statement)) {
		selectedNode= selectedNode.getParent();
	}
	if (!(selectedNode instanceof ParameterizedType)) {
		return;
	}
	ParameterizedType parameterizedType= (ParameterizedType) selectedNode;

	AST ast= astRoot.getAST();
	ASTRewrite rewrite= ASTRewrite.create(ast);
	ListRewrite listRewrite= rewrite.getListRewrite(parameterizedType, ParameterizedType.TYPE_ARGUMENTS_PROPERTY);

	List<Type> typeArguments= parameterizedType.typeArguments();
	for (Iterator<Type> iterator= typeArguments.iterator(); iterator.hasNext();) {
		listRewrite.remove(iterator.next(), null);
	}

	Image image= JavaPlugin.getDefault().getWorkbench().getSharedImages().getImage(ISharedImages.IMG_TOOL_DELETE);
	String label= CorrectionMessages.LocalCorrectionsSubProcessor_remove_type_arguments;
	ASTRewriteCorrectionProposal proposal= new ASTRewriteCorrectionProposal(label, context.getCompilationUnit(), rewrite, 6, image);
	proposals.add(proposal);
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion-Juno38,代码行数:29,代码来源:LocalCorrectionsSubProcessor.java

示例12: transferTypeArguments

import org.eclipse.jdt.core.dom.ParameterizedType; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
private void transferTypeArguments(ParameterizedType existingType, ParameterizedType newType) {
    // This is similar to the implementation from EntrySetResolution
    List<Type> oldTypeArgs = existingType.typeArguments();

    while (!oldTypeArgs.isEmpty()) {
        // transfer the type from one to the other.
        Type oldType = oldTypeArgs.get(0);
        oldType.delete();
        // oldType is okay to add now w/o a clone, because it is detached.
        newType.typeArguments().add(oldType);
    }
}
 
开发者ID:kjlubick,项目名称:fb-contrib-eclipse-quick-fixes,代码行数:14,代码来源:OverlyConcreteParametersResolution.java

示例13: computeSyncReturnType

import org.eclipse.jdt.core.dom.ParameterizedType; //导入方法依赖的package包/类
/**
 * Sync method has same return type as parameterization of last async
 * parameter (AsyncCallback). If the async callback parameter type is raw,
 * just assume sync return type of void.
 *
 * @param ast {@link AST} associated with the destination compilation unit
 * @param asyncMethod the GWT RPC async method declaration
 * @param imports {@link ImportRewrite} associated with the destination
 *          compilation unit
 * @return the computed return {@link Type}
 */
public static Type computeSyncReturnType(AST ast,
    MethodDeclaration asyncMethod, ImportRewrite imports) {
  Type returnType = ast.newPrimitiveType(PrimitiveType.VOID);
  @SuppressWarnings("unchecked")
  List<SingleVariableDeclaration> asyncParameters = asyncMethod.parameters();

  // Check for no parameters on async method... just in case
  if (asyncParameters.isEmpty()) {
    return returnType;
  }

  // Grab the last parameter type, which should be the callback
  Type callbackType = asyncParameters.get(asyncParameters.size() - 1).getType();

  // Make sure we have a parameterized callback type; otherwise, we can't
  // infer the return type of the sync method.
  if (callbackType.isParameterizedType()) {
    ParameterizedType callbackParamType = (ParameterizedType) callbackType;

    ITypeBinding callbackBinding = callbackParamType.getType().resolveBinding();
    if (callbackBinding == null) {
      return returnType;
    }

    // Make sure the callback is of type AsyncCallback
    String callbackBaseTypeName = callbackBinding.getErasure().getQualifiedName();
    if (callbackBaseTypeName.equals(RemoteServiceUtilities.ASYNCCALLBACK_QUALIFIED_NAME)) {
      @SuppressWarnings("unchecked")
      List<Type> callbackTypeArgs = callbackParamType.typeArguments();

      // Make sure we only have one type argument
      if (callbackTypeArgs.size() == 1) {
        Type callbackTypeParameter = callbackTypeArgs.get(0);

        // Check for primitive wrapper type; if we have one use the actual
        // primitive for the sync return type.
        // TODO(): Maybe used linked mode to let the user choose whether to
        // return the primitive or its wrapper type.
        String qualifiedName = callbackTypeParameter.resolveBinding().getQualifiedName();
        String primitiveTypeName = JavaASTUtils.getPrimitiveTypeName(qualifiedName);
        if (primitiveTypeName != null) {
          return ast.newPrimitiveType(PrimitiveType.toCode(primitiveTypeName));
        }

        returnType = JavaASTUtils.normalizeTypeAndAddImport(ast,
            callbackTypeParameter, imports);
      }
    }
  }

  return returnType;
}
 
开发者ID:gwt-plugins,项目名称:gwt-eclipse-plugin,代码行数:64,代码来源:Util.java

示例14: createType

import org.eclipse.jdt.core.dom.ParameterizedType; //导入方法依赖的package包/类
private Type createType(String typeSig, AST ast) {
	int sigKind = Signature.getTypeSignatureKind(typeSig);
       switch (sigKind) {
           case Signature.BASE_TYPE_SIGNATURE:
               return ast.newPrimitiveType(PrimitiveType.toCode(Signature.toString(typeSig)));
           case Signature.ARRAY_TYPE_SIGNATURE:
               Type elementType = createType(Signature.getElementType(typeSig), ast);
               return ast.newArrayType(elementType, Signature.getArrayCount(typeSig));
           case Signature.CLASS_TYPE_SIGNATURE:
               String erasureSig = Signature.getTypeErasure(typeSig);

               String erasureName = Signature.toString(erasureSig);
               if (erasureSig.charAt(0) == Signature.C_RESOLVED) {
                   erasureName = addImport(erasureName);
               }
               
               Type baseType= ast.newSimpleType(ast.newName(erasureName));
               String[] typeArguments = Signature.getTypeArguments(typeSig);
               if (typeArguments.length > 0) {
                   ParameterizedType type = ast.newParameterizedType(baseType);
                   List argNodes = type.typeArguments();
                   for (int i = 0; i < typeArguments.length; i++) {
                       String curr = typeArguments[i];
                       if (containsNestedCapture(curr)) {
                           argNodes.add(ast.newWildcardType());
                       } else {
                           argNodes.add(createType(curr, ast));
                       }
                   }
                   return type;
               }
               return baseType;
           case Signature.TYPE_VARIABLE_SIGNATURE:
               return ast.newSimpleType(ast.newSimpleName(Signature.toString(typeSig)));
           case Signature.WILDCARD_TYPE_SIGNATURE:
               WildcardType wildcardType= ast.newWildcardType();
               char ch = typeSig.charAt(0);
               if (ch != Signature.C_STAR) {
                   Type bound= createType(typeSig.substring(1), ast);
                   wildcardType.setBound(bound, ch == Signature.C_EXTENDS);
               }
               return wildcardType;
           case Signature.CAPTURE_TYPE_SIGNATURE:
               return createType(typeSig.substring(1), ast);
       }
       
       return ast.newSimpleType(ast.newName("java.lang.Object"));
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:49,代码来源:JavaStatementPostfixContext.java

示例15: getReturnTypeStr

import org.eclipse.jdt.core.dom.ParameterizedType; //导入方法依赖的package包/类
public String getReturnTypeStr()
{
	Type returnType = methodDeclaration.getReturnType2();
	if (returnType == null || isVoid(returnType))
	{
		return null;
	}
	else if (returnType.isPrimitiveType())
	{
		return "_" + returnType.toString();
	}
	else if (returnType.isArrayType())
	{
		Type componentType = ((ArrayType)returnType).getElementType();
		if (componentType.isPrimitiveType())
			return "_" + returnType.toString();
		else
			return NameUtil.stripTypeArguments(componentType.resolveBinding().getQualifiedName());
	}
	else if (returnType.isParameterizedType())
	{
		ParameterizedType parameterizedType = (ParameterizedType)returnType;
		@SuppressWarnings("unchecked")
		List<Type> typeArgs = parameterizedType.typeArguments();
		IType rawType = (IType)parameterizedType.getType().resolveBinding().getJavaElement();
		if (SupertypeHierarchyCache.getInstance().isCollection(rawType))
		{
			if (typeArgs.size() == 1)
				return NameUtil
					.stripTypeArguments(typeArgs.get(0).resolveBinding().getQualifiedName());
		}
		else if (SupertypeHierarchyCache.getInstance().isMap(rawType))
		{
			if (!isHasMapKey())
				return rawType.getFullyQualifiedName();
			else if (typeArgs.size() == 2)
				return NameUtil
					.stripTypeArguments(typeArgs.get(0).resolveBinding().getQualifiedName());
		}
	}
	ITypeBinding binding = returnType.resolveBinding();
	return binding == null ? null : binding.getQualifiedName();
}
 
开发者ID:mybatis,项目名称:mybatipse,代码行数:44,代码来源:JavaQuickAssistProcessor.java


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