/** * Finds the ancestor type of <code>node</code> (includes <code>node</code> in the search). * * @param node the node to start the search from, can be <code>null</code> * @return returns the ancestor type of <code>node</code> (AbstractTypeDeclaration or * AnonymousTypeDeclaration) if any (including <code>node</code>), <code>null</code> * otherwise */ public static ASTNode findParentType(ASTNode node) { return findParentType(node, false); }
public static ASTNode findParentType(ASTNode node) { return findParentType(node, false); }
private void initializeDestinations() { List<ASTNode> result= new ArrayList<>(); BodyDeclaration decl= fAnalyzer.getEnclosingBodyDeclaration(); ASTNode current= ASTResolving.findParentType(decl.getParent()); if (fAnalyzer.isValidDestination(current)) { result.add(current); } if (current != null && (decl instanceof MethodDeclaration || decl instanceof Initializer || decl instanceof FieldDeclaration)) { ITypeBinding binding= ASTNodes.getEnclosingType(current); ASTNode next= ASTResolving.findParentType(current.getParent()); while (next != null && binding != null && binding.isNested()) { if (fAnalyzer.isValidDestination(next)) { result.add(next); } current= next; binding= ASTNodes.getEnclosingType(current); next= ASTResolving.findParentType(next.getParent()); } } fDestinations= result.toArray(new ASTNode[result.size()]); fDestination= fDestinations[fDestinationIndex]; }
public static String getCatchBodyContent(ICompilationUnit cu, String exceptionType, String variableName, ASTNode locationInAST, String lineDelimiter) throws CoreException { String enclosingType= ""; //$NON-NLS-1$ String enclosingMethod= ""; //$NON-NLS-1$ if (locationInAST != null) { MethodDeclaration parentMethod= ASTResolving.findParentMethodDeclaration(locationInAST); if (parentMethod != null) { enclosingMethod= parentMethod.getName().getIdentifier(); locationInAST= parentMethod; } ASTNode parentType= ASTResolving.findParentType(locationInAST); if (parentType instanceof AbstractTypeDeclaration) { enclosingType= ((AbstractTypeDeclaration) parentType).getName().getIdentifier(); } } return getCatchBodyContent(cu, exceptionType, variableName, enclosingType, enclosingMethod, lineDelimiter); }
public static String getCatchBodyContent(ICompilationUnit cu, String exceptionType, String variableName, ASTNode locationInAST, String lineDelimiter) throws CoreException { String enclosingType= ""; //$NON-NLS-1$ String enclosingMethod= ""; //$NON-NLS-1$ if (locationInAST != null) { MethodDeclaration parentMethod= ASTResolving.findParentMethodDeclaration(locationInAST); if (parentMethod != null) { enclosingMethod= parentMethod.getName().getIdentifier(); locationInAST= parentMethod; } ASTNode parentType= ASTResolving.findParentType(locationInAST); if (parentType instanceof AbstractTypeDeclaration) { enclosingType= ((AbstractTypeDeclaration)parentType).getName().getIdentifier(); } } return getCatchBodyContent(cu, exceptionType, variableName, enclosingType, enclosingMethod, lineDelimiter); }
ASTNode destination= ASTResolving.findParentType(fEnclosingBodyDeclaration.getParent()); while (destination != null) { if (isValidDestination(destination)) { validDestinations.add(destination); destination= ASTResolving.findParentType(destination.getParent());
private static boolean getAssignToVariableProposals(IInvocationContext context, ASTNode node, Collection resultingCollections) { Statement statement= ASTResolving.findParentStatement(node); if (!(statement instanceof ExpressionStatement)) { return false; } ExpressionStatement expressionStatement= (ExpressionStatement) statement; Expression expression= expressionStatement.getExpression(); if (expression.getNodeType() == ASTNode.ASSIGNMENT) { return false; // too confusing and not helpful } ITypeBinding typeBinding= expression.resolveTypeBinding(); typeBinding= Bindings.normalizeTypeBinding(typeBinding); if (typeBinding == null) { return false; } if (resultingCollections == null) { return true; } ICompilationUnit cu= context.getCompilationUnit(); AssignToVariableAssistProposal localProposal= new AssignToVariableAssistProposal(cu, AssignToVariableAssistProposal.LOCAL, expressionStatement, typeBinding, 2); localProposal.setCommandId(ASSIGN_TO_LOCAL_ID); resultingCollections.add(localProposal); ASTNode type= ASTResolving.findParentType(expression); if (type != null) { AssignToVariableAssistProposal fieldProposal= new AssignToVariableAssistProposal(cu, AssignToVariableAssistProposal.FIELD, expressionStatement, typeBinding, 1); fieldProposal.setCommandId(ASSIGN_TO_FIELD_ID); resultingCollections.add(fieldProposal); } return false; }
resultingCollections.add(localProposal); ASTNode type= ASTResolving.findParentType(expression); if (type != null) { AssignToVariableAssistProposal fieldProposal= new AssignToVariableAssistProposal(cu, AssignToVariableAssistProposal.FIELD, expressionStatement, typeBinding, IProposalRelevance.ASSIGN_TO_FIELD);
ASTNode node= ASTResolving.findParentType(fOriginalNode, true); if (newTypeDecl.equals(node)) { modifiers |= Modifier.PRIVATE;
ASTNode node= ASTResolving.findParentType(fOriginalNode, true); if (newTypeDecl.equals(node)) { modifiers |= Modifier.PRIVATE;
ASTNode typeNode= ASTResolving.findParentType(fAnalyzer.getEnclosingBodyDeclaration()); RefactoringStatus status= new RefactoringStatus(); while (fDestination != typeNode) {
ASTNode parentType= ASTResolving.findParentType(decl); TypeDeclaration parentTypeDecl= null; boolean parentIsAbstractClass= false;
modifiers |= Modifier.STATIC; ASTNode node= ASTResolving.findParentType(invocationNode); if (targetTypeDecl.equals(node)) { modifiers |= Modifier.PRIVATE;
@Override public RefactoringStatus checkInitialConditions(IProgressMonitor pm) throws CoreException { RefactoringStatus result= Checks.validateModifiesFiles( ResourceUtil.getFiles(new ICompilationUnit[]{fCu}), getValidationContext()); if (result.hasFatalError()) return result; initAST(pm); if (fTempDeclarationNode == null) return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.PromoteTempToFieldRefactoring_select_declaration); if (! Checks.isDeclaredIn(fTempDeclarationNode, MethodDeclaration.class)) return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.PromoteTempToFieldRefactoring_only_declared_in_methods); if (isMethodParameter()) return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.PromoteTempToFieldRefactoring_method_parameters); if (isTempAnExceptionInCatchBlock()) return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.PromoteTempToFieldRefactoring_exceptions); ASTNode declaringType= ASTResolving.findParentType(fTempDeclarationNode); if (declaringType instanceof TypeDeclaration && ((TypeDeclaration) declaringType).isInterface()) return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.PromoteTempToFieldRefactoring_interface_methods); result.merge(checkTempTypeForLocalTypeUsage()); if (result.hasFatalError()) return result; checkTempInitializerForLocalTypeUsage(); if (!fSelfInitializing) initializeDefaults(); return result; }
ASTNode parentType= ASTResolving.findParentType(decl); if (parentType instanceof AbstractTypeDeclaration) { boolean isInterface= parentType instanceof TypeDeclaration && ((TypeDeclaration) parentType).isInterface();
ASTNode parentType= ASTResolving.findParentType(decl); if (parentType instanceof AbstractTypeDeclaration) { boolean isInterface= parentType instanceof TypeDeclaration && ((TypeDeclaration) parentType).isInterface();
modifiers |= Modifier.STATIC; ASTNode node= ASTResolving.findParentType(invocationNode); boolean isParentInterface= node instanceof TypeDeclaration && ((TypeDeclaration) node).isInterface(); if (isTargetInterface || isParentInterface) {
result.addTextEditGroup(insertDesc); if (fDestination == ASTResolving.findParentType(declaration.getParent())) { ChildListPropertyDescriptor desc= (ChildListPropertyDescriptor)declaration.getLocationInParent(); ListRewrite container= fRewriter.getListRewrite(declaration.getParent(), desc);
ChildListPropertyDescriptor descriptor= null; ASTNode node= NodeFinder.perform(unit, offset, 1); node= ASTResolving.findParentType(node); if (node instanceof AnonymousClassDeclaration) { declaringType= ((AnonymousClassDeclaration) node).resolveBinding();
private ASTRewrite doAddField() throws CoreException { boolean isParamToField= fNodeToAssign.getNodeType() == ASTNode.SINGLE_VARIABLE_DECLARATION; ASTNode newTypeDecl= ASTResolving.findParentType(fNodeToAssign); if (newTypeDecl == null) { return null;