use of org.eclipse.jdt.core.JavaModelException in project che by eclipse.
the class DeltaProcessor method createExternalArchiveDelta.
/*
* Check if external archives have changed for the given elements and create the corresponding deltas.
* Returns whether at least one delta was created.
*/
private boolean createExternalArchiveDelta(HashSet refreshedElements, IProgressMonitor monitor) {
HashMap externalArchivesStatus = new HashMap();
boolean hasDelta = false;
// find JARs to refresh
HashSet archivePathsToRefresh = new HashSet();
Iterator iterator = refreshedElements.iterator();
while (iterator.hasNext()) {
IJavaElement element = (IJavaElement) iterator.next();
switch(element.getElementType()) {
case IJavaElement.PACKAGE_FRAGMENT_ROOT:
archivePathsToRefresh.add(element.getPath());
break;
case IJavaElement.JAVA_PROJECT:
JavaProject javaProject = (JavaProject) element;
if (!JavaProject.hasJavaNature(javaProject.getProject())) {
// project is not accessible or has lost its Java nature
break;
}
IClasspathEntry[] classpath;
try {
classpath = javaProject.getResolvedClasspath();
for (int j = 0, cpLength = classpath.length; j < cpLength; j++) {
if (classpath[j].getEntryKind() == IClasspathEntry.CPE_LIBRARY) {
archivePathsToRefresh.add(classpath[j].getPath());
}
}
} catch (JavaModelException e) {
// project doesn't exist -> ignore
}
break;
case IJavaElement.JAVA_MODEL:
// }
throw new UnsupportedOperationException();
}
}
// }
return hasDelta;
}
use of org.eclipse.jdt.core.JavaModelException in project che by eclipse.
the class JavaProject method writeFileEntries.
/**
* Writes the classpath in a sharable format (VCM-wise) only when necessary, that is, if it is semantically different
* from the existing one in file. Will never write an identical one.
*
* @param newClasspath IClasspathEntry[]
* @param newOutputLocation IPath
* @return boolean Return whether the .classpath file was modified.
* @throws JavaModelException
*/
public boolean writeFileEntries(IClasspathEntry[] newClasspath, IClasspathEntry[] referencedEntries, IPath newOutputLocation) throws JavaModelException {
if (!this.project.isAccessible())
return false;
Map unknownElements = new HashMap();
IClasspathEntry[][] fileEntries = readFileEntries(unknownElements);
if (fileEntries[0] != JavaProject.INVALID_CLASSPATH && areClasspathsEqual(newClasspath, newOutputLocation, fileEntries[0]) && (referencedEntries == null || areClasspathsEqual(referencedEntries, fileEntries[1]))) {
// no need to save it, it is the same
return false;
}
// actual file saving
try {
setSharedProperty(JavaProject.CLASSPATH_FILENAME, encodeClasspath(newClasspath, referencedEntries, newOutputLocation, true, unknownElements));
return true;
} catch (CoreException e) {
throw new JavaModelException(e);
}
}
use of org.eclipse.jdt.core.JavaModelException in project che by eclipse.
the class JavaProject method setOptions.
@Override
public void setOptions(Map newOptions) {
IEclipsePreferences projectPreferences = getEclipsePreferences();
if (projectPreferences == null)
return;
try {
if (newOptions == null) {
projectPreferences.clear();
} else {
Iterator entries = newOptions.entrySet().iterator();
JavaModelManager javaModelManager = getJavaModelManager();
while (entries.hasNext()) {
Map.Entry entry = (Map.Entry) entries.next();
String key = (String) entry.getKey();
String value = (String) entry.getValue();
javaModelManager.storePreference(key, value, projectPreferences, newOptions);
}
// reset to default all options not in new map
// @see https://bugs.eclipse.org/bugs/show_bug.cgi?id=26255
// @see https://bugs.eclipse.org/bugs/show_bug.cgi?id=49691
String[] pNames = projectPreferences.keys();
int ln = pNames.length;
for (int i = 0; i < ln; i++) {
String key = pNames[i];
if (!newOptions.containsKey(key)) {
// old preferences => remove from preferences table
projectPreferences.remove(key);
}
}
}
// persist options
projectPreferences.flush();
// flush cache immediately
try {
getPerProjectInfo().options = null;
} catch (JavaModelException e) {
// do nothing
}
} catch (BackingStoreException e) {
// problem with pref store - quietly ignore
}
}
use of org.eclipse.jdt.core.JavaModelException in project che by eclipse.
the class SourceMapper method mapSource.
/**
* Maps the given source code to the given binary type and its children.
* If a non-null java element is passed, finds the name range for the
* given java element without storing it.
*/
public synchronized ISourceRange mapSource(IType type, char[] contents, IBinaryType info, IJavaElement elementToFind) {
this.binaryType = (BinaryType) type;
// check whether it is already mapped
if (this.sourceRanges.get(type) != null)
return (elementToFind != null) ? getNameRange(elementToFind) : null;
this.importsTable.remove(this.binaryType);
this.importsCounterTable.remove(this.binaryType);
this.searchedElement = elementToFind;
this.types = new IType[1];
this.typeDeclarationStarts = new int[1];
this.typeNameRanges = new SourceRange[1];
this.typeModifiers = new int[1];
this.typeDepth = -1;
this.memberDeclarationStart = new int[1];
this.memberName = new String[1];
this.memberNameRange = new SourceRange[1];
this.methodParameterTypes = new char[1][][];
this.methodParameterNames = new char[1][][];
this.anonymousCounter = 0;
HashMap oldSourceRanges = null;
if (elementToFind != null) {
oldSourceRanges = (HashMap) this.sourceRanges.clone();
}
try {
IProblemFactory factory = new DefaultProblemFactory();
SourceElementParser parser = null;
this.anonymousClassName = 0;
if (info == null) {
try {
info = (IBinaryType) this.binaryType.getElementInfo();
} catch (JavaModelException e) {
return null;
}
}
boolean isAnonymousClass = info.isAnonymous();
char[] fullName = info.getName();
if (isAnonymousClass) {
String eltName = this.binaryType.getParent().getElementName();
eltName = eltName.substring(eltName.lastIndexOf('$') + 1, eltName.length());
try {
this.anonymousClassName = Integer.parseInt(eltName);
} catch (NumberFormatException e) {
// ignore
}
}
boolean doFullParse = hasToRetrieveSourceRangesForLocalClass(fullName);
parser = new SourceElementParser(this, factory, new CompilerOptions(this.options), doFullParse, true);
// disable javadoc parsing
parser.javadocParser.checkDocComment = false;
IJavaElement javaElement = this.binaryType.getCompilationUnit();
if (javaElement == null)
javaElement = this.binaryType.getParent();
parser.parseCompilationUnit(new BasicCompilationUnit(contents, null, this.binaryType.sourceFileName(info), javaElement), doFullParse, null);
if (elementToFind != null) {
ISourceRange range = getNameRange(elementToFind);
return range;
} else {
return null;
}
} finally {
if (elementToFind != null) {
this.sourceRanges = oldSourceRanges;
}
this.binaryType = null;
this.searchedElement = null;
this.types = null;
this.typeDeclarationStarts = null;
this.typeNameRanges = null;
this.typeDepth = -1;
}
}
use of org.eclipse.jdt.core.JavaModelException in project che by eclipse.
the class DeltaProcessor method processResourceDelta.
/*
* Converts a <code>IResourceDelta</code> rooted in a <code>Workspace</code> into
* the corresponding set of <code>IJavaElementDelta</code>, rooted in the
* relevant <code>JavaModel</code>s.
*/
private IJavaElementDelta processResourceDelta(IResourceDelta changes) {
try {
IJavaModel model = this.manager.getJavaModel();
if (!model.isOpen()) {
// force opening of java model so that java element delta are reported
try {
model.open(null);
} catch (JavaModelException e) {
if (VERBOSE) {
e.printStackTrace();
}
return null;
}
}
this.state.initializeRoots(false);
this.currentElement = null;
// get the workspace delta, and start processing there.
// IResourceDelta[] deltas = (IResourceDelta[])changes.getAffectedChildren(IResourceDelta.ADDED | IResourceDelta.REMOVED |
// IResourceDelta.CHANGED, IContainer.INCLUDE_HIDDEN);
// for (int i = 0; i < deltas.length; i++) {
// IResourceDelta delta = deltas[i];
// File res = delta.getFile();
//
// // find out the element type
// RootInfo rootInfo = null;
// int elementType;
// IProject proj = (IProject)res;
// boolean wasJavaProject = this.state.findJavaProject(proj.getName()) != null;
// boolean isJavaProject = JavaProject.hasJavaNature(proj);
// if (!wasJavaProject && !isJavaProject) {
// elementType = NON_JAVA_RESOURCE;
// } else {
// IPath rootPath = externalPath(res);
// rootInfo = enclosingRootInfo(rootPath, delta.getKind());
// if (rootInfo != null && rootInfo.isRootOfProject(rootPath)) {
// elementType = IJavaElement.PACKAGE_FRAGMENT_ROOT;
// } else {
// elementType = IJavaElement.JAVA_PROJECT;
// }
// }
//
// // traverse delta
// traverseDelta(changes, IJavaElement.JAVA_PROJECT, null, null);
updateCurrentDeltaAndIndex(changes, IJavaElement.COMPILATION_UNIT, null);
//
// if (elementType == NON_JAVA_RESOURCE
// || (wasJavaProject != isJavaProject && (delta.getKind()) == IResourceDelta.CHANGED)) { // project has changed
// nature (description or open/closed)
// try {
// // add child as non java resource
// nonJavaResourcesChanged((JavaModel)model, delta);
// } catch (JavaModelException e) {
// // java model could not be opened
// }
// }
//
// }
resetProjectCaches();
return this.currentDelta;
} finally {
this.currentDelta = null;
}
}
Aggregations