private static void makeJavaProject() throws CoreException { testProject = JavaProjectHelper.createJavaProject(PROJECT_NAME, BIN_FOLDER_NAME); JavaProjectHelper.addRTJar17(testProject); JavaProjectHelper.addSourceContainer(testProject, SRC_FOLDER_NAME); testProject.setOption("org.eclipse.jdt.core.formatter.tabulation.char", JavaCore.SPACE); testIProject = testProject.getProject(); }
public void testRemoveFromBuildpathBug153299Src() throws Exception { fJavaProject = createProject(null); // Use the old behavior in order to test the fallback code. Set to ERROR since 3.8. fJavaProject.setOption( JavaCore.CORE_OUTPUT_LOCATION_OVERLAPPING_ANOTHER_SOURCE, JavaCore.IGNORE); IPackageFragmentRoot p01 = JavaProjectHelper.addSourceContainer(fJavaProject, null, new IPath[] {new Path("src1/")}); JavaProjectHelper.addSourceContainer(fJavaProject, "src1"); CPJavaProject cpProject = CPJavaProject.createFromExisting(fJavaProject); BuildpathDelta delta = ClasspathModifier.removeFromBuildpath( new CPListElement[] { CPListElement.createFromExisting(p01.getRawClasspathEntry(), fJavaProject) }, cpProject); assertDeltaResources(delta, new IPath[0], new IPath[] {}, new IPath[0], new IPath[0]); assertDeltaDefaultOutputFolder( delta, fJavaProject.getPath().append(DEFAULT_OUTPUT_FOLDER_NAME)); assertDeltaRemovedEntries(delta, new IPath[] {p01.getPath()}); assertDeltaAddedEntries(delta, new IPath[0]); ClasspathModifier.commitClassPath(cpProject, null); IClasspathEntry[] classpathEntries = fJavaProject.getRawClasspath(); assertNumberOfEntries(classpathEntries, 2); }
public void testRemoveFromBuildpath01() throws Exception { fJavaProject = createProject(DEFAULT_OUTPUT_FOLDER_NAME); IPackageFragmentRoot src1 = JavaProjectHelper.addSourceContainer(fJavaProject, "src1"); IPackageFragmentRoot src2 = JavaProjectHelper.addSourceContainer(fJavaProject, "src2"); CPJavaProject cpProject = CPJavaProject.createFromExisting(fJavaProject); CPListElement[] toRemove = new CPListElement[2]; toRemove[0] = CPListElement.createFromExisting(src1.getRawClasspathEntry(), fJavaProject); toRemove[1] = CPListElement.createFromExisting(src2.getRawClasspathEntry(), fJavaProject); BuildpathDelta delta = ClasspathModifier.removeFromBuildpath(toRemove, cpProject); assertDeltaResources( delta, new IPath[0], new IPath[] {src1.getPath(), src2.getPath()}, new IPath[0], new IPath[0]); assertDeltaDefaultOutputFolder( delta, fJavaProject.getPath().append(DEFAULT_OUTPUT_FOLDER_NAME)); assertDeltaRemovedEntries(delta, new IPath[] {src1.getPath(), src2.getPath()}); assertDeltaAddedEntries(delta, new IPath[0]); ClasspathModifier.commitClassPath(cpProject, null); IClasspathEntry[] classpathEntries = fJavaProject.getRawClasspath(); assertNumberOfEntries(classpathEntries, 1); }
public void testCuGetClass2() throws Exception { // Test for https://bugs.eclipse.org/bugs/show_bug.cgi?id=211037 // In 1.6, Object#getClass() declares return type Class<?>, but in 1.5, it's Class<? extends // Object>. performCuOK(); // Test the same with 1.5: IJavaProject project = RefactoringTestSetup.getProject(); ArrayList classpath = new ArrayList(Arrays.asList(project.getRawClasspath())); IClasspathEntry jreEntry = RefactoringTestSetup.getJRELibrary().getRawClasspathEntry(); classpath.remove(jreEntry); IClasspathEntry[] noRTJarCPEs = (IClasspathEntry[]) classpath.toArray(new IClasspathEntry[classpath.size()]); project.setRawClasspath(noRTJarCPEs, new NullProgressMonitor()); JavaProjectHelper.addRTJar15(project); try { performCuOK(); } finally { project.setRawClasspath(noRTJarCPEs, new NullProgressMonitor()); JavaProjectHelper.addRTJar16(project); } }
public void testJUnitWithCloneNotRaw() throws Exception { fAssumeCloneReturnsSameType = true; fLeaveUnconstrainedRaw = false; IJavaProject javaProject = JavaProjectHelper.createJavaProject("InferTypeArguments", "bin"); try { IPackageFragmentRoot jdk = JavaProjectHelper.addRTJar(javaProject); Assert.assertNotNull(jdk); File junitSrcArchive = JavaTestPlugin.getDefault().getFileInPlugin(JavaProjectHelper.JUNIT_SRC_381); Assert.assertTrue(junitSrcArchive != null && junitSrcArchive.exists()); IPackageFragmentRoot src = JavaProjectHelper.addSourceContainerWithImport( javaProject, "src", junitSrcArchive, JavaProjectHelper.JUNIT_SRC_ENCODING); boolean performed = perform(new IJavaElement[] {javaProject}, RefactoringStatus.OK, RefactoringStatus.OK); assertTrue(performed); compareWithZipFile(src, "junit381-noUI-clone-not-raw-src.zip"); } finally { if (javaProject != null && javaProject.exists()) JavaProjectHelper.delete(javaProject); } }
public void testAddSafeVarargsToDeclaration5() throws Exception { JavaProjectHelper.set15CompilerOptions(fJProject1); try { IPackageFragment pack1 = fSourceFolder.createPackageFragment("p", false, null); StringBuffer buf = new StringBuffer(); buf.append("package p;\n"); buf.append("import java.util.List;\n"); buf.append("public class E {\n"); buf.append(" void foo() {\n"); buf.append(" Y.asList(Y.asList(\"Hello\", \" World\"));\n"); buf.append(" }\n"); buf.append("}\n"); buf.append("class Y {\n"); buf.append(" public static <T> List<T> asList(T... a) {\n"); buf.append(" return null;\n"); buf.append(" }\n"); buf.append("}\n"); ICompilationUnit cu = pack1.createCompilationUnit("E.java", buf.toString(), false, null); CompilationUnit astRoot = getASTRoot(cu); ArrayList<IJavaCompletionProposal> proposals = collectCorrections(cu, astRoot); assertNumberOfProposals(proposals, 2); assertProposalDoesNotExist(proposals, "Add @SafeVarargs to 'asList(..)'"); } finally { JavaProjectHelper.set17CompilerOptions(fJProject1); } }
public void setUp() throws Exception { fJavaProject1 = JavaProjectHelper.createJavaProject("TestProject1", "bin"); fJavaProject2 = JavaProjectHelper.createJavaProject("TestProject2", "bin"); fType1 = null; fType2 = null; fPack1 = null; fPack2 = null; }
private static IJavaProject createProject(String defaultOutputFolder) throws CoreException { IJavaProject result = JavaProjectHelper.createJavaProject(PROJECT_NAME, defaultOutputFolder); IPath[] rtJarPath = JavaProjectHelper.findRtJar(JavaProjectHelper.RT_STUBS_15); result.setRawClasspath( new IClasspathEntry[] { JavaCore.newLibraryEntry(rtJarPath[0], rtJarPath[1], rtJarPath[2], true) }, null); return result; }
public void testEditOutputFolder04RemoveProjectAndExcludeOutput() throws Exception { fJavaProject = createProject(null); // Use the old behavior in order to test the fallback code. Set to ERROR since 3.8. fJavaProject.setOption( JavaCore.CORE_OUTPUT_LOCATION_OVERLAPPING_ANOTHER_SOURCE, JavaCore.IGNORE); JavaProjectHelper.addSourceContainer( fJavaProject, null, new IPath[] {new Path("src1/"), new Path("src2/")}); IPackageFragmentRoot src1 = JavaProjectHelper.addSourceContainer(fJavaProject, "src1"); IPackageFragmentRoot src2 = JavaProjectHelper.addSourceContainer(fJavaProject, "src2"); IPath projectPath = fJavaProject.getProject().getFullPath(); IPath outputPath = projectPath.append("src2").append(DEFAULT_OUTPUT_FOLDER_NAME); CPJavaProject cpProject = CPJavaProject.createFromExisting(fJavaProject); CPListElement element = cpProject.getCPElement( CPListElement.createFromExisting(src1.getRawClasspathEntry(), fJavaProject)); IStatus status = ClasspathModifier.checkSetOutputLocationPrecondition(element, outputPath, false, cpProject); assertTrue(status.getMessage(), status.getSeverity() == IStatus.INFO); BuildpathDelta delta = ClasspathModifier.setOutputLocation(element, outputPath, false, cpProject); assertDeltaResources(delta, new IPath[] {outputPath}, new IPath[0], new IPath[0], new IPath[0]); assertDeltaDefaultOutputFolder( delta, fJavaProject.getPath().append(DEFAULT_OUTPUT_FOLDER_NAME)); assertDeltaRemovedEntries(delta, new IPath[] {fJavaProject.getPath()}); assertDeltaAddedEntries(delta, new IPath[0]); ClasspathModifier.commitClassPath(cpProject, null); assertTrue( "Default output folder was not set to bin", fJavaProject .getOutputLocation() .equals(fJavaProject.getPath().append(DEFAULT_OUTPUT_FOLDER_NAME))); IClasspathEntry[] classpathEntries = fJavaProject.getRawClasspath(); assertNumberOfEntries(classpathEntries, 3); IClasspathEntry entry = classpathEntries[1]; assertTrue(src1.getRawClasspathEntry() == entry); IPath location = entry.getOutputLocation(); assertTrue( "Output path is " + location + " expected was " + outputPath, outputPath.equals(location)); entry = classpathEntries[2]; assertTrue(src2.getRawClasspathEntry() == entry); IPath[] exclusionPatterns = entry.getExclusionPatterns(); assertTrue(exclusionPatterns.length == 1); assertTrue(exclusionPatterns[0].toString().equals("bin/")); }
/** * Creates two packages (pack1 and pack2) in different projects. Sets the instance fields fPack1 * and fPack2. */ public void createPackages() throws CoreException, JavaModelException { JavaProjectHelper.addRTJar(fJavaProject1); IPackageFragmentRoot root1 = JavaProjectHelper.addSourceContainer(fJavaProject1, "src"); fPack1 = root1.createPackageFragment("pack1", true, null); JavaProjectHelper.addRTJar(fJavaProject2); JavaProjectHelper.addRequiredProject(fJavaProject2, fJavaProject1); IPackageFragmentRoot root2 = JavaProjectHelper.addSourceContainer(fJavaProject2, "src"); fPack2 = root2.createPackageFragment("pack2", true, null); }
/** * Removes contents of {@link #getPackageP()}, of {@link #getRoot()} (except for p) and of the * Java project (except for src and the JRE library). * * @throws Exception in case of errors */ protected void tearDown() throws Exception { refreshFromLocal(); performDummySearch(); final boolean pExists = getPackageP().exists(); if (pExists) { tryDeletingAllJavaChildren(getPackageP()); tryDeletingAllNonJavaChildResources(getPackageP()); } if (getRoot().exists()) { IJavaElement[] packages = getRoot().getChildren(); for (int i = 0; i < packages.length; i++) { IPackageFragment pack = (IPackageFragment) packages[i]; if (!pack.equals(getPackageP()) && pack.exists() && !pack.isReadOnly()) if (pack.isDefaultPackage()) pack.delete(true, null); else JavaProjectHelper.delete(pack.getResource()); // also delete packages with subpackages } // Restore package 'p' if (!pExists) getRoot().createPackageFragment("p", true, null); tryDeletingAllNonJavaChildResources(getRoot()); } restoreTestProject(); }
public void testRemoveFromBuildpathBug153299Lib() throws Exception { fJavaProject = createProject(null); IPackageFragmentRoot p01 = JavaProjectHelper.addSourceContainer(fJavaProject, null, new IPath[] {new Path("src1/")}); CPJavaProject cpProject = CPJavaProject.createFromExisting(fJavaProject); IPath[] jarPaths = new IPath[] {JavaProjectHelper.MYLIB.makeAbsolute()}; ClasspathModifier.addExternalJars(jarPaths, cpProject); ClasspathModifier.commitClassPath(cpProject, null); cpProject = CPJavaProject.createFromExisting(fJavaProject); BuildpathDelta delta = ClasspathModifier.removeFromBuildpath( new CPListElement[] { CPListElement.createFromExisting(p01.getRawClasspathEntry(), fJavaProject) }, cpProject); assertDeltaResources(delta, new IPath[0], new IPath[] {}, new IPath[0], new IPath[0]); assertDeltaDefaultOutputFolder(delta, fJavaProject.getPath()); assertDeltaRemovedEntries(delta, new IPath[] {p01.getPath()}); assertDeltaAddedEntries(delta, new IPath[0]); ClasspathModifier.commitClassPath(cpProject, null); IClasspathEntry[] classpathEntries = fJavaProject.getRawClasspath(); assertNumberOfEntries(classpathEntries, 2); }
public void testEditOutputFolder05CannotOutputToSource() throws Exception { fJavaProject = createProject(DEFAULT_OUTPUT_FOLDER_NAME); IPackageFragmentRoot src1 = JavaProjectHelper.addSourceContainer(fJavaProject, "src1"); JavaProjectHelper.addSourceContainer(fJavaProject, "src2"); IPath projectPath = fJavaProject.getProject().getFullPath(); IPath outputPath = projectPath.append("src2"); CPJavaProject cpProject = CPJavaProject.createFromExisting(fJavaProject); CPListElement element = cpProject.getCPElement( CPListElement.createFromExisting(src1.getRawClasspathEntry(), fJavaProject)); IStatus status = ClasspathModifier.checkSetOutputLocationPrecondition(element, outputPath, false, cpProject); assertTrue(status.getMessage(), status.getSeverity() == IStatus.ERROR); }
public void testEditOutputFolder01SetOutputFolderForSourceFolder() throws Exception { fJavaProject = createProject(DEFAULT_OUTPUT_FOLDER_NAME); IPackageFragmentRoot src = JavaProjectHelper.addSourceContainer(fJavaProject, "src"); IPath projectPath = fJavaProject.getProject().getFullPath(); IPath outputPath = projectPath.append("srcbin"); CPJavaProject cpProject = CPJavaProject.createFromExisting(fJavaProject); CPListElement element = cpProject.getCPElement( CPListElement.createFromExisting(src.getRawClasspathEntry(), fJavaProject)); IStatus status = ClasspathModifier.checkSetOutputLocationPrecondition(element, outputPath, false, cpProject); assertTrue(status.getMessage(), status.getSeverity() != IStatus.ERROR); BuildpathDelta delta = ClasspathModifier.setOutputLocation(element, outputPath, false, cpProject); assertDeltaResources(delta, new IPath[] {outputPath}, new IPath[0], new IPath[0], new IPath[0]); assertDeltaDefaultOutputFolder(delta, fJavaProject.getOutputLocation()); assertDeltaAddedEntries(delta, new IPath[0]); assertDeltaRemovedEntries(delta, new IPath[0]); ClasspathModifier.commitClassPath(cpProject, null); IClasspathEntry[] classpathEntries = fJavaProject.getRawClasspath(); assertNumberOfEntries(classpathEntries, 2); IClasspathEntry entry = classpathEntries[1]; assertTrue(src.getRawClasspathEntry() == entry); IPath location = entry.getOutputLocation(); assertTrue( "Output path is " + location + " expected was " + outputPath, outputPath.equals(location)); }
private void restoreTestProject() throws Exception { IJavaProject javaProject = getRoot().getJavaProject(); if (javaProject.exists()) { IClasspathEntry srcEntry = getRoot().getRawClasspathEntry(); IClasspathEntry jreEntry = RefactoringTestSetup.getJRELibrary().getRawClasspathEntry(); IClasspathEntry[] cpes = javaProject.getRawClasspath(); ArrayList newCPEs = new ArrayList(); boolean cpChanged = false; for (int i = 0; i < cpes.length; i++) { IClasspathEntry cpe = cpes[i]; if (cpe.equals(srcEntry) || cpe.equals(jreEntry)) { newCPEs.add(cpe); } else { cpChanged = true; } } if (cpChanged) { IClasspathEntry[] newCPEsArray = (IClasspathEntry[]) newCPEs.toArray(new IClasspathEntry[newCPEs.size()]); javaProject.setRawClasspath(newCPEsArray, null); } Object[] nonJavaResources = javaProject.getNonJavaResources(); for (int i = 0; i < nonJavaResources.length; i++) { Object kid = nonJavaResources[i]; if (kid instanceof IResource) { IResource resource = (IResource) kid; if (!PROJECT_RESOURCE_CHILDREN.contains(resource.getName())) { JavaProjectHelper.delete(resource); } } } } }
/** * Creates a Java project with JUnit source and rt.jar from {@link #addVariableRTJar(IJavaProject, * String, String, String)}. * * @param projectName the project name * @param srcContainerName the source container name * @param outputFolderName the output folder name * @return the IJavaProject * @throws CoreException * @throws IOException * @throws InvocationTargetException * @since 3.1 */ public static IJavaProject createJavaProjectWithJUnitSource( String projectName, String srcContainerName, String outputFolderName) throws CoreException, IOException, InvocationTargetException { IJavaProject project = createJavaProject(projectName, outputFolderName); IPackageFragmentRoot jdk = JavaProjectHelper.addVariableRTJar(project, "JRE_LIB_TEST", null, null); // $NON-NLS-1$ Assert.assertNotNull(jdk); File junitSrcArchive = JavaTestPlugin.getDefault().getFileInPlugin(JUNIT_SRC_381); Assert.assertTrue(junitSrcArchive != null && junitSrcArchive.exists()); JavaProjectHelper.addSourceContainerWithImport( project, srcContainerName, junitSrcArchive, JUNIT_SRC_ENCODING); return project; }
private static void tryDeletingAllJavaChildren(IPackageFragment pack) throws CoreException { IJavaElement[] kids = pack.getChildren(); for (int i = 0; i < kids.length; i++) { if (kids[i] instanceof ISourceManipulation) { if (kids[i].exists() && !kids[i].isReadOnly()) JavaProjectHelper.delete(kids[i]); } } }
public static IPackageFragmentRoot addRTJar13(IJavaProject jproject) throws CoreException { IPath[] rtJarPath = findRtJar(RT_STUBS_13); Map options = jproject.getOptions(false); JavaProjectHelper.set13CompilerOptions(options); jproject.setOptions(options); return addLibrary(jproject, rtJarPath[0], rtJarPath[1], rtJarPath[2]); }
private static void tryDeletingAllNonJavaChildResources(IPackageFragmentRoot root) throws CoreException { Object[] nonJavaKids = root.getNonJavaResources(); for (int i = 0; i < nonJavaKids.length; i++) { if (nonJavaKids[i] instanceof IResource) { IResource resource = (IResource) nonJavaKids[i]; JavaProjectHelper.delete(resource); } } }
protected void launchTests(String prefixForErrorMessage, int howManyNumbersInErrorString) throws CoreException, JavaModelException { // have to set up an 1.3 project to avoid requiring a 5.0 VM JavaProjectHelper.addRTJar13(fProject); JavaProjectHelper.addVariableEntry(fProject, new Path("JUNIT_HOME/junit.jar"), null, null); IPackageFragmentRoot root = JavaProjectHelper.addSourceContainer(fProject, "src"); IPackageFragment pack = root.createPackageFragment("pack", true, null); ICompilationUnit cu1 = pack.getCompilationUnit("LongTraceLines.java"); String initialString = prefixForErrorMessage + "Numbers:"; String initializeString = "String errorString = \"" + initialString + "\";"; String contents = "public class LongTraceLines extends TestCase {\n" + " public void testLongTraceLine() throws Exception {\n" + (" " + initializeString + "\n") + (" for (int i = 0; i < " + howManyNumbersInErrorString + "; i++) {\n") + " errorString += \" \" + i;\n" + " }\n" + " throw new RuntimeException(errorString);\n" + " }\n" + "}"; IType type = cu1.createType(contents, null, true, null); cu1.createImport("junit.framework.TestCase", null, Flags.AccDefault, null); cu1.createImport("java.util.Arrays", null, Flags.AccDefault, null); ILaunchManager lm = DebugPlugin.getDefault().getLaunchManager(); lm.addLaunchListener(this); LaunchConfigurationManager manager = DebugUIPlugin.getDefault().getLaunchConfigurationManager(); List launchShortcuts = manager.getLaunchShortcuts(); LaunchShortcutExtension ext = null; for (Iterator iter = launchShortcuts.iterator(); iter.hasNext(); ) { ext = (LaunchShortcutExtension) iter.next(); if (ext.getLabel().equals("JUnit Test")) break; } ext.launch(new StructuredSelection(type), ILaunchManager.RUN_MODE); }
@Override protected void setUp() throws Exception { Hashtable<String, String> options = TestOptions.getDefaultOptions(); options.put(DefaultCodeFormatterConstants.FORMATTER_TAB_CHAR, JavaCore.SPACE); options.put(DefaultCodeFormatterConstants.FORMATTER_TAB_SIZE, "4"); JavaCore.setOptions(options); IPreferenceStore store = JavaPlugin.getDefault().getPreferenceStore(); store.setValue(PreferenceConstants.CODEGEN_ADD_COMMENTS, false); fJProject1 = ProjectTestSetup.getProject(); fSourceFolder = JavaProjectHelper.addSourceContainer(fJProject1, "src"); }
public void testEditOutputFolderBug154044() throws Exception { fJavaProject = createProject(DEFAULT_OUTPUT_FOLDER_NAME); IPackageFragmentRoot src1 = JavaProjectHelper.addSourceContainer(fJavaProject, "src1"); IPath projectPath = fJavaProject.getProject().getFullPath(); IPath oldOutputPath = projectPath.append("src1").append("sub").append(DEFAULT_OUTPUT_FOLDER_NAME); CPJavaProject cpProject = CPJavaProject.createFromExisting(fJavaProject); CPListElement element = cpProject.getCPElement( CPListElement.createFromExisting(src1.getRawClasspathEntry(), fJavaProject)); ClasspathModifier.setOutputLocation(element, oldOutputPath, false, cpProject); ClasspathModifier.commitClassPath(cpProject, null); IPath outputPath = projectPath.append("src1").append("sub").append("newBin"); cpProject = CPJavaProject.createFromExisting(fJavaProject); element = cpProject.getCPElement( CPListElement.createFromExisting(src1.getRawClasspathEntry(), fJavaProject)); IStatus status = ClasspathModifier.checkSetOutputLocationPrecondition(element, outputPath, false, cpProject); assertTrue(status.getMessage(), status.isOK()); BuildpathDelta delta = ClasspathModifier.setOutputLocation(element, outputPath, false, cpProject); assertDeltaResources( delta, new IPath[] {outputPath}, new IPath[] {oldOutputPath}, new IPath[0], new IPath[0]); assertDeltaDefaultOutputFolder( delta, fJavaProject.getPath().append(DEFAULT_OUTPUT_FOLDER_NAME)); assertDeltaRemovedEntries(delta, new IPath[0]); assertDeltaAddedEntries(delta, new IPath[0]); ClasspathModifier.commitClassPath(cpProject, null); IClasspathEntry[] classpathEntries = fJavaProject.getRawClasspath(); assertNumberOfEntries(classpathEntries, 2); IClasspathEntry entry = classpathEntries[1]; assertTrue(src1.getRawClasspathEntry() == entry); IPath location = entry.getOutputLocation(); assertTrue( "Output path is " + location + " expected was " + outputPath, outputPath.equals(location)); IPath[] exclusionPatterns = entry.getExclusionPatterns(); assertTrue(exclusionPatterns.length == 1); assertTrue( exclusionPatterns[0].toString(), exclusionPatterns[0].toString().equals("sub/newBin/")); }
/** * Removes all files in the project and sets the given classpath * * @param jproject The project to clear * @param entries The default class path to set * @throws Exception Clearing the project failed */ public static void clear(final IJavaProject jproject, final IClasspathEntry[] entries) throws Exception { performDummySearch(); IWorkspaceRunnable runnable = new IWorkspaceRunnable() { public void run(IProgressMonitor monitor) throws CoreException { jproject.setRawClasspath(entries, null); IResource[] resources = jproject.getProject().members(); for (int i = 0; i < resources.length; i++) { if (!resources[i].getName().startsWith(".")) { delete(resources[i]); } } } }; ResourcesPlugin.getWorkspace().run(runnable, null); JavaProjectHelper.emptyDisplayLoop(); }
@Override protected void setUp() throws Exception { Hashtable<String, String> options = TestOptions.getDefaultOptions(); options.put(DefaultCodeFormatterConstants.FORMATTER_TAB_CHAR, JavaCore.SPACE); options.put(DefaultCodeFormatterConstants.FORMATTER_TAB_SIZE, "4"); options.put( DefaultCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_AFTER_ANNOTATION_ON_LOCAL_VARIABLE, JavaCore.DO_NOT_INSERT); JavaCore.setOptions(options); IPreferenceStore store = JavaPlugin.getDefault().getPreferenceStore(); store.setValue(PreferenceConstants.CODEGEN_ADD_COMMENTS, false); fJProject1 = Java18ProjectTestSetup.getProject(); StubUtility.setCodeTemplate(CodeTemplateContextType.METHODSTUB_ID, "", null); StubUtility.setCodeTemplate(CodeTemplateContextType.CONSTRUCTORSTUB_ID, "", null); fSourceFolder = JavaProjectHelper.addSourceContainer(fJProject1, "src"); }
public void testRemoveFromBuildpath01RemoveProject() throws Exception { fJavaProject = createProject(null); IPackageFragmentRoot p01 = JavaProjectHelper.addSourceContainer(fJavaProject, null); CPJavaProject cpProject = CPJavaProject.createFromExisting(fJavaProject); BuildpathDelta delta = ClasspathModifier.removeFromBuildpath( new CPListElement[] { CPListElement.createFromExisting(p01.getRawClasspathEntry(), fJavaProject) }, cpProject); assertDeltaResources(delta, new IPath[0], new IPath[] {}, new IPath[0], new IPath[0]); assertDeltaDefaultOutputFolder(delta, fJavaProject.getPath()); assertDeltaRemovedEntries(delta, new IPath[] {p01.getPath()}); assertDeltaAddedEntries(delta, new IPath[0]); ClasspathModifier.commitClassPath(cpProject, null); IClasspathEntry[] classpathEntries = fJavaProject.getRawClasspath(); assertNumberOfEntries(classpathEntries, 1); }
protected void tearDown() throws Exception { JavaProjectHelper.delete(fProject); }
/** * Sets the compiler options to 1.4 for the given project. * * @param project the java project */ public static void set14CompilerOptions(IJavaProject project) { Map options = project.getOptions(false); JavaProjectHelper.set14CompilerOptions(options); project.setOptions(options); }
protected void tearDown() throws Exception { if (fJavaProject != null) { JavaProjectHelper.delete(fJavaProject); fJavaProject = null; } }
/** * Invokes the introduce indirection ref. Some pointers: * * @param topLevelName This is an array of fully qualified top level(!) type names with exactly * one package prefix (e.g. "p.Foo"). Simple names must correspond to .java files. The first * cu will be used for the invocation of the refactoring (see positioning) * @param newName name of indirection method * @param qTypeName qualified type name of the type for the indirection method. Should be one of * the cus in topLevelName. * @param startLine starting line of selection in topLevelName[0] * @param startColumn starting column of selection in topLevelName[0] * @param endLine ending line of selection in topLevelName[0] * @param endColumn ending column of selection in topLevelName[0] * @param updateReferences true if references should be updated * @param shouldWarn if true, warnings will be expected in the result * @param shouldError if true, errors will be expected in the result * @param shouldFail if true, fatal errors will be expected in the result * @throws Exception * @throws JavaModelException * @throws CoreException * @throws IOException */ private void helper( String[] topLevelName, String newName, String qTypeName, int startLine, int startColumn, int endLine, int endColumn, boolean updateReferences, boolean shouldWarn, boolean shouldError, boolean shouldFail) throws Exception, JavaModelException, CoreException, IOException { ICompilationUnit[] cu = new ICompilationUnit[topLevelName.length]; for (int i = 0; i < topLevelName.length; i++) { String packName = topLevelName[i].substring(0, topLevelName[i].indexOf('.')); String className = topLevelName[i].substring(topLevelName[i].indexOf('.') + 1); IPackageFragment cPackage = getRoot().createPackageFragment(packName, true, null); cu[i] = createCUfromTestFile(cPackage, className); } ISourceRange selection = TextRangeUtil.getSelection(cu[0], startLine, startColumn, endLine, endColumn); try { IntroduceIndirectionRefactoring ref = new IntroduceIndirectionRefactoring(cu[0], selection.getOffset(), selection.getLength()); ref.setEnableUpdateReferences(updateReferences); if (qTypeName != null) ref.setIntermediaryClassName(qTypeName); if (newName != null) ref.setIntermediaryMethodName(newName); boolean failed = false; RefactoringStatus status = performRefactoringWithStatus(ref); if (status.hasFatalError()) { assertTrue( "Failed but shouldn't: " + status.getMessageMatchingSeverity(RefactoringStatus.FATAL), shouldFail); failed = true; } else assertFalse("Didn't fail although expected", shouldFail); if (!failed) { if (status.hasError()) assertTrue( "Had errors but shouldn't: " + status.getMessageMatchingSeverity(RefactoringStatus.ERROR), shouldError); else assertFalse("No error although expected", shouldError); if (status.hasWarning()) assertTrue( "Had warnings but shouldn't: " + status.getMessageMatchingSeverity(RefactoringStatus.WARNING), shouldWarn); else assertFalse("No warning although expected", shouldWarn); for (int i = 0; i < topLevelName.length; i++) { String className = topLevelName[i].substring(topLevelName[i].indexOf('.') + 1); assertEqualLines( "invalid output.", getFileContents(getOutputTestFileName(className)), cu[i].getSource()); } } } finally { for (int i = 0; i < topLevelName.length; i++) JavaProjectHelper.delete(cu[i]); } }
protected void performDummySearch() throws Exception { JavaProjectHelper.performDummySearch(getPackageP()); }