use of org.eclipse.jdt.core.JavaModelException in project xtext-xtend by eclipse.
the class XtendUIValidator method getExpectedPackageName.
protected String getExpectedPackageName(XtendFile xtendFile) {
URI fileURI = xtendFile.eResource().getURI();
for (Pair<IStorage, IProject> storage : storage2UriMapper.getStorages(fileURI)) {
if (storage.getFirst() instanceof IFile) {
IPath fileWorkspacePath = storage.getFirst().getFullPath();
IJavaProject javaProject = JavaCore.create(storage.getSecond());
if (javaProject != null && javaProject.exists() && javaProject.isOpen()) {
try {
for (IPackageFragmentRoot root : javaProject.getPackageFragmentRoots()) {
if (!root.isArchive() && !root.isExternal()) {
IResource resource = root.getResource();
if (resource != null) {
IPath sourceFolderPath = resource.getFullPath();
if (sourceFolderPath.isPrefixOf(fileWorkspacePath)) {
IPath claspathRelativePath = fileWorkspacePath.makeRelativeTo(sourceFolderPath);
return claspathRelativePath.removeLastSegments(1).toString().replace("/", ".");
}
}
}
}
} catch (JavaModelException e) {
LOG.error("Error resolving expected path for XtendFile", e);
}
}
}
}
return null;
}
use of org.eclipse.jdt.core.JavaModelException in project bndtools by bndtools.
the class JavaSearchScopeTestCaseLister method getTestCases.
@Override
public String[] getTestCases(boolean includeNonSource, ITestCaseFilter filter) throws TestCaseListException {
final List<IJavaElement> testCaseList = new LinkedList<IJavaElement>();
//$NON-NLS-1$ //$NON-NLS-2$
search(Arrays.asList("junit.framework.TestCase", "junit.framework.TestSuite"), testCaseList);
// Remove non-source and excludes
Set<String> testCaseNames = new LinkedHashSet<String>();
for (Iterator<IJavaElement> iter = testCaseList.iterator(); iter.hasNext(); ) {
boolean omit = false;
IJavaElement element = iter.next();
try {
IType type = (IType) element.getAncestor(IJavaElement.TYPE);
if (Flags.isAbstract(type.getFlags())) {
omit = true;
}
if (!includeNonSource) {
IPackageFragment pkgFragment = (IPackageFragment) element.getAncestor(IJavaElement.PACKAGE_FRAGMENT);
if (pkgFragment.getCompilationUnits().length == 0) {
omit = true;
}
}
} catch (JavaModelException e) {
throw new TestCaseListException(e);
}
String className = getClassName(element);
if (filter != null && !filter.select(className)) {
omit = true;
}
if (!omit) {
testCaseNames.add(className);
}
}
return testCaseNames.toArray(new String[0]);
}
use of org.eclipse.jdt.core.JavaModelException in project che by eclipse.
the class PlainJavaInitHandler method initializeClasspath.
@Override
protected void initializeClasspath(IJavaProject javaProject) throws ServerException {
IClasspathEntry[] projectClasspath;
try {
projectClasspath = javaProject.getRawClasspath();
} catch (JavaModelException e) {
LOG.warn("Can't get classpath for: " + javaProject.getProject().getFullPath().toOSString(), e);
throw new ServerException(e);
}
//default classpath
IClasspathEntry[] defaultClasspath = new IClasspathEntry[] { JavaCore.newSourceEntry(javaProject.getPath()) };
if (!Arrays.equals(defaultClasspath, projectClasspath)) {
//classpath is already initialized
return;
}
RegisteredProject project = projectRegistryProvider.get().getProject(javaProject.getPath().toOSString());
List<String> sourceFolders = project.getAttributes().get(Constants.SOURCE_FOLDER);
List<String> library = project.getAttributes().get(LIBRARY_FOLDER);
classpathBuilder.generateClasspath(javaProject, sourceFolders, library);
}
use of org.eclipse.jdt.core.JavaModelException in project che by eclipse.
the class CompilationUnitChangeNode method createChildNodes.
@Override
protected ChildNode[] createChildNodes() {
TextEditBasedChange change = getTextEditBasedChange();
if (change instanceof MultiStateTextFileChange) {
// no edit preview & edit disabling possible in the MultiStateTextFileChange (edits must be applied
return new ChildNode[0];
// in sequence)
}
ICompilationUnit cunit = (ICompilationUnit) change.getAdapter(ICompilationUnit.class);
if (cunit != null) {
List<ChildNode> children = new ArrayList<ChildNode>(5);
Map<IJavaElement, JavaLanguageNode> map = new HashMap<IJavaElement, JavaLanguageNode>(20);
TextEditBasedChangeGroup[] changes = getSortedChangeGroups(change);
for (int i = 0; i < changes.length; i++) {
TextEditBasedChangeGroup tec = changes[i];
try {
IJavaElement element = getModifiedJavaElement(tec, cunit);
if (element.equals(cunit)) {
children.add(createTextEditGroupNode(this, tec));
} else {
JavaLanguageNode pjce = getChangeElement(map, element, children, this);
pjce.addChild(createTextEditGroupNode(pjce, tec));
}
} catch (JavaModelException e) {
children.add(createTextEditGroupNode(this, tec));
}
}
return children.toArray(new ChildNode[children.size()]);
} else {
return EMPTY_CHILDREN;
}
}
use of org.eclipse.jdt.core.JavaModelException in project che by eclipse.
the class CompilationUnitChangeNode method getModifiedJavaElement.
private IJavaElement getModifiedJavaElement(TextEditBasedChangeGroup edit, ICompilationUnit cunit) throws JavaModelException {
IRegion range = edit.getRegion();
if (range.getOffset() == 0 && range.getLength() == 0)
return cunit;
IJavaElement result = cunit.getElementAt(range.getOffset());
if (result == null)
return cunit;
try {
while (true) {
ISourceReference ref = (ISourceReference) result;
IRegion sRange = new Region(ref.getSourceRange().getOffset(), ref.getSourceRange().getLength());
if (result.getElementType() == IJavaElement.COMPILATION_UNIT || result.getParent() == null || coveredBy(edit, sRange))
break;
result = result.getParent();
}
} catch (JavaModelException e) {
// Do nothing, use old value.
} catch (ClassCastException e) {
// Do nothing, use old value.
}
return result;
}
Aggregations