use of org.eclipse.jdt.core.IPackageFragmentRoot in project che by eclipse.
the class ImportOrganizeTest method testBaseGroups1.
@Test
public void testBaseGroups1() throws Exception {
IPackageFragmentRoot sourceFolder = JavaProjectHelper.addSourceContainer(fJProject1, "src");
IPackageFragment pack2 = sourceFolder.createPackageFragment("pack0", false, null);
StringBuffer buf = new StringBuffer();
buf.append("package pack0;\n");
buf.append("public class List1 {\n");
buf.append("}\n");
pack2.createCompilationUnit("List1.java", buf.toString(), false, null);
IPackageFragment pack1 = sourceFolder.createPackageFragment("pack1", false, null);
buf = new StringBuffer();
buf.append("package pack1;\n");
buf.append("\n");
buf.append("public class C {\n");
buf.append(" File f;\n");
buf.append(" IOException f1;\n");
buf.append(" RandomAccessFile f2;\n");
buf.append(" ArrayList f3;\n");
buf.append(" List1 f4;\n");
buf.append("}\n");
ICompilationUnit cu = pack1.createCompilationUnit("C.java", buf.toString(), false, null);
String[] order = new String[] { "java", "java.io" };
IChooseImportQuery query = createQuery("C", new String[] {}, new int[] {});
OrganizeImportsOperation op = createOperation(cu, order, 99, false, true, true, query);
op.run(null);
buf = new StringBuffer();
buf.append("package pack1;\n");
buf.append("\n");
buf.append("import java.util.ArrayList;\n");
buf.append("\n");
buf.append("import java.io.File;\n");
buf.append("import java.io.IOException;\n");
buf.append("import java.io.RandomAccessFile;\n");
buf.append("\n");
buf.append("import pack0.List1;\n");
buf.append("\n");
buf.append("public class C {\n");
buf.append(" File f;\n");
buf.append(" IOException f1;\n");
buf.append(" RandomAccessFile f2;\n");
buf.append(" ArrayList f3;\n");
buf.append(" List1 f4;\n");
buf.append("}\n");
assertEqualString(cu.getSource(), buf.toString());
}
use of org.eclipse.jdt.core.IPackageFragmentRoot in project che by eclipse.
the class RenamePackageTest method testImportFromMultiRoots4.
@Test
@Ignore
public void testImportFromMultiRoots4() throws Exception {
//circular buildpath references
IJavaProject projectPrg = null;
IJavaProject projectTest = null;
Hashtable options = JavaCore.getOptions();
Object cyclicPref = JavaCore.getOption(JavaCore.CORE_CIRCULAR_CLASSPATH);
try {
projectPrg = JavaProjectHelper.createJavaProject("RenamePack1", "bin");
assertNotNull(JavaProjectHelper.addRTJar(projectPrg));
IPackageFragmentRoot srcPrg = JavaProjectHelper.addSourceContainer(projectPrg, "srcPrg");
projectTest = JavaProjectHelper.createJavaProject("RenamePack2", "bin");
assertNotNull(JavaProjectHelper.addRTJar(projectTest));
IPackageFragmentRoot srcTest = JavaProjectHelper.addSourceContainer(projectTest, "srcTest");
options.put(JavaCore.CORE_CIRCULAR_CLASSPATH, JavaCore.WARNING);
JavaCore.setOptions(options);
JavaProjectHelper.addRequiredProject(projectTest, projectPrg);
JavaProjectHelper.addRequiredProject(projectPrg, projectTest);
helperMultiProjects(new IPackageFragmentRoot[] { srcPrg, srcTest }, new String[][] { new String[] { "p" }, new String[] { "p" } }, "a.b.c", new String[][][] { new String[][] { new String[] { "A", "B" } }, new String[][] { new String[] { "ATest" } } });
} finally {
options.put(JavaCore.CORE_CIRCULAR_CLASSPATH, cyclicPref);
JavaCore.setOptions(options);
JavaProjectHelper.delete(projectPrg);
JavaProjectHelper.delete(projectTest);
}
}
use of org.eclipse.jdt.core.IPackageFragmentRoot in project che by eclipse.
the class RenamePackageTest method helperProjectsPrgTest.
/**
* 2 Projects with a root each: Project RenamePack2 (root: srcTest) requires project RenamePack1
* (root: srcPrg).
*
* @param packageNames package names per root
* @param newPackageName the new package name for packageNames[0][0]
* @param cuNames cu names per package
* @throws Exception if one of the resources cannot be created
*/
private void helperProjectsPrgTest(String[][] packageNames, String newPackageName, String[][][] cuNames) throws Exception {
IJavaProject projectPrg = null;
IJavaProject projectTest = null;
try {
projectPrg = JavaProjectHelper.createJavaProject("RenamePack1", "bin");
assertNotNull(JavaProjectHelper.addRTJar(projectPrg));
IPackageFragmentRoot srcPrg = JavaProjectHelper.addSourceContainer(projectPrg, "srcPrg");
Map optionsPrg = projectPrg.getOptions(false);
JavaProjectHelper.set15CompilerOptions(optionsPrg);
projectPrg.setOptions(optionsPrg);
projectTest = JavaProjectHelper.createJavaProject("RenamePack2", "bin");
assertNotNull(JavaProjectHelper.addRTJar(projectTest));
IPackageFragmentRoot srcTest = JavaProjectHelper.addSourceContainer(projectTest, "srcTest");
Map optionsTest = projectTest.getOptions(false);
JavaProjectHelper.set15CompilerOptions(optionsTest);
projectTest.setOptions(optionsTest);
JavaProjectHelper.addRequiredProject(projectTest, projectPrg);
helperMultiProjects(new IPackageFragmentRoot[] { srcPrg, srcTest }, packageNames, newPackageName, cuNames);
} finally {
JavaProjectHelper.delete(projectPrg);
JavaProjectHelper.delete(projectTest);
}
}
use of org.eclipse.jdt.core.IPackageFragmentRoot in project tdi-studio-se by Talend.
the class JobJavaScriptsManager method getSrcRootLocation.
/**
* Get the path of .JAVA/src
*
* @throws Exception
*/
protected IPath getSrcRootLocation() throws Exception {
ITalendProcessJavaProject talendProcessJavaProject = RepositoryPlugin.getDefault().getRunProcessService().getTalendProcessJavaProject();
if (talendProcessJavaProject == null) {
//$NON-NLS-1$
return new Path("");
}
IProject project = talendProcessJavaProject.getProject();
IJavaProject javaProject = talendProcessJavaProject.getJavaProject();
IPackageFragmentRoot[] pp = javaProject.getAllPackageFragmentRoots();
IPackageFragmentRoot src = null;
for (IPackageFragmentRoot root : pp) {
if (root.getKind() == IPackageFragmentRoot.K_SOURCE) {
src = root;
break;
}
}
IPath root = project.getParent().getLocation();
root = root.append(src.getPath());
return root;
}
use of org.eclipse.jdt.core.IPackageFragmentRoot in project tdi-studio-se by Talend.
the class AddPackageDialog method getPackageFragments.
/**
* Gets the package fragments.
*
* @param javaModel The java model
* @return The package fragments
*/
private Object[] getPackageFragments(IJavaModel javaModel) {
Set<String> packageElements = new HashSet<String>();
IJavaProject[] projects;
try {
projects = javaModel.getJavaProjects();
} catch (JavaModelException e) {
Activator.log(IStatus.ERROR, Messages.getJavaModelFailedMsg, e);
return new Object[0];
}
for (IJavaProject project : projects) {
if (EXTERNAL_PLUGIN_LIBRARIES.equals(project.getResource().getName())) {
continue;
}
IPackageFragmentRoot[] packageFragmentRoots;
try {
packageFragmentRoots = project.getPackageFragmentRoots();
} catch (JavaModelException e) {
continue;
}
for (IPackageFragmentRoot packageFragment : packageFragmentRoots) {
try {
addPackage(packageElements, packageFragment);
} catch (JavaModelException e) {
// do nothing
}
}
}
for (Object packageName : filteringPackages) {
packageElements.remove(packageName);
}
return packageElements.toArray(new String[0]);
}
Aggregations