protected CompilationUnit getCU() { return (CompilationUnit) fMethodDecl.getRoot(); }
protected CompilationUnit getCU() { return (CompilationUnit) fMethodDecl.getRoot(); }
protected CompilationUnit getCU() { return (CompilationUnit) fMethodDecl.getRoot(); }
@SuppressWarnings("unchecked") @Override public boolean visit(MethodDeclaration node) { if (importer.topOfContainerStack() instanceof Type) { IMethodBinding binding = node.resolveBinding(); Method method; if (binding != null) { method = importer.ensureMethodFromMethodBindingToCurrentContainer(binding); Arrays.stream(binding.getExceptionTypes()) .forEach(e -> importer.createDeclaredExceptionFromTypeBinding(e, method)); } else { logNullBinding("method declaration", node.getName(), ((CompilationUnit) node.getRoot()).getLineNumber(node.getStartPosition())); method = importer.ensureMethodFromMethodDeclaration(node); } method.setIsStub(false); method.setCyclomaticComplexity(1); importer.pushOnContainerStack(method); node.parameters().stream().forEach( p -> importer.ensureParameterFromSingleVariableDeclaration((SingleVariableDeclaration) p, method)); importer.createSourceAnchor(method, node); importer.createLightweightSourceAnchor(method, node.getName()); importer.ensureCommentFromBodyDeclaration(method, node); } return true; }
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 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); }
ASTNode root= methodDecl.getRoot(); if (root instanceof CompilationUnit) { ITypeRoot typeRoot= ((CompilationUnit) root).getTypeRoot();
ASTNode root= methodDecl.getRoot(); if (root instanceof CompilationUnit) { ITypeRoot typeRoot= ((CompilationUnit) root).getTypeRoot();
ASTNode root= methodDecl.getRoot(); if (root instanceof CompilationUnit) { ITypeRoot typeRoot= ((CompilationUnit) root).getTypeRoot();
@Override protected ASTRewrite getRewrite() throws CoreException { if (fMethodDeclaration == null) { CompilationUnit astRoot= ASTResolving.createQuickFixAST(getCompilationUnit(), null); fMethodDeclaration= (MethodDeclaration) astRoot.findDeclaringNode(fMethodBinding.getKey()); } AST ast= fMethodDeclaration.getAST(); ASTRewrite rewrite= ASTRewrite.create(ast); ListRewrite listRewrite= rewrite.getListRewrite(fMethodDeclaration, MethodDeclaration.MODIFIERS2_PROPERTY); MarkerAnnotation annotation= ast.newMarkerAnnotation(); String importString= createImportRewrite((CompilationUnit) fMethodDeclaration.getRoot()).addImport("java.lang.SafeVarargs"); //$NON-NLS-1$ annotation.setTypeName(ast.newName(importString)); listRewrite.insertFirst(annotation, null); // set up linked mode addLinkedPosition(rewrite.track(annotation), true, "annotation"); //$NON-NLS-1$ return rewrite; }
@Override protected ASTRewrite getRewrite() throws CoreException { if (fMethodDeclaration == null) { CompilationUnit astRoot= ASTResolving.createQuickFixAST(getCompilationUnit(), null); fMethodDeclaration= (MethodDeclaration) astRoot.findDeclaringNode(fMethodBinding.getKey()); } AST ast= fMethodDeclaration.getAST(); ASTRewrite rewrite= ASTRewrite.create(ast); ListRewrite listRewrite= rewrite.getListRewrite(fMethodDeclaration, MethodDeclaration.MODIFIERS2_PROPERTY); MarkerAnnotation annotation= ast.newMarkerAnnotation(); String importString= createImportRewrite((CompilationUnit) fMethodDeclaration.getRoot()).addImport("java.lang.SafeVarargs"); //$NON-NLS-1$ annotation.setTypeName(ast.newName(importString)); listRewrite.insertFirst(annotation, null); // set up linked mode addLinkedPosition(rewrite.track(annotation), true, "annotation"); //$NON-NLS-1$ return rewrite; }
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; }
CompilationUnit root= (CompilationUnit) methodDecl.getRoot(); IBinding[] bindings= (new ScopeAnalyzer(root)).getDeclarationsAfter(methodDecl.getBody().getStartPosition(), ScopeAnalyzer.VARIABLES); for (int i= 0; i < bindings.length; i++) {
CompilationUnit root= (CompilationUnit) methodDecl.getRoot(); IBinding[] bindings= (new ScopeAnalyzer(root)).getDeclarationsAfter(methodDecl.getBody().getStartPosition(), ScopeAnalyzer.VARIABLES); for (int i= 0; i < bindings.length; i++) {
CompilationUnit root= (CompilationUnit) methodDecl.getRoot(); IBinding[] bindings= (new ScopeAnalyzer(root)).getDeclarationsAfter(methodDecl.getBody().getStartPosition(), ScopeAnalyzer.VARIABLES); for (int i= 0; i < bindings.length; i++) {
CompilationUnit root= (CompilationUnit) methodDecl.getRoot(); IBinding[] bindings= (new ScopeAnalyzer(root)).getDeclarationsAfter(methodDecl.getBody().getStartPosition(), ScopeAnalyzer.VARIABLES); for (int i= 0; i < bindings.length; i++) {