List of usage examples for org.eclipse.jdt.core.compiler CharOperation lastIndexOf
public static final int lastIndexOf(char toBeFound, char[] array, int startIndex, int endIndex)
From source file:com.ibm.research.tours.content.url.Signature.java
License:Open Source License
/** * Returns a char array containing all but the last segment of the given * dot-separated qualified name. Returns the empty char array if it is not qualified. * <p>//w w w . j av a 2s . c o m * For example: * <pre> * <code> * getQualifier({'j', 'a', 'v', 'a', '.', 'l', 'a', 'n', 'g', '.', 'O', 'b', 'j', 'e', 'c', 't'}) -> {'j', 'a', 'v', 'a', '.', 'l', 'a', 'n', 'g'} * getQualifier({'O', 'u', 't', 'e', 'r', '.', 'I', 'n', 'n', 'e', 'r'}) -> {'O', 'u', 't', 'e', 'r'} * getQualifier({'j', 'a', 'v', 'a', '.', 'u', 't', 'i', 'l', '.', 'L', 'i', 's', 't', '<', 'j', 'a', 'v', 'a', '.', 'l', 'a', 'n', 'g', '.', 'S', 't', 'r', 'i', 'n', 'g', '>'}) -> {'j', 'a', 'v', 'a', '.', 'u', 't', 'i', 'l'} * </code> * </pre> * </p> * * @param name the name * @return the qualifier prefix, or the empty char array if the name contains no * dots * @exception NullPointerException if name is null * @since 2.0 */ public static char[] getQualifier(char[] name) { int firstGenericStart = CharOperation.indexOf(C_GENERIC_START, name); int lastDot = CharOperation.lastIndexOf(C_DOT, name, 0, firstGenericStart == -1 ? name.length - 1 : firstGenericStart); if (lastDot == -1) { return CharOperation.NO_CHAR; } return CharOperation.subarray(name, 0, lastDot); }
From source file:org.eclipse.jdt.internal.core.hierarchy.HierarchyResolver.java
License:Open Source License
private IType[] findSuperInterfaces(IGenericType type, ReferenceBinding typeBinding) { char[][] superInterfaceNames; char separator; if (type instanceof IBinaryType) { superInterfaceNames = ((IBinaryType) type).getInterfaceNames(); separator = '/'; } else if (type instanceof ISourceType) { ISourceType sourceType = (ISourceType) type; if (sourceType.getName().length == 0) { // if anonymous type if (typeBinding.superInterfaces() != null && typeBinding.superInterfaces().length > 0) { superInterfaceNames = new char[][] { sourceType.getSuperclassName() }; } else { superInterfaceNames = sourceType.getInterfaceNames(); }/*from w w w. j av a2 s . c om*/ } else { if (TypeDeclaration.kind(sourceType.getModifiers()) == TypeDeclaration.ANNOTATION_TYPE_DECL) superInterfaceNames = new char[][] { TypeConstants.CharArray_JAVA_LANG_ANNOTATION_ANNOTATION }; else superInterfaceNames = sourceType.getInterfaceNames(); } separator = '.'; } else if (type instanceof HierarchyType) { HierarchyType hierarchyType = (HierarchyType) type; if (hierarchyType.name.length == 0) { // if anonymous type if (typeBinding.superInterfaces() != null && typeBinding.superInterfaces().length > 0) { superInterfaceNames = new char[][] { hierarchyType.superclassName }; } else { superInterfaceNames = hierarchyType.superInterfaceNames; } } else { superInterfaceNames = hierarchyType.superInterfaceNames; } separator = '.'; } else { return null; } ReferenceBinding[] interfaceBindings = typeBinding.superInterfaces(); int bindingIndex = 0; int bindingLength = interfaceBindings == null ? 0 : interfaceBindings.length; int length = superInterfaceNames == null ? 0 : superInterfaceNames.length; IType[] superinterfaces = new IType[length]; int index = 0; next: for (int i = 0; i < length; i++) { char[] superInterfaceName = superInterfaceNames[i]; int end = superInterfaceName.length; // find the end of simple name int genericStart = CharOperation.indexOf(Signature.C_GENERIC_START, superInterfaceName); if (genericStart != -1) end = genericStart; // find the start of simple name int lastSeparator = CharOperation.lastIndexOf(separator, superInterfaceName, 0, end); int start = lastSeparator + 1; // case of binary inner type -> take the last part int lastDollar = CharOperation.lastIndexOf('$', superInterfaceName, start); if (lastDollar != -1) start = lastDollar + 1; char[] simpleName = CharOperation.subarray(superInterfaceName, start, end); if (bindingIndex < bindingLength) { ReferenceBinding interfaceBinding = (ReferenceBinding) interfaceBindings[bindingIndex].erasure(); // ensure that the binding corresponds to the interface defined by the user if (CharOperation.equals(simpleName, interfaceBinding.sourceName)) { bindingIndex++; for (int t = this.typeIndex; t >= 0; t--) { if (this.typeBindings[t] == interfaceBinding) { IType handle = this.builder.getHandle(this.typeModels[t], interfaceBinding); if (handle != null) { superinterfaces[index++] = handle; continue next; } } } } } this.builder.hierarchy.missingTypes.add(new String(simpleName)); } if (index != length) System.arraycopy(superinterfaces, 0, superinterfaces = new IType[index], 0, index); return superinterfaces; }
From source file:org.eclipse.tycho.compiler.jdt.JDTCompiler.java
License:Open Source License
/** * check the compiler arguments. Extract from files specified using @, lines marked with * ADAPTER_PREFIX These lines specify information that needs to be interpreted by us. * /*from w w w .j a va 2 s.c om*/ * @param args * compiler arguments to process */ private void checkCompilerArgs(Map<String, String> args) { for (String arg : args.keySet()) { if (arg.charAt(0) == '@') { try { char[] content = Util.getFileCharContent(new File(arg.substring(1)), null); int offset = 0; int prefixLength = ADAPTER_PREFIX.length; while ((offset = CharOperation.indexOf(ADAPTER_PREFIX, content, true, offset)) > -1) { int start = offset + prefixLength; int end = CharOperation.indexOf('\n', content, start); if (end == -1) end = content.length; while (CharOperation.isWhitespace(content[end])) { end--; } // end is inclusive, but in the API end is exclusive if (CharOperation.equals(ADAPTER_ENCODING, content, start, start + ADAPTER_ENCODING.length)) { CharOperation.replace(content, SEPARATOR_CHARS, File.separatorChar, start, end + 1); // file or folder level custom encoding start += ADAPTER_ENCODING.length; int encodeStart = CharOperation.lastIndexOf('[', content, start, end); if (start < encodeStart && encodeStart < end) { boolean isFile = CharOperation.equals(SuffixConstants.SUFFIX_java, content, encodeStart - 5, encodeStart, false); String str = String.valueOf(content, start, encodeStart - start); String enc = String.valueOf(content, encodeStart, end - encodeStart + 1); if (isFile) { if (fileEncodings == null) fileEncodings = new HashMap<String, String>(); // use File to translate the string into a // path with the correct File.seperator fileEncodings.put(str, enc); } else { if (dirEncodings == null) dirEncodings = new HashMap<String, String>(); dirEncodings.put(str, enc); } } } else if (CharOperation.equals(ADAPTER_ACCESS, content, start, start + ADAPTER_ACCESS.length)) { // access rules for the classpath start += ADAPTER_ACCESS.length; int accessStart = CharOperation.indexOf('[', content, start, end); // CharOperation.replace(content, SEPARATOR_CHARS, // File.separatorChar, start, accessStart); if (start < accessStart && accessStart < end) { String path = String.valueOf(content, start, accessStart - start); String access = String.valueOf(content, accessStart, end - accessStart + 1); if (accessRules == null) accessRules = new ArrayList<String>(); accessRules.add(path); accessRules.add(access); } } offset = end; } } catch (IOException e) { // ignore } } } }