Search in sources :

Example 81 with IJavaProject

use of org.eclipse.jdt.core.IJavaProject in project che by eclipse.

the class RenamePackageTest method test1.

//-------
@Test
public void test1() throws Exception {
    fIsPreDeltaTest = true;
    RenamePackageProcessor proc = helper2(new String[] { "r" }, new String[][] { { "A" } }, "p1");
    IJavaElementMapper jm = (IJavaElementMapper) proc.getAdapter(IJavaElementMapper.class);
    IResourceMapper rm = (IResourceMapper) proc.getAdapter(IResourceMapper.class);
    IJavaModel javaModel = JavaCore.create(ResourcesPlugin.getWorkspace().getRoot());
    IJavaProject project = getRoot().getJavaProject();
    IFile _project = project.getProject().getFile(".project");
    checkMappingUnchanged(jm, rm, new Object[] { project, _project, getRoot(), getPackageP(), getRoot().getPackageFragment("inexistent"), getRoot().getPackageFragment("r.inexistent"), getRoot().getPackageFragment("p1.inexistent") });
    IPackageFragment r = getRoot().getPackageFragment("p1");
    ICompilationUnit r_A = r.getCompilationUnit("A.java");
    IType r_A_A = r_A.getType("A");
    IField r_A_A_a = r_A_A.getField("a");
    IPackageFragment p1 = getRoot().getPackageFragment("p1");
    ICompilationUnit p1_A = p1.getCompilationUnit("A.java");
    IType p1_A_A = p1_A.getType("A");
    IField p1_A_A_a = p1_A_A.getField("a");
    checkMappingChanged(jm, rm, new Object[][] { { r, p1 }, { r_A, p1_A }, { r_A_A, p1_A_A }, { r_A_A_a, p1_A_A_a } });
}
Also used : IResourceMapper(org.eclipse.ltk.core.refactoring.IResourceMapper) ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) IPackageFragment(org.eclipse.jdt.core.IPackageFragment) RenamePackageProcessor(org.eclipse.jdt.internal.corext.refactoring.rename.RenamePackageProcessor) IJavaProject(org.eclipse.jdt.core.IJavaProject) IFile(org.eclipse.core.resources.IFile) IJavaElementMapper(org.eclipse.jdt.core.refactoring.IJavaElementMapper) IField(org.eclipse.jdt.core.IField) IJavaModel(org.eclipse.jdt.core.IJavaModel) IType(org.eclipse.jdt.core.IType) Test(org.junit.Test)

Example 82 with IJavaProject

use of org.eclipse.jdt.core.IJavaProject 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);
    }
}
Also used : IJavaProject(org.eclipse.jdt.core.IJavaProject) Map(java.util.Map) IPackageFragmentRoot(org.eclipse.jdt.core.IPackageFragmentRoot)

Example 83 with IJavaProject

use of org.eclipse.jdt.core.IJavaProject 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;
}
Also used : Path(org.eclipse.core.runtime.Path) IPath(org.eclipse.core.runtime.IPath) IJavaProject(org.eclipse.jdt.core.IJavaProject) IPath(org.eclipse.core.runtime.IPath) ITalendProcessJavaProject(org.talend.core.runtime.process.ITalendProcessJavaProject) IProject(org.eclipse.core.resources.IProject) IPackageFragmentRoot(org.eclipse.jdt.core.IPackageFragmentRoot)

Example 84 with IJavaProject

use of org.eclipse.jdt.core.IJavaProject in project tdi-studio-se by Talend.

the class TalendProcessJavaProjectTest method testGetJavaProject.

/**
     * Test method for {@link org.talend.designer.runprocess.java.TalendProcessJavaProject#getJavaProject()}.
     */
@Test
public void testGetJavaProject() {
    IJavaProject javaProject = talendJavaProject.getJavaProject();
    Assert.assertNotNull(javaProject);
    Assert.assertTrue(javaProject.exists());
    Assert.assertTrue(javaProject.isOpen());
    Assert.assertNotNull(javaProject.getProject());
}
Also used : IJavaProject(org.eclipse.jdt.core.IJavaProject) Test(org.junit.Test)

Example 85 with IJavaProject

use of org.eclipse.jdt.core.IJavaProject 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]);
}
Also used : JavaModelException(org.eclipse.jdt.core.JavaModelException) IJavaProject(org.eclipse.jdt.core.IJavaProject) HashSet(java.util.HashSet) IPackageFragmentRoot(org.eclipse.jdt.core.IPackageFragmentRoot)

Aggregations

IJavaProject (org.eclipse.jdt.core.IJavaProject)743 IProject (org.eclipse.core.resources.IProject)178 IFile (org.eclipse.core.resources.IFile)149 Test (org.junit.Test)146 CoreException (org.eclipse.core.runtime.CoreException)127 JavaModelException (org.eclipse.jdt.core.JavaModelException)124 IClasspathEntry (org.eclipse.jdt.core.IClasspathEntry)123 IPath (org.eclipse.core.runtime.IPath)110 IPackageFragmentRoot (org.eclipse.jdt.core.IPackageFragmentRoot)103 ArrayList (java.util.ArrayList)87 IFolder (org.eclipse.core.resources.IFolder)78 IResource (org.eclipse.core.resources.IResource)75 IJavaElement (org.eclipse.jdt.core.IJavaElement)63 IType (org.eclipse.jdt.core.IType)63 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)62 Path (org.eclipse.core.runtime.Path)57 IPackageFragment (org.eclipse.jdt.core.IPackageFragment)56 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)47 StringInputStream (org.eclipse.xtext.util.StringInputStream)39 HashMap (java.util.HashMap)38