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


Java ClassInstanceCreation.setAnonymousClassDeclaration方法代码示例

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


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

示例1: createNewClassInstanceCreation

import org.eclipse.jdt.core.dom.ClassInstanceCreation; //导入方法依赖的package包/类
private ASTNode createNewClassInstanceCreation(
    CompilationUnitRewrite rewrite, ITypeBinding[] parameters) {
  AST ast = fAnonymousInnerClassNode.getAST();
  ClassInstanceCreation newClassCreation = ast.newClassInstanceCreation();
  newClassCreation.setAnonymousClassDeclaration(null);
  Type type = null;
  SimpleName newNameNode = ast.newSimpleName(fClassName);
  if (parameters.length > 0) {
    final ParameterizedType parameterized =
        ast.newParameterizedType(ast.newSimpleType(newNameNode));
    for (int index = 0; index < parameters.length; index++)
      parameterized
          .typeArguments()
          .add(ast.newSimpleType(ast.newSimpleName(parameters[index].getName())));
    type = parameterized;
  } else type = ast.newSimpleType(newNameNode);
  newClassCreation.setType(type);
  copyArguments(rewrite, newClassCreation);
  addArgumentsForLocalsUsedInInnerClass(newClassCreation);

  addLinkedPosition(KEY_TYPE_NAME, newNameNode, rewrite.getASTRewrite(), true);

  return newClassCreation;
}
 
开发者ID:eclipse,项目名称:che,代码行数:25,代码来源:ConvertAnonymousToNestedRefactoring.java

示例2: createNewClassInstanceCreation

import org.eclipse.jdt.core.dom.ClassInstanceCreation; //导入方法依赖的package包/类
private ASTNode createNewClassInstanceCreation(CompilationUnitRewrite rewrite, ITypeBinding[] parameters) {
	AST ast= fAnonymousInnerClassNode.getAST();
	ClassInstanceCreation newClassCreation= ast.newClassInstanceCreation();
	newClassCreation.setAnonymousClassDeclaration(null);
	Type type= null;
	SimpleName newNameNode= ast.newSimpleName(fClassName);
	if (parameters.length > 0) {
		final ParameterizedType parameterized= ast.newParameterizedType(ast.newSimpleType(newNameNode));
		for (int index= 0; index < parameters.length; index++)
			parameterized.typeArguments().add(ast.newSimpleType(ast.newSimpleName(parameters[index].getName())));
		type= parameterized;
	} else
		type= ast.newSimpleType(newNameNode);
	newClassCreation.setType(type);
	copyArguments(rewrite, newClassCreation);
	addArgumentsForLocalsUsedInInnerClass(newClassCreation);

	addLinkedPosition(KEY_TYPE_NAME, newNameNode, rewrite.getASTRewrite(), true);

	return newClassCreation;
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:22,代码来源:ConvertAnonymousToNestedRefactoring.java

示例3: createPrivilegedActionCreation

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

    ClassInstanceCreation privilegedActionCreation = ast.newClassInstanceCreation();
    ParameterizedType privilegedActionType = createPrivilegedActionType(rewrite, classLoaderCreation);
    AnonymousClassDeclaration anonymousClassDeclaration = createAnonymousClassDeclaration(rewrite, classLoaderCreation);

    privilegedActionCreation.setType(privilegedActionType);
    privilegedActionCreation.setAnonymousClassDeclaration(anonymousClassDeclaration);

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

示例4: createFactoryMethod

import org.eclipse.jdt.core.dom.ClassInstanceCreation; //导入方法依赖的package包/类
/**
 * Creates and returns a new MethodDeclaration that represents the factory method to be used in
 * place of direct calls to the constructor in question.
 *
 * @param ast An AST used as a factory for various AST nodes
 * @param ctorBinding binding for the constructor being wrapped
 * @param unitRewriter the ASTRewrite to be used
 * @return the new method declaration
 * @throws CoreException if an exception occurs while accessing its corresponding resource
 */
private MethodDeclaration createFactoryMethod(
    AST ast, IMethodBinding ctorBinding, ASTRewrite unitRewriter) throws CoreException {
  MethodDeclaration newMethod = ast.newMethodDeclaration();
  SimpleName newMethodName = ast.newSimpleName(fNewMethodName);
  ClassInstanceCreation newCtorCall = ast.newClassInstanceCreation();
  ReturnStatement ret = ast.newReturnStatement();
  Block body = ast.newBlock();
  List<Statement> stmts = body.statements();
  String retTypeName = ctorBinding.getName();

  createFactoryMethodSignature(ast, newMethod);

  newMethod.setName(newMethodName);
  newMethod.setBody(body);

  ITypeBinding declaringClass = fCtorBinding.getDeclaringClass();
  ITypeBinding[] ctorOwnerTypeParameters = declaringClass.getTypeParameters();

  setMethodReturnType(newMethod, retTypeName, ctorOwnerTypeParameters, ast);

  newMethod
      .modifiers()
      .addAll(ASTNodeFactory.newModifiers(ast, Modifier.STATIC | Modifier.PUBLIC));

  setCtorTypeArguments(newCtorCall, retTypeName, ctorOwnerTypeParameters, ast);

  createFactoryMethodConstructorArgs(ast, newCtorCall);

  if (Modifier.isAbstract(declaringClass.getModifiers())) {
    AnonymousClassDeclaration decl = ast.newAnonymousClassDeclaration();
    IMethodBinding[] unimplementedMethods = getUnimplementedMethods(declaringClass);
    CodeGenerationSettings settings =
        JavaPreferencesSettings.getCodeGenerationSettings(fCUHandle.getJavaProject());
    ImportRewriteContext context =
        new ContextSensitiveImportRewriteContext(
            fFactoryCU, decl.getStartPosition(), fImportRewriter);
    for (int i = 0; i < unimplementedMethods.length; i++) {
      IMethodBinding unImplementedMethod = unimplementedMethods[i];
      MethodDeclaration newMethodDecl =
          StubUtility2.createImplementationStub(
              fCUHandle,
              unitRewriter,
              fImportRewriter,
              context,
              unImplementedMethod,
              unImplementedMethod.getDeclaringClass().getName(),
              settings,
              false);
      decl.bodyDeclarations().add(newMethodDecl);
    }
    newCtorCall.setAnonymousClassDeclaration(decl);
  }

  ret.setExpression(newCtorCall);
  stmts.add(ret);

  return newMethod;
}
 
开发者ID:eclipse,项目名称:che,代码行数:69,代码来源:IntroduceFactoryRefactoring.java

示例5: createFactoryMethod

import org.eclipse.jdt.core.dom.ClassInstanceCreation; //导入方法依赖的package包/类
/**
 * Creates and returns a new MethodDeclaration that represents the factory method to be used in
 * place of direct calls to the constructor in question.
 * 
 * @param ast An AST used as a factory for various AST nodes
 * @param ctorBinding binding for the constructor being wrapped
 * @param unitRewriter the ASTRewrite to be used
 * @return the new method declaration
 * @throws CoreException if an exception occurs while accessing its corresponding resource
 */
private MethodDeclaration createFactoryMethod(AST ast, IMethodBinding ctorBinding, ASTRewrite unitRewriter) throws CoreException{
	MethodDeclaration		newMethod= ast.newMethodDeclaration();
	SimpleName				newMethodName= ast.newSimpleName(fNewMethodName);
	ClassInstanceCreation	newCtorCall= ast.newClassInstanceCreation();
	ReturnStatement			ret= ast.newReturnStatement();
	Block		body= ast.newBlock();
	List<Statement>		stmts= body.statements();
	String		retTypeName= ctorBinding.getName();

	createFactoryMethodSignature(ast, newMethod);

	newMethod.setName(newMethodName);
	newMethod.setBody(body);

	ITypeBinding declaringClass= fCtorBinding.getDeclaringClass();
	ITypeBinding[] ctorOwnerTypeParameters= declaringClass.getTypeParameters();

	setMethodReturnType(newMethod, retTypeName, ctorOwnerTypeParameters, ast);

	newMethod.modifiers().addAll(ASTNodeFactory.newModifiers(ast, Modifier.STATIC | Modifier.PUBLIC));

	setCtorTypeArguments(newCtorCall, retTypeName, ctorOwnerTypeParameters, ast);

	createFactoryMethodConstructorArgs(ast, newCtorCall);

	if (Modifier.isAbstract(declaringClass.getModifiers())) {
		AnonymousClassDeclaration decl= ast.newAnonymousClassDeclaration();
		IMethodBinding[] unimplementedMethods= getUnimplementedMethods(declaringClass);
		CodeGenerationSettings settings= JavaPreferencesSettings.getCodeGenerationSettings(fCUHandle.getJavaProject());
		ImportRewriteContext context= new ContextSensitiveImportRewriteContext(fFactoryCU, decl.getStartPosition(), fImportRewriter);
		for (int i= 0; i < unimplementedMethods.length; i++) {
			IMethodBinding unImplementedMethod= unimplementedMethods[i];
			MethodDeclaration newMethodDecl= StubUtility2.createImplementationStub(fCUHandle, unitRewriter, fImportRewriter, context, unImplementedMethod, unImplementedMethod.getDeclaringClass()
					.getName(), settings, false);
			decl.bodyDeclarations().add(newMethodDecl);
		}
		newCtorCall.setAnonymousClassDeclaration(decl);
	}

	ret.setExpression(newCtorCall);
	stmts.add(ret);

	return newMethod;
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:55,代码来源:IntroduceFactoryRefactoring.java


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