Java Code Examples for org.eclipse.jdt.core.dom.ClassInstanceCreation#setAnonymousClassDeclaration()
The following examples show how to use
org.eclipse.jdt.core.dom.ClassInstanceCreation#setAnonymousClassDeclaration() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ConvertAnonymousToNestedRefactoring.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
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; }
Example 2
Source File: CreateDoPrivilegedBlockResolution.java From spotbugs with GNU Lesser General Public License v2.1 | 5 votes |
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; }
Example 3
Source File: IntroduceFactoryRefactoring.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
/** * 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; }