public MethodImpl(final O parent) { init(parent); method = ast.newMethodDeclaration(); method.setConstructor(false); }
@Override final boolean internalGetSetBooleanProperty(SimplePropertyDescriptor property, boolean get, boolean value) { if (property == CONSTRUCTOR_PROPERTY) { if (get) { return isConstructor(); } else { setConstructor(value); return false; } } // allow default implementation to flag the error return super.internalGetSetBooleanProperty(property, get, value); }
final boolean internalGetSetBooleanProperty(SimplePropertyDescriptor property, boolean get, boolean value) { if (property == CONSTRUCTOR_PROPERTY) { if (get) { return isConstructor(); } else { setConstructor(value); return false; } } // allow default implementation to flag the error return super.internalGetSetBooleanProperty(property, get, value); }
final boolean internalGetSetBooleanProperty(SimplePropertyDescriptor property, boolean get, boolean value) { if (property == CONSTRUCTOR_PROPERTY) { if (get) { return isConstructor(); } else { setConstructor(value); return false; } } // allow default implementation to flag the error return super.internalGetSetBooleanProperty(property, get, value); }
final boolean internalGetSetBooleanProperty(SimplePropertyDescriptor property, boolean get, boolean value) { if (property == CONSTRUCTOR_PROPERTY) { if (get) { return isConstructor(); } else { setConstructor(value); return false; } } // allow default implementation to flag the error return super.internalGetSetBooleanProperty(property, get, value); }
final boolean internalGetSetBooleanProperty(SimplePropertyDescriptor property, boolean get, boolean value) { if (property == CONSTRUCTOR_PROPERTY) { if (get) { return isConstructor(); } else { setConstructor(value); return false; } } // allow default implementation to flag the error return super.internalGetSetBooleanProperty(property, get, value); }
public MethodImpl(final O parent) { init(parent); method = ast.newMethodDeclaration(); method.setConstructor(false); }
final boolean internalGetSetBooleanProperty(SimplePropertyDescriptor property, boolean get, boolean value) { if (property == CONSTRUCTOR_PROPERTY) { if (get) { return isConstructor(); } else { setConstructor(value); return false; } } // allow default implementation to flag the error return super.internalGetSetBooleanProperty(property, get, value); }
@Override public MethodSource<O> setConstructor(final boolean constructor) { method.setConstructor(constructor); if (isConstructor()) { method.setName(ast.newSimpleName(parent.getName())); } return this; }
@Override public MethodSource<O> setConstructor(final boolean constructor) { method.setConstructor(constructor); if (isConstructor()) { method.setName(ast.newSimpleName(parent.getName())); } return this; }
/** * Add constructor declaration. * * @param name simple class name * @return constructor builder */ public MethodBuilder addConstructor(String name) { MethodDeclaration constr = getAST().newMethodDeclaration(); constr.setName(getAST().newSimpleName(name)); constr.setConstructor(true); m_methods.add(constr); return new MethodBuilder(this, constr); }
private void copyMethodToDestination(IMethod method, CompilationUnitRewrite targetRewriter, CompilationUnit sourceCuNode, CompilationUnit targetCuNode) throws JavaModelException { MethodDeclaration newMethod= (MethodDeclaration) targetRewriter.getASTRewrite().createStringPlaceholder(getUnindentedSource(method), ASTNode.METHOD_DECLARATION); newMethod.setConstructor(method.isConstructor()); copyMemberToDestination(method, targetRewriter, sourceCuNode, targetCuNode, newMethod); }
private void copyMethodToDestination(IMethod method, CompilationUnitRewrite targetRewriter, CompilationUnit sourceCuNode, CompilationUnit targetCuNode) throws JavaModelException { MethodDeclaration newMethod= (MethodDeclaration) targetRewriter.getASTRewrite().createStringPlaceholder(getUnindentedSource(method), ASTNode.METHOD_DECLARATION); newMethod.setConstructor(method.isConstructor()); copyMemberToDestination(method, targetRewriter, sourceCuNode, targetCuNode, newMethod); }
private void copyMethodToDestination(IMethod method, CompilationUnitRewrite targetRewriter, CompilationUnit sourceCuNode, CompilationUnit targetCuNode) throws JavaModelException { MethodDeclaration newMethod= (MethodDeclaration) targetRewriter.getASTRewrite().createStringPlaceholder(getUnindentedSource(method), ASTNode.METHOD_DECLARATION); newMethod.setConstructor(method.isConstructor()); copyMemberToDestination(method, targetRewriter, sourceCuNode, targetCuNode, newMethod); }
@SuppressWarnings("unchecked") private void generateConstructorDefault(Classifier clazz, AST ast, TypeDeclaration td) { MethodDeclaration constructor = ast.newMethodDeclaration(); constructor.setConstructor(true); constructor.setName(ast.newSimpleName(clazz.getName())); constructor.modifiers().add( ast.newModifier(Modifier.ModifierKeyword.PUBLIC_KEYWORD)); Block block = ast.newBlock(); constructor.setBody(block); td.bodyDeclarations().add(constructor); }
private CAstEntity createDefaultConstructor(ITypeBinding classBinding, WalkContext oldContext, ArrayList<ASTNode> inits, ASTNode positioningNode) { MethodDeclaration fakeCtor = ast.newMethodDeclaration(); fakeCtor.setConstructor(true); // fakeCtor.setName(ast.newSimpleName(className)); will crash on anonymous types... fakeCtor.setSourceRange(positioningNode.getStartPosition(), positioningNode.getLength()); fakeCtor.setBody(ast.newBlock()); return visit(fakeCtor, classBinding, oldContext, inits); }
/** * This method initializes all variables used in the process of generating <code>toString</code> * method. */ protected void initialize() { needMaxLenVariable= false; needCollectionToStringMethod= false; typesThatNeedArrayToStringMethod= new ArrayList<>(); checkNeedForHelperMethods(); toStringMethod= fAst.newMethodDeclaration(); toStringMethod.modifiers().addAll(ASTNodeFactory.newModifiers(fAst, Modifier.PUBLIC)); toStringMethod.setName(fAst.newSimpleName(METHODNAME_TO_STRING)); toStringMethod.setConstructor(false); toStringMethod.setReturnType2(fAst.newSimpleType(fAst.newName(TYPENAME_STRING))); Block body= fAst.newBlock(); toStringMethod.setBody(body); fMaxLenVariableName= createNameSuggestion(MAX_LEN_VARIABLE_NAME, NamingConventions.VK_LOCAL); }
private MethodDeclaration createGetEnclosingInstanceHelper() { String enclosingTypeName= fType.getDeclaringClass().getTypeDeclaration().getName(); MethodDeclaration helperMethod= fAst.newMethodDeclaration(); helperMethod.modifiers().addAll(ASTNodeFactory.newModifiers(fAst, Modifier.PRIVATE)); helperMethod.setName(fAst.newSimpleName(METHODNAME_GET_ENCLOSING_INSTANCE)); helperMethod.setConstructor(false); helperMethod.setReturnType2(fAst.newSimpleType(fAst.newSimpleName(enclosingTypeName))); Block body= fAst.newBlock(); helperMethod.setBody(body); ThisExpression thisExpression= fAst.newThisExpression(); thisExpression.setQualifier(fAst.newSimpleName(enclosingTypeName)); ReturnStatement endReturn= fAst.newReturnStatement(); endReturn.setExpression(thisExpression); body.statements().add(endReturn); return helperMethod; }
private MethodDeclaration createGetOuterHelper() { String outerTypeName= fType.getDeclaringClass().getTypeDeclaration().getName(); MethodDeclaration helperMethod= fAst.newMethodDeclaration(); helperMethod.modifiers().addAll(ASTNodeFactory.newModifiers(fAst, Modifier.PRIVATE)); helperMethod.setName(fAst.newSimpleName(METHODNAME_OUTER_TYPE)); helperMethod.setConstructor(false); helperMethod.setReturnType2(fAst.newSimpleType(fAst.newSimpleName(outerTypeName))); Block body= fAst.newBlock(); helperMethod.setBody(body); ThisExpression thisExpression= fAst.newThisExpression(); thisExpression.setQualifier(fAst.newSimpleName(outerTypeName)); ReturnStatement endReturn= fAst.newReturnStatement(); endReturn.setExpression(thisExpression); body.statements().add(endReturn); return helperMethod; }
private void addMethodStubForAbstractMethod(final IMethod sourceMethod, final CompilationUnit declaringCuNode, final AbstractTypeDeclaration typeToCreateStubIn, final ICompilationUnit newCu, final CompilationUnitRewrite rewriter, final Map adjustments, final IProgressMonitor monitor, final RefactoringStatus status) throws CoreException { final MethodDeclaration methodToCreateStubFor= ASTNodeSearchUtil.getMethodDeclarationNode(sourceMethod, declaringCuNode); final AST ast= rewriter.getRoot().getAST(); final MethodDeclaration newMethod= ast.newMethodDeclaration(); newMethod.setBody(createMethodStub(methodToCreateStubFor, ast)); newMethod.setConstructor(false); newMethod.setExtraDimensions(methodToCreateStubFor.getExtraDimensions()); newMethod.modifiers().addAll(ASTNodeFactory.newModifiers(ast, getModifiersWithUpdatedVisibility(sourceMethod, JdtFlags.clearFlag(Modifier.NATIVE | Modifier.ABSTRACT, methodToCreateStubFor.getModifiers()), adjustments, new SubProgressMonitor(monitor, 1), false, status))); newMethod.setName(((SimpleName) ASTNode.copySubtree(ast, methodToCreateStubFor.getName()))); final TypeVariableMaplet[] mapping= TypeVariableUtil.composeMappings(TypeVariableUtil.subTypeToSuperType(getDeclaringType(), getDestinationType()), TypeVariableUtil.superTypeToInheritedType(getDestinationType(), ((IType) typeToCreateStubIn.resolveBinding().getJavaElement()))); copyReturnType(rewriter.getASTRewrite(), getDeclaringType().getCompilationUnit(), methodToCreateStubFor, newMethod, mapping); copyParameters(rewriter.getASTRewrite(), getDeclaringType().getCompilationUnit(), methodToCreateStubFor, newMethod, mapping); copyThrownExceptions(methodToCreateStubFor, newMethod); newMethod.setJavadoc(createJavadocForStub(typeToCreateStubIn.getName().getIdentifier(), methodToCreateStubFor, newMethod, newCu, rewriter.getASTRewrite())); ImportRewriteUtil.addImports(rewriter, newMethod, new HashMap(), new HashMap(), false); rewriter.getASTRewrite().getListRewrite(typeToCreateStubIn, typeToCreateStubIn.getBodyDeclarationsProperty()).insertAt(newMethod, ASTNodes.getInsertionIndex(newMethod, typeToCreateStubIn.bodyDeclarations()), rewriter.createCategorizedGroupDescription(RefactoringCoreMessages.PullUpRefactoring_add_method_stub, SET_PULL_UP)); }