### Eclipse Workspace Patch 1.0 #P org.eclipse.jdt.core Index: codeassist/org/eclipse/jdt/internal/codeassist/complete/CompletionOnPackageReference.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/codeassist/org/eclipse/jdt/internal/codeassist/complete/CompletionOnPackageReference.java,v retrieving revision 1.23 diff -u -r1.23 CompletionOnPackageReference.java --- codeassist/org/eclipse/jdt/internal/codeassist/complete/CompletionOnPackageReference.java 7 Mar 2009 00:58:59 -0000 1.23 +++ codeassist/org/eclipse/jdt/internal/codeassist/complete/CompletionOnPackageReference.java 28 Jul 2010 15:31:16 -0000 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2009 IBM Corporation and others. + * Copyright (c) 2000, 2010 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 @@ -37,7 +37,7 @@ public class CompletionOnPackageReference extends ImportReference { public CompletionOnPackageReference(char[][] tokens , long[] positions) { - super(tokens, positions, true, ClassFileConstants.AccDefault); + super(tokens, positions, false, ClassFileConstants.AccDefault); } public StringBuffer print(int indent, StringBuffer output, boolean withOnDemand) { Index: codeassist/org/eclipse/jdt/internal/codeassist/impl/AssistParser.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/codeassist/org/eclipse/jdt/internal/codeassist/impl/AssistParser.java,v retrieving revision 1.93 diff -u -r1.93 AssistParser.java --- codeassist/org/eclipse/jdt/internal/codeassist/impl/AssistParser.java 20 May 2010 18:03:14 -0000 1.93 +++ codeassist/org/eclipse/jdt/internal/codeassist/impl/AssistParser.java 28 Jul 2010 15:31:16 -0000 @@ -717,6 +717,8 @@ /* build specific assist node on import statement */ ImportReference reference = createAssistImportReference(subset, positions, ClassFileConstants.AccStatic); reference.bits |= ASTNode.OnDemand; + // star end position + reference.trailingStarPosition = this.intStack[this.intPtr--]; this.assistNode = reference; this.lastCheckPoint = reference.sourceEnd + 1; @@ -839,6 +841,8 @@ /* build specific assist node on import statement */ ImportReference reference = createAssistImportReference(subset, positions, ClassFileConstants.AccDefault); reference.bits |= ASTNode.OnDemand; + // star end position + reference.trailingStarPosition = this.intStack[this.intPtr--]; this.assistNode = reference; this.lastCheckPoint = reference.sourceEnd + 1; Index: codeassist/org/eclipse/jdt/internal/codeassist/select/SelectionOnPackageReference.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/codeassist/org/eclipse/jdt/internal/codeassist/select/SelectionOnPackageReference.java,v retrieving revision 1.24 diff -u -r1.24 SelectionOnPackageReference.java --- codeassist/org/eclipse/jdt/internal/codeassist/select/SelectionOnPackageReference.java 7 Mar 2009 01:08:06 -0000 1.24 +++ codeassist/org/eclipse/jdt/internal/codeassist/select/SelectionOnPackageReference.java 28 Jul 2010 15:31:16 -0000 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2009 IBM Corporation and others. + * Copyright (c) 2000, 2010 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 @@ -34,7 +34,7 @@ public class SelectionOnPackageReference extends ImportReference { public SelectionOnPackageReference(char[][] tokens , long[] positions) { - super(tokens, positions, true, ClassFileConstants.AccDefault); + super(tokens, positions, false, ClassFileConstants.AccDefault); } public StringBuffer print(int tab, StringBuffer output, boolean withOnDemand) { printIndent(tab, output).append("null if this import declaration does not have + * associated source code (for example, a binary type). + * + *

The source range for the name includes the trailing '*' if the import declaration + * .

+ * + * @exception JavaModelException if this element does not exist or if an + * exception occurs while accessing its corresponding resource. + * @return the source range of this import declaration's name, + * or null if this import declaration does not have + * associated source code (for example, a binary type) + * @since 3.7 + */ +ISourceRange getNameRange() throws JavaModelException; } Index: model/org/eclipse/jdt/core/IPackageDeclaration.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/core/IPackageDeclaration.java,v retrieving revision 1.17 diff -u -r1.17 IPackageDeclaration.java --- model/org/eclipse/jdt/core/IPackageDeclaration.java 27 Jun 2008 16:04:01 -0000 1.17 +++ model/org/eclipse/jdt/core/IPackageDeclaration.java 28 Jul 2010 15:31:17 -0000 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2008 IBM Corporation and others. + * Copyright (c) 2000, 2010 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 @@ -24,4 +24,18 @@ * @return the name of the package the statement */ String getElementName(); +/** + * Returns the source range of this package declaration's name, + * or null if this package declaration does not have + * associated source code (for example, a binary type). + * + * @exception JavaModelException if this element does not exist or if an + * exception occurs while accessing its corresponding resource. + * @return the source range of this package declaration's name, + * or null if this package declaration does not have + * associated source code (for example, a binary type) + * @since 3.7 + */ +ISourceRange getNameRange() throws JavaModelException; + } Index: model/org/eclipse/jdt/internal/compiler/ISourceElementRequestor.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/compiler/ISourceElementRequestor.java,v retrieving revision 1.25 diff -u -r1.25 ISourceElementRequestor.java --- model/org/eclipse/jdt/internal/compiler/ISourceElementRequestor.java 16 Jan 2009 14:29:29 -0000 1.25 +++ model/org/eclipse/jdt/internal/compiler/ISourceElementRequestor.java 28 Jul 2010 15:31:17 -0000 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2009 IBM Corporation and others. + * Copyright (c) 2000, 2010 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 @@ -120,6 +120,12 @@ * @param declarationEnd * This is the position of the ';' ending the import statement or * the end of the comment following the import. + * @param nameStart + * This is the position of the first character of the import declaration's + * name. + * @param nameEnd + * This is the position of the last character of the import declaration's + * name. * @param tokens * This are the tokens of the import like specified in the source. * @param onDemand @@ -128,7 +134,7 @@ * @param modifiers * can be set to static from 1.5 on. */ - void acceptImport(int declarationStart, int declarationEnd, char[][] tokens, boolean onDemand, int modifiers); + void acceptImport(int declarationStart, int declarationEnd, int nameStart, int nameEnd, char[][] tokens, boolean onDemand, int modifiers); /* * Table of line separator position. This table is passed once at the end of Index: model/org/eclipse/jdt/internal/compiler/SourceElementNotifier.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/compiler/SourceElementNotifier.java,v retrieving revision 1.6 diff -u -r1.6 SourceElementNotifier.java --- model/org/eclipse/jdt/internal/compiler/SourceElementNotifier.java 16 Jan 2009 14:29:29 -0000 1.6 +++ model/org/eclipse/jdt/internal/compiler/SourceElementNotifier.java 28 Jul 2010 15:31:17 -0000 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2008, 2009 IBM Corporation and others. + * Copyright (c) 2008, 2010 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 @@ -543,11 +543,14 @@ if (isPackage) { this.requestor.acceptPackage(importReference); } else { + final boolean onDemand = (importReference.bits & ASTNode.OnDemand) != 0; this.requestor.acceptImport( importReference.declarationSourceStart, importReference.declarationSourceEnd, + importReference.sourceStart, + onDemand ? importReference.trailingStarPosition : importReference.sourceEnd, importReference.tokens, - (importReference.bits & ASTNode.OnDemand) != 0, + onDemand, importReference.modifiers); } } Index: model/org/eclipse/jdt/internal/compiler/SourceElementParser.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/compiler/SourceElementParser.java,v retrieving revision 1.90 diff -u -r1.90 SourceElementParser.java --- model/org/eclipse/jdt/internal/compiler/SourceElementParser.java 28 Apr 2009 16:53:03 -0000 1.90 +++ model/org/eclipse/jdt/internal/compiler/SourceElementParser.java 28 Jul 2010 15:31:17 -0000 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2009 IBM Corporation and others. + * Copyright (c) 2000, 2010 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 @@ -631,6 +631,8 @@ System.arraycopy(this.identifierPositionStack, this.identifierPtr + 1, positions, 0, length); pushOnAstStack(impt = new ImportReference(tokens, positions, true, ClassFileConstants.AccStatic)); + // star end position + impt.trailingStarPosition = this.intStack[this.intPtr--]; this.modifiers = ClassFileConstants.AccDefault; this.modifiersSourceStart = -1; // <-- see comment into modifiersFlag(int) @@ -675,6 +677,8 @@ System.arraycopy(this.identifierPositionStack, this.identifierPtr + 1, positions, 0, length); pushOnAstStack(impt = new ImportReference(tokens, positions, true, ClassFileConstants.AccDefault)); + // star end position + impt.trailingStarPosition = this.intStack[this.intPtr--]; if (this.currentToken == TokenNameSEMICOLON){ impt.declarationSourceEnd = this.scanner.currentPosition - 1; } else { Index: model/org/eclipse/jdt/internal/compiler/SourceElementRequestorAdapter.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/compiler/SourceElementRequestorAdapter.java,v retrieving revision 1.20 diff -u -r1.20 SourceElementRequestorAdapter.java --- model/org/eclipse/jdt/internal/compiler/SourceElementRequestorAdapter.java 27 Jun 2008 16:04:07 -0000 1.20 +++ model/org/eclipse/jdt/internal/compiler/SourceElementRequestorAdapter.java 28 Jul 2010 15:31:17 -0000 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2008 IBM Corporation and others. + * Copyright (c) 2000, 2010 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 @@ -51,11 +51,13 @@ } /** - * @see ISourceElementRequestor#acceptImport(int, int, char[][], boolean, int) + * @see ISourceElementRequestor#acceptImport(int, int, int, int, char[][], boolean, int) */ public void acceptImport( int declarationStart, int declarationEnd, + int nameStart, + int nameEnd, char[][] tokens, boolean onDemand, int modifiers) { Index: model/org/eclipse/jdt/internal/core/AnnotatableInfo.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/AnnotatableInfo.java,v retrieving revision 1.4 diff -u -r1.4 AnnotatableInfo.java --- model/org/eclipse/jdt/internal/core/AnnotatableInfo.java 7 Mar 2009 00:58:56 -0000 1.4 +++ model/org/eclipse/jdt/internal/core/AnnotatableInfo.java 28 Jul 2010 15:31:17 -0000 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2009 IBM Corporation and others. + * Copyright (c) 2000, 2010 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 @@ -11,6 +11,8 @@ package org.eclipse.jdt.internal.core; import org.eclipse.jdt.core.IAnnotation; +import org.eclipse.jdt.core.ISourceRange; +import org.eclipse.jdt.core.SourceRange; public class AnnotatableInfo extends MemberElementInfo { @@ -61,4 +63,7 @@ protected void setNameSourceStart(int start) { this.nameStart= start; } + protected ISourceRange getNameRange() { + return new SourceRange(this.nameStart, this.nameEnd - this.nameStart + 1); + } } Index: model/org/eclipse/jdt/internal/core/CompilationUnitStructureRequestor.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/CompilationUnitStructureRequestor.java,v retrieving revision 1.86 diff -u -r1.86 CompilationUnitStructureRequestor.java --- model/org/eclipse/jdt/internal/core/CompilationUnitStructureRequestor.java 10 Nov 2009 16:53:03 -0000 1.86 +++ model/org/eclipse/jdt/internal/core/CompilationUnitStructureRequestor.java 28 Jul 2010 15:31:17 -0000 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2009 IBM Corporation and others. + * Copyright (c) 2000, 2010 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 @@ -125,7 +125,7 @@ /** * @see ISourceElementRequestor */ -public void acceptImport(int declarationStart, int declarationEnd, char[][] tokens, boolean onDemand, int modifiers) { +public void acceptImport(int declarationStart, int declarationEnd, int nameSourceStart, int nameSourceEnd, char[][] tokens, boolean onDemand, int modifiers) { JavaElement parentHandle= (JavaElement) this.handleStack.peek(); if (!(parentHandle.getElementType() == IJavaElement.COMPILATION_UNIT)) { Assert.isTrue(false); // Should not happen @@ -148,6 +148,8 @@ ImportDeclarationElementInfo info = new ImportDeclarationElementInfo(); info.setSourceRangeStart(declarationStart); info.setSourceRangeEnd(declarationEnd); + info.setNameSourceStart(nameSourceStart); + info.setNameSourceEnd(nameSourceEnd); info.setFlags(modifiers); addToChildren(this.importContainerInfo, handle); @@ -184,6 +186,8 @@ AnnotatableInfo info = new AnnotatableInfo(); info.setSourceRangeStart(importReference.declarationSourceStart); info.setSourceRangeEnd(importReference.declarationSourceEnd); + info.setNameSourceStart(importReference.sourceStart); + info.setNameSourceEnd(importReference.sourceEnd); addToChildren(parentInfo, handle); this.newElements.put(handle, info); Index: model/org/eclipse/jdt/internal/core/ImportDeclaration.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/ImportDeclaration.java,v retrieving revision 1.40 diff -u -r1.40 ImportDeclaration.java --- model/org/eclipse/jdt/internal/core/ImportDeclaration.java 7 Mar 2009 01:08:07 -0000 1.40 +++ model/org/eclipse/jdt/internal/core/ImportDeclaration.java 28 Jul 2010 15:31:17 -0000 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2009 IBM Corporation and others. + * Copyright (c) 2000, 2010 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 @@ -77,6 +77,10 @@ Assert.isTrue(false, "Should not be called"); //$NON-NLS-1$ return 0; } +public ISourceRange getNameRange() throws JavaModelException { + ImportDeclarationElementInfo info = (ImportDeclarationElementInfo) getElementInfo(); + return info.getNameRange(); +} /* * @see JavaElement#getPrimaryElement(boolean) */ Index: model/org/eclipse/jdt/internal/core/ImportDeclarationElementInfo.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/ImportDeclarationElementInfo.java,v retrieving revision 1.11 diff -u -r1.11 ImportDeclarationElementInfo.java --- model/org/eclipse/jdt/internal/core/ImportDeclarationElementInfo.java 7 Mar 2009 01:08:07 -0000 1.11 +++ model/org/eclipse/jdt/internal/core/ImportDeclarationElementInfo.java 28 Jul 2010 15:31:17 -0000 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2009 IBM Corporation and others. + * Copyright (c) 2000, 2010 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 @@ -10,6 +10,8 @@ *******************************************************************************/ package org.eclipse.jdt.internal.core; +import org.eclipse.jdt.core.ISourceRange; +import org.eclipse.jdt.core.SourceRange; import org.eclipse.jdt.internal.compiler.env.ISourceImport; /** @@ -18,5 +20,34 @@ */ public class ImportDeclarationElementInfo extends MemberElementInfo implements ISourceImport{ - // empty element info + /** + * The start position of this import declaration's name in the its + * openable's buffer. + */ + protected int nameStart= -1; + + /** + * The last position of this import declaration's name in the its + * openable's buffer. + */ + protected int nameEnd= -1; + + /** + * Sets the last position of this import declaration's name, relative + * to its openable's source buffer. + */ + protected void setNameSourceEnd(int end) { + this.nameEnd= end; + } + /** + * Sets the start position of this import declaration's name, relative + * to its openable's source buffer. + */ + protected void setNameSourceStart(int start) { + this.nameStart= start; + } + + protected ISourceRange getNameRange() { + return new SourceRange(this.nameStart, this.nameEnd - this.nameStart + 1); + } } Index: model/org/eclipse/jdt/internal/core/PackageDeclaration.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/PackageDeclaration.java,v retrieving revision 1.31 diff -u -r1.31 PackageDeclaration.java --- model/org/eclipse/jdt/internal/core/PackageDeclaration.java 27 Jun 2008 16:03:51 -0000 1.31 +++ model/org/eclipse/jdt/internal/core/PackageDeclaration.java 28 Jul 2010 15:31:17 -0000 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2008 IBM Corporation and others. + * Copyright (c) 2000, 2010 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 @@ -11,7 +11,6 @@ package org.eclipse.jdt.internal.core; import org.eclipse.jdt.core.*; -import org.eclipse.jdt.core.IPackageDeclaration; /** * @see IPackageDeclaration @@ -44,6 +43,13 @@ protected char getHandleMementoDelimiter() { return JavaElement.JEM_PACKAGEDECLARATION; } +/** + * @see IPackageDeclaration#getNameRange() + */ +public ISourceRange getNameRange() throws JavaModelException { + AnnotatableInfo info = (AnnotatableInfo) getElementInfo(); + return info.getNameRange(); +} /* * @see JavaElement#getPrimaryElement(boolean) */ Index: model/org/eclipse/jdt/internal/core/SourceMapper.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/SourceMapper.java,v retrieving revision 1.149 diff -u -r1.149 SourceMapper.java --- model/org/eclipse/jdt/internal/core/SourceMapper.java 10 Dec 2009 16:00:06 -0000 1.149 +++ model/org/eclipse/jdt/internal/core/SourceMapper.java 28 Jul 2010 15:31:17 -0000 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2009 IBM Corporation and others. + * Copyright (c) 2000, 2010 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 @@ -220,6 +220,8 @@ public void acceptImport( int declarationStart, int declarationEnd, + int nameStart, + int nameEnd, char[][] tokens, boolean onDemand, int modifiers) { Index: model/org/eclipse/jdt/internal/core/jdom/SimpleDOMBuilder.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/jdom/SimpleDOMBuilder.java,v retrieving revision 1.50 diff -u -r1.50 SimpleDOMBuilder.java --- model/org/eclipse/jdt/internal/core/jdom/SimpleDOMBuilder.java 27 Jun 2008 16:04:07 -0000 1.50 +++ model/org/eclipse/jdt/internal/core/jdom/SimpleDOMBuilder.java 28 Jul 2010 15:31:17 -0000 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2008 IBM Corporation and others. + * Copyright (c) 2000, 2010 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 @@ -39,7 +39,7 @@ // nothing to do } -public void acceptImport(int declarationStart, int declarationEnd, char[][] tokens, boolean onDemand, int modifiers) { +public void acceptImport(int declarationStart, int declarationEnd, int nameStart, int nameEnd, char[][] tokens, boolean onDemand, int modifiers) { int[] sourceRange = {declarationStart, declarationEnd}; String importName = new String(CharOperation.concatWith(tokens, '.')); /** name is set to contain the '*' */ Index: search/org/eclipse/jdt/internal/core/search/indexing/SourceIndexerRequestor.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/indexing/SourceIndexerRequestor.java,v retrieving revision 1.48 diff -u -r1.48 SourceIndexerRequestor.java --- search/org/eclipse/jdt/internal/core/search/indexing/SourceIndexerRequestor.java 16 Jan 2009 14:29:29 -0000 1.48 +++ search/org/eclipse/jdt/internal/core/search/indexing/SourceIndexerRequestor.java 28 Jul 2010 15:31:17 -0000 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2009 IBM Corporation and others. + * Copyright (c) 2000, 2010 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 @@ -74,9 +74,9 @@ this.indexer.addFieldReference(fieldName); } /** - * @see ISourceElementRequestor#acceptImport(int, int, char[][], boolean, int) + * @see ISourceElementRequestor#acceptImport(int, int, int, int, char[][], boolean, int) */ -public void acceptImport(int declarationStart, int declarationEnd, char[][] tokens, boolean onDemand, int modifiers) { +public void acceptImport(int declarationStart, int declarationEnd, int nameStart, int nameEnd, char[][] tokens, boolean onDemand, int modifiers) { // imports have already been reported while creating the ImportRef node (see SourceElementParser#comsume*ImportDeclarationName() methods) } /** #P org.eclipse.jdt.core.tests.compiler Index: src/org/eclipse/jdt/core/tests/compiler/parser/SourceElementParserTest.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/parser/SourceElementParserTest.java,v retrieving revision 1.46 diff -u -r1.46 SourceElementParserTest.java --- src/org/eclipse/jdt/core/tests/compiler/parser/SourceElementParserTest.java 11 May 2010 18:53:51 -0000 1.46 +++ src/org/eclipse/jdt/core/tests/compiler/parser/SourceElementParserTest.java 28 Jul 2010 15:31:18 -0000 @@ -93,6 +93,8 @@ public void acceptImport( int declarationStart, int declarationEnd, + int nameStart, + int nameEnd, char[][] tokens, boolean onDemand, int modifiers) { Index: src/org/eclipse/jdt/core/tests/compiler/parser/TestSourceElementRequestor.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/parser/TestSourceElementRequestor.java,v retrieving revision 1.22 diff -u -r1.22 TestSourceElementRequestor.java --- src/org/eclipse/jdt/core/tests/compiler/parser/TestSourceElementRequestor.java 27 May 2008 23:53:59 -0000 1.22 +++ src/org/eclipse/jdt/core/tests/compiler/parser/TestSourceElementRequestor.java 28 Jul 2010 15:31:18 -0000 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2008 IBM Corporation and others. + * Copyright (c) 2000, 2010 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 @@ -41,7 +41,7 @@ /** * acceptImport method comment. */ -public void acceptImport(int declarationStart, int declarationEnd, char[][] tokens, boolean onDemand, int modifiers) {} +public void acceptImport(int declarationStart, int declarationEnd, int nameStart, int nameEnd, char[][] tokens, boolean onDemand, int modifiers) {} /** * acceptLineSeparatorPositions method comment. */ #P org.eclipse.jdt.core.tests.model Index: src/org/eclipse/jdt/core/tests/model/AbstractJavaModelTests.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/AbstractJavaModelTests.java,v retrieving revision 1.240 diff -u -r1.240 AbstractJavaModelTests.java --- src/org/eclipse/jdt/core/tests/model/AbstractJavaModelTests.java 28 Jun 2010 13:28:41 -0000 1.240 +++ src/org/eclipse/jdt/core/tests/model/AbstractJavaModelTests.java 28 Jul 2010 15:31:19 -0000 @@ -1938,6 +1938,12 @@ case IJavaElement.ANNOTATION: nameRange = ((IAnnotation) element).getNameRange(); break; + case IJavaElement.PACKAGE_DECLARATION : + nameRange = ((IPackageDeclaration) element).getNameRange(); + break; + case IJavaElement.IMPORT_DECLARATION : + nameRange = ((IImportDeclaration) element).getNameRange(); + break; default: nameRange = ((IMember) element).getNameRange(); break; Index: src/org/eclipse/jdt/core/tests/model/GetSourceTests.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/GetSourceTests.java,v retrieving revision 1.27 diff -u -r1.27 GetSourceTests.java --- src/org/eclipse/jdt/core/tests/model/GetSourceTests.java 28 Apr 2009 17:46:10 -0000 1.27 +++ src/org/eclipse/jdt/core/tests/model/GetSourceTests.java 28 Jul 2010 15:31:19 -0000 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2009 IBM Corporation and others. + * Copyright (c) 2000, 2010 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 @@ -476,6 +476,75 @@ } /* + * https://bugs.eclipse.org/bugs/show_bug.cgi?id=150980 + */ + public void testNameRange09() throws CoreException { // was testNameRangeAnonymous + try { + String cuSource = + "package p . q . r. s ;\n" + + "public class Y {\n" + + " void foo() {\n" + + " Y y = new Y() {};\n" + + " class C {\n" + + " }\n"+ + " }\n" + + "}"; + createFolder("/P/p/q/r/s/"); + createFile("/P/p/q/r/s/Y.java", cuSource); + final IPackageDeclaration[] packageDeclarations = getCompilationUnit("/P/p/q/r/s/Y.java").getPackageDeclarations(); + assertEquals("Wrong size", 1, packageDeclarations.length); + + String actualSource = getNameSource(cuSource, packageDeclarations[0]); + String expectedSource = "p . q . r. s"; + assertSourceEquals("Unexpected source'", expectedSource, actualSource); + } finally { + deleteFile("/P/p/q/r/s/Y.java"); + } + } + + /* + * https://bugs.eclipse.org/bugs/show_bug.cgi?id=150980 + */ + public void testNameRange10() throws CoreException { // was testNameRangeAnonymous + try { + String cuSource = + "import java . lang . * ;\n" + + "public class Y {\n" + + "}"; + createFile("/P/Y.java", cuSource); + final IImportDeclaration[] imports = getCompilationUnit("/P/Y.java").getImports(); + assertEquals("Wrong size", 1, imports.length); + + String actualSource = getNameSource(cuSource, imports[0]); + String expectedSource = "java . lang . *"; + assertSourceEquals("Unexpected source'", expectedSource, actualSource); + } finally { + deleteFile("/P/Y.java"); + } + } + + /* + * https://bugs.eclipse.org/bugs/show_bug.cgi?id=150980 + */ + public void testNameRange11() throws CoreException { // was testNameRangeAnonymous + try { + String cuSource = + "import java . lang . Object ;\n" + + "public class Y {\n" + + "}"; + createFile("/P/Y.java", cuSource); + final IImportDeclaration[] imports = getCompilationUnit("/P/Y.java").getImports(); + assertEquals("Wrong size", 1, imports.length); + + String actualSource = getNameSource(cuSource, imports[0]); + String expectedSource = "java . lang . Object"; + assertSourceEquals("Unexpected source'", expectedSource, actualSource); + } finally { + deleteFile("/P/Y.java"); + } + } + + /* * Ensures that the source range for an annotation on a local variable is correct. * (regression test for https://bugs.eclipse.org/bugs/show_bug.cgi?id=209823) */