private void removeExtraDimensions(MethodDeclaration methDecl) { if (methDecl.getExtraDimensions() != 0) getASTRewrite().set(methDecl, MethodDeclaration.EXTRA_DIMENSIONS_PROPERTY, new Integer(0), fDescription); }
protected Expression createDefaultExpression(AST ast) { return ASTNodeFactory.newDefaultExpression(ast, fMethodDecl.getReturnType2(), fMethodDecl.getExtraDimensions()); }
protected Expression createDefaultExpression(AST ast) { return ASTNodeFactory.newDefaultExpression(ast, fMethodDecl.getReturnType2(), fMethodDecl.getExtraDimensions()); }
protected Expression createDefaultExpression(AST ast) { return ASTNodeFactory.newDefaultExpression(ast, fMethodDecl.getReturnType2(), fMethodDecl.getExtraDimensions()); }
private static Block createMethodStub(final MethodDeclaration method, final AST ast) { final Block body= ast.newBlock(); final Expression expression= ASTNodeFactory.newDefaultExpression(ast, method.getReturnType2(), method.getExtraDimensions()); if (expression != null) { final ReturnStatement returnStatement= ast.newReturnStatement(); returnStatement.setExpression(expression); body.statements().add(returnStatement); } return body; }
private static Block createMethodStub(final MethodDeclaration method, final AST ast) { final Block body= ast.newBlock(); final Expression expression= ASTNodeFactory.newDefaultExpression(ast, method.getReturnType2(), method.getExtraDimensions()); if (expression != null) { final ReturnStatement returnStatement= ast.newReturnStatement(); returnStatement.setExpression(expression); body.statements().add(returnStatement); } return body; }
final int internalGetSetIntProperty(SimplePropertyDescriptor property, boolean get, int value) { if (property == MODIFIERS_PROPERTY) { if (get) { return getModifiers(); } else { internalSetModifiers(value); return 0; } } if (property == EXTRA_DIMENSIONS_PROPERTY) { if (get) { return getExtraDimensions(); } else { setExtraDimensions(value); return 0; } } // allow default implementation to flag the error return super.internalGetSetIntProperty(property, get, value); }
final int internalGetSetIntProperty(SimplePropertyDescriptor property, boolean get, int value) { if (property == MODIFIERS_PROPERTY) { if (get) { return getModifiers(); } else { internalSetModifiers(value); return 0; } } if (property == EXTRA_DIMENSIONS_PROPERTY) { if (get) { return getExtraDimensions(); } else { setExtraDimensions(value); return 0; } } // allow default implementation to flag the error return super.internalGetSetIntProperty(property, get, value); }
final int internalGetSetIntProperty(SimplePropertyDescriptor property, boolean get, int value) { if (property == MODIFIERS_PROPERTY) { if (get) { return getModifiers(); } else { internalSetModifiers(value); return 0; } } if (property == EXTRA_DIMENSIONS_PROPERTY) { if (get) { return getExtraDimensions(); } else { setExtraDimensions(value); return 0; } } // allow default implementation to flag the error return super.internalGetSetIntProperty(property, get, value); }
@Override final int internalGetSetIntProperty(SimplePropertyDescriptor property, boolean get, int value) { if (property == MODIFIERS_PROPERTY) { if (get) { return getModifiers(); } else { internalSetModifiers(value); return 0; } } if (property == EXTRA_DIMENSIONS_PROPERTY) { if (get) { return getExtraDimensions(); } else { setExtraDimensions(value); return 0; } } // allow default implementation to flag the error return super.internalGetSetIntProperty(property, get, value); }
final int internalGetSetIntProperty(SimplePropertyDescriptor property, boolean get, int value) { if (property == MODIFIERS_PROPERTY) { if (get) { return getModifiers(); } else { internalSetModifiers(value); return 0; } } if (property == EXTRA_DIMENSIONS_PROPERTY) { if (get) { return getExtraDimensions(); } else { setExtraDimensions(value); return 0; } } // allow default implementation to flag the error return super.internalGetSetIntProperty(property, get, value); }
final int internalGetSetIntProperty(SimplePropertyDescriptor property, boolean get, int value) { if (property == MODIFIERS_PROPERTY) { if (get) { return getModifiers(); } else { internalSetModifiers(value); return 0; } } if (property == EXTRA_DIMENSIONS_PROPERTY) { if (get) { return getExtraDimensions(); } else { setExtraDimensions(value); return 0; } } // allow default implementation to flag the error return super.internalGetSetIntProperty(property, get, value); }
public String getReturnType() { if (returnType == UNITIALIZED_STRING) { returnType = getFacadeHelper().toString(getASTNode().getReturnType2()); if (returnType != null) { // append extra dimensions since they are not stored in Type object for (int i = 0; i < getASTNode().getExtraDimensions(); i++) { returnType += "[]"; } } } return returnType; }
public String getReturnType() { if (returnType == UNITIALIZED_STRING) { returnType = getFacadeHelper().toString(getASTNode().getReturnType2()); if (returnType != null) { // append extra dimensions since they are not stored in Type object for (int i = 0; i < getASTNode().getExtraDimensions(); i++) { returnType += "[]"; } } } return returnType; }
public static void extractParametersAndReturnType(MethodDeclaration methodDeclaration, SDMethod method) { Type returnType = methodDeclaration.getReturnType2(); if (returnType != null) { method.setReturnType(AstUtils.normalizeTypeName(returnType, methodDeclaration.getExtraDimensions(), false)); } else { method.setReturnType(null); } Iterator<SingleVariableDeclaration> parameters = methodDeclaration.parameters().iterator(); while (parameters.hasNext()) { SingleVariableDeclaration parameter = parameters.next(); Type parameterType = parameter.getType(); String typeName = AstUtils.normalizeTypeName(parameterType, parameter.getExtraDimensions(), parameter.isVarargs()); method.addParameter(parameter.getName().getIdentifier(), typeName); } }
private static Block createMethodStub(final MethodDeclaration method, final AST ast, ICompilationUnit cu, ASTRewrite rewrite, String targetTypeName) { final Block body= ast.newBlock(); final Expression expression= ASTNodeFactory.newDefaultExpression(ast, method.getReturnType2(), method.getExtraDimensions()); try { String delimiter= cu.findRecommendedLineSeparator(); String bodyStatement= ""; //$NON-NLS-1$ if (expression != null) { final ReturnStatement returnStatement= ast.newReturnStatement(); returnStatement.setExpression(expression); bodyStatement= ASTNodes.asFormattedString(returnStatement, 0, delimiter, FormatterProfileManager.getProjectSettings(cu.getJavaProject())); } String placeHolder= CodeGeneration.getMethodBodyContent(cu, targetTypeName, method.getName().getIdentifier(), false, bodyStatement, delimiter); if (placeHolder != null) { ReturnStatement todoNode= (ReturnStatement) rewrite.createStringPlaceholder(placeHolder, ASTNode.RETURN_STATEMENT); body.statements().add(todoNode); } } catch (CoreException e) { // return empty body } return body; }
private Expression evaluateReturnExpressions(AST ast, ITypeBinding returnBinding, int returnOffset) { CompilationUnit root= (CompilationUnit) fMethodDecl.getRoot(); Expression result= null; if (returnBinding != null) { ScopeAnalyzer analyzer= new ScopeAnalyzer(root); IBinding[] bindings= analyzer.getDeclarationsInScope(returnOffset, ScopeAnalyzer.VARIABLES | ScopeAnalyzer.CHECK_VISIBILITY ); for (int i= 0; i < bindings.length; i++) { IVariableBinding curr= (IVariableBinding) bindings[i]; ITypeBinding type= curr.getType(); if (type != null && type.isAssignmentCompatible(returnBinding) && testModifier(curr)) { if (result == null) { result= ast.newSimpleName(curr.getName()); } addLinkedPositionProposal(RETURN_EXPRESSION_KEY, curr.getName(), null); } } } Expression defaultExpression= ASTNodeFactory.newDefaultExpression(ast, fMethodDecl.getReturnType2(), fMethodDecl.getExtraDimensions()); addLinkedPositionProposal(RETURN_EXPRESSION_KEY, ASTNodes.asString(defaultExpression), null); if (result == null) { return defaultExpression; } return result; }
private void createAbstractMethod(final IMethod sourceMethod, final CompilationUnitRewrite sourceRewriter, final CompilationUnit declaringCuNode, final AbstractTypeDeclaration destination, final TypeVariableMaplet[] mapping, final CompilationUnitRewrite targetRewrite, final Map adjustments, final IProgressMonitor monitor, final RefactoringStatus status) throws JavaModelException { final MethodDeclaration oldMethod= ASTNodeSearchUtil.getMethodDeclarationNode(sourceMethod, declaringCuNode); if (JavaModelUtil.is50OrHigher(sourceMethod.getJavaProject()) && (fSettings.overrideAnnotation || JavaCore.ERROR.equals(sourceMethod.getJavaProject().getOption(JavaCore.COMPILER_PB_MISSING_OVERRIDE_ANNOTATION, true)))) { final MarkerAnnotation annotation= sourceRewriter.getAST().newMarkerAnnotation(); annotation.setTypeName(sourceRewriter.getAST().newSimpleName("Override")); //$NON-NLS-1$ sourceRewriter.getASTRewrite().getListRewrite(oldMethod, MethodDeclaration.MODIFIERS2_PROPERTY).insertFirst(annotation, sourceRewriter.createCategorizedGroupDescription(RefactoringCoreMessages.PullUpRefactoring_add_override_annotation, SET_PULL_UP)); } final MethodDeclaration newMethod= targetRewrite.getAST().newMethodDeclaration(); newMethod.setBody(null); newMethod.setConstructor(false); newMethod.setExtraDimensions(oldMethod.getExtraDimensions()); newMethod.setJavadoc(null); int modifiers= getModifiersWithUpdatedVisibility(sourceMethod, Modifier.ABSTRACT | JdtFlags.clearFlag(Modifier.NATIVE | Modifier.FINAL, sourceMethod.getFlags()), adjustments, monitor, false, status); if (oldMethod.isVarargs()) modifiers&= ~Flags.AccVarargs; newMethod.modifiers().addAll(ASTNodeFactory.newModifiers(targetRewrite.getAST(), modifiers)); newMethod.setName(((SimpleName) ASTNode.copySubtree(targetRewrite.getAST(), oldMethod.getName()))); copyReturnType(targetRewrite.getASTRewrite(), getDeclaringType().getCompilationUnit(), oldMethod, newMethod, mapping); copyParameters(targetRewrite.getASTRewrite(), getDeclaringType().getCompilationUnit(), oldMethod, newMethod, mapping); copyThrownExceptions(oldMethod, newMethod); ImportRewriteUtil.addImports(targetRewrite, newMethod, new HashMap(), new HashMap(), false); targetRewrite.getASTRewrite().getListRewrite(destination, destination.getBodyDeclarationsProperty()).insertAt(newMethod, ASTNodes.getInsertionIndex(newMethod, destination.bodyDeclarations()), targetRewrite.createCategorizedGroupDescription(RefactoringCoreMessages.PullUpRefactoring_add_abstract_method, SET_PULL_UP)); }
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)); }
private MethodDeclaration createNewMethodDeclarationNode(final CompilationUnitRewrite sourceRewrite, final CompilationUnitRewrite targetRewrite, final IMethod sourceMethod, final MethodDeclaration oldMethod, final CompilationUnit declaringCuNode, final TypeVariableMaplet[] mapping, final Map adjustments, final IProgressMonitor monitor, final RefactoringStatus status) throws JavaModelException { final ASTRewrite rewrite= targetRewrite.getASTRewrite(); final AST ast= rewrite.getAST(); final MethodDeclaration newMethod= ast.newMethodDeclaration(); if (!getDestinationType().isInterface()) copyBodyOfPulledUpMethod(sourceRewrite, targetRewrite, sourceMethod, oldMethod, newMethod, mapping, monitor); newMethod.setConstructor(oldMethod.isConstructor()); newMethod.setExtraDimensions(oldMethod.getExtraDimensions()); copyJavadocNode(rewrite, sourceMethod, oldMethod, newMethod); int modifiers= getModifiersWithUpdatedVisibility(sourceMethod, sourceMethod.getFlags(), adjustments, monitor, true, status); if (oldMethod.isVarargs()) modifiers&= ~Flags.AccVarargs; copyAnnotations(oldMethod, newMethod); newMethod.modifiers().addAll(ASTNodeFactory.newModifiers(ast, modifiers)); newMethod.setName(((SimpleName) ASTNode.copySubtree(ast, oldMethod.getName()))); copyReturnType(rewrite, getDeclaringType().getCompilationUnit(), oldMethod, newMethod, mapping); copyParameters(rewrite, getDeclaringType().getCompilationUnit(), oldMethod, newMethod, mapping); copyThrownExceptions(oldMethod, newMethod); copyTypeParameters(oldMethod, newMethod); return newMethod; }