List of usage examples for org.eclipse.jdt.core IJavaElement CLASS_FILE
int CLASS_FILE
To view the source code for org.eclipse.jdt.core IJavaElement CLASS_FILE.
Click Source Link
From source file:com.codenvy.ide.ext.java.server.internal.core.JavaModelCache.java
License:Open Source License
public IJavaElement getExistingElement(IJavaElement element) { switch (element.getElementType()) { case IJavaElement.JAVA_MODEL: return element; case IJavaElement.JAVA_PROJECT: return element; // projectCache is a Hashtable and Hashtables don't support getKey(...) case IJavaElement.PACKAGE_FRAGMENT_ROOT: return (IJavaElement) this.rootCache.getKey(element); case IJavaElement.PACKAGE_FRAGMENT: return (IJavaElement) this.pkgCache.getKey(element); case IJavaElement.COMPILATION_UNIT: case IJavaElement.CLASS_FILE: return (IJavaElement) this.openableCache.getKey(element); case IJavaElement.TYPE: return element; // jarTypeCache or childrenCache are Hashtables and Hashtables don't support getKey(...) default://from w ww . java 2 s . c om return element; // childrenCache is a Hashtable and Hashtables don't support getKey(...) } }
From source file:com.codenvy.ide.ext.java.server.internal.core.JavaModelCache.java
License:Open Source License
/** * Returns the info for this element without * disturbing the cache ordering.//from w w w . j a va 2 s . c o m */ protected Object peekAtInfo(IJavaElement element) { switch (element.getElementType()) { case IJavaElement.JAVA_MODEL: return this.modelInfo; case IJavaElement.JAVA_PROJECT: return this.projectCache.get(element); case IJavaElement.PACKAGE_FRAGMENT_ROOT: return this.rootCache.peek(element); case IJavaElement.PACKAGE_FRAGMENT: return this.pkgCache.peek(element); case IJavaElement.COMPILATION_UNIT: case IJavaElement.CLASS_FILE: return this.openableCache.peek(element); case IJavaElement.TYPE: Object result = this.jarTypeCache.peek(element); if (result != null) return result; else return this.childrenCache.get(element); default: return this.childrenCache.get(element); } }
From source file:com.codenvy.ide.ext.java.server.internal.core.JavaModelCache.java
License:Open Source License
/** * Remember the info for the element./*from w w w.j a va2 s .co m*/ */ protected void putInfo(IJavaElement element, Object info) { switch (element.getElementType()) { case IJavaElement.JAVA_MODEL: this.modelInfo = info; break; case IJavaElement.JAVA_PROJECT: this.projectCache.put(element, info); this.rootCache.ensureSpaceLimit(info, element); break; case IJavaElement.PACKAGE_FRAGMENT_ROOT: this.rootCache.put(element, info); this.pkgCache.ensureSpaceLimit(info, element); break; case IJavaElement.PACKAGE_FRAGMENT: this.pkgCache.put(element, info); this.openableCache.ensureSpaceLimit(info, element); break; case IJavaElement.COMPILATION_UNIT: case IJavaElement.CLASS_FILE: this.openableCache.put(element, info); break; default: this.childrenCache.put(element, info); } }
From source file:com.codenvy.ide.ext.java.server.internal.core.JavaModelCache.java
License:Open Source License
/** * Removes the info of the element from the cache. *//* w ww . ja va2 s .co m*/ protected void removeInfo(JavaElement element) { switch (element.getElementType()) { case IJavaElement.JAVA_MODEL: this.modelInfo = null; break; case IJavaElement.JAVA_PROJECT: this.projectCache.remove(element); this.rootCache.resetSpaceLimit((int) (DEFAULT_ROOT_SIZE * getMemoryRatio()), element); break; case IJavaElement.PACKAGE_FRAGMENT_ROOT: this.rootCache.remove(element); this.pkgCache.resetSpaceLimit((int) (DEFAULT_PKG_SIZE * getMemoryRatio()), element); break; case IJavaElement.PACKAGE_FRAGMENT: this.pkgCache.remove(element); this.openableCache.resetSpaceLimit( (int) (DEFAULT_OPENABLE_SIZE * getMemoryRatio() * getOpenableRatio()), element); break; case IJavaElement.COMPILATION_UNIT: case IJavaElement.CLASS_FILE: this.openableCache.remove(element); break; default: this.childrenCache.remove(element); } }
From source file:com.codenvy.ide.ext.java.server.internal.core.ModelUpdater.java
License:Open Source License
/** * Converts an <code>IResourceDelta</code> and its children into * the corresponding <code>IJavaElementDelta</code>s. * Return whether the delta corresponds to a resource on the classpath. * If it is not a resource on the classpath, it will be added as a non-java * resource by the sender of this method. *//*w w w. j a va2 s . co m*/ protected void traverseDelta(IJavaElementDelta delta, IPackageFragmentRoot root, IJavaProject project) { boolean processChildren = true; Openable element = (Openable) delta.getElement(); switch (element.getElementType()) { case IJavaElement.JAVA_PROJECT: project = (IJavaProject) element; break; case IJavaElement.PACKAGE_FRAGMENT_ROOT: root = (IPackageFragmentRoot) element; break; case IJavaElement.COMPILATION_UNIT: // filter out working copies that are not primary (we don't want to add/remove them to/from the package fragment CompilationUnit cu = (CompilationUnit) element; if (cu.isWorkingCopy() && !cu.isPrimary()) { return; } // $FALL-THROUGH$ case IJavaElement.CLASS_FILE: processChildren = false; break; } switch (delta.getKind()) { case IJavaElementDelta.ADDED: elementAdded(element); break; case IJavaElementDelta.REMOVED: elementRemoved(element); break; case IJavaElementDelta.CHANGED: if ((delta.getFlags() & IJavaElementDelta.F_CONTENT) != 0) { elementChanged(element); } break; } if (processChildren) { IJavaElementDelta[] children = delta.getAffectedChildren(); for (int i = 0; i < children.length; i++) { IJavaElementDelta childDelta = children[i]; traverseDelta(childDelta, root, project); } } }
From source file:com.codenvy.ide.ext.java.server.internal.core.NamedMember.java
License:Open Source License
public String getTypeQualifiedName(char enclosingTypeSeparator, boolean showParameters) throws JavaModelException { NamedMember declaringType;/*from w ww . j av a2 s. c om*/ switch (this.parent.getElementType()) { case IJavaElement.COMPILATION_UNIT: if (showParameters) { StringBuffer buffer = new StringBuffer(this.name); appendTypeParameters(buffer); return buffer.toString(); } return this.name; case IJavaElement.CLASS_FILE: String classFileName = this.parent.getElementName(); String typeName; if (classFileName.indexOf('$') == -1) { // top level class file: name of type is same as name of class file typeName = this.name; } else { // anonymous or local class file typeName = classFileName.substring(0, classFileName.lastIndexOf('.'))/*remove .class*/.replace('$', enclosingTypeSeparator); } if (showParameters) { StringBuffer buffer = new StringBuffer(typeName); appendTypeParameters(buffer); return buffer.toString(); } return typeName; case IJavaElement.TYPE: declaringType = (NamedMember) this.parent; break; case IJavaElement.FIELD: case IJavaElement.INITIALIZER: case IJavaElement.METHOD: declaringType = (NamedMember) ((IMember) this.parent).getDeclaringType(); break; default: return null; } StringBuffer buffer = new StringBuffer( declaringType.getTypeQualifiedName(enclosingTypeSeparator, showParameters)); buffer.append(enclosingTypeSeparator); String simpleName = this.name.length() == 0 ? getOccurrenceCountSignature() : this.name; buffer.append(simpleName); if (showParameters) { appendTypeParameters(buffer); } return buffer.toString(); }
From source file:com.codenvy.ide.ext.java.server.internal.core.search.JavaSearchScope.java
License:Open Source License
private IPath getPath(IJavaElement element, boolean relativeToRoot) { switch (element.getElementType()) { case IJavaElement.JAVA_MODEL: return Path.EMPTY; case IJavaElement.JAVA_PROJECT: return element.getPath(); case IJavaElement.PACKAGE_FRAGMENT_ROOT: if (relativeToRoot) return Path.EMPTY; return element.getPath(); case IJavaElement.PACKAGE_FRAGMENT: String relativePath = Util.concatWith(((PackageFragment) element).names, '/'); return getPath(element.getParent(), relativeToRoot).append(new Path(relativePath)); case IJavaElement.COMPILATION_UNIT: case IJavaElement.CLASS_FILE: return getPath(element.getParent(), relativeToRoot).append(new Path(element.getElementName())); default:/*from w ww . ja v a2s . c o m*/ return getPath(element.getParent(), relativeToRoot); } }
From source file:com.codenvy.ide.ext.java.server.internal.core.search.TypeNameMatchRequestorWrapper.java
License:Open Source License
public void acceptType(int modifiers, char[] packageName, char[] simpleTypeName, char[][] enclosingTypeNames, String path, AccessRestriction access) { // Get type/* w ww.ja v a 2 s . c o m*/ try { IType type = null; if (this.handleFactory != null) { //todo openable Openable openable = null;//this.handleFactory.createOpenable(path, this.scope); if (openable == null) return; switch (openable.getElementType()) { case IJavaElement.COMPILATION_UNIT: ICompilationUnit cu = (ICompilationUnit) openable; if (enclosingTypeNames != null && enclosingTypeNames.length > 0) { type = cu.getType(new String(enclosingTypeNames[0])); for (int j = 1, l = enclosingTypeNames.length; j < l; j++) { type = type.getType(new String(enclosingTypeNames[j])); } type = type.getType(new String(simpleTypeName)); } else { type = cu.getType(new String(simpleTypeName)); } break; case IJavaElement.CLASS_FILE: type = ((IClassFile) openable).getType(); break; } } else { int separatorIndex = path.indexOf(IJavaSearchScope.JAR_FILE_ENTRY_SEPARATOR); type = separatorIndex == -1 ? createTypeFromPath(path, new String(simpleTypeName), enclosingTypeNames) : createTypeFromJar(path, separatorIndex); } // Accept match if the type has been found if (type != null) { // hierarchy scopes require one more check: if (!(this.scope instanceof org.eclipse.jdt.internal.core.search.HierarchyScope) || ((HierarchyScope) this.scope).enclosesFineGrained(type)) { // Create the match final JavaSearchTypeNameMatch match = new JavaSearchTypeNameMatch(type, modifiers); // Update match accessibility if (access != null) { switch (access.getProblemId()) { case IProblem.ForbiddenReference: match.setAccessibility(IAccessRule.K_NON_ACCESSIBLE); break; case IProblem.DiscouragedReference: match.setAccessibility(IAccessRule.K_DISCOURAGED); break; } } // Accept match this.requestor.acceptTypeNameMatch(match); } } } catch (JavaModelException e) { // skip } }
From source file:com.drgarbage.bytecodevisualizer.compare.ClassFileMergeViewer.java
License:Apache License
public static InputStream createStream(IJavaElement javaElement) throws CoreException { IClassFile classFile = (IClassFile) javaElement.getAncestor(IJavaElement.CLASS_FILE); InputStream stream = null;//w w w . j av a 2 s.c o m if (classFile != null) { stream = new ByteArrayInputStream(classFile.getBytes()); } else { if (javaElement.getParent().getElementType() == IJavaElement.COMPILATION_UNIT) { IType t = (IType) javaElement; IJavaProject javaProject = t.getJavaProject(); String fullyQualifiedName = t.getFullyQualifiedName(); String className = JavaSourceUtils.getSimpleName(fullyQualifiedName); String packageName = JavaSourceUtils.getPackage(fullyQualifiedName); String classPath[] = JavaLangUtils.computeRuntimeClassPath(javaProject); try { stream = JavaLangUtils.findResource(classPath, packageName, className); } catch (IOException e) { throw new CoreException( new Status(IStatus.ERROR, BytecodeVisualizerPlugin.PLUGIN_ID, e.getMessage(), e)); } } else { return null; } } return stream; }
From source file:com.drgarbage.bytecodevisualizer.compare.CompareElement.java
License:Apache License
/** * Returns the class name for the given java element. * @param javaElement/*from ww w .j a v a 2 s.c o m*/ * @return class name */ private static String getClassName(IJavaElement javaElement) { String name; IClassFile classFile = (IClassFile) javaElement.getAncestor(IJavaElement.CLASS_FILE); if (classFile != null) { name = classFile.getPath().toOSString(); } else { if (javaElement.getPath() != null) { name = javaElement.getPath().toOSString(); } else { name = javaElement.getElementName(); } } return name; }