Example usage for org.eclipse.jdt.core.dom QualifiedName getFullyQualifiedName

List of usage examples for org.eclipse.jdt.core.dom QualifiedName getFullyQualifiedName

Introduction

In this page you can find the example usage for org.eclipse.jdt.core.dom QualifiedName getFullyQualifiedName.

Prototype

public final String getFullyQualifiedName() 

Source Link

Document

Returns the standard dot-separated representation of this name.

Usage

From source file:boa.datagen.util.Java7Visitor.java

License:Apache License

@Override
public boolean visit(QualifiedName node) {
    boa.types.Ast.Expression.Builder b = boa.types.Ast.Expression.newBuilder();
    //      b.setPosition(pos.build());
    b.setKind(boa.types.Ast.Expression.ExpressionKind.VARACCESS);
    b.setVariable(node.getFullyQualifiedName());
    expressions.push(b.build());/*from w ww  .j  a  v a 2  s. co  m*/
    return false;
}

From source file:ca.mcgill.cs.swevo.ppa.PPAASTUtil.java

License:Open Source License

/**
 * <p>//from   www  .  j a va  2 s  .co  m
 * Returns the name + its qualifier if any. Does not return the suffix of
 * the FQN.
 * </p>
 * <ol>
 * <li>A : returns A</li>
 * <li>A.B : returns A</li>
 * <li>C.A : return C.A</li>
 * <li>C.A.B : returns C.A</li>
 * </ol>
 * 
 * @param name
 * @return
 */
public static String getQualifierPlusName(SimpleName name) {
    String qualifierPlusName = name.getFullyQualifiedName();

    ASTNode parent = name.getParent();
    if (parent != null && parent instanceof QualifiedName) {
        QualifiedName qName = (QualifiedName) parent;
        if (qName.getName().equals(name)) {
            qualifierPlusName = qName.getFullyQualifiedName();
        }
    }
    return qualifierPlusName;
}

From source file:changetypes.ASTVisitorAtomicChange.java

License:Open Source License

public boolean visit(QualifiedName node) {
    if ((this.mtbStack.isEmpty()) && (!this.itbStack.isEmpty())) {
        return false;
    }/*w  w w  .  j a  v  a  2  s . c  o m*/
    if (!this.mtbStack.isEmpty()) {
        if (node.getName().getIdentifier().equals("length")) {
            return true;
        }
        try {
            return visitName(node.resolveBinding(), (IMethodBinding) this.mtbStack.peek());
        } catch (Exception localException) {
            System.err.println(
                    "Cannot resolve qualified name \"" + node.getFullyQualifiedName().toString() + "\"");
            return false;
        }
    }
    return false;
}

From source file:com.android.ide.eclipse.adt.internal.build.ConvertSwitchQuickFixProcessor.java

License:Open Source License

@Override
public IJavaCompletionProposal[] getCorrections(IInvocationContext context, IProblemLocation[] location)
        throws CoreException {
    if (location == null || location.length == 0) {
        return null;
    }/*from   w w w . j a  v  a2s .c  o  m*/
    ASTNode coveringNode = context.getCoveringNode();
    if (coveringNode == null) {
        return null;
    }

    // Look up the fully qualified name of the non-constant expression, if any, and
    // make sure it's R-something.
    if (coveringNode.getNodeType() == ASTNode.SIMPLE_NAME) {
        coveringNode = coveringNode.getParent();
        if (coveringNode == null) {
            return null;
        }
    }
    if (coveringNode.getNodeType() != ASTNode.QUALIFIED_NAME) {
        return null;
    }
    QualifiedName name = (QualifiedName) coveringNode;
    if (!name.getFullyQualifiedName().startsWith("R.")) { //$NON-NLS-1$
        return null;
    }

    IProblemLocation error = location[0];
    int errorStart = error.getOffset();
    int errorLength = error.getLength();
    int caret = context.getSelectionOffset();

    // Even though the hasCorrections() method above will return false for everything
    // other than non-constant expression errors, it turns out this getCorrections()
    // method will ALSO be called on lines where there is no such error. In particular,
    // if you have an invalid cast expression like this:
    //     Button button = findViewById(R.id.textView);
    // then this method will be called, and the expression will pass all of the above
    // checks. However, we -don't- want to show a migrate code suggestion in that case!
    // Therefore, we'll need to check if we're *actually* on a line with the given
    // problem.
    //
    // Unfortunately, we don't get passed the problemId again, and there's no access
    // to it. So instead we'll need to look up the markers on the line, and see
    // if we actually have a constant expression warning. This is not pretty!!

    boolean foundError = false;
    ICompilationUnit compilationUnit = context.getCompilationUnit();
    IResource file = compilationUnit.getResource();
    if (file != null) {
        IDocumentProvider provider = new TextFileDocumentProvider();
        try {
            provider.connect(file);
            IDocument document = provider.getDocument(file);
            if (document != null) {
                List<IMarker> markers = AdtUtils.findMarkersOnLine(IMarker.PROBLEM, file, document, errorStart);
                for (IMarker marker : markers) {
                    String message = marker.getAttribute(IMarker.MESSAGE, "");
                    // There are no other attributes in the marker we can use to identify
                    // the exact error, so we'll need to resort to the actual message
                    // text even though that would not work if the messages had been
                    // localized... This can also break if the error messages change. Yuck.
                    if (message.contains("constant expressions")) { //$NON-NLS-1$
                        foundError = true;
                    }
                }
            }
        } catch (Exception e) {
            AdtPlugin.log(e, "Can't validate error message in %1$s", file.getName());
        } finally {
            provider.disconnect(file);
        }
    }
    if (!foundError) {
        // Not a constant-expression warning, so do nothing
        return null;
    }

    IBuffer buffer = compilationUnit.getBuffer();
    boolean sameLine = false;
    // See if the caret is on the same line as the error
    if (caret <= errorStart) {
        // Search backwards to beginning of line
        for (int i = errorStart; i >= 0; i--) {
            if (i <= caret) {
                sameLine = true;
                break;
            }
            char c = buffer.getChar(i);
            if (c == '\n') {
                break;
            }
        }
    } else {
        // Search forwards to the end of the line
        for (int i = errorStart + errorLength, n = buffer.getLength(); i < n; i++) {
            if (i >= caret) {
                sameLine = true;
                break;
            }
            char c = buffer.getChar(i);
            if (c == '\n') {
                break;
            }
        }
    }

    if (sameLine) {
        String expression = buffer.getText(errorStart, errorLength);
        return new IJavaCompletionProposal[] { new MigrateProposal(expression) };
    }

    return null;
}

From source file:com.facebook.buck.jvm.java.JavaFileParser.java

License:Apache License

public JavaFileFeatures extractFeaturesFromJavaCode(String code) {
    // For now, we will harcode this. Ultimately, we probably want to make this configurable via
    // .buckconfig. For example, the Buck project itself is diligent about disallowing wildcard
    // imports, but the one exception is the Java code generated via Thrift in src-gen.
    boolean shouldThrowForUnsupportedWildcardImport = false;

    AtomicBoolean isPoisonedByUnsupportedWildcardImport = new AtomicBoolean(false);

    CompilationUnit compilationUnit = makeCompilationUnitFromSource(code);

    ImmutableSortedSet.Builder<String> providedSymbols = ImmutableSortedSet.naturalOrder();
    ImmutableSortedSet.Builder<String> requiredSymbols = ImmutableSortedSet.naturalOrder();
    ImmutableSortedSet.Builder<String> exportedSymbols = ImmutableSortedSet.naturalOrder();
    ImmutableSortedSet.Builder<String> requiredSymbolsFromExplicitImports = ImmutableSortedSet.naturalOrder();

    compilationUnit.accept(new ASTVisitor() {

        @Nullable/*from  w  ww  .jav a 2 s.c o m*/
        private String packageName;

        /** Maps simple name to fully-qualified name. */
        private Map<String, String> simpleImportedTypes = new HashMap<>();

        /**
         * Maps wildcard import prefixes, such as {@code "java.util"} to the types in the
         * respective package if a wildcard import such as {@code import java.util.*} is used.
         */
        private Map<String, ImmutableSet<String>> wildcardImports = new HashMap<>();

        @Override
        public boolean visit(PackageDeclaration node) {
            Preconditions.checkState(packageName == null, "There should be at most one package declaration");
            packageName = node.getName().getFullyQualifiedName();
            return false;
        }

        // providedSymbols

        @Override
        public boolean visit(TypeDeclaration node) {
            // Local classes can be declared inside of methods. Skip over these.
            if (node.getParent() instanceof TypeDeclarationStatement) {
                return true;
            }

            String fullyQualifiedName = getFullyQualifiedTypeName(node);
            if (fullyQualifiedName != null) {
                providedSymbols.add(fullyQualifiedName);
            }

            @SuppressWarnings("unchecked")
            List<Type> interfaceTypes = node.superInterfaceTypes();
            for (Type interfaceType : interfaceTypes) {
                tryAddType(interfaceType, DependencyType.EXPORTED);
            }

            Type superclassType = node.getSuperclassType();
            if (superclassType != null) {
                tryAddType(superclassType, DependencyType.EXPORTED);
            }

            return true;
        }

        @Override
        public boolean visit(EnumDeclaration node) {
            String fullyQualifiedName = getFullyQualifiedTypeName(node);
            if (fullyQualifiedName != null) {
                providedSymbols.add(fullyQualifiedName);
            }
            return true;
        }

        @Override
        public boolean visit(AnnotationTypeDeclaration node) {
            String fullyQualifiedName = getFullyQualifiedTypeName(node);
            if (fullyQualifiedName != null) {
                providedSymbols.add(fullyQualifiedName);
            }
            return true;
        }

        // requiredSymbols

        /**
         * Uses heuristics to try to figure out what type of QualifiedName this is. Returns a
         * non-null value if this is believed to be a reference that qualifies as a "required
         * symbol" relationship.
         */
        @Override
        public boolean visit(QualifiedName node) {
            QualifiedName ancestor = findMostQualifiedAncestor(node);
            ASTNode parent = ancestor.getParent();
            if (!(parent instanceof PackageDeclaration) && !(parent instanceof ImportDeclaration)) {
                String symbol = ancestor.getFullyQualifiedName();

                // If it does not start with an uppercase letter, it is probably because it is a
                // property lookup.
                if (CharMatcher.javaUpperCase().matches(symbol.charAt(0))) {
                    addTypeFromDotDelimitedSequence(symbol, DependencyType.REQUIRED);
                }
            }

            return false;
        }

        /**
         * @param expr could be "Example", "Example.field", "com.example.Example". Note it could
         *     also be a built-in type, such as "java.lang.Integer", in which case it will not be
         *     added to the set of required symbols.
         */
        private void addTypeFromDotDelimitedSequence(String expr, DependencyType dependencyType) {
            // At this point, symbol could be `System.out`. We want to reduce it to `System` and
            // then check it against JAVA_LANG_TYPES.
            if (startsWithUppercaseChar(expr)) {
                int index = expr.indexOf('.');
                if (index >= 0) {
                    String leftmostComponent = expr.substring(0, index);
                    if (JAVA_LANG_TYPES.contains(leftmostComponent)) {
                        return;
                    }
                }
            }

            expr = qualifyWithPackageNameIfNecessary(expr);
            addSymbol(expr, dependencyType);
        }

        @Override
        public boolean visit(ImportDeclaration node) {
            String fullyQualifiedName = node.getName().getFullyQualifiedName();

            // Apparently, "on demand" means "uses a wildcard," such as "import java.util.*".
            // Although we can choose to prohibit these in our own code, it is much harder to
            // enforce for third-party code. As such, we will tolerate these for some of the common
            // cases.
            if (node.isOnDemand()) {
                ImmutableSet<String> value = SUPPORTED_WILDCARD_IMPORTS.get(fullyQualifiedName);
                if (value != null) {
                    wildcardImports.put(fullyQualifiedName, value);
                    return false;
                } else if (shouldThrowForUnsupportedWildcardImport) {
                    throw new RuntimeException(String.format(
                            "Use of wildcard 'import %s.*' makes it impossible to statically determine "
                                    + "required symbols in this file. Please enumerate explicit imports.",
                            fullyQualifiedName));
                } else {
                    isPoisonedByUnsupportedWildcardImport.set(true);
                    return false;
                }
            }

            // Only worry about the dependency on the enclosing type.
            Optional<String> simpleName = getSimpleNameFromFullyQualifiedName(fullyQualifiedName);
            if (simpleName.isPresent()) {
                String name = simpleName.get();
                int index = fullyQualifiedName.indexOf("." + name);
                String enclosingType = fullyQualifiedName.substring(0, index + name.length() + 1);
                requiredSymbolsFromExplicitImports.add(enclosingType);

                simpleImportedTypes.put(name, enclosingType);
            } else {
                LOG.warn("Suspicious import lacks obvious enclosing type: %s", fullyQualifiedName);
                // The one example we have seen of this in the wild is
                // "org.whispersystems.curve25519.java.curve_sigs". In practice, we still need to add
                // it as a required symbol in this case.
                requiredSymbols.add(fullyQualifiedName);
            }
            return false;
        }

        @Override
        public boolean visit(MethodInvocation node) {
            if (node.getExpression() == null) {
                return true;
            }

            String receiver = node.getExpression().toString();
            if (looksLikeAType(receiver)) {
                addTypeFromDotDelimitedSequence(receiver, DependencyType.REQUIRED);
            }
            return true;
        }

        /** An annotation on a member with zero arguments. */
        @Override
        public boolean visit(MarkerAnnotation node) {
            DependencyType dependencyType = findDependencyTypeForAnnotation(node);
            addSimpleTypeName(node.getTypeName(), dependencyType);
            return true;
        }

        /** An annotation on a member with named arguments. */
        @Override
        public boolean visit(NormalAnnotation node) {
            DependencyType dependencyType = findDependencyTypeForAnnotation(node);
            addSimpleTypeName(node.getTypeName(), dependencyType);
            return true;
        }

        /** An annotation on a member with a single, unnamed argument. */
        @Override
        public boolean visit(SingleMemberAnnotation node) {
            DependencyType dependencyType = findDependencyTypeForAnnotation(node);
            addSimpleTypeName(node.getTypeName(), dependencyType);
            return true;
        }

        private DependencyType findDependencyTypeForAnnotation(Annotation annotation) {
            ASTNode parentNode = annotation.getParent();
            if (parentNode == null) {
                return DependencyType.REQUIRED;
            }

            if (parentNode instanceof BodyDeclaration) {
                // Note that BodyDeclaration is an abstract class. Its subclasses are things like
                // FieldDeclaration and MethodDeclaration. We want to be sure that an annotation on
                // any non-private declaration is considered an exported symbol.
                BodyDeclaration declaration = (BodyDeclaration) parentNode;

                int modifiers = declaration.getModifiers();
                if ((modifiers & Modifier.PRIVATE) == 0) {
                    return DependencyType.EXPORTED;
                }
            }
            return DependencyType.REQUIRED;
        }

        @Override
        public boolean visit(SimpleType node) {
            // This method is responsible for finding the overwhelming majority of the required
            // symbols in the AST.
            tryAddType(node, DependencyType.REQUIRED);
            return true;
        }

        // exportedSymbols

        @Override
        public boolean visit(MethodDeclaration node) {
            // Types from private method signatures need not be exported.
            if ((node.getModifiers() & Modifier.PRIVATE) != 0) {
                return true;
            }

            Type returnType = node.getReturnType2();
            if (returnType != null) {
                tryAddType(returnType, DependencyType.EXPORTED);
            }

            @SuppressWarnings("unchecked")
            List<SingleVariableDeclaration> params = node.parameters();
            for (SingleVariableDeclaration decl : params) {
                tryAddType(decl.getType(), DependencyType.EXPORTED);
            }

            @SuppressWarnings("unchecked")
            List<Type> exceptions = node.thrownExceptionTypes();
            for (Type exception : exceptions) {
                tryAddType(exception, DependencyType.EXPORTED);
            }

            return true;
        }

        @Override
        public boolean visit(FieldDeclaration node) {
            // Types from private fields need not be exported.
            if ((node.getModifiers() & Modifier.PRIVATE) == 0) {
                tryAddType(node.getType(), DependencyType.EXPORTED);
            }
            return true;
        }

        private void tryAddType(Type type, DependencyType dependencyType) {
            if (type.isSimpleType()) {
                SimpleType simpleType = (SimpleType) type;
                Name simpleTypeName = simpleType.getName();
                String simpleName = simpleTypeName.toString();

                // For a Type such as IExample<T>, both "IExample" and "T" will be submitted here as
                // simple types. As such, we use this imperfect heuristic to filter out "T" from being
                // added. Note that this will erroneously exclude "URI". In practice, this should
                // generally be OK. For example, assuming "URI" is also imported, then at least it
                // will end up in the set of required symbols. To this end, we perform a second check
                // for "all caps" types to see if there is a corresponding import and if it should be
                // exported rather than simply required.
                if (!CharMatcher.javaUpperCase().matchesAllOf(simpleName)
                        || (dependencyType == DependencyType.EXPORTED
                                && simpleImportedTypes.containsKey(simpleName))) {
                    addSimpleTypeName(simpleTypeName, dependencyType);
                }
            } else if (type.isArrayType()) {
                ArrayType arrayType = (ArrayType) type;
                tryAddType(arrayType.getElementType(), dependencyType);
            } else if (type.isParameterizedType()) {
                ParameterizedType parameterizedType = (ParameterizedType) type;
                tryAddType(parameterizedType.getType(), dependencyType);
                @SuppressWarnings("unchecked")
                List<Type> argTypes = parameterizedType.typeArguments();
                for (Type argType : argTypes) {
                    tryAddType(argType, dependencyType);
                }
            }
        }

        private void addSimpleTypeName(Name simpleTypeName, DependencyType dependencyType) {
            String simpleName = simpleTypeName.toString();
            if (JAVA_LANG_TYPES.contains(simpleName)) {
                return;
            }

            String fullyQualifiedNameForSimpleName = simpleImportedTypes.get(simpleName);
            if (fullyQualifiedNameForSimpleName != null) {
                // May need to promote from required to exported in this case.
                if (dependencyType == DependencyType.EXPORTED) {
                    addSymbol(fullyQualifiedNameForSimpleName, DependencyType.EXPORTED);
                }
                return;
            }

            // For well-behaved source code, this will always be empty, so don't even bother to
            // create the iterator most of the time.
            if (!wildcardImports.isEmpty()) {
                for (Map.Entry<String, ImmutableSet<String>> entry : wildcardImports.entrySet()) {
                    Set<String> types = entry.getValue();
                    if (types.contains(simpleName)) {
                        String packageName = entry.getKey();
                        addSymbol(packageName + "." + simpleName, dependencyType);
                        return;
                    }
                }
            }

            String symbol = simpleTypeName.getFullyQualifiedName();
            symbol = qualifyWithPackageNameIfNecessary(symbol);
            addSymbol(symbol, dependencyType);
        }

        private void addSymbol(String symbol, DependencyType dependencyType) {
            ((dependencyType == DependencyType.REQUIRED) ? requiredSymbols : exportedSymbols).add(symbol);
        }

        private String qualifyWithPackageNameIfNecessary(String symbol) {
            if (!startsWithUppercaseChar(symbol)) {
                return symbol;
            }

            // If the symbol starts with a capital letter, then we assume that it is a reference to
            // a type in the same package.
            int index = symbol.indexOf('.');
            if (index >= 0) {
                symbol = symbol.substring(0, index);
            }
            if (packageName != null) {
                symbol = packageName + "." + symbol;
            }

            return symbol;
        }
    });

    // TODO(mbolin): Special treatment for exportedSymbols when poisoned by wildcard import.
    ImmutableSortedSet<String> totalExportedSymbols = exportedSymbols.build();

    // If we were poisoned by an unsupported wildcard import, then we should rely exclusively on
    // the explicit imports to determine the required symbols.
    Set<String> totalRequiredSymbols = new HashSet<>();
    if (isPoisonedByUnsupportedWildcardImport.get()) {
        totalRequiredSymbols.addAll(requiredSymbolsFromExplicitImports.build());
    } else {
        totalRequiredSymbols.addAll(requiredSymbolsFromExplicitImports.build());
        totalRequiredSymbols.addAll(requiredSymbols.build());
    }
    // Make sure that required and exported symbols are disjoint sets.
    totalRequiredSymbols.removeAll(totalExportedSymbols);

    return new JavaFileFeatures(providedSymbols.build(), ImmutableSortedSet.copyOf(totalRequiredSymbols),
            totalExportedSymbols);
}

From source file:com.windowtester.eclipse.ui.convert.WTAPIAbstractVisitor.java

License:Open Source License

/**
 * If the node represents a WindowTester type, then cache the expression information
 * for the parent node./*from  w w  w  .  j  av a2 s  .co m*/
 */
public void endVisit(QualifiedName node) {
    String typeName = context.resolve(node.getFullyQualifiedName());
    if (typeName != null) {
        currentScope.setNodeType(node, typeName);
        currentScope.setNodeValue(node, null);
    }
}

From source file:de.crowdcode.kissmda.extensions.importpacker.ImportPacker.java

License:Apache License

private void writeImports() {
    List<QualifiedName> imports = new LinkedList<QualifiedName>(importedTypes.values());
    Collections.sort(imports, new Comparator<QualifiedName>() {

        @Override/*from   w  w w .  j  a  v a  2  s.c  o  m*/
        public int compare(QualifiedName o1, QualifiedName o2) {
            return o1.getFullyQualifiedName().compareTo(o2.getFullyQualifiedName());
        }
    });
    AST ast = compilationUnit.getAST();
    for (QualifiedName qualifiedName : imports) {
        if (!isTypeNameInCUPackage(qualifiedName) && !isJavaLang(qualifiedName))
            addImport(ast, qualifiedName);
    }
}

From source file:de.crowdcode.kissmda.extensions.importpacker.ImportPacker.java

License:Apache License

@SuppressWarnings("unchecked")
private void addImport(AST ast, QualifiedName qualifiedName) {
    ImportDeclaration impDecl = ast.newImportDeclaration();
    impDecl.setName(ast.newName(qualifiedName.getFullyQualifiedName()));
    compilationUnit.imports().add(impDecl);
}

From source file:fr.labri.harmony.rta.junit.jdt.JDTVisitorRTA.java

License:Open Source License

public boolean visit(QualifiedName n) {

    if (n.resolveBinding() != null) {
        if (n.resolveBinding().getKind() == 3) {
            if (((IVariableBinding) n.resolveBinding()) != null) {
                if (((IVariableBinding) n.resolveBinding()).getDeclaringClass() != null) {
                    if (((IVariableBinding) n.resolveBinding()).getDeclaringClass()
                            .getQualifiedName() != null) {
                        String id = ((IVariableBinding) n.resolveBinding()).getDeclaringClass()
                                .getQualifiedName() + "." + n.getFullyQualifiedName();
                        //System.err.println("Add "+id);
                        if (currentJavaMethod != null)
                            currentJavaMethod.getCallsSite().add(id);
                    }/*from  w  w w  .  j a v a 2  s  .c  om*/
                }
            }
        }
    }
    return true;
}

From source file:net.atos.optimus.common.tools.ltk.ImportsGenerationVisitor.java

License:Open Source License

/**
 * Checks Qualified Type, represented by its use in parent node, its name,
 * and its type binding./*from  w  ww .  j  a v  a 2s  .c o  m*/
 * 
 * @param node
 *            : Parent Node
 * @param qualifiedName
 *            : Qualified Name
 * @param typeBinding
 *            : Type Binding
 */
@SuppressWarnings("unchecked")
private void checkQualifiedType(ASTNode node, QualifiedName qualifiedName, ITypeBinding typeBinding) {

    // At first we extract package name & type for Type, by :
    // - Splitting the String if Type Binding has been deduced (recovered)
    // - Taking it from Binding otherwise
    String fullyQualifiedName = qualifiedName.getFullyQualifiedName();
    String typeName = null;
    String packageName = null;

    if (typeBinding == null || typeBinding.isRecovered()) {
        typeName = qualifiedName.getFullyQualifiedName()
                .substring(qualifiedName.getFullyQualifiedName().lastIndexOf(".") + 1);
        packageName = qualifiedName.getFullyQualifiedName().substring(0,
                qualifiedName.getFullyQualifiedName().lastIndexOf("."));
    } else {
        typeBinding = typeBinding.getErasure();
        typeName = typeBinding.getName();
        IPackageBinding packageBinding = typeBinding.getPackage();
        if (packageBinding == null)
            return;
        packageName = packageBinding.getName();
    }

    // Checks if name should be trimmed (if class with same name but
    // different package has already been registered), and trims it if
    // needed
    if (shouldTrimName(packageName, typeName)) {
        StructuralPropertyDescriptor locationInParent = qualifiedName.getLocationInParent();
        if (locationInParent == null)
            return;
        if (locationInParent.isChildListProperty()) {
            ChildListPropertyDescriptor clpd = (ChildListPropertyDescriptor) locationInParent;
            List<ASTNode> astNodes = (List<ASTNode>) node.getStructuralProperty(clpd);
            astNodes.remove(qualifiedName);
            astNodes.add(node.getAST().newName(typeName));
        } else {
            node.setStructuralProperty(locationInParent, node.getAST().newName(typeName));
        }
        hasModifications = true;
    }

    // Checks if import should be added (e.g. package is not java.lang) and
    // does it if needed
    if (shouldAddImport(node, typeName, packageName, fullyQualifiedName)) {
        this.tryAddImport(node.getAST(), fullyQualifiedName);
        if (!typesToPackageBinding.containsKey(typeName))
            typesToPackageBinding.put(typeName, packageName);
    } else if (this.currentPackageName.equals(packageName))
        if (!typesToPackageBinding.containsKey(typeName))
            typesToPackageBinding.put(typeName, packageName);
}