View | Details | Raw Unified | Return to bug 171019 | Differences between
and this patch

Collapse All | Expand All

(-)codeassist/org/eclipse/jdt/internal/codeassist/SelectionEngine.java (-2 / +196 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2010 IBM Corporation and others.
2
 * Copyright (c) 2000, 2011 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 10-21 Link Here
10
 *******************************************************************************/
10
 *******************************************************************************/
11
package org.eclipse.jdt.internal.codeassist;
11
package org.eclipse.jdt.internal.codeassist;
12
12
13
import java.util.ArrayList;
14
import java.util.Iterator;
13
import java.util.Locale;
15
import java.util.Locale;
14
import java.util.Map;
16
import java.util.Map;
15
17
16
import org.eclipse.core.resources.IFile;
18
import org.eclipse.core.resources.IFile;
17
import org.eclipse.core.runtime.IProgressMonitor;
19
import org.eclipse.core.runtime.IProgressMonitor;
18
import org.eclipse.core.runtime.OperationCanceledException;
20
import org.eclipse.core.runtime.OperationCanceledException;
21
import org.eclipse.jdt.core.IBuffer;
22
import org.eclipse.jdt.core.IMember;
23
import org.eclipse.jdt.core.IOpenable;
24
import org.eclipse.jdt.core.ISourceRange;
19
import org.eclipse.jdt.core.IType;
25
import org.eclipse.jdt.core.IType;
20
import org.eclipse.jdt.core.JavaModelException;
26
import org.eclipse.jdt.core.JavaModelException;
21
import org.eclipse.jdt.core.Signature;
27
import org.eclipse.jdt.core.Signature;
Lines 1106-1112 Link Here
1106
			}
1112
			}
1107
			this.acceptedAnswer = true;
1113
			this.acceptedAnswer = true;
1108
		} else if (binding instanceof MethodBinding) {
1114
		} else if (binding instanceof MethodBinding) {
1109
			MethodBinding methodBinding = (MethodBinding) binding;
1115
			MethodBinding methodBinding = getCorrectMethodBinding((MethodBinding) binding);
1110
			this.noProposal = false;
1116
			this.noProposal = false;
1111
1117
1112
			boolean isValuesOrValueOf = false;
1118
			boolean isValuesOrValueOf = false;
Lines 1608-1611 Link Here
1608
1614
1609
		return false;
1615
		return false;
1610
	}
1616
	}
1617
	
1618
	/*
1619
	 * Returns the correct method binding according to whether the selection is on the method declaration
1620
	 * or on the inheritDoc tag in its javadoc.
1621
	 */
1622
	private MethodBinding getCorrectMethodBinding(MethodBinding binding) {
1623
		if (this.parser.javadocParser instanceof SelectionJavadocParser) {
1624
			if (((SelectionJavadocParser)this.parser.javadocParser).inheritDocTagSelected){
1625
				try {
1626
					Object res = findMethodWithAttachedDocInHierarchy(binding);
1627
					if (res instanceof MethodBinding) {
1628
						return (MethodBinding) res;
1629
					}
1630
				} catch (JavaModelException e) {
1631
					return null;
1632
				}
1633
			}
1634
		}
1635
		return binding;
1636
	}
1637
	
1638
	protected MethodBinding findOverriddenMethodInType(ReferenceBinding overriddenType, MethodBinding overriding) throws JavaModelException {
1639
		if (overriddenType == null)
1640
			return null;
1641
		MethodBinding[] overriddenMethods= overriddenType.availableMethods();
1642
		LookupEnvironment lookupEnv = this.lookupEnvironment;
1643
		if (lookupEnv != null && overriddenMethods != null) {
1644
			for (int i= 0; i < overriddenMethods.length; i++) {
1645
				if (lookupEnv.methodVerifier().isMethodSubsignature(overriding, overriddenMethods[i])) {
1646
					return overriddenMethods[i];
1647
				}
1648
			}
1649
		}
1650
		return null;
1651
	}
1652
	
1653
	private Object findMethodWithAttachedDocInHierarchy(final MethodBinding method) throws JavaModelException {
1654
		ReferenceBinding type= method.declaringClass;
1655
		final SelectionRequestor requestor1 = (SelectionRequestor) this.requestor;
1656
		return new InheritDocVisitor() {
1657
			public Object visit(ReferenceBinding currType) throws JavaModelException {
1658
				MethodBinding overridden =  findOverriddenMethodInType(currType, method);
1659
				if (overridden == null)
1660
					return InheritDocVisitor.CONTINUE;
1661
				TypeBinding args[] = overridden.parameters;
1662
				String names[] = new String[args.length];
1663
				for (int i = 0; i < args.length; i++) {
1664
					names[i] = Signature.createTypeSignature(args[i].sourceName(), false);
1665
				}
1666
				IMember member = (IMember) requestor1.findMethodFromBinding(overridden, names, overridden.declaringClass);
1667
				if (member == null)
1668
					return InheritDocVisitor.CONTINUE;
1669
				if (member.getAttachedJavadoc(null) != null ) {  
1670
					// for binary methods with attached javadoc and no source attached
1671
					return overridden;
1672
				}
1673
				IOpenable openable = member.getOpenable();
1674
				if (openable == null)
1675
					return InheritDocVisitor.CONTINUE;
1676
				IBuffer buf= openable.getBuffer();
1677
				if (buf == null) {
1678
					// no source attachment found. This method maybe the one. Stop.
1679
					return InheritDocVisitor.STOP_BRANCH;
1680
				}
1681
1682
				ISourceRange javadocRange= member.getJavadocRange();
1683
				if (javadocRange == null)
1684
					return InheritDocVisitor.CONTINUE;	// this method doesn't have javadoc, continue to look.
1685
				String rawJavadoc= buf.getText(javadocRange.getOffset(), javadocRange.getLength());
1686
				if (rawJavadoc != null) {
1687
					return overridden;
1688
				}
1689
				return InheritDocVisitor.CONTINUE;
1690
			}
1691
		}.visitInheritDoc(type);
1692
	}
1693
	
1694
	/**
1695
	 * Implements the "Algorithm for Inheriting Method Comments" as specified for
1696
	 * <a href="http://java.sun.com/j2se/1.4.2/docs/tooldocs/solaris/javadoc.html#inheritingcomments">1.4.2</a>,
1697
	 * <a href="http://java.sun.com/j2se/1.5.0/docs/tooldocs/windows/javadoc.html#inheritingcomments">1.5</a>, and
1698
	 * <a href="http://java.sun.com/javase/6/docs/technotes/tools/windows/javadoc.html#inheritingcomments">1.6</a>.
1699
	 *
1700
	 * <p>
1701
	 * Unfortunately, the implementation is broken in Javadoc implementations since 1.5, see
1702
	 * <a href="http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6376959">Sun's bug</a>.
1703
	 * </p>
1704
	 *
1705
	 * <p>
1706
	 * We adhere to the spec.
1707
	 * </p>
1708
	 */
1709
	static abstract class InheritDocVisitor {
1710
		public static final Object STOP_BRANCH= new Object() {
1711
			public String toString() { return "STOP_BRANCH"; } //$NON-NLS-1$
1712
		};
1713
		public static final Object CONTINUE= new Object() {
1714
			public String toString() { return "CONTINUE"; } //$NON-NLS-1$
1715
		};
1716
1717
		/**
1718
		 * Visits a type and decides how the visitor should proceed.
1719
		 *
1720
		 * @param currType the current type
1721
		 * @return <ul>
1722
		 *         <li>{@link #STOP_BRANCH} to indicate that no Javadoc has been found and visiting
1723
		 *         super types should stop here</li>
1724
		 *         <li>{@link #CONTINUE} to indicate that no Javadoc has been found and visiting
1725
		 *         super types should continue</li>
1726
		 *         <li>an {@link Object} or <code>null</code>, to indicate that visiting should be
1727
		 *         cancelled immediately. The returned value is the result of
1728
		 *         {@link #visitInheritDoc(ReferenceBinding)}</li>
1729
		 *         </ul>
1730
		 * @throws JavaModelException unexpected problem
1731
		 * @see #visitInheritDoc(ReferenceBinding)
1732
		 */
1733
		public abstract Object visit(ReferenceBinding currType) throws JavaModelException;
1734
1735
		/**
1736
		 * Visits the super types of the given <code>currentType</code>.
1737
		 *
1738
		 * @param currentType the starting type
1739
		 * @return the result from a call to {@link #visit(ReferenceBinding)}, or <code>null</code> if none of
1740
		 *         the calls returned a result
1741
		 * @throws JavaModelException unexpected problem
1742
		 */
1743
		public Object visitInheritDoc(ReferenceBinding currentType) throws JavaModelException {
1744
			ArrayList visited= new ArrayList();
1745
			visited.add(currentType);
1746
			Object result= visitInheritDocInterfaces(visited, currentType);
1747
			if (result != InheritDocVisitor.CONTINUE)
1748
				return result;
1749
1750
			ReferenceBinding superClass= currentType.superclass();
1751
1752
			while (superClass != null && ! visited.contains(superClass)) {
1753
				result= visit(superClass);
1754
				if (result == InheritDocVisitor.STOP_BRANCH) {
1755
					return null;
1756
				} else if (result == InheritDocVisitor.CONTINUE) {
1757
					visited.add(superClass);
1758
					result= visitInheritDocInterfaces(visited, superClass);
1759
					if (result != InheritDocVisitor.CONTINUE)
1760
						return result;
1761
					else
1762
						superClass= superClass.superclass();
1763
				} else {
1764
					return result;
1765
				}
1766
			}
1767
1768
			return null;
1769
		}
1770
1771
		/**
1772
		 * Visits the super interfaces of the given type in the given hierarchy, thereby skipping already visited types.
1773
		 * 
1774
		 * @param visited set of visited types
1775
		 * @param currentType type whose super interfaces should be visited
1776
		 * @return the result, or {@link #CONTINUE} if no result has been found
1777
		 * @throws JavaModelException unexpected problem
1778
		 */
1779
		private Object visitInheritDocInterfaces(ArrayList visited, ReferenceBinding currentType) throws JavaModelException {
1780
			ArrayList toVisitChildren= new ArrayList();
1781
			ReferenceBinding[] superInterfaces= currentType.superInterfaces();
1782
			for (int i= 0; i < superInterfaces.length; i++) {
1783
				ReferenceBinding superInterface= superInterfaces[i];
1784
				if (visited.contains(superInterface))
1785
					continue;
1786
				visited.add(superInterface);
1787
				Object result= visit(superInterface);
1788
				if (result == InheritDocVisitor.STOP_BRANCH) {
1789
					//skip
1790
				} else if (result == InheritDocVisitor.CONTINUE) {
1791
					toVisitChildren.add(superInterface);
1792
				} else {
1793
					return result;
1794
				}
1795
			}
1796
			for (Iterator iter= toVisitChildren.iterator(); iter.hasNext(); ) {
1797
				ReferenceBinding child= (ReferenceBinding) iter.next();
1798
				Object result= visitInheritDocInterfaces(visited, child);
1799
				if (result != InheritDocVisitor.CONTINUE)
1800
					return result;
1801
			}
1802
			return InheritDocVisitor.CONTINUE;
1803
		}
1804
	}
1611
}
1805
}
(-)codeassist/org/eclipse/jdt/internal/codeassist/select/SelectionJavadoc.java (-1 / +13 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2009 IBM Corporation and others.
2
 * Copyright (c) 2000, 2011 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 11-16 Link Here
11
package org.eclipse.jdt.internal.codeassist.select;
11
package org.eclipse.jdt.internal.codeassist.select;
12
12
13
import org.eclipse.jdt.internal.compiler.ast.*;
13
import org.eclipse.jdt.internal.compiler.ast.*;
14
import org.eclipse.jdt.internal.compiler.impl.ReferenceContext;
14
import org.eclipse.jdt.internal.compiler.lookup.*;
15
import org.eclipse.jdt.internal.compiler.lookup.*;
15
16
16
/**
17
/**
Lines 19-27 Link Here
19
public class SelectionJavadoc extends Javadoc {
20
public class SelectionJavadoc extends Javadoc {
20
21
21
	Expression selectedNode;
22
	Expression selectedNode;
23
	// https://bugs.eclipse.org/bugs/show_bug.cgi?id=171019
24
	// Flag raised when selection is done on inheritDoc javadoc tag
25
	boolean inheritDocSelected;
22
26
23
	public SelectionJavadoc(int sourceStart, int sourceEnd) {
27
	public SelectionJavadoc(int sourceStart, int sourceEnd) {
24
		super(sourceStart, sourceEnd);
28
		super(sourceStart, sourceEnd);
29
		this.inheritDocSelected = false;
25
	}
30
	}
26
31
27
	/* (non-Javadoc)
32
	/* (non-Javadoc)
Lines 106-111 Link Here
106
				binding = this.selectedNode.resolvedType;
111
				binding = this.selectedNode.resolvedType;
107
			}
112
			}
108
			throw new SelectionNodeFound(binding);
113
			throw new SelectionNodeFound(binding);
114
		} else if (this.inheritDocSelected) {
115
			// no selection node when inheritDoc tag is selected
116
			// But we need to detect it to enable code select on inheritDoc
117
			ReferenceContext referenceContext = scope.referenceContext();
118
			if (referenceContext instanceof MethodDeclaration) {
119
				throw new SelectionNodeFound(((MethodDeclaration) referenceContext).binding);
120
			}
109
		}
121
		}
110
	}
122
	}
111
123
(-)codeassist/org/eclipse/jdt/internal/codeassist/select/SelectionJavadocParser.java (-1 / +14 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2009 IBM Corporation and others.
2
 * Copyright (c) 2000, 2011 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 25-36 Link Here
25
	int selectionStart;
25
	int selectionStart;
26
	int selectionEnd;
26
	int selectionEnd;
27
	ASTNode selectedNode;
27
	ASTNode selectedNode;
28
	// https://bugs.eclipse.org/bugs/show_bug.cgi?id=171019
29
	public boolean inheritDocTagSelected;
28
30
29
	public SelectionJavadocParser(SelectionParser sourceParser) {
31
	public SelectionJavadocParser(SelectionParser sourceParser) {
30
		super(sourceParser);
32
		super(sourceParser);
31
		this.shouldReportProblems = false;
33
		this.shouldReportProblems = false;
32
		this.reportProblems = false;
34
		this.reportProblems = false;
33
		this.kind = SELECTION_PARSER | TEXT_PARSE;
35
		this.kind = SELECTION_PARSER | TEXT_PARSE;
36
		this.inheritDocTagSelected = false;
34
	}
37
	}
35
38
36
	/*
39
	/*
Lines 186-191 Link Here
186
	protected void updateDocComment() {
189
	protected void updateDocComment() {
187
		if (this.selectedNode instanceof Expression) {
190
		if (this.selectedNode instanceof Expression) {
188
			((SelectionJavadoc) this.docComment).selectedNode = (Expression) this.selectedNode;
191
			((SelectionJavadoc) this.docComment).selectedNode = (Expression) this.selectedNode;
192
		} else if (this.inheritDocTagSelected) {
193
			((SelectionJavadoc) this.docComment).inheritDocSelected = true;
189
		}
194
		}
190
	}
195
	}
196
	
197
	/*
198
	 * Sets a flag to denote that selection has taken place on an inheritDoc tag
199
	 */
200
	protected void parseInheritDocTag() {
201
		if (this.tagSourceStart == this.selectionStart && this.tagSourceEnd == this.selectionEnd)
202
			this.inheritDocTagSelected = true;
203
	}
191
}
204
}
(-)compiler/org/eclipse/jdt/internal/compiler/parser/JavadocParser.java (+8 lines)
Lines 568-573 Link Here
568
							if (this.reportProblems) {
568
							if (this.reportProblems) {
569
								recordInheritedPosition((((long) this.tagSourceStart) << 32) + this.tagSourceEnd);
569
								recordInheritedPosition((((long) this.tagSourceStart) << 32) + this.tagSourceEnd);
570
							}
570
							}
571
							if (this.inlineTagStarted) {
572
								// parse a 'valid' inheritDoc tag
573
								parseInheritDocTag();
574
							}
571
							break;
575
							break;
572
						default:
576
						default:
573
							valid = false;
577
							valid = false;
Lines 692-697 Link Here
692
		return valid;
696
		return valid;
693
	}
697
	}
694
698
699
	protected void parseInheritDocTag() {
700
		// do nothing
701
	}
702
695
	/*
703
	/*
696
	 * Parse @param tag declaration and flag missing description if corresponding option is enabled
704
	 * Parse @param tag declaration and flag missing description if corresponding option is enabled
697
	 */
705
	 */
(-)model/org/eclipse/jdt/internal/core/SelectionRequestor.java (-1 / +27 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2010 IBM Corporation and others.
2
 * Copyright (c) 2000, 2011 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 34-39 Link Here
34
import org.eclipse.jdt.internal.compiler.lookup.LocalVariableBinding;
34
import org.eclipse.jdt.internal.compiler.lookup.LocalVariableBinding;
35
import org.eclipse.jdt.internal.compiler.lookup.MethodBinding;
35
import org.eclipse.jdt.internal.compiler.lookup.MethodBinding;
36
import org.eclipse.jdt.internal.compiler.lookup.ParameterizedTypeBinding;
36
import org.eclipse.jdt.internal.compiler.lookup.ParameterizedTypeBinding;
37
import org.eclipse.jdt.internal.compiler.lookup.ReferenceBinding;
37
import org.eclipse.jdt.internal.compiler.lookup.SourceTypeBinding;
38
import org.eclipse.jdt.internal.compiler.lookup.SourceTypeBinding;
38
import org.eclipse.jdt.internal.compiler.lookup.TypeBinding;
39
import org.eclipse.jdt.internal.compiler.lookup.TypeBinding;
39
import org.eclipse.jdt.internal.compiler.lookup.TypeConstants;
40
import org.eclipse.jdt.internal.compiler.lookup.TypeConstants;
Lines 842-847 Link Here
842
	}
843
	}
843
	return res;
844
	return res;
844
}
845
}
846
847
/**
848
 * This method returns an IMethod element from the given method and declaring type bindings. However,
849
 * unlike {@link Util#findMethod(IType, char[], String[], boolean)} , this does not require an IType to get 
850
 * the IMethod element.
851
 * @param method the given method binding
852
 * @param signatures the type signatures of the method arguments
853
 * @param declaringClass the binding of the method's declaring class
854
 * @return an IMethod corresponding to the method binding given, or null if none is found.
855
 */
856
public IJavaElement findMethodFromBinding(MethodBinding method, String[] signatures, ReferenceBinding declaringClass) {
857
	IType foundType = this.resolveType(declaringClass.qualifiedPackageName(), declaringClass.qualifiedSourceName(), NameLookup.ACCEPT_CLASSES & NameLookup.ACCEPT_INTERFACES);
858
	if (foundType != null) {
859
		if (foundType instanceof BinaryType) {
860
			try {
861
				return Util.findMethod(foundType, method.selector, signatures, method.isConstructor());
862
			} catch (JavaModelException e) {
863
				return null;
864
			}
865
		} else {
866
			return foundType.getMethod(new String(method.selector), signatures);
867
		}
868
	}
869
	return null;
870
}
845
/**
871
/**
846
 * Returns the resolved elements.
872
 * Returns the resolved elements.
847
 */
873
 */
(-)model/org/eclipse/jdt/internal/core/util/Util.java (+38 lines)
Lines 3612-3615 Link Here
3612
			}
3612
			}
3613
		}
3613
		}
3614
	}
3614
	}
3615
	/**
3616
	 * Finds the IMethod element corresponding to the given selector, 
3617
	 * without creating a new dummy instance of a binary method. 
3618
	 * @param type the type in which the method is declared
3619
	 * @param selector the method name
3620
	 * @param paramTypeSignatures the type signatures of the method arguments
3621
	 * @param isConstructor whether we're looking for a constructor
3622
	 * @return an IMethod if found, otherwise null
3623
	 * @throws JavaModelException
3624
	 */
3625
	public static IMethod findMethod(IType type, char[] selector, String[] paramTypeSignatures, boolean isConstructor) throws JavaModelException {
3626
		IMethod method = null;
3627
		int startingIndex = 0;
3628
		String[] args;
3629
		IType enclosingType = type.getDeclaringType();
3630
		// If the method is a constructor of a non-static inner type, add the enclosing type as an 
3631
		// additional parameter to the constructor
3632
		if (enclosingType != null
3633
				&& isConstructor
3634
				&& !Flags.isStatic(type.getFlags())) {
3635
			args = new String[paramTypeSignatures.length+1];
3636
			startingIndex = 1;
3637
			args[0] = Signature.createTypeSignature(enclosingType.getFullyQualifiedName(), true);
3638
		} else {
3639
			args = new String[paramTypeSignatures.length];
3640
		}
3641
		int length = args.length;
3642
		for(int i = startingIndex;	i< length ; i++){
3643
			args[i] = new String(paramTypeSignatures[i-startingIndex]);
3644
		}
3645
		method = type.getMethod(new String(selector), args);
3646
		
3647
		IMethod[] methods = type.findMethods(method);
3648
		if (methods != null && methods.length > 0) {
3649
			method = methods[0];
3650
		}
3651
		return method;
3652
	}
3615
}
3653
}
(-)src/org/eclipse/jdt/core/tests/model/SelectionJavadocModelTests.java (-1 / +227 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2008 IBM Corporation and others.
2
 * Copyright (c) 2000, 2011 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 1311-1314 Link Here
1311
			elements
1311
			elements
1312
		);
1312
		);
1313
	}
1313
	}
1314
	// https://bugs.eclipse.org/bugs/show_bug.cgi?id=171019
1315
	// To verify that inheritDoc tag is recognized as a valid selection and
1316
	// pressing F3 on it navigates to the overriden method with the javadoc according to spec
1317
	// as documented in org.eclipse.jdt.internal.codeassist.SelectionEngine.InheritDocVisitor
1318
	public void testBug171019() throws CoreException {
1319
		this.wcOwner = new WorkingCopyOwner() {};
1320
		this.workingCopies = new ICompilationUnit[1];
1321
		this.workingCopies[0] = getWorkingCopy("/Tests/b171019/X.java",
1322
			"package b171019;\n" +
1323
			"interface X {\n" +
1324
			"   /**\n" +
1325
			"	 * Main desc of foo..\n" +
1326
			"	 */\n" +
1327
			"	void foo(int x);\n" +
1328
			"}\n" +
1329
			"interface Y extends X {\n" +
1330
			"   /**\n" +
1331
			"	 * {@inheritDoc}\n" +	// should navigate to X.foo(int)
1332
			"	 */\n" +
1333
			"	void foo(int x);\n\n" +
1334
			"   /**\n" +
1335
			"	 * {@inheritDoc}\n" +	// should navigate to Y.foo(String)
1336
			"	 */\n" +
1337
			"	void foo(String s);\n" +
1338
			"}\n"
1339
		);
1340
		IJavaElement[] elements = new IJavaElement[2];
1341
		elements[0] = selectMethod(this.workingCopies[0], "@inheritDoc", 1);
1342
		elements[1] = selectMethod(this.workingCopies[0], "@inheritDoc", 2);
1343
		assertElementsEqual("Invalid selection(s)",
1344
			"foo(int) [in X [in [Working copy] X.java [in b171019 [in <project root> [in Tests]]]]]\n" + 
1345
			"foo(String) [in Y [in [Working copy] X.java [in b171019 [in <project root> [in Tests]]]]]",
1346
			elements
1347
		);
1348
	}
1349
	// https://bugs.eclipse.org/bugs/show_bug.cgi?id=171019
1350
	// To verify that inheritDoc tag is recognized as a valid selection and
1351
	// pressing F3 on it navigates to the overriden method with the javadoc according to spec
1352
	// as documented in org.eclipse.jdt.internal.codeassist.SelectionEngine.InheritDocVisitor
1353
	public void testBug171019b() throws CoreException {
1354
		this.wcOwner = new WorkingCopyOwner() {};
1355
		this.workingCopies = new ICompilationUnit[1];
1356
		this.workingCopies[0] = getWorkingCopy("/Tests/b171019/X.java",
1357
			"package b171019;\n" +
1358
			"interface X {\n" +
1359
			"   /**\n" +
1360
			"	 * Main desc of foo..\n" +
1361
			"	 */\n" +
1362
			"	void foo(int x);\n" +
1363
			"}\n" +
1364
			"class X1 implements X{\n" +
1365
			"	void foo(int x){}\n" +
1366
			"}\n" +
1367
			"class Y extends X1 {\n" +
1368
			"   /**\n" +
1369
			"	 * {@inheritDoc}\n" +	// should navigate to X.foo(int)
1370
			"	 */\n" +
1371
			"	void foo(int x);\n\n" +
1372
			"   /**\n" +
1373
			"	 * {@inheritDoc}\n" +	// should navigate to Y.foo(String)
1374
			"	 */\n" +
1375
			"	void foo(String s);\n" +
1376
			"}\n"
1377
		);
1378
		IJavaElement[] elements = new IJavaElement[2];
1379
		elements[0] = selectMethod(this.workingCopies[0], "@inheritDoc", 1);
1380
		elements[1] = selectMethod(this.workingCopies[0], "@inheritDoc", 2);
1381
		assertElementsEqual("Invalid selection(s)",
1382
			"foo(int) [in X [in [Working copy] X.java [in b171019 [in <project root> [in Tests]]]]]\n" + 
1383
			"foo(String) [in Y [in [Working copy] X.java [in b171019 [in <project root> [in Tests]]]]]",
1384
			elements
1385
		);
1386
	}
1387
	// https://bugs.eclipse.org/bugs/show_bug.cgi?id=171019
1388
	// To verify that inheritDoc tag is recognized as a valid selection and
1389
	// pressing F3 on it navigates to the overriden method with the javadoc according to spec
1390
	// as documented in org.eclipse.jdt.internal.codeassist.SelectionEngine.InheritDocVisitor
1391
	public void testBug171019c() throws CoreException {
1392
		this.wcOwner = new WorkingCopyOwner() {};
1393
		this.workingCopies = new ICompilationUnit[1];
1394
		this.workingCopies[0] = getWorkingCopy("/Tests/b171019/X.java",
1395
			"package b171019;\n" +
1396
			"interface X1 {\n" +
1397
			"   /**\n" +
1398
			"	 * Main desc of foo in X1..\n" +
1399
			"	 */\n" +
1400
			"	void foo(int x);\n" +
1401
			"}\n" +
1402
			"interface X2 {\n" +
1403
			"   /**\n" +
1404
			"	 * Main desc of foo in X2..\n" +
1405
			"	 */\n" +
1406
			"	void foo(int x);\n" +
1407
			"}\n" +
1408
			"class X implements X1 {\n" +
1409
			"   /**\n" +
1410
			"	 * X desc of foo..\n" +
1411
			"	 */\n" +
1412
			"	void foo(int x){}\n" +
1413
			"}\n" +
1414
			"class Y extends X implements X2 {\n" +
1415
			"   /**\n" +
1416
			"	 * {@inheritDoc}\n" +	// should navigate to X2.foo(int)
1417
			"	 */\n" +
1418
			"	void foo(int x);\n\n" +
1419
			"}\n"
1420
		);
1421
		IJavaElement[] elements = new IJavaElement[1];
1422
		elements[0] = selectMethod(this.workingCopies[0], "@inheritDoc", 1);
1423
		assertElementsEqual("Invalid selection(s)",
1424
			"foo(int) [in X2 [in [Working copy] X.java [in b171019 [in <project root> [in Tests]]]]]",
1425
			elements
1426
		);
1427
	}
1428
	// https://bugs.eclipse.org/bugs/show_bug.cgi?id=171019
1429
	// To verify that inheritDoc tag is recognized as a valid selection and
1430
	// pressing F3 on it navigates to the overriden method with the javadoc according to spec
1431
	// as documented in org.eclipse.jdt.internal.codeassist.SelectionEngine.InheritDocVisitor
1432
	public void testBug171019d() throws CoreException {
1433
		this.wcOwner = new WorkingCopyOwner() {};
1434
		this.workingCopies = new ICompilationUnit[1];
1435
		this.workingCopies[0] = getWorkingCopy("/Tests/b171019/X.java",
1436
			"package b171019;\n" +
1437
			"interface X1 {\n" +
1438
			"   /**\n" +
1439
			"	 * Main desc of foo in X1..\n" +
1440
			"	 */\n" +
1441
			"	void foo(int x);\n" +
1442
			"}\n" +
1443
			"interface X2 {\n" +
1444
			"	void foo(int x);\n" +
1445
			"}\n" +
1446
			"class X implements X1 {\n" +
1447
			"   /**\n" +
1448
			"	 * X desc of foo..\n" +
1449
			"	 */\n" +
1450
			"	void foo(int x){}\n" +
1451
			"}\n" +
1452
			"class Y extends X implements X2 {\n" +
1453
			"   /**\n" +
1454
			"	 * {@inheritDoc}\n" +	// should navigate to X.foo(int)
1455
			"	 */\n" +
1456
			"	void foo(int x);\n\n" +
1457
			"}\n"
1458
		);
1459
		IJavaElement[] elements = new IJavaElement[1];
1460
		elements[0] = selectMethod(this.workingCopies[0], "@inheritDoc", 1);
1461
		assertElementsEqual("Invalid selection(s)",
1462
			"foo(int) [in X [in [Working copy] X.java [in b171019 [in <project root> [in Tests]]]]]",
1463
			elements
1464
		);
1465
	}
1466
	// https://bugs.eclipse.org/bugs/show_bug.cgi?id=171019
1467
	// To verify that inheritDoc tag is recognized as a valid selection and
1468
	// pressing F3 on it navigates to the overriden method with the javadoc according to spec
1469
	// as documented in org.eclipse.jdt.internal.codeassist.SelectionEngine.InheritDocVisitor
1470
	public void testBug171019e() throws CoreException {
1471
		this.wcOwner = new WorkingCopyOwner() {};
1472
		this.workingCopies = new ICompilationUnit[1];
1473
		this.workingCopies[0] = getWorkingCopy("/Tests/b171019/X.java",
1474
			"package b171019;\n" +
1475
			"interface X {\n" +
1476
			"   /**\n" +
1477
			"	 * Main desc of foo..\n" +
1478
			"	 */\n" +
1479
			"	void foo(int x);\n" +
1480
			"}\n" +
1481
			"interface Y {\n" +
1482
			"	void foo(String str);\n" +
1483
			"}\n" +
1484
			"abstract class Z implements X, Y {\n" +
1485
			"	/**\n" +
1486
			"	 * {@inheritDoc}\n" +	// navigates to X.foo(int)
1487
			"	 */\n" +
1488
			"	void foo(int x) {\n" +
1489
			"	}\n" +
1490
			"}"
1491
		);
1492
		IJavaElement[] elements = new IJavaElement[1];
1493
		elements[0] = selectMethod(this.workingCopies[0], "@inheritDoc", 1);
1494
		assertElementsEqual("Invalid selection(s)",
1495
			"foo(int) [in X [in [Working copy] X.java [in b171019 [in <project root> [in Tests]]]]]",
1496
			elements
1497
		);
1498
	}
1499
	// https://bugs.eclipse.org/bugs/show_bug.cgi?id=171019
1500
	// To verify that inheritDoc tag is recognized as a valid selection and
1501
	// pressing F3 on it navigates to the overriden method with the javadoc according to spec
1502
	// as documented in org.eclipse.jdt.internal.codeassist.SelectionEngine.InheritDocVisitor
1503
	// Here the inheritDoc should work when it occurs inside another valid block tag viz.
1504
	// @param, @throws, @exception, @return
1505
	public void testBug171019f() throws CoreException {
1506
		this.wcOwner = new WorkingCopyOwner() {};
1507
		this.workingCopies = new ICompilationUnit[1];
1508
		this.workingCopies[0] = getWorkingCopy("/Tests/b171019/X.java",
1509
			"package b171019;\n" +
1510
			"interface X {\n" +
1511
			"   /**\n" +
1512
			"	 * Main desc of foo..\n" +
1513
			"	 */\n" +
1514
			"	void foo(int x);\n" +
1515
			"}\n" +
1516
			"interface Y extends X {\n" +
1517
			"   /**\n" +
1518
			"	 * {@inheritDoc}\n" +	// should navigate to X.foo(int)
1519
			"	 * @param {@inheritDoc}\n" +	// should navigate to X.foo(int)
1520
			"	 * @return {@inheritDoc}\n" +	// should navigate to X.foo(int)
1521
			"	 * @throws {@inheritDoc}\n" +	// should navigate to X.foo(int)
1522
			"	 * @exception {@inheritDoc}\n" +	// should navigate to X.foo(int)
1523
			"	 */\n" +
1524
			"	void foo(int x);\n\n" +
1525
			"}\n"
1526
		);
1527
		IJavaElement[] elements = new IJavaElement[4];
1528
		elements[0] = selectMethod(this.workingCopies[0], "@inheritDoc", 1);
1529
		elements[1] = selectMethod(this.workingCopies[0], "@inheritDoc", 2);
1530
		elements[2] = selectMethod(this.workingCopies[0], "@inheritDoc", 3);
1531
		elements[3] = selectMethod(this.workingCopies[0], "@inheritDoc", 4);
1532
		assertElementsEqual("Invalid selection(s)",
1533
			"foo(int) [in X [in [Working copy] X.java [in b171019 [in <project root> [in Tests]]]]]\n" + 
1534
			"foo(int) [in X [in [Working copy] X.java [in b171019 [in <project root> [in Tests]]]]]\n" + 
1535
			"foo(int) [in X [in [Working copy] X.java [in b171019 [in <project root> [in Tests]]]]]\n" + 
1536
			"foo(int) [in X [in [Working copy] X.java [in b171019 [in <project root> [in Tests]]]]]",
1537
			elements
1538
		);
1539
	}
1314
}
1540
}

Return to bug 171019