Search in sources :

Example 96 with IPackageFragment

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

the class JavaModelManager method createCompilationUnitFrom.

/**
     * Creates and returns a compilation unit element for the given <code>.java</code>
     * file, its project being the given project. Returns <code>null</code> if unable
     * to recognize the compilation unit.
     */
public static ICompilationUnit createCompilationUnitFrom(IFile file, IJavaProject project) {
    if (file == null)
        return null;
    if (project == null) {
        project = JavaCore.create(file.getProject());
    }
    IPackageFragment pkg = (IPackageFragment) determineIfOnClasspath(file, project);
    if (pkg == null) {
        // not on classpath - make the root its folder, and a default package
        PackageFragmentRoot root = (PackageFragmentRoot) project.getPackageFragmentRoot(file.getParent());
        pkg = root.getPackageFragment(CharOperation.NO_STRINGS);
        if (VERBOSE) {
            System.out.println("WARNING : creating unit element outside classpath (" + Thread.currentThread() + "): " + //$NON-NLS-1$//$NON-NLS-2$
            file.getFullPath());
        }
    }
    return pkg.getCompilationUnit(file.getName());
}
Also used : IPackageFragment(org.eclipse.jdt.core.IPackageFragment) IPackageFragmentRoot(org.eclipse.jdt.core.IPackageFragmentRoot)

Example 97 with IPackageFragment

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

the class JavaModelManager method createClassFileFrom.

/**
     * Creates and returns a class file element for the given <code>.class</code> file,
     * its project being the given project. Returns <code>null</code> if unable
     * to recognize the class file.
     */
public static IClassFile createClassFileFrom(IFile file, IJavaProject project) {
    if (file == null) {
        return null;
    }
    if (project == null) {
        project = JavaCore.create(file.getProject());
    }
    IPackageFragment pkg = (IPackageFragment) determineIfOnClasspath(file, (JavaProject) project);
    if (pkg == null) {
        // fix for 1FVS7WE
        // not on classpath - make the root its folder, and a default package
        PackageFragmentRoot root = (PackageFragmentRoot) project.getPackageFragmentRoot(file.getParent());
        pkg = root.getPackageFragment(CharOperation.NO_STRINGS);
    }
    return pkg.getClassFile(file.getName());
}
Also used : IPackageFragment(org.eclipse.jdt.core.IPackageFragment) IJavaProject(org.eclipse.jdt.core.IJavaProject) IPackageFragmentRoot(org.eclipse.jdt.core.IPackageFragmentRoot)

Example 98 with IPackageFragment

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

the class DeltaProcessor method popUntilPrefixOf.

private void popUntilPrefixOf(IPath path) {
    while (this.currentElement != null) {
        IPath currentElementPath = null;
        if (this.currentElement instanceof IPackageFragmentRoot) {
            currentElementPath = ((IPackageFragmentRoot) this.currentElement).getPath();
        } else {
            IResource currentElementResource = this.currentElement.resource();
            if (currentElementResource != null) {
                currentElementPath = currentElementResource.getFullPath();
            }
        }
        if (currentElementPath != null) {
            if (this.currentElement instanceof IPackageFragment && ((IPackageFragment) this.currentElement).isDefaultPackage() && currentElementPath.segmentCount() != path.segmentCount() - 1) {
                // default package and path is not a direct child
                this.currentElement = (Openable) this.currentElement.getParent();
            }
            if (currentElementPath.isPrefixOf(path)) {
                return;
            }
        }
        this.currentElement = (Openable) this.currentElement.getParent();
    }
}
Also used : IPackageFragment(org.eclipse.jdt.core.IPackageFragment) IPath(org.eclipse.core.runtime.IPath) IResource(org.eclipse.core.resources.IResource) IPackageFragmentRoot(org.eclipse.jdt.core.IPackageFragmentRoot)

Example 99 with IPackageFragment

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

the class LogicalPackage method equals.

@Override
public boolean equals(Object o) {
    if (!(o instanceof LogicalPackage))
        return false;
    LogicalPackage lp = (LogicalPackage) o;
    if (!fJavaProject.equals(lp.getJavaProject()))
        return false;
    IPackageFragment[] fragments = lp.getFragments();
    if (fragments.length != getFragments().length)
        return false;
    //this works because a LogicalPackage cannot contain the same IPackageFragment twice
    for (int i = 0; i < fragments.length; i++) {
        IPackageFragment fragment = fragments[i];
        if (!fPackages.contains(fragment))
            return false;
    }
    return true;
}
Also used : IPackageFragment(org.eclipse.jdt.core.IPackageFragment)

Example 100 with IPackageFragment

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

the class AdvancedQuickAssistTest method testExchangeOperands7.

@Test
public void testExchangeOperands7() throws Exception {
    IPackageFragment pack1 = fSourceFolder.createPackageFragment("test1", false, null);
    StringBuffer buf = new StringBuffer();
    buf.append("package test1;\n");
    buf.append("public class E {\n");
    buf.append("    public boolean foo(int a, int b) {\n");
    buf.append("        return (a >= b);\n");
    buf.append("    }\n");
    buf.append("}\n");
    ICompilationUnit cu = pack1.createCompilationUnit("E.java", buf.toString(), false, null);
    int offset = buf.toString().indexOf(">=");
    AssistContext context = getCorrectionContext(cu, offset, 0);
    assertNoErrors(context);
    List proposals = collectAssists(context, false);
    assertCorrectLabels(proposals);
    buf = new StringBuffer();
    buf.append("package test1;\n");
    buf.append("public class E {\n");
    buf.append("    public boolean foo(int a, int b) {\n");
    buf.append("        return (b <= a);\n");
    buf.append("    }\n");
    buf.append("}\n");
    String expected1 = buf.toString();
    assertExpectedExistInProposals(proposals, new String[] { expected1 });
}
Also used : ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) IPackageFragment(org.eclipse.jdt.core.IPackageFragment) AssistContext(org.eclipse.jdt.internal.ui.text.correction.AssistContext) ArrayList(java.util.ArrayList) List(java.util.List) Test(org.junit.Test)

Aggregations

IPackageFragment (org.eclipse.jdt.core.IPackageFragment)1145 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)1051 Test (org.junit.Test)1039 ArrayList (java.util.ArrayList)754 List (java.util.List)453 CompilationUnit (org.eclipse.jdt.core.dom.CompilationUnit)435 AssistContext (org.eclipse.jdt.internal.ui.text.correction.AssistContext)384 CUCorrectionProposal (org.eclipse.jdt.ui.text.java.correction.CUCorrectionProposal)284 Hashtable (java.util.Hashtable)136 IPackageFragmentRoot (org.eclipse.jdt.core.IPackageFragmentRoot)98 OrganizeImportsOperation (org.eclipse.jdt.internal.corext.codemanipulation.OrganizeImportsOperation)67 IChooseImportQuery (org.eclipse.jdt.internal.corext.codemanipulation.OrganizeImportsOperation.IChooseImportQuery)67 Ignore (org.junit.Ignore)43 IType (org.eclipse.jdt.core.IType)37 IJavaElement (org.eclipse.jdt.core.IJavaElement)30 RefactoringStatus (org.eclipse.ltk.core.refactoring.RefactoringStatus)24 HashMap (java.util.HashMap)23 ASTRewriteCorrectionProposal (org.eclipse.jdt.ui.text.java.correction.ASTRewriteCorrectionProposal)23 BaseTest (org.eclipse.che.plugin.java.server.che.BaseTest)21 Map (java.util.Map)19