Refine search
for (Object modifier : declaration.modifiers()) { if (modifier instanceof org.eclipse.jdt.core.dom.Annotation) { org.eclipse.jdt.core.dom.Annotation annotation = (org.eclipse.jdt.core.dom.Annotation)modifier; String qualifiedAnnotationName = annotation.resolveTypeBinding().getQualifiedName(); if (!"java.lang.Override".equals(qualifiedAnnotationName) && !"java.lang.SuppressWarnings".equals(qualifiedAnnotationName)) annotations.add(annotation); .append(declaration.getReturnType2().toString()) .append(" ").append(declaration.getName().getFullyQualifiedName()) .append("("); for (Object parameter : declaration.parameters()) { if (!first) signature.append(", "); first = false;
CompilationUnit cu = ast.newCompilationUnit(); PackageDeclaration p1 = ast.newPackageDeclaration(); p1.setName(ast.newSimpleName("foo")); cu.setPackage(p1); Block block = ast.newBlock(); md.setBody(block); MethodInvocation mi = ast.newMethodInvocation();
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 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 void copyTypeParameters(MethodDeclaration intermediary, CompilationUnitRewrite rew, ImportRewriteContext context) { ITypeBinding[] typeParameters= fTargetMethodBinding.getTypeParameters(); for (int i= 0; i < typeParameters.length; i++) { ITypeBinding current= typeParameters[i]; TypeParameter parameter= rew.getAST().newTypeParameter(); parameter.setName(rew.getAST().newSimpleName(current.getName())); ITypeBinding[] bounds= current.getTypeBounds(); for (int j= 0; j < bounds.length; j++) if (!"java.lang.Object".equals(bounds[j].getQualifiedName())) //$NON-NLS-1$ parameter.typeBounds().add(rew.getImportRewrite().addImport(bounds[j], rew.getAST(), context)); intermediary.typeParameters().add(parameter); } }
void populateNames(final MethodDeclaration declaration) { methodName = declaration.getName().getIdentifier(); for (final Object param : declaration.parameters()) { ((ASTNode) param).accept(this); } if (declaration.getBody() != null) { declaration.getBody().accept(this); } }
@Override public void endVisit(MethodDeclaration node) { if (skipNode(node)) { return; } GenericSequentialFlowInfo info = processSequential(node, node.getReturnType2()); process(info, node.parameters()); process(info, node.thrownExceptionTypes()); process(info, node.getBody()); }
private boolean haveSameParameters(final MethodDeclaration node, final SuperMethodInvocation bodyMi) { final List<?> parameters = node.parameters(); for (int i = 0; i < node.parameters().size(); i++) { final SingleVariableDeclaration paramName = (SingleVariableDeclaration) parameters.get(i); final Expression paramExpr = (Expression) bodyMi.arguments().get(i); if (!(paramExpr instanceof SimpleName) || !paramName.getName().getIdentifier().equals(((SimpleName) paramExpr).getIdentifier())) { return false; } } return true; }
@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); }
@Override public boolean visit(MethodDeclaration node) { final String simpleName = node.getName().getIdentifier(); final IMethodBinding methodBinding = node.resolveBinding(); if (methodBinding != null) { final QName qname = QName.valueOf(methodBinding.getDeclaringClass().getQualifiedName(), simpleName); methods.addName(FQN.fromMember(qname)); } else { // We cannot determine the FQN, so we cannot safely replace it methods.cannotReplaceSimpleName(simpleName); } return VISIT_SUBTREE; }
@Override public boolean visit(MethodDeclaration node) { IMethodBinding binding= node.resolveBinding(); if (binding != null && !Modifier.isStatic(binding.getModifiers())) { IMethodBinding method= Bindings.findOverriddenMethodInHierarchy(fSelectedType, binding); if (method != null) { SimpleName name= node.getName(); fResult.add(new OccurrenceLocation(name.getStartPosition(), name.getLength(), 0, fDescription)); } } return super.visit(node); }
@Override public boolean visit(MethodDeclaration node) { if (node.isConstructor()) { AbstractTypeDeclaration decl= ASTNodes.getParent(node, AbstractTypeDeclaration.class); NameData name= fNames.get(decl.getName().resolveBinding()); if (name != null) { name.addReference(node.getName()); } } return true; } @Override
public boolean visit(Javadoc javaDoc) { if (currentMethod != null) { SMethod method = getSMethod(currentMethod.getName().getIdentifier()); if (method == null) { LOGGER.error("Method " + currentMethod.getName().getIdentifier() + " not found in class"); } else { for (Object tag : javaDoc.tags()) { Object fragment = tagElement.fragments().get(i); if (i == 0 && fragment instanceof SimpleName) { parameter = method.getParameter(((SimpleName) fragment).getIdentifier()); } else if (i == 1 && parameter != null && fragment instanceof TextElement) { parameter.setDoc(((TextElement) fragment).getText());
public IMethodBinding getDeclaringMethod() { ASTNode parent = this.variableDeclaration.getParent(); while (parent != null && parent.getNodeType() != ASTNode.METHOD_DECLARATION) { parent = parent.getParent(); } if (parent != null) { return ((MethodDeclaration) parent).resolveBinding(); } return null; }
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); }
@Override public boolean visit(MethodDeclaration node) { if (isInside(node)) { Block body= node.getBody(); if (body != null) { body.accept(this); } visitBackwards(node.parameters()); visitBackwards(node.typeParameters()); } return false; }
public static void createOverrideAnnotation(ASTRewrite rewrite, ImportRewrite imports, MethodDeclaration decl, TextEditGroup group) { if (findAnnotation("java.lang.Override", decl.modifiers()) != null) { //$NON-NLS-1$ return; // No need to add duplicate annotation } AST ast= rewrite.getAST(); ASTNode root= decl.getRoot(); ImportRewriteContext context= null; if (root instanceof CompilationUnit) { context= new ContextSensitiveImportRewriteContext((CompilationUnit) root, decl.getStartPosition(), imports); } Annotation marker= ast.newMarkerAnnotation(); marker.setTypeName(ast.newName(imports.addImport("java.lang.Override", context))); //$NON-NLS-1$ rewrite.getListRewrite(decl, MethodDeclaration.MODIFIERS2_PROPERTY).insertFirst(marker, group); }
public boolean visit(MethodDeclaration node) { if (isInside(node)) { Block body= node.getBody(); if (body != null) { body.accept(this); } visitBackwards(node.parameters()); if (node.getAST().apiLevel() >= AST.JLS3) { visitBackwards(node.typeParameters()); } } return false; }
private void addFieldInitializationToConstructor(ASTRewrite rewrite, MethodDeclaration constructor) { if (constructor.getBody() == null) constructor.setBody(getAST().newBlock()); Statement newStatement= createNewAssignmentStatement(rewrite); rewrite.getListRewrite(constructor.getBody(), Block.STATEMENTS_PROPERTY).insertLast(newStatement, null); }