while (declaringType != null) { typeStack.push(declaringType); declaringType = declaringType.getDeclaringType();
/** * Returns <code>true</code> if <code>type</code> is not a top-level type, <code>false</code> if it is. * * @param type the type to test * @return <code>true</code> if <code>type</code> is an inner type */ private boolean isInnerType(IType type) { return type.getDeclaringType() != null; }
private static boolean isEqualOrEnclosedType(IType inner, IType outer) { while (inner != null) { if (inner.equals(outer)) return true; else inner= inner.getDeclaringType(); } return false; }
private static IType findEnclosingType(IType type, String newName) { IType enclosing = type.getDeclaringType(); while (enclosing != null) { if (newName.equals(enclosing.getElementName())) { return enclosing; } else { enclosing = enclosing.getDeclaringType(); } } return null; }
private static IType findEnclosingType(IType type, String newName) { IType enclosing= type.getDeclaringType(); while (enclosing != null){ if (newName.equals(enclosing.getElementName())) return enclosing; else enclosing= enclosing.getDeclaringType(); } return null; }
private static IType findEnclosingType(IType type, String newName) { IType enclosing= type.getDeclaringType(); while (enclosing != null){ if (newName.equals(enclosing.getElementName())) return enclosing; else enclosing= enclosing.getDeclaringType(); } return null; }
public static boolean isInsideLocalType(IType type) throws JavaModelException { while (type != null) { if (type.isLocal()) return true; type= type.getDeclaringType(); } return false; }
private static boolean containsTopLevelTypes(IStructuredSelection selection) { for (Iterator<?> iter = selection.iterator(); iter.hasNext();) { Object each= iter.next(); if (each instanceof IType && ((IType)each).getDeclaringType() == null) return true; } return false; }
private static List getDeclaringTypes(IType type) { IType declaringType= type.getDeclaringType(); if (declaringType == null) return new ArrayList(0); List result= getDeclaringTypes(declaringType); result.add(declaringType); return result; }
private static boolean containsTopLevelTypes(IStructuredSelection selection) { for (Iterator iter = selection.iterator(); iter.hasNext();) { Object each= iter.next(); if ((each instanceof IType) && ((IType)each).getDeclaringType() == null) return true; } return false; }
public static boolean isInsideLocalType(IType type) throws JavaModelException { while (type != null) { if (type.isLocal()) return true; type= type.getDeclaringType(); } return false; }
private static boolean isPrimaryType(IType type) { String cuName = type.getCompilationUnit().getElementName(); String typeName = type.getElementName(); return type.getDeclaringType() == null && JavaCore.removeJavaLikeExtension(cuName).equals(typeName); }
private Type createEnclosingType(final AST ast) throws JavaModelException { Assert.isNotNull(ast); final ITypeParameter[] parameters= fType.getDeclaringType().getTypeParameters(); final Type type= ASTNodeFactory.newType(ast, fType.getDeclaringType().getTypeQualifiedName('.')); if (parameters.length > 0) { final ParameterizedType parameterized= ast.newParameterizedType(type); for (int index= 0; index < parameters.length; index++) parameterized.typeArguments().add(ast.newSimpleType(ast.newSimpleName(parameters[index].getElementName()))); return parameterized; } return type; }
/** * Returns the fully qualified name of a type's container. (package name or enclosing type name) */ public static String getTypeContainerName(IType type) { IType outerType= type.getDeclaringType(); if (outerType != null) { return getFullyQualifiedName(outerType); } else { return type.getPackageFragment().getElementName(); } }
private boolean isInsideTypeNestedInDeclaringType(ASTNode node) { Assert.isTrue((node instanceof ClassInstanceCreation) || (node instanceof SuperConstructorInvocation)); final AbstractTypeDeclaration declaration= ASTNodes.getParent(node, AbstractTypeDeclaration.class); Assert.isNotNull(declaration); ITypeBinding enclosing= declaration.resolveBinding(); while (enclosing != null) { if (isCorrespondingTypeBinding(enclosing, fType.getDeclaringType())) return true; enclosing= enclosing.getDeclaringClass(); } return false; }
private boolean isInsideTypeNestedInDeclaringType(ASTNode node) { Assert.isTrue((node instanceof ClassInstanceCreation) || (node instanceof SuperConstructorInvocation)); final AbstractTypeDeclaration declaration= (AbstractTypeDeclaration) ASTNodes.getParent(node, AbstractTypeDeclaration.class); Assert.isNotNull(declaration); ITypeBinding enclosing= declaration.resolveBinding(); while (enclosing != null) { if (isCorrespondingTypeBinding(enclosing, fType.getDeclaringType())) return true; enclosing= enclosing.getDeclaringClass(); } return false; }
private RefactoringStatus checkTypesInCompilationUnit() { RefactoringStatus result = new RefactoringStatus(); if (!Checks.isTopLevel(fType)) { //the other case checked in checkTypesInPackage IType siblingType = fType.getDeclaringType().getType(getNewElementName()); if (siblingType.exists()) { String msg = Messages.format(RefactoringCoreMessages.RenameTypeRefactoring_member_type_exists, new String[] { getNewElementLabel(), BasicElementLabels.getJavaElementName(fType.getDeclaringType().getFullyQualifiedName('.')) }); result.addError(msg, JavaStatusContext.create(siblingType)); } } return result; }
private RefactoringStatus checkTypesInCompilationUnit() { RefactoringStatus result= new RefactoringStatus(); if (! Checks.isTopLevel(fType)){ //the other case checked in checkTypesInPackage IType siblingType= fType.getDeclaringType().getType(getNewElementName()); if (siblingType.exists()){ String msg= Messages.format(RefactoringCoreMessages.RenameTypeRefactoring_member_type_exists, new String[] { getNewElementLabel(), BasicElementLabels.getJavaElementName(fType.getDeclaringType().getFullyQualifiedName('.'))}); result.addError(msg, JavaStatusContext.create(siblingType)); } } return result; }
@Override public Object getNewElement() { if (Checks.isTopLevel(fType)) { return getNewCompilationUnit().getType(getNewElementName()); } else { return fType.getDeclaringType().getType(getNewElementName()); } }
private Expression createAccessExpressionToEnclosingInstanceFieldText(ASTNode node, IBinding binding, AbstractTypeDeclaration declaration) { if (Modifier.isStatic(binding.getModifiers())) return node.getAST().newName(JavaModelUtil.getTypeQualifiedName(fType.getDeclaringType())); else if ((isInAnonymousTypeInsideInputType(node, declaration) || isInLocalTypeInsideInputType(node, declaration) || isInNonStaticMemberTypeInsideInputType(node, declaration))) return createQualifiedReadAccessExpressionForEnclosingInstance(node.getAST()); else return createReadAccessExpressionForEnclosingInstance(node.getAST()); }