### Eclipse Workspace Patch 1.0 #P org.eclipse.jdt.ui diff --git core extension/org/eclipse/jdt/internal/corext/codemanipulation/ImportReferencesCollector.java core extension/org/eclipse/jdt/internal/corext/codemanipulation/ImportReferencesCollector.java index 63fe565..9cc6b88 100644 --- core extension/org/eclipse/jdt/internal/corext/codemanipulation/ImportReferencesCollector.java +++ core extension/org/eclipse/jdt/internal/corext/codemanipulation/ImportReferencesCollector.java @@ -1,9 +1,13 @@ /******************************************************************************* - * Copyright (c) 2000, 2012 IBM Corporation and others. + * Copyright (c) 2000, 2013 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html + * + * This is an implementation of an early-draft specification developed under the Java Community Process (JCP) and + * is made available for testing and evaluation purposes only. + * The code is not compatible with any specification of the JCP. * * Contributors: * IBM Corporation - initial API and implementation @@ -206,7 +210,8 @@ @Override public boolean visit(SimpleType node) { typeRefFound(node.getName()); - return false; + // visit annotations of SimpleType + return true; } /* @@ -385,10 +390,15 @@ if (!node.isConstructor()) { doVisitNode(node.getReturnType2()); } + if(node.getReceiverType() != null){ + doVisitChildren(node.getReceiverType().annotations()); + } doVisitChildren(node.parameters()); - Iterator iter=node.thrownExceptions().iterator(); - while (iter.hasNext()) { - typeRefFound(iter.next()); + // TODO below modifications are done to avoid exception while testing and is not part of this fix + Iterator iterator= node.thrownExceptionTypes().iterator(); + while (iterator.hasNext()) { + SimpleType object= iterator.next(); + typeRefFound(object.getName()); } if (!fSkipMethodBodies) { doVisitNode(node.getBody()); diff --git core extension/org/eclipse/jdt/internal/corext/codemanipulation/StubUtility2.java core extension/org/eclipse/jdt/internal/corext/codemanipulation/StubUtility2.java index e550cb7..df77f02 100644 --- core extension/org/eclipse/jdt/internal/corext/codemanipulation/StubUtility2.java +++ core extension/org/eclipse/jdt/internal/corext/codemanipulation/StubUtility2.java @@ -1,9 +1,13 @@ /******************************************************************************* - * Copyright (c) 2000, 2012 IBM Corporation and others. + * Copyright (c) 2000, 2013 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html + * + * This is an implementation of an early-draft specification developed under the Java Community Process (JCP) and + * is made available for testing and evaluation purposes only. + * The code is not compatible with any specification of the JCP. * * Contributors: * IBM Corporation - initial API and implementation @@ -120,11 +124,12 @@ List parameters= createParameters(unit.getJavaProject(), imports, context, ast, binding, decl); - List thrownExceptions= decl.thrownExceptions(); + // TODO Below changes are not part of the current bug fix. + List thrownExceptions= decl.thrownExceptionTypes(); ITypeBinding[] excTypes= binding.getExceptionTypes(); for (int i= 0; i < excTypes.length; i++) { String excTypeName= imports.addImport(excTypes[i], context); - thrownExceptions.add(ASTNodeFactory.newName(ast, excTypeName)); + thrownExceptions.add(ASTNodeFactory.newType(ast, excTypeName)); } Block body= ast.newBlock(); diff --git core refactoring/org/eclipse/jdt/internal/corext/refactoring/code/flow/FlowAnalyzer.java core refactoring/org/eclipse/jdt/internal/corext/refactoring/code/flow/FlowAnalyzer.java index 06b797b..e574544 100644 --- core refactoring/org/eclipse/jdt/internal/corext/refactoring/code/flow/FlowAnalyzer.java +++ core refactoring/org/eclipse/jdt/internal/corext/refactoring/code/flow/FlowAnalyzer.java @@ -1,9 +1,13 @@ /******************************************************************************* - * Copyright (c) 2000, 2011 IBM Corporation and others. + * Copyright (c) 2000, 2013 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html + * + * This is an implementation of an early-draft specification developed under the Java Community Process (JCP) and + * is made available for testing and evaluation purposes only. + * The code is not compatible with any specification of the JCP. * * Contributors: * IBM Corporation - initial API and implementation @@ -711,7 +715,8 @@ return; GenericSequentialFlowInfo info= processSequential(node, node.getReturnType2()); process(info, node.parameters()); - process(info, node.thrownExceptions()); + // TODO Below changes are not part of the current bug fix. + process(info, node.thrownExceptionTypes()); process(info, node.getBody()); } diff --git core refactoring/org/eclipse/jdt/internal/corext/refactoring/structure/ExtractInterfaceProcessor.java core refactoring/org/eclipse/jdt/internal/corext/refactoring/structure/ExtractInterfaceProcessor.java index 4aee33c..f239f13 100644 --- core refactoring/org/eclipse/jdt/internal/corext/refactoring/structure/ExtractInterfaceProcessor.java +++ core refactoring/org/eclipse/jdt/internal/corext/refactoring/structure/ExtractInterfaceProcessor.java @@ -1,9 +1,13 @@ /******************************************************************************* - * Copyright (c) 2000, 2012 IBM Corporation and others. + * Copyright (c) 2000, 2013 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html + * + * This is an implementation of an early-draft specification developed under the Java Community Process (JCP) and + * is made available for testing and evaluation purposes only. + * The code is not compatible with any specification of the JCP. * * Contributors: * IBM Corporation - initial API and implementation @@ -79,6 +83,8 @@ import org.eclipse.jdt.core.dom.Modifier; import org.eclipse.jdt.core.dom.NodeFinder; import org.eclipse.jdt.core.dom.ParameterizedType; +import org.eclipse.jdt.core.dom.SimpleName; +import org.eclipse.jdt.core.dom.SimpleType; import org.eclipse.jdt.core.dom.SingleVariableDeclaration; import org.eclipse.jdt.core.dom.Type; import org.eclipse.jdt.core.dom.TypeDeclaration; @@ -699,6 +705,7 @@ if (fAbstract && !abstractFound) rewriter.setModifiers(Modifier.ABSTRACT, 0, null); + updateReceiverParameter(declaration, rewrite, targetDeclaration.getName().getIdentifier()); for (SingleVariableDeclaration param : (List) declaration.parameters()) { ListRewrite modifierRewrite= rewrite.getListRewrite(param, SingleVariableDeclaration.MODIFIERS2_PROPERTY); for (IExtendedModifier extended : (List) param.modifiers()) { @@ -730,6 +737,25 @@ RefactoringFileBuffers.release(unit); } } + + private void updateReceiverParameter(final MethodDeclaration declaration, final ASTRewrite rewrite, final String targetName) { + if (declaration.getReceiverType() != null) { + AST ast= rewrite.getAST(); + SimpleName simpleName= ast.newSimpleName(targetName); + SimpleType simpleType= ast.newSimpleType(simpleName); + Iterator iterator= declaration.getReceiverType().annotations().iterator(); + while (iterator.hasNext()) { + Annotation annotation= iterator.next(); + simpleType.annotations().add(rewrite.createCopyTarget(annotation)); + } + rewrite.set(declaration, MethodDeclaration.RECEIVER_TYPE_PROPERTY, simpleType, null); + + if (declaration.getReceiverQualifier() != null) { + SimpleName qualifierName= ast.newSimpleName(targetName); + rewrite.set(declaration, MethodDeclaration.RECEIVER_QUALIFIER_PROPERTY, qualifierName, null); + } + } + } /** * Creates the new signature of the source type. diff --git core refactoring/org/eclipse/jdt/internal/corext/refactoring/structure/HierarchyProcessor.java core refactoring/org/eclipse/jdt/internal/corext/refactoring/structure/HierarchyProcessor.java index 726fd5f..e1cbeed 100644 --- core refactoring/org/eclipse/jdt/internal/corext/refactoring/structure/HierarchyProcessor.java +++ core refactoring/org/eclipse/jdt/internal/corext/refactoring/structure/HierarchyProcessor.java @@ -1,9 +1,13 @@ /******************************************************************************* - * Copyright (c) 2006, 2012 IBM Corporation and others. + * Copyright (c) 2006, 2013 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html + * + * This is an implementation of an early-draft specification developed under the Java Community Process (JCP) and + * is made available for testing and evaluation purposes only. + * The code is not compatible with any specification of the JCP. * * Contributors: * IBM Corporation - initial API and implementation @@ -64,8 +68,8 @@ import org.eclipse.jdt.core.dom.Javadoc; import org.eclipse.jdt.core.dom.MethodDeclaration; import org.eclipse.jdt.core.dom.Modifier; -import org.eclipse.jdt.core.dom.Name; import org.eclipse.jdt.core.dom.SimpleName; +import org.eclipse.jdt.core.dom.SimpleType; import org.eclipse.jdt.core.dom.SingleVariableDeclaration; import org.eclipse.jdt.core.dom.Type; import org.eclipse.jdt.core.dom.TypeDeclaration; @@ -242,8 +246,9 @@ protected static void copyThrownExceptions(final MethodDeclaration oldMethod, final MethodDeclaration newMethod) { final AST ast= newMethod.getAST(); - for (int index= 0, n= oldMethod.thrownExceptions().size(); index < n; index++) - newMethod.thrownExceptions().add(ASTNode.copySubtree(ast, (Name) oldMethod.thrownExceptions().get(index))); + // TODO Below changes are not part of the current bug fix. + for (int index= 0, n= oldMethod.thrownExceptionTypes().size(); index < n; index++) + newMethod.thrownExceptionTypes().add(ASTNode.copySubtree(ast, (SimpleType) oldMethod.thrownExceptionTypes().get(index))); } protected static void copyTypeParameters(final MethodDeclaration oldMethod, final MethodDeclaration newMethod) { @@ -714,4 +719,31 @@ return true; return hasNonMovedReferences(member, monitor, status); } + + /** + * Updates the receiver parameter properties of the new method. + * + * @param type the new type where the new method will be placed + * @param oldMethod the existing method from where the receiver parameter properties will be + * copied + * @param newMethod the method whose receiver parameter properties will be updated + * @since 3.9 BETA_JAVA8 + */ + protected void updateReceiverParameter(IType type, MethodDeclaration oldMethod, MethodDeclaration newMethod) { + AST ast= newMethod.getAST(); + String elementName= type.getElementName(); + if (oldMethod.getReceiverType() != null) { + SimpleType simpleType= ast.newSimpleType(ast.newSimpleName(elementName)); + Iterator iterator= oldMethod.getReceiverType().annotations().iterator(); + while (iterator.hasNext()) { + Annotation annotation= iterator.next(); + simpleType.annotations().add(ASTNode.copySubtree(ast, annotation)); + } + newMethod.setReceiverType(simpleType); + if (oldMethod.getReceiverQualifier() != null) { + newMethod.setReceiverQualifier(ast.newSimpleName(elementName)); + } + } + } + } \ No newline at end of file diff --git core refactoring/org/eclipse/jdt/internal/corext/refactoring/structure/MoveInnerToTopRefactoring.java core refactoring/org/eclipse/jdt/internal/corext/refactoring/structure/MoveInnerToTopRefactoring.java index d602cc1..f00d85e 100644 --- core refactoring/org/eclipse/jdt/internal/corext/refactoring/structure/MoveInnerToTopRefactoring.java +++ core refactoring/org/eclipse/jdt/internal/corext/refactoring/structure/MoveInnerToTopRefactoring.java @@ -1,9 +1,13 @@ /******************************************************************************* - * Copyright (c) 2000, 2012 IBM Corporation and others. + * Copyright (c) 2000, 2013 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html + * + * This is an implementation of an early-draft specification developed under the Java Community Process (JCP) and + * is made available for testing and evaluation purposes only. + * The code is not compatible with any specification of the JCP. * * Contributors: * IBM Corporation - initial API and implementation @@ -901,6 +905,7 @@ addInheritedTypeQualifications(declaration, targetRewrite, qualifierGroup); addEnclosingInstanceDeclaration(declaration, rewrite); } + updateConstructorReceiverParameter(declaration, rewrite); fTypeImports= new HashSet(); fStaticImports= new HashSet(); ImportRewriteUtil.collectImports(fType.getJavaProject(), declaration, fTypeImports, fStaticImports, false); @@ -1392,6 +1397,26 @@ } } + /** + * Updates the receiver parameter properties of the constructor. The receiver parameter properties are set to null. + * + * @param declaration the type declaration AST node + * @param rewrite the ASTRewrite node used for the modification + * @since 3.9 BETA_JAVA8 + */ + private void updateConstructorReceiverParameter(AbstractTypeDeclaration declaration, final ASTRewrite rewrite) { + final MethodDeclaration[] declarations= getConstructorDeclarationNodes(declaration); + for (int index= 0; index < declarations.length; index++) { + MethodDeclaration methodDeclaration= declarations[index]; + if (methodDeclaration.getReceiverType() != null) { + rewrite.set(methodDeclaration, MethodDeclaration.RECEIVER_TYPE_PROPERTY, null, null); + if (methodDeclaration.getReceiverQualifier() != null) { + rewrite.set(methodDeclaration, MethodDeclaration.RECEIVER_QUALIFIER_PROPERTY, null, null); + } + } + } + } + private void modifyInterfaceMemberModifiers(final ITypeBinding binding) { Assert.isNotNull(binding); ITypeBinding declaring= binding.getDeclaringClass(); diff --git core refactoring/org/eclipse/jdt/internal/corext/refactoring/structure/MoveInstanceMethodProcessor.java core refactoring/org/eclipse/jdt/internal/corext/refactoring/structure/MoveInstanceMethodProcessor.java index 48d6687..8263b1c 100644 --- core refactoring/org/eclipse/jdt/internal/corext/refactoring/structure/MoveInstanceMethodProcessor.java +++ core refactoring/org/eclipse/jdt/internal/corext/refactoring/structure/MoveInstanceMethodProcessor.java @@ -1,10 +1,14 @@ /******************************************************************************* - * Copyright (c) 2000, 2012 IBM Corporation and others. + * Copyright (c) 2000, 2013 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * + * This is an implementation of an early-draft specification developed under the Java Community Process (JCP) and + * is made available for testing and evaluation purposes only. + * The code is not compatible with any specification of the JCP. + * * Contributors: * IBM Corporation - initial API and implementation *******************************************************************************/ @@ -69,6 +73,7 @@ import org.eclipse.jdt.core.dom.ASTNode; import org.eclipse.jdt.core.dom.ASTVisitor; import org.eclipse.jdt.core.dom.AbstractTypeDeclaration; +import org.eclipse.jdt.core.dom.Annotation; import org.eclipse.jdt.core.dom.AnnotationTypeDeclaration; import org.eclipse.jdt.core.dom.AnonymousClassDeclaration; import org.eclipse.jdt.core.dom.Assignment; @@ -95,6 +100,7 @@ import org.eclipse.jdt.core.dom.PrimitiveType; import org.eclipse.jdt.core.dom.QualifiedName; import org.eclipse.jdt.core.dom.SimpleName; +import org.eclipse.jdt.core.dom.SimpleType; import org.eclipse.jdt.core.dom.SingleVariableDeclaration; import org.eclipse.jdt.core.dom.SuperFieldAccess; import org.eclipse.jdt.core.dom.SuperMethodInvocation; @@ -2255,6 +2261,7 @@ adjustments.put(fMethod, adjustment); } } + updateReceiverParameter(declaration, rewrite); target= createMethodArguments(rewrites, rewrite, declaration, adjustments, status); createMethodTypeParameters(rewrite, declaration, status); createMethodComment(rewrite, declaration); @@ -2266,6 +2273,25 @@ return target; } + private void updateReceiverParameter(final MethodDeclaration declaration, final ASTRewrite rewrite) throws JavaModelException { + if (declaration.getReceiverType() != null) { + IType targetType= getTargetType(); + AST ast= rewrite.getAST(); + SimpleName simpleName= ast.newSimpleName(targetType.getElementName()); + SimpleType simpleType= ast.newSimpleType(simpleName); + Iterator iterator= declaration.getReceiverType().annotations().iterator(); + while (iterator.hasNext()) { + Annotation annotation= iterator.next(); + simpleType.annotations().add(rewrite.createCopyTarget(annotation)); + } + rewrite.set(declaration, MethodDeclaration.RECEIVER_TYPE_PROPERTY, simpleType, null); + if (declaration.getReceiverQualifier() != null) { + SimpleName qualifierName= ast.newSimpleName(targetType.getElementName()); + rewrite.set(declaration, MethodDeclaration.RECEIVER_QUALIFIER_PROPERTY, qualifierName, null); + } + } + } + /** * Creates the necessary changes to replace the body of the method * declaration with an expression to invoke the delegate. diff --git core refactoring/org/eclipse/jdt/internal/corext/refactoring/structure/PullUpRefactoringProcessor.java core refactoring/org/eclipse/jdt/internal/corext/refactoring/structure/PullUpRefactoringProcessor.java index e542ceb..e5bc7ec 100644 --- core refactoring/org/eclipse/jdt/internal/corext/refactoring/structure/PullUpRefactoringProcessor.java +++ core refactoring/org/eclipse/jdt/internal/corext/refactoring/structure/PullUpRefactoringProcessor.java @@ -1,10 +1,14 @@ /******************************************************************************* - * Copyright (c) 2006, 2011 IBM Corporation and others. + * Copyright (c) 2006, 2013 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * + * This is an implementation of an early-draft specification developed under the Java Community Process (JCP) and + * is made available for testing and evaluation purposes only. + * The code is not compatible with any specification of the JCP. + * * Contributors: * IBM Corporation - initial API and implementation * Benjamin Muskalla - 228950: [pull up] exception if target calls super with multiple parameters @@ -510,6 +514,7 @@ copyReturnType(rewriter.getASTRewrite(), getDeclaringType().getCompilationUnit(), methodToCreateStubFor, newMethod, mapping); copyParameters(rewriter.getASTRewrite(), getDeclaringType().getCompilationUnit(), methodToCreateStubFor, newMethod, mapping); copyThrownExceptions(methodToCreateStubFor, newMethod); + updateReceiverParameter(getDestinationType(), methodToCreateStubFor, newMethod); newMethod.setJavadoc(createJavadocForStub(typeToCreateStubIn.getName().getIdentifier(), methodToCreateStubFor, newMethod, newCu, rewriter.getASTRewrite())); ImportRewriteContext context= new ContextSensitiveImportRewriteContext(typeToCreateStubIn, rewriter.getImportRewrite()); ImportRewriteUtil.addImports(rewriter, context, newMethod, new HashMap(), new HashMap(), false); @@ -1023,7 +1028,8 @@ final MethodDeclaration newMethod= targetRewrite.getAST().newMethodDeclaration(); newMethod.setBody(null); newMethod.setConstructor(false); - newMethod.setExtraDimensions(oldMethod.getExtraDimensions()); + // TODO Below change is not part of the current fix. +// newMethod.setExtraDimensions(oldMethod.getExtraDimensions()); newMethod.setJavadoc(null); int modifiers= getModifiersWithUpdatedVisibility(sourceMethod, Modifier.ABSTRACT | JdtFlags.clearFlag(Modifier.NATIVE | Modifier.FINAL, sourceMethod.getFlags()), adjustments, monitor, false, status); if (oldMethod.isVarargs()) @@ -1033,8 +1039,9 @@ copyReturnType(targetRewrite.getASTRewrite(), getDeclaringType().getCompilationUnit(), oldMethod, newMethod, mapping); copyParameters(targetRewrite.getASTRewrite(), getDeclaringType().getCompilationUnit(), oldMethod, newMethod, mapping); copyThrownExceptions(oldMethod, newMethod); + updateReceiverParameter(getDestinationType(), oldMethod, newMethod); ImportRewriteContext context= new ContextSensitiveImportRewriteContext(destination, targetRewrite.getImportRewrite()); - ImportRewriteUtil.addImports(targetRewrite, context, newMethod, new HashMap(), new HashMap(), false); + ImportRewriteUtil.addImports(targetRewrite, context, oldMethod, new HashMap(), new HashMap(), false); targetRewrite.getASTRewrite().getListRewrite(destination, destination.getBodyDeclarationsProperty()).insertAt(newMethod, ASTNodes.getInsertionIndex(newMethod, destination.bodyDeclarations()), targetRewrite.createCategorizedGroupDescription(RefactoringCoreMessages.PullUpRefactoring_add_abstract_method, SET_PULL_UP)); } @@ -1323,7 +1330,8 @@ if (!getDestinationType().isInterface()) copyBodyOfPulledUpMethod(sourceRewrite, targetRewrite, sourceMethod, oldMethod, newMethod, mapping, monitor); newMethod.setConstructor(oldMethod.isConstructor()); - newMethod.setExtraDimensions(oldMethod.getExtraDimensions()); + // TODO Below change is not part of the current fix. +// newMethod.setExtraDimensions(oldMethod.getExtraDimensions()); copyJavadocNode(rewrite, oldMethod, newMethod); int modifiers= getModifiersWithUpdatedVisibility(sourceMethod, sourceMethod.getFlags(), adjustments, monitor, true, status); if (fDeletedMethods.length == 0 || getDestinationType().isInterface()) { @@ -1339,6 +1347,7 @@ copyParameters(rewrite, getDeclaringType().getCompilationUnit(), oldMethod, newMethod, mapping); copyThrownExceptions(oldMethod, newMethod); copyTypeParameters(oldMethod, newMethod); + updateReceiverParameter(getDestinationType(), oldMethod, newMethod); return newMethod; } diff --git core refactoring/org/eclipse/jdt/internal/corext/refactoring/structure/PushDownRefactoringProcessor.java core refactoring/org/eclipse/jdt/internal/corext/refactoring/structure/PushDownRefactoringProcessor.java index b63b04c..92128f4 100644 --- core refactoring/org/eclipse/jdt/internal/corext/refactoring/structure/PushDownRefactoringProcessor.java +++ core refactoring/org/eclipse/jdt/internal/corext/refactoring/structure/PushDownRefactoringProcessor.java @@ -1,10 +1,14 @@ /******************************************************************************* - * Copyright (c) 2006, 2011 IBM Corporation and others. + * Copyright (c) 2006, 2013 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html - * + * + * This is an implementation of an early-draft specification developed under the Java Community Process (JCP) and + * is made available for testing and evaluation purposes only. + * The code is not compatible with any specification of the JCP. + * * Contributors: * IBM Corporation - initial API and implementation *******************************************************************************/ @@ -654,7 +658,7 @@ } else { final MethodDeclaration oldMethod= ASTNodeSearchUtil.getMethodDeclarationNode((IMethod) infos[offset].getMember(), sourceRewriter.getRoot()); if (oldMethod != null) { - MethodDeclaration newMethod= createNewMethodDeclarationNode(infos[offset], mapping, unitRewriter, oldMethod); + MethodDeclaration newMethod= createNewMethodDeclarationNode(type, infos[offset], mapping, unitRewriter, oldMethod); unitRewriter.getASTRewrite().getListRewrite(declaration, declaration.getBodyDeclarationsProperty()).insertAt(newMethod, ASTNodes.getInsertionIndex(newMethod, declaration.bodyDeclarations()), unitRewriter.createCategorizedGroupDescription(RefactoringCoreMessages.HierarchyRefactoring_add_member, SET_PUSH_DOWN)); ImportRewriteUtil.addImports(unitRewriter, context, oldMethod, new HashMap(), new HashMap(), false); } @@ -819,7 +823,7 @@ return newField; } - private MethodDeclaration createNewMethodDeclarationNode(MemberActionInfo info, TypeVariableMaplet[] mapping, CompilationUnitRewrite rewriter, MethodDeclaration oldMethod) throws JavaModelException { + private MethodDeclaration createNewMethodDeclarationNode(IType type, MemberActionInfo info, TypeVariableMaplet[] mapping, CompilationUnitRewrite rewriter, MethodDeclaration oldMethod) throws JavaModelException { Assert.isTrue(!info.isFieldInfo()); IMethod method= (IMethod) info.getMember(); ASTRewrite rewrite= rewriter.getASTRewrite(); @@ -827,7 +831,8 @@ MethodDeclaration newMethod= ast.newMethodDeclaration(); copyBodyOfPushedDownMethod(rewrite, method, oldMethod, newMethod, mapping); newMethod.setConstructor(oldMethod.isConstructor()); - newMethod.setExtraDimensions(oldMethod.getExtraDimensions()); + // TODO Below change is not part of the current fix. +// newMethod.setExtraDimensions(oldMethod.getExtraDimensions()); if (info.copyJavadocToCopiesInSubclasses()) copyJavadocNode(rewrite, oldMethod, newMethod); final IJavaProject project= rewriter.getCu().getJavaProject(); @@ -843,6 +848,7 @@ copyParameters(rewrite, method.getCompilationUnit(), oldMethod, newMethod, mapping); copyThrownExceptions(oldMethod, newMethod); copyTypeParameters(oldMethod, newMethod); + updateReceiverParameter(type, oldMethod, newMethod); return newMethod; } diff --git core refactoring/org/eclipse/jdt/internal/corext/refactoring/structure/constraints/SuperTypeConstraintsCreator.java core refactoring/org/eclipse/jdt/internal/corext/refactoring/structure/constraints/SuperTypeConstraintsCreator.java index 823027a..7bd9e8e 100644 --- core refactoring/org/eclipse/jdt/internal/corext/refactoring/structure/constraints/SuperTypeConstraintsCreator.java +++ core refactoring/org/eclipse/jdt/internal/corext/refactoring/structure/constraints/SuperTypeConstraintsCreator.java @@ -1,9 +1,13 @@ /******************************************************************************* - * Copyright (c) 2000, 2012 IBM Corporation and others. + * Copyright (c) 2000, 2013 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html + * + * This is an implementation of an early-draft specification developed under the Java Community Process (JCP) and + * is made available for testing and evaluation purposes only. + * The code is not compatible with any specification of the JCP. * * Contributors: * IBM Corporation - initial API and implementation @@ -53,6 +57,7 @@ import org.eclipse.jdt.core.dom.QualifiedName; import org.eclipse.jdt.core.dom.ReturnStatement; import org.eclipse.jdt.core.dom.SimpleName; +import org.eclipse.jdt.core.dom.SimpleType; import org.eclipse.jdt.core.dom.SingleVariableDeclaration; import org.eclipse.jdt.core.dom.SuperConstructorInvocation; import org.eclipse.jdt.core.dom.SuperFieldAccess; @@ -503,16 +508,17 @@ } } } - final List exceptions= node.thrownExceptions(); + // TODO: Below changes are not part of the current fix, but was required to test the feature. + final List exceptions= node.thrownExceptionTypes(); if (!exceptions.isEmpty()) { final ITypeBinding throwable= node.getAST().resolveWellKnownType("java.lang.Throwable"); //$NON-NLS-1$ if (throwable != null) { ancestor= fModel.createImmutableTypeVariable(throwable); if (ancestor != null) { - Name exception= null; + SimpleType exception= null; for (int index= 0; index < exceptions.size(); index++) { exception= exceptions.get(index); - descendant= (ConstraintVariable2) exception.getProperty(PROPERTY_CONSTRAINT_VARIABLE); + descendant= (ConstraintVariable2) exception.getName().getProperty(PROPERTY_CONSTRAINT_VARIABLE); if (descendant != null) fModel.createSubtypeConstraint(descendant, ancestor); } diff --git core refactoring/org/eclipse/jdt/internal/corext/refactoring/structure/constraints/SuperTypeRefactoringProcessor.java core refactoring/org/eclipse/jdt/internal/corext/refactoring/structure/constraints/SuperTypeRefactoringProcessor.java index b2de6bd..b066993 100644 --- core refactoring/org/eclipse/jdt/internal/corext/refactoring/structure/constraints/SuperTypeRefactoringProcessor.java +++ core refactoring/org/eclipse/jdt/internal/corext/refactoring/structure/constraints/SuperTypeRefactoringProcessor.java @@ -1,9 +1,13 @@ /******************************************************************************* - * Copyright (c) 2000, 2012 IBM Corporation and others. + * Copyright (c) 2000, 2013 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html + * + * This is an implementation of an early-draft specification developed under the Java Community Process (JCP) and + * is made available for testing and evaluation purposes only. + * The code is not compatible with any specification of the JCP. * * Contributors: * IBM Corporation - initial API and implementation @@ -71,6 +75,7 @@ import org.eclipse.jdt.core.dom.QualifiedName; import org.eclipse.jdt.core.dom.SimpleName; import org.eclipse.jdt.core.dom.SingleVariableDeclaration; +import org.eclipse.jdt.core.dom.StructuralPropertyDescriptor; import org.eclipse.jdt.core.dom.Type; import org.eclipse.jdt.core.dom.TypeDeclaration; import org.eclipse.jdt.core.dom.TypeParameter; @@ -845,8 +850,10 @@ IBinding binding= null; final CompilationUnit target= rewrite.getRoot(); node= NodeFinder.perform(copy, range.getSourceRange()); - if (node != null) { - node= ASTNodes.getNormalizedNode(node).getParent(); + ASTNode normalizedNode= ASTNodes.getNormalizedNode(node); + if (node != null && normalizedNode != null) { + StructuralPropertyDescriptor locationInParent= normalizedNode.getLocationInParent(); + node= normalizedNode.getParent(); if (node instanceof VariableDeclaration) { binding= ((VariableDeclaration) node).resolveBinding(); node= target.findDeclaringNode(binding.getKey()); @@ -863,7 +870,7 @@ node= target.findDeclaringNode(binding.getKey()); if (node instanceof VariableDeclarationFragment) rewriteTypeOccurrence(estimate, rewrite, ((VariableDeclarationStatement) ((VariableDeclarationFragment) node).getParent()).getType(), group); - } else if (node instanceof MethodDeclaration) { + } else if (node instanceof MethodDeclaration && MethodDeclaration.RETURN_TYPE2_PROPERTY.equals(locationInParent)) { binding= ((MethodDeclaration) node).resolveBinding(); node= target.findDeclaringNode(binding.getKey()); if (node instanceof MethodDeclaration) diff --git ui/org/eclipse/jdt/internal/ui/search/ExceptionOccurrencesFinder.java ui/org/eclipse/jdt/internal/ui/search/ExceptionOccurrencesFinder.java index b989651..ddc8f05 100644 --- ui/org/eclipse/jdt/internal/ui/search/ExceptionOccurrencesFinder.java +++ ui/org/eclipse/jdt/internal/ui/search/ExceptionOccurrencesFinder.java @@ -1,10 +1,14 @@ /******************************************************************************* - * Copyright (c) 2000, 2011 IBM Corporation and others. + * Copyright (c) 2000, 2013 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * + * This is an implementation of an early-draft specification developed under the Java Community Process (JCP) and + * is made available for testing and evaluation purposes only. + * The code is not compatible with any specification of the JCP. + * * Contributors: * IBM Corporation - initial API and implementation *******************************************************************************/ @@ -33,6 +37,7 @@ import org.eclipse.jdt.core.dom.Name; import org.eclipse.jdt.core.dom.NodeFinder; import org.eclipse.jdt.core.dom.SimpleName; +import org.eclipse.jdt.core.dom.SimpleType; import org.eclipse.jdt.core.dom.SingleVariableDeclaration; import org.eclipse.jdt.core.dom.SuperConstructorInvocation; import org.eclipse.jdt.core.dom.SuperMethodInvocation; @@ -118,9 +123,10 @@ private boolean methodThrowsException(MethodDeclaration method, Name exception) { ASTMatcher matcher = new ASTMatcher(); - for (Iterator iter = method.thrownExceptions().iterator(); iter.hasNext();) { - Name thrown = iter.next(); - if (exception.subtreeMatch(matcher, thrown)) + // TODO Below changes are not part of the current bug fix, but was required to test the feature. + for (Iterator iter = method.thrownExceptionTypes().iterator(); iter.hasNext();) { + SimpleType thrown = iter.next(); + if (exception.subtreeMatch(matcher, thrown.getName())) return true; } return false;