This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

View | Details | Raw Unified | Return to bug 175309
Collapse All | Expand All

(-)a/refactoring.java/src/org/netbeans/modules/refactoring/java/plugins/RenameRefactoringPlugin.java (-1 / +54 lines)
Lines 45-50 Link Here
45
import com.sun.source.tree.Tree;
45
import com.sun.source.tree.Tree;
46
import com.sun.source.util.TreePath;
46
import com.sun.source.util.TreePath;
47
import java.io.IOException;
47
import java.io.IOException;
48
import java.net.MalformedURLException;
49
import java.net.URL;
48
import java.text.MessageFormat;
50
import java.text.MessageFormat;
49
import java.util.*;
51
import java.util.*;
50
import javax.lang.model.element.*;
52
import javax.lang.model.element.*;
Lines 52-62 Link Here
52
import javax.lang.model.util.ElementFilter;
54
import javax.lang.model.util.ElementFilter;
53
import javax.lang.model.util.Elements;
55
import javax.lang.model.util.Elements;
54
import org.netbeans.api.java.source.*;
56
import org.netbeans.api.java.source.*;
57
import org.netbeans.api.project.FileOwnerQuery;
58
import org.netbeans.api.project.Project;
59
import org.netbeans.api.project.SourceGroup;
60
import org.netbeans.api.project.Sources;
55
import org.netbeans.modules.refactoring.api.*;
61
import org.netbeans.modules.refactoring.api.*;
56
import org.netbeans.modules.refactoring.java.RetoucheUtils;
62
import org.netbeans.modules.refactoring.java.RetoucheUtils;
57
import org.netbeans.modules.refactoring.java.spi.JavaRefactoringPlugin;
63
import org.netbeans.modules.refactoring.java.spi.JavaRefactoringPlugin;
58
import org.openide.filesystems.FileObject;
64
import org.openide.filesystems.FileObject;
59
import org.netbeans.modules.refactoring.spi.RefactoringElementsBag;
65
import org.netbeans.modules.refactoring.spi.RefactoringElementsBag;
66
import org.netbeans.spi.java.queries.MultipleRootsUnitTestForSourceQueryImplementation;
67
import org.openide.filesystems.URLMapper;
68
import org.openide.util.Exceptions;
60
import org.openide.util.NbBundle;
69
import org.openide.util.NbBundle;
61
import org.openide.util.Utilities;
70
import org.openide.util.Utilities;
62
71
Lines 267-272 Link Here
267
                
276
                
268
//                String fqn = "".equals(pkgname) ? newName : pkgname + '.' + newName;
277
//                String fqn = "".equals(pkgname) ? newName : pkgname + '.' + newName;
269
//                ClassPath cp = ClassPath.getClassPath(fo, ClassPath.SOURCE);
278
//                ClassPath cp = ClassPath.getClassPath(fo, ClassPath.SOURCE);
279
                String conflictingSource=checkClassRenameInComplementarySource(primFile,newFqn+newName);
280
                if(conflictingSource!=null) {
281
                    String msg = new MessageFormat(getString("ERR_ClassClash")).format(
282
                            new Object[] {newName, conflictingSource}
283
                    );
284
                    fastCheckProblem = createProblem(fastCheckProblem, true, msg);
285
                    return fastCheckProblem;
286
                }
287
270
                if (RetoucheUtils.typeExist(treePathHandle, newFqn)) {
288
                if (RetoucheUtils.typeExist(treePathHandle, newFqn)) {
271
                    String msg = new MessageFormat(getString("ERR_ClassClash")).format(
289
                    String msg = new MessageFormat(getString("ERR_ClassClash")).format(
272
                            new Object[] {newName, pkgname}
290
                            new Object[] {newName, pkgname}
Lines 308-314 Link Here
308
        }
326
        }
309
        return fastCheckProblem;
327
        return fastCheckProblem;
310
    }
328
    }
311
    
329
330
    /**
331
     * Check if file rename is ok looking in a complementary source.<br/>
332
     * For normal sources it checks the rename in test and form test sources in normal sources
333
     * @param oldFile The file to rename
334
     * @param newFQNClassName New FQN of the class
335
     * @return null if the rename is correct, conflicting path otherwise
336
     */
337
    private String checkClassRenameInComplementarySource(FileObject oldFile,String newFQNClassName) {
338
            Project project=FileOwnerQuery.getOwner(oldFile);
339
            Sources sources=project.getLookup().lookup(Sources.class);
340
341
            MultipleRootsUnitTestForSourceQueryImplementation mrufqi=project.getLookup().lookup(MultipleRootsUnitTestForSourceQueryImplementation.class);
342
            for(SourceGroup sg:sources.getSourceGroups(org.netbeans.api.java.project.JavaProjectConstants.SOURCES_TYPE_JAVA)) {
343
                URL urlut[]=mrufqi.findUnitTests(sg.getRootFolder());
344
                URL urlso[]=mrufqi.findSources(sg.getRootFolder());
345
346
                assert !(urlut!=null && urlso!=null);
347
                URL[] urlstolook=urlut!=null?urlut:urlso;
348
349
               if(urlstolook!=null) {
350
                    for(URL u:urlstolook) {
351
                        try {
352
                            URL newURL = new URL(u, newFQNClassName.replaceAll("\\.", "/")+"."+oldFile.getExt());
353
                            FileObject file=URLMapper.findFileObject(newURL);
354
                            if(file!=null)
355
                                return file.getParent().getPath();
356
                        } catch (MalformedURLException ex) {
357
                            Exceptions.printStackTrace(ex);
358
                        }
359
                    }
360
                }
361
            }
362
            return null;
363
    }
364
312
    @Override
365
    @Override
313
    protected Problem checkParameters(CompilationController info) throws IOException {
366
    protected Problem checkParameters(CompilationController info) throws IOException {
314
        
367
        

Return to bug 175309