Java Code Examples for org.eclipse.jdt.core.IJavaProject#getPackageFragmentRoot()
The following examples show how to use
org.eclipse.jdt.core.IJavaProject#getPackageFragmentRoot() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DiagnosticHandlerTest.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 6 votes |
@Test public void testDeprecated() throws Exception { IJavaProject javaProject = newEmptyProject(); IPackageFragmentRoot sourceFolder = javaProject.getPackageFragmentRoot(javaProject.getProject().getFolder("src")); IPackageFragment pack1 = sourceFolder.createPackageFragment("test1", false, null); StringBuilder buf = new StringBuilder(); buf.append("package test1;\n"); buf.append("import java.security.Certificate;\n"); ICompilationUnit cu = pack1.createCompilationUnit("E.java", buf.toString(), false, null); CompilationUnit astRoot = CoreASTProvider.getInstance().getAST(cu, CoreASTProvider.WAIT_YES, monitor); IProblem[] problems = astRoot.getProblems(); List<Diagnostic> diagnostics = DiagnosticsHandler.toDiagnosticsArray(cu, Arrays.asList(problems), true); assertEquals(2, diagnostics.size()); List<DiagnosticTag> tags = diagnostics.get(0).getTags(); assertEquals(1, tags.size()); assertEquals(DiagnosticTag.Deprecated, tags.get(0)); }
Example 2
Source File: NativeLibrariesPropertyPage.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
private IJavaElement getJavaElement() { IAdaptable adaptable= getElement(); IJavaElement elem= (IJavaElement) adaptable.getAdapter(IJavaElement.class); if (elem == null) { IResource resource= (IResource) adaptable.getAdapter(IResource.class); //special case when the .jar is a file try { if (resource instanceof IFile && ArchiveFileFilter.isArchivePath(resource.getFullPath(), false)) { IProject proj= resource.getProject(); if (proj.hasNature(JavaCore.NATURE_ID)) { IJavaProject jproject= JavaCore.create(proj); elem= jproject.getPackageFragmentRoot(resource); // create a handle } } } catch (CoreException e) { JavaPlugin.log(e); } } return elem; }
Example 3
Source File: JavaProjectHelper.java From spotbugs with GNU Lesser General Public License v2.1 | 6 votes |
/** * Adds a source container to a IJavaProject. * * @param jproject * The parent project * @param containerName * The name of the new source container * @param inclusionFilters * Inclusion filters to set * @param exclusionFilters * Exclusion filters to set * @return The handle to the new source container * @throws CoreException * Creation failed */ public static IPackageFragmentRoot addSourceContainer(IJavaProject jproject, String containerName, IPath[] inclusionFilters, IPath[] exclusionFilters) throws CoreException { IProject project = jproject.getProject(); IContainer container = null; if (containerName == null || containerName.length() == 0) { container = project; } else { IFolder folder = project.getFolder(containerName); if (!folder.exists()) { CoreUtility.createFolder(folder, false, true, null); } container = folder; } IPackageFragmentRoot root = jproject.getPackageFragmentRoot(container); IClasspathEntry cpe = JavaCore.newSourceEntry(root.getPath(), inclusionFilters, exclusionFilters, null); addToClasspath(jproject, cpe); return root; }
Example 4
Source File: JavaClassPathResourceForIEditorInputFactoryTest.java From xtext-eclipse with Eclipse Public License 2.0 | 6 votes |
@Test(expected=CoreException.class) public void testBug463258_05() throws Throwable { IJavaProject project = createJavaProject("foo"); IPackageFragmentRoot root = project.getPackageFragmentRoot("does/not/exist.jar"); IPackageFragment foo = root.getPackageFragment("foo"); final JarEntryFile fileInJar = new JarEntryFile("bar.testlanguage"); fileInJar.setParent(foo); XtextReadonlyEditorInput editorInput = new XtextReadonlyEditorInput(fileInJar); try { factory.createResource(editorInput); } catch(WrappedException e) { throw e.getCause(); } }
Example 5
Source File: DocumentLifeCycleHandlerTest.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 5 votes |
@Test public void testDidOpenStandaloneFileWithSyntaxError() throws Exception { IJavaProject javaProject = newDefaultProject(); IPackageFragmentRoot sourceFolder = javaProject.getPackageFragmentRoot(javaProject.getProject().getFolder("src")); IPackageFragment pack1 = sourceFolder.createPackageFragment("java", false, null); // @formatter:off String standaloneFileContent = "package java;\n"+ "public class Foo extends UnknownType {\n"+ " public void method1(){\n"+ " super.whatever()\n"+ " }\n"+ "}"; // @formatter:on ICompilationUnit cu1 = pack1.createCompilationUnit("Foo.java", standaloneFileContent, false, null); openDocument(cu1, cu1.getSource(), 1); List<PublishDiagnosticsParams> diagnosticReports = getClientRequests("publishDiagnostics"); assertEquals(1, diagnosticReports.size()); PublishDiagnosticsParams diagParam = diagnosticReports.get(0); assertEquals("Unexpected number of errors " + diagParam.getDiagnostics(), 2, diagParam.getDiagnostics().size()); Diagnostic d = diagParam.getDiagnostics().get(0); assertEquals("Foo.java is a non-project file, only syntax errors are reported", d.getMessage()); assertRange(0, 0, 1, d.getRange()); d = diagParam.getDiagnostics().get(1); assertEquals("Syntax error, insert \";\" to complete BlockStatements", d.getMessage()); assertRange(3, 17, 18, d.getRange()); }
Example 6
Source File: ExportSarlApplicationPage.java From sarl with Apache License 2.0 | 5 votes |
@Override protected IPackageFragmentRoot[] getRequiredPackageFragmentRoots(IPath[] classpathEntries, String projectName, MultiStatus status) { final List<IPackageFragmentRoot> result = new ArrayList<>(); final IJavaProject[] searchOrder = getProjectSearchOrder(projectName); final IJavaProject project = getJavaProject(projectName); for (int i = 0; i < classpathEntries.length; ++i) { final IPath entry = classpathEntries[i]; final IPackageFragmentRoot[] elements = findRootsForClasspath(entry, searchOrder); if (elements == null) { final IPackageFragmentRoot element; final File file = entry.toFile(); if (file.exists()) { element = project.getPackageFragmentRoot(file.getAbsolutePath()); } else { element = null; } if (element != null) { result.add(element); } else { status.add(new Status(IStatus.WARNING, JavaUI.ID_PLUGIN, org.eclipse.jdt.internal.corext.util.Messages.format( FatJarPackagerMessages.FatJarPackageWizardPage_error_missingClassFile, getPathLabel(entry, false)))); } } else { for (int j = 0; j < elements.length; ++j) { result.add(elements[j]); } } } return result.toArray(new IPackageFragmentRoot[result.size()]); }
Example 7
Source File: FindLinksHandlerTest.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 5 votes |
@Before public void setup() throws Exception { IJavaProject javaProject = newEmptyProject(); sourceFolder = javaProject.getPackageFragmentRoot(javaProject.getProject().getFolder("src")); ClientPreferences clientPreferences = preferenceManager.getClientPreferences(); when(clientPreferences.isResourceOperationSupported()).thenReturn(true); }
Example 8
Source File: BuildPathWizard.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
/** * {@inheritDoc} */ @Override protected void finishPage(IProgressMonitor monitor) throws InterruptedException, CoreException { if (fDoFlushChange) { IJavaProject javaProject= getEntryToEdit().getJavaProject(); BuildPathsBlock.flush(getExistingEntries(), getOutputLocation(), javaProject, null, monitor); IProject project= javaProject.getProject(); IPath path= getEntryToEdit().getPath(); IResource folder= project.getWorkspace().getRoot().findMember(path); fPackageFragmentRoot= javaProject.getPackageFragmentRoot(folder); } }
Example 9
Source File: HoverHandlerTest.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 5 votes |
@Before public void setup() throws Exception { importProjects("eclipse/hello"); project = WorkspaceHelper.getProject("hello"); IJavaProject javaProject = JavaCore.create(project); sourceFolder = javaProject.getPackageFragmentRoot(javaProject.getProject().getFolder("src")); preferenceManager = mock(PreferenceManager.class); when(preferenceManager.getPreferences()).thenReturn(new Preferences()); handler = new HoverHandler(preferenceManager); }
Example 10
Source File: SignatureHelpHandlerTest.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 5 votes |
@Override @Before public void setup() throws Exception { importProjects("eclipse/hello"); project = WorkspaceHelper.getProject("hello"); IJavaProject javaProject = JavaCore.create(project); sourceFolder = javaProject.getPackageFragmentRoot(javaProject.getProject().getFolder("src")); preferenceManager = mock(PreferenceManager.class); Preferences p = mock(Preferences.class); when(preferenceManager.getPreferences(null)).thenReturn(p); when(p.isSignatureHelpEnabled()).thenReturn(true); handler = new SignatureHelpHandler(preferenceManager); }
Example 11
Source File: WorkspaceEventHandlerTest.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 5 votes |
@Test public void testDiscardStaleWorkingCopies() throws Exception { IJavaProject javaProject = newEmptyProject(); IFolder src = javaProject.getProject().getFolder("src"); IPackageFragmentRoot srcRoot = javaProject.getPackageFragmentRoot(src); IPackageFragment mypack = srcRoot.createPackageFragment("mypack", true, null); // @formatter:off String contents = "package mypack;\n" + "public class Foo {" + "}\n"; // @formatter:on ICompilationUnit unit = mypack.createCompilationUnit("Foo.java", contents, true, null); openDocument(unit, contents, 1); assertTrue(unit.isWorkingCopy()); String oldUri = JDTUtils.getFileURI(srcRoot.getResource()); String parentUri = JDTUtils.getFileURI(src); String newUri = oldUri.replace("mypack", "mynewpack"); File oldPack = mypack.getResource().getLocation().toFile(); File newPack = new File(oldPack.getParent(), "mynewpack"); Files.move(oldPack, newPack); assertTrue(unit.isWorkingCopy()); DidChangeWatchedFilesParams params = new DidChangeWatchedFilesParams(Arrays.asList( new FileEvent(newUri, FileChangeType.Created), new FileEvent(parentUri, FileChangeType.Changed), new FileEvent(oldUri, FileChangeType.Deleted) )); new WorkspaceEventsHandler(projectsManager, javaClient, lifeCycleHandler).didChangeWatchedFiles(params); assertFalse(unit.isWorkingCopy()); }
Example 12
Source File: Storage2UriMapperJdtImplTest.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
@Test public void testBug463258_02() throws Exception { IJavaProject project = createJavaProject("foo"); IFile file = project.getProject().getFile("foo.jar"); file.create(jarInputStream(new TextFile("do/not", "care")), true, monitor()); addJarToClasspath(project, file); Storage2UriMapperJavaImpl impl = getStorage2UriMapper(); IPackageFragmentRoot root = project.getPackageFragmentRoot(file); IPackageFragment foo = root.getPackageFragment("unknown"); JarEntryFile fileInJar = new JarEntryFile("doesNotExist.notindexed"); fileInJar.setParent(foo); URI uri = impl.getUri(fileInJar); assertEquals("archive:platform:/resource/foo/foo.jar!/unknown/doesNotExist.notindexed", uri.toString()); }
Example 13
Source File: MoveHandlerTest.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 5 votes |
@Before public void setup() throws Exception { IJavaProject javaProject = newEmptyProject(); sourceFolder = javaProject.getPackageFragmentRoot(javaProject.getProject().getFolder("src")); ClientPreferences clientPreferences = preferenceManager.getClientPreferences(); when(clientPreferences.isResourceOperationSupported()).thenReturn(true); }
Example 14
Source File: TestUtils.java From CogniCrypt with Eclipse Public License 2.0 | 4 votes |
/** * This method creates a empty JavaProject in the current workspace * * @param projectName for the JavaProject * @return new created JavaProject * @throws CoreException */ public static IJavaProject createJavaProject(final String projectName) throws CoreException { final IWorkspaceRoot workSpaceRoot = ResourcesPlugin.getWorkspace().getRoot(); deleteProject(workSpaceRoot.getProject(projectName)); final IProject project = workSpaceRoot.getProject(projectName); project.create(null); project.open(null); final IProjectDescription description = project.getDescription(); description.setNatureIds(new String[] {JavaCore.NATURE_ID}); project.setDescription(description, null); final IJavaProject javaProject = JavaCore.create(project); final IFolder binFolder = project.getFolder("bin"); binFolder.create(false, true, null); javaProject.setOutputLocation(binFolder.getFullPath(), null); final List<IClasspathEntry> entries = new ArrayList<IClasspathEntry>(); final IVMInstall vmInstall = JavaRuntime.getDefaultVMInstall(); final LibraryLocation[] locations = JavaRuntime.getLibraryLocations(vmInstall); for (final LibraryLocation element : locations) { entries.add(JavaCore.newLibraryEntry(element.getSystemLibraryPath(), null, null)); } // add libs to project class path javaProject.setRawClasspath(entries.toArray(new IClasspathEntry[entries.size()]), null); final IFolder sourceFolder = project.getFolder("src"); sourceFolder.create(false, true, null); final IPackageFragmentRoot packageRoot = javaProject.getPackageFragmentRoot(sourceFolder); final IClasspathEntry[] oldEntries = javaProject.getRawClasspath(); final IClasspathEntry[] newEntries = new IClasspathEntry[oldEntries.length + 1]; System.arraycopy(oldEntries, 0, newEntries, 0, oldEntries.length); newEntries[oldEntries.length] = JavaCore.newSourceEntry(packageRoot.getPath()); javaProject.setRawClasspath(newEntries, null); return javaProject; }
Example 15
Source File: DocumentLifeCycleHandlerTest.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 4 votes |
@Test public void testCloseMissingResource() throws Exception { IJavaProject javaProject = newEmptyProject(); IPackageFragmentRoot sourceFolder = javaProject.getPackageFragmentRoot(javaProject.getProject().getFolder("src")); IPackageFragment pack1 = sourceFolder.createPackageFragment("test1", false, null); StringBuilder buf = new StringBuilder(); buf.append("package test1;\n"); buf.append("public class E123 {\n"); buf.append(" public boolean foo() {\n"); buf.append(" return x;\n"); buf.append(" }\n"); buf.append("}\n"); ICompilationUnit cu1 = pack1.createCompilationUnit("E123.java", buf.toString(), false, null); openDocument(cu1, cu1.getSource(), 1); assertEquals(true, cu1.isWorkingCopy()); assertEquals(false, cu1.hasUnsavedChanges()); assertNewProblemReported(new ExpectedProblemReport(cu1, 1)); assertEquals(1, getCacheSize()); assertNewASTsCreated(1); StringBuilder buf2 = new StringBuilder(); buf2.append("package test1;\n"); buf2.append("public class E123 {\n"); buf2.append(" public boolean foo() {\n"); buf2.append(" return true;\n"); buf2.append(" }\n"); buf2.append("}\n"); changeDocumentFull(cu1, buf2.toString(), 2); File file = cu1.getResource().getRawLocation().toFile(); boolean deleted = file.delete(); assertTrue(file.getAbsolutePath() + " hasn't been deleted", deleted); closeDocument(cu1); assertEquals(false, cu1.isWorkingCopy()); assertEquals(false, cu1.hasUnsavedChanges()); assertNewProblemReported(new ExpectedProblemReport(cu1, 0)); assertEquals(0, getCacheSize()); assertNewASTsCreated(0); }
Example 16
Source File: ProjectsManager.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 4 votes |
public static IProject createJavaProject(IProject project, IPath projectLocation, String src, String bin, IProgressMonitor monitor) throws CoreException, OperationCanceledException { if (project.exists()) { return project; } JavaLanguageServerPlugin.logInfo("Creating the Java project " + project.getName()); //Create project IProjectDescription description = ResourcesPlugin.getWorkspace().newProjectDescription(project.getName()); if (projectLocation != null) { description.setLocation(projectLocation); } project.create(description, monitor); project.open(monitor); //Turn into Java project description = project.getDescription(); description.setNatureIds(new String[] { JavaCore.NATURE_ID }); project.setDescription(description, monitor); IJavaProject javaProject = JavaCore.create(project); configureJVMSettings(javaProject); //Add build output folder if (StringUtils.isNotBlank(bin)) { IFolder output = project.getFolder(bin); if (!output.exists()) { output.create(true, true, monitor); } javaProject.setOutputLocation(output.getFullPath(), monitor); } List<IClasspathEntry> classpaths = new ArrayList<>(); //Add source folder if (StringUtils.isNotBlank(src)) { IFolder source = project.getFolder(src); if (!source.exists()) { source.create(true, true, monitor); } IPackageFragmentRoot root = javaProject.getPackageFragmentRoot(source); IClasspathEntry srcClasspath = JavaCore.newSourceEntry(root.getPath()); classpaths.add(srcClasspath); } //Find default JVM IClasspathEntry jre = JavaRuntime.getDefaultJREContainerEntry(); classpaths.add(jre); //Add JVM to project class path javaProject.setRawClasspath(classpaths.toArray(new IClasspathEntry[0]), monitor); JavaLanguageServerPlugin.logInfo("Finished creating the Java project " + project.getName()); return project; }
Example 17
Source File: DocumentLifeCycleHandlerTest.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 4 votes |
@Test public void testBasicBufferLifeCycleWithoutSave() throws Exception { IJavaProject javaProject = newEmptyProject(); IPackageFragmentRoot sourceFolder = javaProject.getPackageFragmentRoot(javaProject.getProject().getFolder("src")); IPackageFragment pack1 = sourceFolder.createPackageFragment("test1", false, null); StringBuilder buf = new StringBuilder(); buf.append("package test1;\n"); buf.append("public class E123 {\n"); buf.append(" public boolean foo() {\n"); buf.append(" return x;\n"); buf.append(" }\n"); buf.append("}\n"); ICompilationUnit cu1 = pack1.createCompilationUnit("E123.java", buf.toString(), false, null); openDocument(cu1, cu1.getSource(), 1); assertEquals(true, cu1.isWorkingCopy()); assertEquals(false, cu1.hasUnsavedChanges()); assertNewProblemReported(new ExpectedProblemReport(cu1, 1)); assertEquals(1, getCacheSize()); assertNewASTsCreated(1); buf = new StringBuilder(); buf.append("package test1;\n"); buf.append("public class E123 {\n"); buf.append(" public boolean foo() {\n"); buf.append(" return true;\n"); buf.append(" }\n"); buf.append("}\n"); changeDocumentFull(cu1, buf.toString(), 2); assertEquals(true, cu1.isWorkingCopy()); assertEquals(true, cu1.hasUnsavedChanges()); assertNewProblemReported(new ExpectedProblemReport(cu1, 0)); assertEquals(1, getCacheSize()); assertNewASTsCreated(1); closeDocument(cu1); assertEquals(false, cu1.isWorkingCopy()); assertEquals(false, cu1.hasUnsavedChanges()); assertNewProblemReported(new ExpectedProblemReport(cu1, 1)); assertEquals(0, getCacheSize()); assertNewASTsCreated(0); }
Example 18
Source File: DocumentLifeCycleHandlerTest.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 4 votes |
@Test public void testDidOpenStandaloneFileWithNonSyntaxErrors() throws Exception { IJavaProject javaProject = newDefaultProject(); IPackageFragmentRoot sourceFolder = javaProject.getPackageFragmentRoot(javaProject.getProject().getFolder("src")); IPackageFragment pack1 = sourceFolder.createPackageFragment("java", false, null); // @formatter:off String standaloneFileContent = "package java;\n"+ "public class Foo {\n"+ " public static void notThis(){\n"+ " System.out.println(this);\n"+ " }\n"+ " public void method1(){\n"+ " }\n"+ " public void method1(){\n"+ " }\n"+ "}"; // @formatter:on ICompilationUnit cu1 = pack1.createCompilationUnit("Foo.java", standaloneFileContent, false, null); openDocument(cu1, cu1.getSource(), 1); List<PublishDiagnosticsParams> diagnosticReports = getClientRequests("publishDiagnostics"); assertEquals(1, diagnosticReports.size()); PublishDiagnosticsParams diagParam = diagnosticReports.get(0); assertEquals("Unexpected number of errors " + diagParam.getDiagnostics(), 4, diagParam.getDiagnostics().size()); Diagnostic d = diagParam.getDiagnostics().get(0); assertEquals("Foo.java is a non-project file, only syntax errors are reported", d.getMessage()); assertRange(0, 0, 1, d.getRange()); d = diagParam.getDiagnostics().get(1); assertEquals("Cannot use this in a static context", d.getMessage()); assertRange(3, 21, 25, d.getRange()); d = diagParam.getDiagnostics().get(2); assertEquals("Duplicate method method1() in type Foo", d.getMessage()); assertRange(5, 13, 22, d.getRange()); d = diagParam.getDiagnostics().get(3); assertEquals("Duplicate method method1() in type Foo", d.getMessage()); assertRange(7, 13, 22, d.getRange()); }
Example 19
Source File: JReFrameworker.java From JReFrameworker with MIT License | 4 votes |
private static void configureProjectClasspath(IJavaProject jProject) throws CoreException, JavaModelException, IOException, URISyntaxException { // create bin folder try { IFolder binFolder = jProject.getProject().getFolder(BINARY_DIRECTORY); binFolder.create(false, true, null); jProject.setOutputLocation(binFolder.getFullPath(), null); } catch (Exception e){ Log.warning("Could not created bin folder.", e); } // create a set of classpath entries List<IClasspathEntry> entries = new ArrayList<IClasspathEntry>(); // adds classpath entry of: <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/> String path = org.eclipse.jdt.launching.JavaRuntime.JRE_CONTAINER + "/" + org.eclipse.jdt.internal.launching.StandardVMType.ID_STANDARD_VM_TYPE + "/" + "JavaSE-1.8"; entries.add(JavaCore.newContainerEntry(new Path(path))); // add the jreframeworker annotations jar addProjectAnnotationsLibrary(jProject); // have to create this manually instead of using JavaCore.newLibraryEntry because JavaCore insists the path be absolute IClasspathEntry relativeAnnotationsLibraryEntry = new ClasspathEntry(IPackageFragmentRoot.K_BINARY, IClasspathEntry.CPE_LIBRARY, new Path(JREF_PROJECT_RESOURCE_DIRECTORY + "/" + JRE_FRAMEWORKER_ANNOTATIONS_JAR), ClasspathEntry.INCLUDE_ALL, // inclusion patterns ClasspathEntry.EXCLUDE_NONE, // exclusion patterns null, null, null, // specific output folder false, // exported ClasspathEntry.NO_ACCESS_RULES, false, // no access rules to combine ClasspathEntry.NO_EXTRA_ATTRIBUTES); entries.add(relativeAnnotationsLibraryEntry); // create source folder and add it to the classpath IFolder sourceFolder = jProject.getProject().getFolder(SOURCE_DIRECTORY); sourceFolder.create(false, true, null); IPackageFragmentRoot sourceFolderRoot = jProject.getPackageFragmentRoot(sourceFolder); entries.add(JavaCore.newSourceEntry(sourceFolderRoot.getPath())); // set the class path jProject.setRawClasspath(entries.toArray(new IClasspathEntry[entries.size()]), null); if(JReFrameworkerPreferences.isVerboseLoggingEnabled()) Log.info("Successfully created JReFrameworker project: " + jProject.getProject().getName()); }
Example 20
Source File: NonProjectFixTest.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 4 votes |
@Test public void testReportSyntaxErrorsFixForNonProjectFile() throws Exception { JavaLanguageServerPlugin.getNonProjectDiagnosticsState().setGlobalErrorLevel(false); IJavaProject javaProject = newDefaultProject(); IPackageFragmentRoot sourceFolder = javaProject.getPackageFragmentRoot(javaProject.getProject().getFolder("src")); IPackageFragment pack1 = sourceFolder.createPackageFragment("java", false, null); // @formatter:off String standaloneFileContent = "package java;\n"+ "public class Foo extends UnknownType {\n"+ " public void method1(){\n"+ " super.whatever()\n"+ " }\n"+ "}"; // @formatter:on ICompilationUnit cu1 = pack1.createCompilationUnit("Foo.java", standaloneFileContent, false, null); final DiagnosticsHandler handler = new DiagnosticsHandler(javaClient, cu1); WorkingCopyOwner wcOwner = createWorkingCopyOwner(cu1, handler); cu1.becomeWorkingCopy(null); try { cu1.reconcile(ICompilationUnit.NO_AST, true, wcOwner, null); List<IProblem> problems = handler.getProblems(); assertFalse(problems.isEmpty()); List<Either<Command, CodeAction>> actions = getCodeActions(cu1, problems.get(0)); assertEquals(2, actions.size()); CodeAction action = actions.get(0).getRight(); assertEquals(CodeActionKind.QuickFix, action.getKind()); assertEquals(ActionMessages.ReportSyntaxErrorsForThisFile, action.getCommand().getTitle()); assertEquals(3, action.getCommand().getArguments().size()); assertEquals("thisFile", action.getCommand().getArguments().get(1)); assertEquals(true, action.getCommand().getArguments().get(2)); action = actions.get(1).getRight(); assertEquals(CodeActionKind.QuickFix, action.getKind()); assertEquals(ActionMessages.ReportSyntaxErrorsForAnyNonProjectFile, action.getCommand().getTitle()); assertEquals(3, action.getCommand().getArguments().size()); assertEquals("anyNonProjectFile", action.getCommand().getArguments().get(1)); assertEquals(true, action.getCommand().getArguments().get(2)); } finally { cu1.discardWorkingCopy(); } }