# This patch file was generated by NetBeans IDE # Following Index: paths are relative to: /Users/beci/source/jet-main # This patch can be applied using context Tools: Patch action on respective folder. # It uses platform neutral UTF-8 encoding and \n newlines. # Above lines and this line are ignored by the patching process. Index: java.hints/nbproject/project.properties --- java.hints/nbproject/project.properties Base (BASE) +++ java.hints/nbproject/project.properties Locally Modified (Based On LOCAL) @@ -40,7 +40,7 @@ # Version 2 license, then the option applies only if the new code is # made subject to such option by the copyright holder. -spec.version.base=1.58.0 +spec.version.base=1.59.0 javac.source=1.6 Index: java.hints/src/org/netbeans/modules/java/hints/introduce/CopyFinderService.java --- java.hints/src/org/netbeans/modules/java/hints/introduce/CopyFinderService.java Base (BASE) +++ java.hints/src/org/netbeans/modules/java/hints/introduce/CopyFinderService.java Locally New @@ -0,0 +1,59 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2011 Oracle and/or its affiliates. All rights reserved. + * + * Oracle and Java are registered trademarks of Oracle and/or its affiliates. + * Other names may be trademarks of their respective owners. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common + * Development and Distribution License("CDDL") (collectively, the + * "License"). You may not use this file except in compliance with the + * License. You can obtain a copy of the License at + * http://www.netbeans.org/cddl-gplv2.html + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the + * specific language governing permissions and limitations under the + * License. When distributing the software, include this License Header + * Notice in each file and include the License file at + * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the GPL Version 2 section of the License file that + * accompanied this code. If applicable, add the following below the + * License Header, with the fields enclosed by brackets [] replaced by + * your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * If you wish your version of this file to be governed by only the CDDL + * or only the GPL Version 2, indicate your decision by adding + * "[Contributor] elects to include this software in this distribution + * under the [CDDL or GPL Version 2] license." If you do not indicate a + * single choice of license, a recipient has the option to distribute + * your version of this file under either the CDDL, the GPL Version 2 or + * to extend the choice of license to its licensees as provided above. + * However, if you add GPL Version 2 code and therefore, elected the GPL + * Version 2 license, then the option applies only if the new code is + * made subject to such option by the copyright holder. + * + * Contributor(s): + * + * Portions Copyrighted 2011 Sun Microsystems, Inc. + */ +package org.netbeans.modules.java.hints.introduce; + +import com.sun.source.util.TreePath; +import java.util.Set; +import java.util.concurrent.atomic.AtomicBoolean; +import org.netbeans.api.java.source.CompilationInfo; +import org.openide.util.lookup.ServiceProvider; + +/** + * + * @author Jan Becicka + */ +@ServiceProvider(service=CopyFinderService.class) +public class CopyFinderService { + public static Set computeDuplicates(CompilationInfo info, TreePath searchingFor, TreePath scope, AtomicBoolean cancel) { + return CopyFinder.computeDuplicates(info, searchingFor, scope, cancel, null).keySet(); + } +} Index: java.hints/src/org/netbeans/modules/java/hints/introduce/IntroduceHint.java --- java.hints/src/org/netbeans/modules/java/hints/introduce/IntroduceHint.java Base (BASE) +++ java.hints/src/org/netbeans/modules/java/hints/introduce/IntroduceHint.java Locally Modified (Based On LOCAL) @@ -117,6 +117,7 @@ import org.netbeans.api.java.source.GeneratorUtilities; import org.netbeans.api.java.source.JavaSource; import org.netbeans.api.java.source.JavaSource.Phase; +import org.netbeans.api.java.source.SourceUtils; import org.netbeans.api.java.source.TreeMaker; import org.netbeans.api.java.source.TreePathHandle; import org.netbeans.api.java.source.TreeUtilities; @@ -422,8 +423,8 @@ TreePath value = resolved.getLeaf().getKind() != Kind.VARIABLE ? resolved : new TreePath(resolved, ((VariableTree) resolved.getLeaf()).getInitializer()); boolean isConstant = checkConstantExpression(info, value) && !expressionStatement; boolean isVariable = findStatement(resolved) != null && method != null && resolved.getLeaf().getKind() != Kind.VARIABLE; - Set duplicatesForVariable = isVariable ? CopyFinder.computeDuplicates(info, resolved, method, cancel, null).keySet() : null; - Set duplicatesForConstant = /*isConstant ? */CopyFinder.computeDuplicates(info, resolved, new TreePath(info.getCompilationUnit()), cancel, null).keySet();// : null; + Set duplicatesForVariable = isVariable ? SourceUtils.computeDuplicates(info, resolved, method, cancel) : null; + Set duplicatesForConstant = /*isConstant ? */SourceUtils.computeDuplicates(info, resolved, new TreePath(info.getCompilationUnit()), cancel);// : null; Scope scope = info.getTrees().getScope(resolved); boolean statik = scope != null ? info.getTreeUtilities().isStaticContext(scope) : false; String guessedName = Utilities.guessName(info, resolved); @@ -1355,7 +1356,7 @@ returnValueComputed = true; } else { if (returnValue != null && currentReturnValue != null) { - Set candidates = CopyFinder.computeDuplicates(info, returnValue, currentReturnValue, cancel, null).keySet(); + Set candidates = SourceUtils.computeDuplicates(info, returnValue, currentReturnValue, cancel); if (candidates.size() != 1 || candidates.iterator().next().getLeaf() != rt.getExpression()) { return "ERR_Different_Return_Values"; // NOI18N @@ -1514,7 +1515,7 @@ parameter.rewrite(pathToClass.getLeaf(), nueClass); if (replaceAll) { - for (TreePath p : CopyFinder.computeDuplicates(parameter, resolved, new TreePath(parameter.getCompilationUnit()), new AtomicBoolean(), null).keySet()) { + for (TreePath p : SourceUtils.computeDuplicates(parameter, resolved, new TreePath(parameter.getCompilationUnit()), new AtomicBoolean())) { parameter.rewrite(p.getLeaf(), make.Identifier(name)); } } @@ -1530,7 +1531,7 @@ int index; if (replaceAll) { - Set candidates = CopyFinder.computeDuplicates(parameter, resolved, method, new AtomicBoolean(), null).keySet(); + Set candidates = SourceUtils.computeDuplicates(parameter, resolved, method, new AtomicBoolean()); for (TreePath p : candidates) { Tree leaf = p.getLeaf(); @@ -1666,7 +1667,7 @@ boolean isAnyOccurenceStatic = false; if (replaceAll) { - for (TreePath p : CopyFinder.computeDuplicates(parameter, resolved, new TreePath(parameter.getCompilationUnit()), new AtomicBoolean(), null).keySet()) { + for (TreePath p : SourceUtils.computeDuplicates(parameter, resolved, new TreePath(parameter.getCompilationUnit()), new AtomicBoolean())) { parameter.rewrite(p.getLeaf(), make.Identifier(name)); Scope occurenceScope = parameter.getTrees().getScope(p); if(parameter.getTreeUtilities().isStaticContext(occurenceScope)) Index: java.source/nbproject/project.properties --- java.source/nbproject/project.properties Base (BASE) +++ java.source/nbproject/project.properties Locally Modified (Based On LOCAL) @@ -46,7 +46,7 @@ javadoc.title=Java Source javadoc.arch=${basedir}/arch.xml javadoc.apichanges=${basedir}/apichanges.xml -spec.version.base=0.84.0 +spec.version.base=0.85.0 test.qa-functional.cp.extra=${refactoring.java.dir}/modules/ext/javac-api-nb-7.0-b07.jar test.unit.run.cp.extra=${o.n.core.dir}/core/core.jar:\ ${o.n.core.dir}/lib/boot.jar:\ Index: java.source/src/org/netbeans/api/java/source/SourceUtils.java --- java.source/src/org/netbeans/api/java/source/SourceUtils.java Base (BASE) +++ java.source/src/org/netbeans/api/java/source/SourceUtils.java Locally Modified (Based On LOCAL) @@ -44,6 +44,8 @@ package org.netbeans.api.java.source; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; import org.netbeans.modules.java.preprocessorbridge.spi.ImportProcessor; import java.io.File; import java.io.IOException; @@ -65,7 +67,6 @@ import com.sun.source.tree.*; import com.sun.source.util.TreePath; -import com.sun.source.util.TreePathScanner; import com.sun.source.util.Trees; import com.sun.tools.javac.api.JavacTaskImpl; import com.sun.tools.javac.code.Flags; @@ -80,6 +81,7 @@ import com.sun.tools.javac.util.Context; import java.net.URISyntaxException; import java.util.concurrent.Future; +import java.util.concurrent.atomic.AtomicBoolean; import java.util.logging.Level; import java.util.logging.Logger; import javax.lang.model.util.ElementScanner6; @@ -152,6 +154,42 @@ return null; } + /** + * Find duplicates for provided expression + * @param info CompilationInfo + * @param searchingFor expression which is being searched + * @param scope scope for search + * @param cancel option to cancel find duplicates + * @return set of TreePaths representing duplicates + * @since 0.85 + */ + public static Set computeDuplicates(CompilationInfo info, TreePath searchingFor, TreePath scope, AtomicBoolean cancel) { + try { + ClassLoader loader = Lookup.getDefault().lookup(ClassLoader.class); + Class copyFinderClass = loader.loadClass("org.netbeans.modules.java.hints.introduce.CopyFinderService"); + Object copyFinderInstance = Lookup.getDefault().lookup(copyFinderClass); + if (copyFinderInstance != null) { + Method method = copyFinderClass.getMethod("computeDuplicates", CompilationInfo.class, TreePath.class, TreePath.class, AtomicBoolean.class); + if (method != null) { + return (Set) method.invoke(copyFinderInstance, info, searchingFor, scope, cancel); + } + } + } catch (IllegalAccessException ex) { + Exceptions.printStackTrace(ex); + } catch (IllegalArgumentException ex) { + Exceptions.printStackTrace(ex); + } catch (InvocationTargetException ex) { + Exceptions.printStackTrace(ex); + } catch (NoSuchMethodException ex) { + Exceptions.printStackTrace(ex); + } catch (SecurityException ex) { + Exceptions.printStackTrace(ex); + } catch (ClassNotFoundException ex) { + Exceptions.printStackTrace(ex); + } + return Collections.emptySet(); + } + public static boolean checkTypesAssignable(CompilationInfo info, TypeMirror from, TypeMirror to) { Context c = ((JavacTaskImpl) info.impl.getJavacTask()).getContext(); if (from.getKind() == TypeKind.WILDCARD) { Index: refactoring.java/nbproject/project.xml --- refactoring.java/nbproject/project.xml Base (BASE) +++ refactoring.java/nbproject/project.xml Locally Modified (Based On LOCAL) @@ -323,6 +323,10 @@ unit + org.netbeans.modules.java.hints + + + org.netbeans.libs.junit4