use of org.eclipse.jdt.core.IJavaElement 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.IJavaElement in project che by eclipse.
the class JavaModel method getHandleFromMemento.
/*
* @see JavaElement
*/
public IJavaElement getHandleFromMemento(String token, MementoTokenizer memento, WorkingCopyOwner owner) {
switch(token.charAt(0)) {
case JavaElement.JEM_JAVAPROJECT:
if (!memento.hasMoreTokens())
return this;
String projectName = memento.nextToken();
JavaElement project = (JavaElement) getJavaProject(projectName);
return project.getHandleFromMemento(memento, owner);
}
return null;
}
use of org.eclipse.jdt.core.IJavaElement in project che by eclipse.
the class JavaProject method getHandleFromMemento.
@Override
public IJavaElement getHandleFromMemento(String token, MementoTokenizer memento, WorkingCopyOwner owner) {
switch(token.charAt(0)) {
case JavaElement.JEM_PACKAGEFRAGMENTROOT:
String rootPath = IPackageFragmentRoot.DEFAULT_PACKAGEROOT_PATH;
token = null;
while (memento.hasMoreTokens()) {
token = memento.nextToken();
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=331821
if (token == MementoTokenizer.PACKAGEFRAGMENT || token == MementoTokenizer.COUNT) {
break;
}
rootPath += token;
}
JavaElement root = (JavaElement) getPackageFragmentRoot(new Path(rootPath));
if (token != null && token.charAt(0) == JavaElement.JEM_PACKAGEFRAGMENT) {
return root.getHandleFromMemento(token, memento, owner);
} else {
return root.getHandleFromMemento(memento, owner);
}
}
return null;
}
use of org.eclipse.jdt.core.IJavaElement in project che by eclipse.
the class SourceMapper method getNameRange.
/**
* Returns the SourceRange for the name of the given element, or
* {-1, -1} if no source range is known for the name of the element.
*/
public SourceRange getNameRange(IJavaElement element) {
switch(element.getElementType()) {
case IJavaElement.METHOD:
if (((IMember) element).isBinary()) {
IJavaElement[] el = getUnqualifiedMethodHandle((IMethod) element, false);
if (el[1] != null && this.sourceRanges.get(el[0]) == null) {
element = getUnqualifiedMethodHandle((IMethod) element, true)[0];
} else {
element = el[0];
}
}
break;
case IJavaElement.TYPE_PARAMETER:
IJavaElement parent = element.getParent();
if (parent.getElementType() == IJavaElement.METHOD) {
IMethod method = (IMethod) parent;
if (method.isBinary()) {
IJavaElement[] el = getUnqualifiedMethodHandle(method, false);
if (el[1] != null && this.sourceRanges.get(el[0]) == null) {
method = (IMethod) getUnqualifiedMethodHandle(method, true)[0];
} else {
method = (IMethod) el[0];
}
element = method.getTypeParameter(element.getElementName());
}
}
break;
case IJavaElement.LOCAL_VARIABLE:
LocalVariableElementKey key = new LocalVariableElementKey(element.getParent(), element.getElementName());
SourceRange[] ranges = (SourceRange[]) this.parametersRanges.get(key);
if (ranges == null) {
return UNKNOWN_RANGE;
} else {
return ranges[1];
}
}
SourceRange[] ranges = (SourceRange[]) this.sourceRanges.get(element);
if (ranges == null) {
return UNKNOWN_RANGE;
} else {
return ranges[1];
}
}
use of org.eclipse.jdt.core.IJavaElement 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;
}
}
Aggregations