Search in sources :

Example 1 with NameData

use of org.eclipse.jdt.internal.corext.refactoring.code.SourceAnalyzer.NameData in project che by eclipse.

the class SourceProvider method makeNamesUnique.

private void makeNamesUnique(ASTRewrite rewriter, CodeScopeBuilder.Scope scope) {
    Collection<NameData> usedCalleeNames = fAnalyzer.getUsedNames();
    for (Iterator<NameData> iter = usedCalleeNames.iterator(); iter.hasNext(); ) {
        SourceAnalyzer.NameData nd = iter.next();
        if (scope.isInUse(nd.getName())) {
            String newName = scope.createName(nd.getName(), true);
            List<SimpleName> references = nd.references();
            for (Iterator<SimpleName> refs = references.iterator(); refs.hasNext(); ) {
                SimpleName element = refs.next();
                ASTNode newNode = rewriter.createStringPlaceholder(newName, ASTNode.SIMPLE_NAME);
                rewriter.replace(element, newNode, null);
            }
        }
    }
}
Also used : SimpleName(org.eclipse.jdt.core.dom.SimpleName) ASTNode(org.eclipse.jdt.core.dom.ASTNode) NameData(org.eclipse.jdt.internal.corext.refactoring.code.SourceAnalyzer.NameData) NameData(org.eclipse.jdt.internal.corext.refactoring.code.SourceAnalyzer.NameData)

Example 2 with NameData

use of org.eclipse.jdt.internal.corext.refactoring.code.SourceAnalyzer.NameData in project che by eclipse.

the class SourceProvider method rewriteReferences.

private void rewriteReferences(ASTRewrite rewriter, ITypeBinding[] typeArguments, List<NameData> typeParameterReferences) {
    if (typeArguments.length == 0)
        return;
    Assert.isTrue(typeArguments.length == typeParameterReferences.size());
    for (int i = 0; i < typeArguments.length; i++) {
        SourceAnalyzer.NameData refData = typeParameterReferences.get(i);
        List<SimpleName> references = refData.references();
        String newName = typeArguments[i].getName();
        for (Iterator<SimpleName> iter = references.iterator(); iter.hasNext(); ) {
            SimpleName name = iter.next();
            rewriter.replace(name, rewriter.createStringPlaceholder(newName, ASTNode.SIMPLE_NAME), null);
        }
    }
}
Also used : SimpleName(org.eclipse.jdt.core.dom.SimpleName) NameData(org.eclipse.jdt.internal.corext.refactoring.code.SourceAnalyzer.NameData)

Aggregations

SimpleName (org.eclipse.jdt.core.dom.SimpleName)2 NameData (org.eclipse.jdt.internal.corext.refactoring.code.SourceAnalyzer.NameData)2 ASTNode (org.eclipse.jdt.core.dom.ASTNode)1