-
Notifications
You must be signed in to change notification settings - Fork 108
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Provide an API to check if an IType is an implicitly declared class.
Signed-off-by: David Thompson <davthomp@redhat.com>
- Loading branch information
Showing
11 changed files
with
142 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
109 changes: 109 additions & 0 deletions
109
...ipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/JavaSearchBugs21Tests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2024 Red Hat Inc. and others. | ||
* | ||
* This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License 2.0 | ||
* which accompanies this distribution, and is available at | ||
* https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* Red Hat Inc. - initial API and implementation | ||
*******************************************************************************/ | ||
package org.eclipse.jdt.core.tests.model; | ||
|
||
import org.eclipse.core.runtime.CoreException; | ||
import org.eclipse.jdt.core.ICompilationUnit; | ||
import org.eclipse.jdt.core.IJavaProject; | ||
import org.eclipse.jdt.core.IType; | ||
import org.eclipse.jdt.core.JavaModelException; | ||
import org.eclipse.jdt.core.WorkingCopyOwner; | ||
import org.eclipse.jdt.core.search.IJavaSearchScope; | ||
import org.eclipse.jdt.core.search.SearchEngine; | ||
import org.eclipse.jdt.core.search.SearchMatch; | ||
|
||
import junit.framework.Test; | ||
|
||
public class JavaSearchBugs21Tests extends AbstractJavaSearchTests { | ||
|
||
public JavaSearchBugs21Tests(String name) { | ||
super(name); | ||
} | ||
|
||
public static Test suite() { | ||
return buildModelTestSuite(JavaSearchBugs21Tests.class, BYTECODE_DECLARATION_ORDER); | ||
} | ||
|
||
class TestCollector extends JavaSearchResultCollector { | ||
@Override | ||
public void acceptSearchMatch(SearchMatch searchMatch) throws CoreException { | ||
super.acceptSearchMatch(searchMatch); | ||
} | ||
} | ||
|
||
@Override | ||
IJavaSearchScope getJavaSearchScope() { | ||
return SearchEngine.createJavaSearchScope(new IJavaProject[] {getJavaProject("JavaSearchBugs")}); | ||
} | ||
IJavaSearchScope getJavaSearchScopeBugs(String packageName, boolean addSubpackages) throws JavaModelException { | ||
if (packageName == null) return getJavaSearchScope(); | ||
return getJavaSearchPackageScope("JavaSearchBugs", packageName, addSubpackages); | ||
} | ||
@Override | ||
public ICompilationUnit getWorkingCopy(String path, String source) throws JavaModelException { | ||
if (this.wcOwner == null) { | ||
this.wcOwner = new WorkingCopyOwner() {}; | ||
} | ||
return getWorkingCopy(path, source, this.wcOwner); | ||
} | ||
@Override | ||
public void setUpSuite() throws Exception { | ||
super.setUpSuite(); | ||
JAVA_PROJECT = setUpJavaProject("JavaSearchBugs", "10"); | ||
} | ||
@Override | ||
public void tearDownSuite() throws Exception { | ||
deleteProject("JavaSearchBugs"); | ||
super.tearDownSuite(); | ||
} | ||
@Override | ||
protected void setUp () throws Exception { | ||
super.setUp(); | ||
this.resultCollector = new TestCollector(); | ||
this.resultCollector.showAccuracy(true); | ||
} | ||
|
||
public void testUnnamedClassInModel() throws CoreException { | ||
this.workingCopies = new ICompilationUnit[1]; | ||
this.workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/X.java", """ | ||
String foo() { | ||
return "foo"; | ||
} | ||
void main() { | ||
System.out.println(foo()); | ||
} | ||
"""); | ||
IType unnamedType = this.workingCopies[0].getType("X"); | ||
assertTrue("Unnamed class should exist in the model", unnamedType.exists()); | ||
assertTrue("Unnamed class should be marked as unnamed", unnamedType.isImplicitlyDeclared()); | ||
} | ||
|
||
public void testNamedClassInModel() throws CoreException { | ||
this.workingCopies = new ICompilationUnit[1]; | ||
this.workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/X.java", """ | ||
public class X { | ||
String foo() { | ||
return "foo"; | ||
} | ||
void main() { | ||
System.out.println(foo()); | ||
} | ||
} | ||
"""); | ||
IType namedTyped = this.workingCopies[0].getType("X"); | ||
assertTrue("class should exist in the model", namedTyped.exists()); | ||
assertTrue("class should be marked as named", !namedTyped.isImplicitlyDeclared()); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters