List of usage examples for org.eclipse.jdt.internal.core.util Util localTypeName
public static String localTypeName(String binaryTypeName, int lastDollar, int end)
From source file:com.codenvy.ide.ext.java.server.internal.core.BinaryType.java
License:Open Source License
public IType getDeclaringType() { IClassFile classFile = getClassFile(); if (classFile.isOpen()) { try {/* w w w .ja v a 2 s . c o m*/ char[] enclosingTypeName = ((IBinaryType) getElementInfo()).getEnclosingTypeName(); if (enclosingTypeName == null) { return null; } enclosingTypeName = ClassFile.unqualifiedName(enclosingTypeName); // workaround problem with class files compiled with javac 1.1.* // that return a non-null enclosing type name for local types defined in anonymous (e.g. A$1$B) if (classFile.getElementName().length() > enclosingTypeName.length + 1 && Character.isDigit(classFile.getElementName().charAt(enclosingTypeName.length + 1))) { return null; } return getPackageFragment().getClassFile(new String(enclosingTypeName) + SUFFIX_STRING_class) .getType(); } catch (JavaModelException npe) { return null; } } else { // cannot access .class file without opening it // and getDeclaringType() is supposed to be a handle-only method, // so default to assuming $ is an enclosing type separator String classFileName = classFile.getElementName(); int lastDollar = -1; for (int i = 0, length = classFileName.length(); i < length; i++) { char c = classFileName.charAt(i); if (Character.isDigit(c) && lastDollar == i - 1) { // anonymous or local type return null; } else if (c == '$') { lastDollar = i; } } if (lastDollar == -1) { return null; } else { String enclosingName = classFileName.substring(0, lastDollar); String enclosingClassFileName = enclosingName + SUFFIX_STRING_class; return new BinaryType((JavaElement) getPackageFragment().getClassFile(enclosingClassFileName), manager, Util.localTypeName(enclosingName, enclosingName.lastIndexOf('$'), enclosingName.length())); } } }
From source file:com.codenvy.ide.ext.java.server.internal.core.ClassFile.java
License:Open Source License
static String simpleName(char[] className) { if (className == null) return null; String simpleName = new String(unqualifiedName(className)); int lastDollar = simpleName.lastIndexOf('$'); if (lastDollar != -1) return Util.localTypeName(simpleName, lastDollar, simpleName.length()); else//from w ww . j a v a 2 s . com return simpleName; }
From source file:com.codenvy.ide.ext.java.server.internal.core.ClassFile.java
License:Open Source License
public String getTypeName() { // Internal class file name doesn't contain ".class" file extension int lastDollar = this.name.lastIndexOf('$'); return lastDollar > -1 ? Util.localTypeName(this.name, lastDollar, this.name.length()) : this.name; }
From source file:com.codenvy.ide.ext.java.server.internal.core.NameLookup.java
License:Open Source License
/** * Performs type search in a binary package. *//*from w w w. j a va 2 s .c om*/ protected void seekTypesInBinaryPackage(String name, IPackageFragment pkg, boolean partialMatch, int acceptFlags, IJavaElementRequestor requestor) { long start = -1; if (VERBOSE) start = System.currentTimeMillis(); try { if (!partialMatch) { // exact match if (requestor.isCanceled()) return; ClassFile classFile = new ClassFile((PackageFragment) pkg, manager, name); if (classFile.existsUsingJarTypeCache()) { IType type = classFile.getType(); if (acceptType(type, acceptFlags, false/*not a source type*/)) { requestor.acceptType(type); } } } else { IJavaElement[] classFiles = null; try { classFiles = pkg.getChildren(); } catch (JavaModelException npe) { return; // the package is not present } int length = classFiles.length; String unqualifiedName = name; int index = name.lastIndexOf('$'); if (index != -1) { //the type name of the inner type unqualifiedName = Util.localTypeName(name, index, name.length()); // unqualifiedName is empty if the name ends with a '$' sign. // See http://dev.eclipse.org/bugs/show_bug.cgi?id=14642 } int matchLength = name.length(); for (int i = 0; i < length; i++) { if (requestor.isCanceled()) return; IJavaElement classFile = classFiles[i]; // MatchName will never have the extension ".class" and the elementName always will. String elementName = classFile.getElementName(); if (elementName.regionMatches(true /*ignore case*/, 0, name, 0, matchLength)) { IType type = ((ClassFile) classFile).getType(); String typeName = type.getElementName(); if (typeName.length() > 0 && !Character.isDigit(typeName.charAt(0))) { //not an anonymous type if (nameMatches(unqualifiedName, type, true/*partial match*/) && acceptType(type, acceptFlags, false/*not a source type*/)) requestor.acceptType(type); } } } } } finally { if (VERBOSE) this.timeSpentInSeekTypesInBinaryPackage += System.currentTimeMillis() - start; } }
From source file:org.codehaus.groovy.eclipse.core.builder.GroovyNameLookup.java
License:Apache License
/** * Copied from parent class/*from w w w . ja v a 2 s . c o m*/ * Changes marked with // GROOVY begin and // GROOVY end */ @Override protected void seekTypesInBinaryPackage(String name, IPackageFragment pkg, boolean partialMatch, int acceptFlags, IJavaElementRequestor requestor) { long start = -1; if (VERBOSE) start = System.currentTimeMillis(); try { // GROOVY begin // ensure ends with .class if (!name.endsWith(".class")) { name += ".class"; } // GROOVY end if (!partialMatch) { // exact match if (requestor.isCanceled()) return; ClassFile classFile = (ClassFile) pkg.getClassFile(name); if (classFile.existsUsingJarTypeCache()) { IType type = classFile.getType(); if (acceptType(type, acceptFlags, false/*not a source type*/)) { requestor.acceptType(type); } } // GROOVY begin // class file may still exist as an inner type IJavaElement[] classFiles = null; try { classFiles = pkg.getChildren(); } catch (JavaModelException npe) { return; // the package is not present } for (IJavaElement elt : classFiles) { classFile = (ClassFile) elt; if (classFile.getElementName().endsWith("$" + name)) { IType type = classFile.getType(); if (acceptType(type, acceptFlags, false/*not a source type*/)) { requestor.acceptType(type); } } } // GROOVY end } else { IJavaElement[] classFiles = null; try { classFiles = pkg.getChildren(); } catch (JavaModelException npe) { return; // the package is not present } int length = classFiles.length; String unqualifiedName = name; int index = name.lastIndexOf('$'); if (index != -1) { //the type name of the inner type unqualifiedName = Util.localTypeName(name, index, name.length()); // unqualifiedName is empty if the name ends with a '$' sign. // See http://dev.eclipse.org/bugs/show_bug.cgi?id=14642 } int matchLength = name.length(); for (int i = 0; i < length; i++) { if (requestor.isCanceled()) return; IJavaElement classFile = classFiles[i]; // MatchName will never have the extension ".class" and the elementName always will. String elementName = classFile.getElementName(); if (elementName.regionMatches(true /*ignore case*/, 0, name, 0, matchLength)) { IType type = ((ClassFile) classFile).getType(); String typeName = type.getElementName(); if (typeName.length() > 0 && !Character.isDigit(typeName.charAt(0))) { //not an anonymous type if (nameMatches(unqualifiedName, type, true/*partial match*/) && acceptType(type, acceptFlags, false/*not a source type*/)) requestor.acceptType(type); } } } } } finally { if (VERBOSE) this.timeSpentInSeekTypesInBinaryPackage += System.currentTimeMillis() - start; } }