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 199106
Collapse All | Expand All

(-)java.hints/nbproject/project.properties (-1 / +1 lines)
Lines 40-46 Link Here
40
# Version 2 license, then the option applies only if the new code is
40
# Version 2 license, then the option applies only if the new code is
41
# made subject to such option by the copyright holder.
41
# made subject to such option by the copyright holder.
42
42
43
spec.version.base=1.58.0
43
spec.version.base=1.59.0
44
44
45
javac.source=1.6
45
javac.source=1.6
46
46
(-)java.hints/src/org/netbeans/modules/java/hints/introduce/CopyFinderService.java (+59 lines)
Line 0 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2011 Oracle and/or its affiliates. All rights reserved.
5
 *
6
 * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
7
 * Other names may be trademarks of their respective owners.
8
 *
9
 * The contents of this file are subject to the terms of either the GNU
10
 * General Public License Version 2 only ("GPL") or the Common
11
 * Development and Distribution License("CDDL") (collectively, the
12
 * "License"). You may not use this file except in compliance with the
13
 * License. You can obtain a copy of the License at
14
 * http://www.netbeans.org/cddl-gplv2.html
15
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
16
 * specific language governing permissions and limitations under the
17
 * License.  When distributing the software, include this License Header
18
 * Notice in each file and include the License file at
19
 * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
20
 * particular file as subject to the "Classpath" exception as provided
21
 * by Oracle in the GPL Version 2 section of the License file that
22
 * accompanied this code. If applicable, add the following below the
23
 * License Header, with the fields enclosed by brackets [] replaced by
24
 * your own identifying information:
25
 * "Portions Copyrighted [year] [name of copyright owner]"
26
 *
27
 * If you wish your version of this file to be governed by only the CDDL
28
 * or only the GPL Version 2, indicate your decision by adding
29
 * "[Contributor] elects to include this software in this distribution
30
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
31
 * single choice of license, a recipient has the option to distribute
32
 * your version of this file under either the CDDL, the GPL Version 2 or
33
 * to extend the choice of license to its licensees as provided above.
34
 * However, if you add GPL Version 2 code and therefore, elected the GPL
35
 * Version 2 license, then the option applies only if the new code is
36
 * made subject to such option by the copyright holder.
37
 *
38
 * Contributor(s):
39
 *
40
 * Portions Copyrighted 2011 Sun Microsystems, Inc.
41
 */
42
package org.netbeans.modules.java.hints.introduce;
43
44
import com.sun.source.util.TreePath;
45
import java.util.Set;
46
import java.util.concurrent.atomic.AtomicBoolean;
47
import org.netbeans.api.java.source.CompilationInfo;
48
import org.openide.util.lookup.ServiceProvider;
49
50
/**
51
 *
52
 * @author Jan Becicka
53
 */
54
@ServiceProvider(service=CopyFinderService.class)
55
public class CopyFinderService {
56
    public static Set<TreePath> computeDuplicates(CompilationInfo info, TreePath searchingFor, TreePath scope, AtomicBoolean cancel) {
57
        return CopyFinder.computeDuplicates(info, searchingFor, scope, cancel, null).keySet();
58
    }
59
}
(-)java.hints/src/org/netbeans/modules/java/hints/introduce/IntroduceHint.java (-6 / +7 lines)
Lines 117-122 Link Here
117
import org.netbeans.api.java.source.GeneratorUtilities;
117
import org.netbeans.api.java.source.GeneratorUtilities;
118
import org.netbeans.api.java.source.JavaSource;
118
import org.netbeans.api.java.source.JavaSource;
119
import org.netbeans.api.java.source.JavaSource.Phase;
119
import org.netbeans.api.java.source.JavaSource.Phase;
120
import org.netbeans.api.java.source.SourceUtils;
120
import org.netbeans.api.java.source.TreeMaker;
121
import org.netbeans.api.java.source.TreeMaker;
121
import org.netbeans.api.java.source.TreePathHandle;
122
import org.netbeans.api.java.source.TreePathHandle;
122
import org.netbeans.api.java.source.TreeUtilities;
123
import org.netbeans.api.java.source.TreeUtilities;
Lines 422-429 Link Here
422
            TreePath value = resolved.getLeaf().getKind() != Kind.VARIABLE ? resolved : new TreePath(resolved, ((VariableTree) resolved.getLeaf()).getInitializer());
423
            TreePath value = resolved.getLeaf().getKind() != Kind.VARIABLE ? resolved : new TreePath(resolved, ((VariableTree) resolved.getLeaf()).getInitializer());
423
            boolean isConstant = checkConstantExpression(info, value) && !expressionStatement;
424
            boolean isConstant = checkConstantExpression(info, value) && !expressionStatement;
424
            boolean isVariable = findStatement(resolved) != null && method != null && resolved.getLeaf().getKind() != Kind.VARIABLE;
425
            boolean isVariable = findStatement(resolved) != null && method != null && resolved.getLeaf().getKind() != Kind.VARIABLE;
425
            Set<TreePath> duplicatesForVariable = isVariable ? CopyFinder.computeDuplicates(info, resolved, method, cancel, null).keySet() : null;
426
            Set<TreePath> duplicatesForVariable = isVariable ? SourceUtils.computeDuplicates(info, resolved, method, cancel) : null;
426
            Set<TreePath> duplicatesForConstant = /*isConstant ? */CopyFinder.computeDuplicates(info, resolved, new TreePath(info.getCompilationUnit()), cancel, null).keySet();// : null;
427
            Set<TreePath> duplicatesForConstant = /*isConstant ? */SourceUtils.computeDuplicates(info, resolved, new TreePath(info.getCompilationUnit()), cancel);// : null;
427
            Scope scope = info.getTrees().getScope(resolved);
428
            Scope scope = info.getTrees().getScope(resolved);
428
            boolean statik = scope != null ? info.getTreeUtilities().isStaticContext(scope) : false;
429
            boolean statik = scope != null ? info.getTreeUtilities().isStaticContext(scope) : false;
429
            String guessedName = Utilities.guessName(info, resolved);
430
            String guessedName = Utilities.guessName(info, resolved);
Lines 1355-1361 Link Here
1355
                            returnValueComputed = true;
1356
                            returnValueComputed = true;
1356
                        } else {
1357
                        } else {
1357
                            if (returnValue != null && currentReturnValue != null) {
1358
                            if (returnValue != null && currentReturnValue != null) {
1358
                                Set<TreePath> candidates = CopyFinder.computeDuplicates(info, returnValue, currentReturnValue, cancel, null).keySet();
1359
                                Set<TreePath> candidates = SourceUtils.computeDuplicates(info, returnValue, currentReturnValue, cancel);
1359
1360
1360
                                if (candidates.size() != 1 || candidates.iterator().next().getLeaf() != rt.getExpression()) {
1361
                                if (candidates.size() != 1 || candidates.iterator().next().getLeaf() != rt.getExpression()) {
1361
                                    return "ERR_Different_Return_Values"; // NOI18N
1362
                                    return "ERR_Different_Return_Values"; // NOI18N
Lines 1514-1520 Link Here
1514
                            parameter.rewrite(pathToClass.getLeaf(), nueClass);
1515
                            parameter.rewrite(pathToClass.getLeaf(), nueClass);
1515
1516
1516
                            if (replaceAll) {
1517
                            if (replaceAll) {
1517
                                for (TreePath p : CopyFinder.computeDuplicates(parameter, resolved, new TreePath(parameter.getCompilationUnit()), new AtomicBoolean(), null).keySet()) {
1518
                                for (TreePath p : SourceUtils.computeDuplicates(parameter, resolved, new TreePath(parameter.getCompilationUnit()), new AtomicBoolean())) {
1518
                                    parameter.rewrite(p.getLeaf(), make.Identifier(name));
1519
                                    parameter.rewrite(p.getLeaf(), make.Identifier(name));
1519
                                }
1520
                                }
1520
                            }
1521
                            }
Lines 1530-1536 Link Here
1530
                            int       index;
1531
                            int       index;
1531
1532
1532
                            if (replaceAll) {
1533
                            if (replaceAll) {
1533
                                Set<TreePath> candidates = CopyFinder.computeDuplicates(parameter, resolved, method, new AtomicBoolean(), null).keySet();
1534
                                Set<TreePath> candidates = SourceUtils.computeDuplicates(parameter, resolved, method, new AtomicBoolean());
1534
                                for (TreePath p : candidates) {
1535
                                for (TreePath p : candidates) {
1535
                                    Tree leaf = p.getLeaf();
1536
                                    Tree leaf = p.getLeaf();
1536
1537
Lines 1666-1672 Link Here
1666
                    boolean isAnyOccurenceStatic = false;
1667
                    boolean isAnyOccurenceStatic = false;
1667
1668
1668
                    if (replaceAll) {
1669
                    if (replaceAll) {
1669
                        for (TreePath p : CopyFinder.computeDuplicates(parameter, resolved, new TreePath(parameter.getCompilationUnit()), new AtomicBoolean(), null).keySet()) {
1670
                        for (TreePath p : SourceUtils.computeDuplicates(parameter, resolved, new TreePath(parameter.getCompilationUnit()), new AtomicBoolean())) {
1670
                            parameter.rewrite(p.getLeaf(), make.Identifier(name));
1671
                            parameter.rewrite(p.getLeaf(), make.Identifier(name));
1671
                            Scope occurenceScope = parameter.getTrees().getScope(p);
1672
                            Scope occurenceScope = parameter.getTrees().getScope(p);
1672
                            if(parameter.getTreeUtilities().isStaticContext(occurenceScope))
1673
                            if(parameter.getTreeUtilities().isStaticContext(occurenceScope))
(-)java.source/nbproject/project.properties (-1 / +1 lines)
Lines 46-52 Link Here
46
javadoc.title=Java Source
46
javadoc.title=Java Source
47
javadoc.arch=${basedir}/arch.xml
47
javadoc.arch=${basedir}/arch.xml
48
javadoc.apichanges=${basedir}/apichanges.xml
48
javadoc.apichanges=${basedir}/apichanges.xml
49
spec.version.base=0.84.0
49
spec.version.base=0.85.0
50
test.qa-functional.cp.extra=${refactoring.java.dir}/modules/ext/javac-api-nb-7.0-b07.jar
50
test.qa-functional.cp.extra=${refactoring.java.dir}/modules/ext/javac-api-nb-7.0-b07.jar
51
test.unit.run.cp.extra=${o.n.core.dir}/core/core.jar:\
51
test.unit.run.cp.extra=${o.n.core.dir}/core/core.jar:\
52
    ${o.n.core.dir}/lib/boot.jar:\
52
    ${o.n.core.dir}/lib/boot.jar:\
(-)java.source/src/org/netbeans/api/java/source/SourceUtils.java (-1 / +38 lines)
Lines 44-49 Link Here
44
44
45
package org.netbeans.api.java.source;
45
package org.netbeans.api.java.source;
46
46
47
import java.lang.reflect.InvocationTargetException;
48
import java.lang.reflect.Method;
47
import org.netbeans.modules.java.preprocessorbridge.spi.ImportProcessor;
49
import org.netbeans.modules.java.preprocessorbridge.spi.ImportProcessor;
48
import java.io.File;
50
import java.io.File;
49
import java.io.IOException;
51
import java.io.IOException;
Lines 65-71 Link Here
65
67
66
import com.sun.source.tree.*;
68
import com.sun.source.tree.*;
67
import com.sun.source.util.TreePath;
69
import com.sun.source.util.TreePath;
68
import com.sun.source.util.TreePathScanner;
69
import com.sun.source.util.Trees;
70
import com.sun.source.util.Trees;
70
import com.sun.tools.javac.api.JavacTaskImpl;
71
import com.sun.tools.javac.api.JavacTaskImpl;
71
import com.sun.tools.javac.code.Flags;
72
import com.sun.tools.javac.code.Flags;
Lines 80-85 Link Here
80
import com.sun.tools.javac.util.Context;
81
import com.sun.tools.javac.util.Context;
81
import java.net.URISyntaxException;
82
import java.net.URISyntaxException;
82
import java.util.concurrent.Future;
83
import java.util.concurrent.Future;
84
import java.util.concurrent.atomic.AtomicBoolean;
83
import java.util.logging.Level;
85
import java.util.logging.Level;
84
import java.util.logging.Logger;
86
import java.util.logging.Logger;
85
import javax.lang.model.util.ElementScanner6;
87
import javax.lang.model.util.ElementScanner6;
Lines 152-157 Link Here
152
        return null;
154
        return null;
153
    }
155
    }
154
    
156
    
157
    /**
158
     * Find duplicates for provided expression
159
     * @param info CompilationInfo
160
     * @param searchingFor expression which is being searched
161
     * @param scope scope for search
162
     * @param cancel option to cancel find duplicates
163
     * @return set of TreePaths representing duplicates
164
     * @since 0.85
165
     */
166
    public static Set<TreePath> computeDuplicates(CompilationInfo info, TreePath searchingFor, TreePath scope, AtomicBoolean cancel) {
167
        try {
168
            Class copyFinderClass = Class.forName("org.netbeans.modules.java.hints.introduce.CopyFinderService");
169
            Object copyFinderInstance = Lookup.getDefault().lookup(copyFinderClass);
170
            if (copyFinderInstance != null) {
171
                Method method = copyFinderClass.getMethod("computeDuplicates", CompilationInfo.class, TreePath.class, TreePath.class, AtomicBoolean.class);
172
                if (method != null) {
173
                    return (Set<TreePath>) method.invoke(copyFinderInstance, info, searchingFor, scope, cancel);
174
                }
175
            }
176
        } catch (IllegalAccessException ex) {
177
            Exceptions.printStackTrace(ex);
178
        } catch (IllegalArgumentException ex) {
179
            Exceptions.printStackTrace(ex);
180
        } catch (InvocationTargetException ex) {
181
            Exceptions.printStackTrace(ex);
182
        } catch (NoSuchMethodException ex) {
183
            Exceptions.printStackTrace(ex);
184
        } catch (SecurityException ex) {
185
            Exceptions.printStackTrace(ex);
186
        } catch (ClassNotFoundException ex) {
187
            Exceptions.printStackTrace(ex);
188
        }
189
        return Collections.emptySet();
190
    }    
191
    
155
    public static boolean checkTypesAssignable(CompilationInfo info, TypeMirror from, TypeMirror to) {
192
    public static boolean checkTypesAssignable(CompilationInfo info, TypeMirror from, TypeMirror to) {
156
        Context c = ((JavacTaskImpl) info.impl.getJavacTask()).getContext();
193
        Context c = ((JavacTaskImpl) info.impl.getJavacTask()).getContext();
157
        if (from.getKind() == TypeKind.WILDCARD) {
194
        if (from.getKind() == TypeKind.WILDCARD) {

Return to bug 199106