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());
}
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());
}
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();
}
}
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;
}
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 });
}
Aggregations