private static boolean unboundedWildcardAllowed(Type originalType) { ASTNode parent= originalType.getParent(); while (parent instanceof Type) parent= parent.getParent(); if (parent instanceof ClassInstanceCreation) { return false; } else if (parent instanceof AbstractTypeDeclaration) { return false; } else if (parent instanceof TypeLiteral) { return false; } return true; }
private static boolean unboundedWildcardAllowed(Type originalType) { ASTNode parent= originalType.getParent(); while (parent instanceof Type) parent= parent.getParent(); if (parent instanceof ClassInstanceCreation) { return false; } else if (parent instanceof AbstractTypeDeclaration) { return false; } else if (parent instanceof TypeLiteral) { return false; } return true; }
private static boolean unboundedWildcardAllowed(Type originalType) { ASTNode parent= originalType.getParent(); while (parent instanceof Type) parent= parent.getParent(); if (parent instanceof ClassInstanceCreation) { return false; } else if (parent instanceof AbstractTypeDeclaration) { return false; } else if (parent instanceof TypeLiteral) { return false; } return true; }
@Override public final void endVisit(final Type node) { final ASTNode parent= node.getParent(); if (!(parent instanceof AbstractTypeDeclaration) && !(parent instanceof ClassInstanceCreation) && !(parent instanceof CreationReference) && !(parent instanceof TypeLiteral) && (!(parent instanceof InstanceofExpression) || fInstanceOf)) node.setProperty(PROPERTY_CONSTRAINT_VARIABLE, fModel.createTypeVariable(node)); }
public final void endVisit(final Type node) { final ASTNode parent= node.getParent(); if (!(parent instanceof AbstractTypeDeclaration) && !(parent instanceof ClassInstanceCreation) && !(parent instanceof TypeLiteral) && (!(parent instanceof InstanceofExpression) || fInstanceOf)) node.setProperty(PROPERTY_CONSTRAINT_VARIABLE, fModel.createTypeVariable(node)); }
@Override public final void endVisit(final Type node) { final ASTNode parent= node.getParent(); if (!(parent instanceof AbstractTypeDeclaration) && !(parent instanceof ClassInstanceCreation) && !(parent instanceof CreationReference) && !(parent instanceof TypeLiteral) && (!(parent instanceof InstanceofExpression) || fInstanceOf)) node.setProperty(PROPERTY_CONSTRAINT_VARIABLE, fModel.createTypeVariable(node)); }
private int getExtraDimensions() { ASTNode parent = type.getParent(); if (parent instanceof FieldDeclaration) { for (Object f : ((FieldDeclaration) parent).fragments()) { if (f instanceof VariableDeclarationFragment) { return ((VariableDeclarationFragment) f).getExtraDimensions(); } } } return 0; } }
private int getExtraDimensions() { ASTNode parentLocal = type.getParent(); if (parentLocal instanceof FieldDeclaration) { for (Object f : ((FieldDeclaration) parentLocal).fragments()) { if (f instanceof VariableDeclarationFragment) { return ((VariableDeclarationFragment) f).getExtraDimensions(); } } } if (parentLocal instanceof SingleVariableDeclaration) { return ((SingleVariableDeclaration) parentLocal).getExtraDimensions(); } return 0; }
public String initialize(CompilationUnit root, ASTNode node) { fAST= root.getAST(); if (node instanceof ReturnStatement) { fMethodDeclaration= (MethodDeclaration)ASTNodes.getParent(node, ASTNode.METHOD_DECLARATION); if (fMethodDeclaration == null) return SearchMessages.MethodExitsFinder_no_return_type_selected; return null; } Type type= null; if (node instanceof Type) { type= (Type)node; } else if (node instanceof Name) { Name name= ASTNodes.getTopMostName((Name)node); if (name.getParent() instanceof Type) { type= (Type)name.getParent(); } } if (type == null) return SearchMessages.MethodExitsFinder_no_return_type_selected; type= ASTNodes.getTopMostType(type); if (!(type.getParent() instanceof MethodDeclaration)) return SearchMessages.MethodExitsFinder_no_return_type_selected; fMethodDeclaration= (MethodDeclaration)type.getParent(); return null; }
if (hit.getParent() instanceof FieldDeclaration == false) { it.remove();
/** * @param root the AST root * @param node the selected node * @return returns a message if there is a problem */ @Override public String initialize(CompilationUnit root, ASTNode node) { fASTRoot= root; if (node instanceof ReturnStatement) { fMethodDeclaration= ASTResolving.findParentMethodDeclaration(node); if (fMethodDeclaration == null) return SearchMessages.MethodExitsFinder_no_return_type_selected; return null; } Type type= ASTNodes.getTopMostType(node); if (type == null) return SearchMessages.MethodExitsFinder_no_return_type_selected; if (type.getLocationInParent() != MethodDeclaration.RETURN_TYPE2_PROPERTY) return SearchMessages.MethodExitsFinder_no_return_type_selected; fMethodDeclaration= (MethodDeclaration)type.getParent(); fExitDescription= Messages.format(SearchMessages.MethodExitsFinder_occurrence_exit_description, BasicElementLabels.getJavaElementName(fMethodDeclaration.getName().toString())); return null; }
/** * @param root the AST root * @param node the selected node * @return returns a message if there is a problem */ @Override public String initialize(CompilationUnit root, ASTNode node) { fASTRoot= root; if (node instanceof ReturnStatement) { fMethodDeclaration= ASTResolving.findParentMethodDeclaration(node); if (fMethodDeclaration == null) return SearchMessages.MethodExitsFinder_no_return_type_selected; return null; } Type type= ASTNodes.getTopMostType(node); if (type == null) return SearchMessages.MethodExitsFinder_no_return_type_selected; if (type.getLocationInParent() != MethodDeclaration.RETURN_TYPE2_PROPERTY) return SearchMessages.MethodExitsFinder_no_return_type_selected; fMethodDeclaration= (MethodDeclaration)type.getParent(); fExitDescription= Messages.format(SearchMessages.MethodExitsFinder_occurrence_exit_description, BasicElementLabels.getJavaElementName(fMethodDeclaration.getName().toString())); return null; }
private void updateType(CompilationUnit cu, Type oldType, CompilationUnitChange unitChange, ASTRewrite unitRewriter, String typeName) { String oldName= fSelectionTypeBinding.getName(); String description= Messages.format(RefactoringCoreMessages.ChangeTypeRefactoring_typeChange, new String[] {oldName, typeName}); TextEditGroup gd= new TextEditGroup(description); AST ast= cu.getAST(); ASTNode nodeToReplace= oldType; if (fSelectionTypeBinding.isParameterizedType() && !fSelectionTypeBinding.isRawType()){ if (oldType.isSimpleType()){ nodeToReplace= oldType.getParent(); } } //TODO handle types other than simple & parameterized (e.g., arrays) Assert.isTrue(fSelectedType.isClass() || fSelectedType.isInterface()); Type newType= null; if (!fSelectedType.isParameterizedType()){ newType= ast.newSimpleType(ASTNodeFactory.newName(ast, typeName)); } else { newType= createParameterizedType(ast, fSelectedType); } unitRewriter.replace(nodeToReplace, newType, gd); unitChange.addTextEditGroup(gd); }
int end = type.getStartPosition() + type.getLength(); int previousSearchStart = end - 1; ArrayType componentType = (ArrayType) type.getParent(); for (int i = 0; i < dimensionsLength; i++) { previousSearchStart = retrieveRightBracketPosition(previousSearchStart + 1, this.compilationUnitSourceLength);
private void updateType(CompilationUnit cu, Type oldType, CompilationUnitChange unitChange, ASTRewrite unitRewriter, String typeName) { String oldName= fSelectionTypeBinding.getName(); String[] keys= { BasicElementLabels.getJavaElementName(oldName), BasicElementLabels.getJavaElementName(typeName)}; String description= Messages.format(RefactoringCoreMessages.ChangeTypeRefactoring_typeChange, keys); TextEditGroup gd= new TextEditGroup(description); AST ast= cu.getAST(); ASTNode nodeToReplace= oldType; if (fSelectionTypeBinding.isParameterizedType() && !fSelectionTypeBinding.isRawType()){ if (oldType.isSimpleType()){ nodeToReplace= oldType.getParent(); } } //TODO handle types other than simple & parameterized (e.g., arrays) Assert.isTrue(fSelectedType.isClass() || fSelectedType.isInterface()); Type newType= null; if (!fSelectedType.isParameterizedType()){ newType= ast.newSimpleType(ASTNodeFactory.newName(ast, typeName)); } else { newType= createParameterizedType(ast, fSelectedType); } unitRewriter.replace(nodeToReplace, newType, gd); unitChange.addTextEditGroup(gd); }
private void updateType(CompilationUnit cu, Type oldType, CompilationUnitChange unitChange, ASTRewrite unitRewriter, String typeName) { String oldName= fSelectionTypeBinding.getName(); String[] keys= { BasicElementLabels.getJavaElementName(oldName), BasicElementLabels.getJavaElementName(typeName)}; String description= Messages.format(RefactoringCoreMessages.ChangeTypeRefactoring_typeChange, keys); TextEditGroup gd= new TextEditGroup(description); AST ast= cu.getAST(); ASTNode nodeToReplace= oldType; if (fSelectionTypeBinding.isParameterizedType() && !fSelectionTypeBinding.isRawType()){ if (oldType.isSimpleType()){ nodeToReplace= oldType.getParent(); } } //TODO handle types other than simple & parameterized (e.g., arrays) Assert.isTrue(fSelectedType.isClass() || fSelectedType.isInterface()); Type newType= null; if (!fSelectedType.isParameterizedType()){ newType= ast.newSimpleType(ASTNodeFactory.newName(ast, typeName)); } else { newType= createParameterizedType(ast, fSelectedType); } unitRewriter.replace(nodeToReplace, newType, gd); unitChange.addTextEditGroup(gd); }
boolean hasDimensionChanges= (dimEvent != null && dimEvent.getChangeKind() != RewriteEvent.UNCHANGED); RewriteEvent[] events= hasDimensionChanges ? dimEvent.getChildren() : null; ArrayType currentLevel = astLevelGTE8 ? null : (ArrayType) replacingType.getElementType().getParent(); int replacingTypeDimensions = replacingType.getDimensions(); int i=0, dimSize= (events == null) ? 0 : events.length;