List of usage examples for org.eclipse.jdt.core.compiler CharOperation indexOf
public static final int indexOf(char toBeFound, char[] array)
From source file:com.codenvy.ide.ext.java.server.internal.codeassist.SelectionEngine.java
License:Open Source License
/** * Asks the engine to compute the selection of the given type * from the given context//from ww w . ja va 2 s . co m * * @param typeName char[] * a type name which is to be resolved in the context of a compilation unit. * NOTE: the type name is supposed to be correctly reduced (no whitespaces, no unicodes left) * * @param context org.eclipse.jdt.core.IType * the context in which code assist is invoked. */ public void selectType(char[] typeName, IType context) throws JavaModelException { try { this.acceptedAnswer = false; // only the type erasure are returned by IType.resolvedType(...) if (CharOperation.indexOf('<', typeName) != -1) { char[] typeSig = Signature.createCharArrayTypeSignature(typeName, false/*not resolved*/); typeSig = Signature.getTypeErasure(typeSig); typeName = Signature.toCharArray(typeSig); } CompilationUnitDeclaration parsedUnit = null; TypeDeclaration typeDeclaration = null; org.eclipse.jdt.core.ICompilationUnit cu = context.getCompilationUnit(); if (cu != null) { IType[] topLevelTypes = cu.getTypes(); int length = topLevelTypes.length; SourceTypeElementInfo[] topLevelInfos = new SourceTypeElementInfo[length]; for (int i = 0; i < length; i++) { topLevelInfos[i] = (SourceTypeElementInfo) ((SourceType) topLevelTypes[i]).getElementInfo(); } CompilationResult result = new CompilationResult( (org.eclipse.jdt.internal.compiler.env.ICompilationUnit) cu, 1, 1, this.compilerOptions.maxProblemsPerUnit); int flags = SourceTypeConverter.FIELD_AND_METHOD | SourceTypeConverter.MEMBER_TYPE; if (context.isAnonymous() || context.isLocal()) flags |= SourceTypeConverter.LOCAL_TYPE; parsedUnit = SourceTypeConverter.buildCompilationUnit(topLevelInfos, flags, this.parser.problemReporter(), result); if (parsedUnit != null && parsedUnit.types != null) { if (DEBUG) { System.out.println("SELECTION - Diet AST :"); //$NON-NLS-1$ System.out.println(parsedUnit.toString()); } // find the type declaration that corresponds to the original source type typeDeclaration = new ASTNodeFinder(parsedUnit).findType(context); } } else { // binary type ClassFile classFile = (ClassFile) context.getClassFile(); ClassFileReader reader = (ClassFileReader) classFile.getBinaryTypeInfo( (IFile) null/*classFile.resource()*/, false/*don't fully initialize so as to keep constant pool (used below)*/); CompilationResult result = new CompilationResult(reader.getFileName(), 1, 1, this.compilerOptions.maxProblemsPerUnit); parsedUnit = new CompilationUnitDeclaration(this.parser.problemReporter(), result, 0); HashSetOfCharArrayArray typeNames = new HashSetOfCharArrayArray(); BinaryTypeConverter converter = new BinaryTypeConverter(this.parser.problemReporter(), result, typeNames); typeDeclaration = converter.buildTypeDeclaration(context, parsedUnit); parsedUnit.imports = converter.buildImports(reader); } if (typeDeclaration != null) { // add fake field with the type we're looking for // note: since we didn't ask for fields above, there is no field defined yet FieldDeclaration field = new FieldDeclaration(); int dot; if ((dot = CharOperation.lastIndexOf('.', typeName)) == -1) { this.selectedIdentifier = typeName; field.type = new SelectionOnSingleTypeReference(typeName, -1); // position not used } else { char[][] previousIdentifiers = CharOperation.splitOn('.', typeName, 0, dot); char[] selectionIdentifier = CharOperation.subarray(typeName, dot + 1, typeName.length); this.selectedIdentifier = selectionIdentifier; field.type = new SelectionOnQualifiedTypeReference(previousIdentifiers, selectionIdentifier, new long[previousIdentifiers.length + 1]); } field.name = "<fakeField>".toCharArray(); //$NON-NLS-1$ typeDeclaration.fields = new FieldDeclaration[] { field }; // build bindings this.lookupEnvironment.buildTypeBindings(parsedUnit, null /*no access restriction*/); if ((this.unitScope = parsedUnit.scope) != null) { try { // build fields // note: this builds fields only in the parsed unit (the buildFieldsAndMethods flag is not passed along) this.lookupEnvironment.completeTypeBindings(parsedUnit, true); // resolve parsedUnit.scope.faultInTypes(); parsedUnit.resolve(); } catch (SelectionNodeFound e) { if (e.binding != null) { if (DEBUG) { System.out.println("SELECTION - Selection binding :"); //$NON-NLS-1$ System.out.println(e.binding.toString()); } // if null then we found a problem in the selection node selectFrom(e.binding, parsedUnit, e.isDeclaration); } } } } if (this.noProposal && this.problem != null) { this.requestor.acceptError(this.problem); } } catch (AbortCompilation e) { // ignore this exception for now since it typically means we cannot find java.lang.Object } finally { reset(true); } }
From source file:com.codenvy.ide.ext.java.server.internal.core.BasicCompilationUnit.java
License:Open Source License
public char[] getMainTypeName() { if (this.mainTypeName == null) { int start = CharOperation.lastIndexOf('/', this.fileName) + 1; if (start == 0 || start < CharOperation.lastIndexOf('\\', this.fileName)) start = CharOperation.lastIndexOf('\\', this.fileName) + 1; int separator = CharOperation.indexOf('|', this.fileName) + 1; if (separator > start) // case of a .class file in a default package in a jar start = separator;//w ww . j a v a 2s.c o m int end = CharOperation.lastIndexOf('$', this.fileName); if (end == -1 || !Util.isClassFileName(this.fileName)) { end = CharOperation.lastIndexOf('.', this.fileName); if (end == -1) end = this.fileName.length; } this.mainTypeName = CharOperation.subarray(this.fileName, start, end); } return this.mainTypeName; }
From source file:com.codenvy.ide.ext.java.server.internal.core.search.indexing.AbstractIndexer.java
License:Open Source License
private char[] erasure(char[] typeName) { int genericStart = CharOperation.indexOf(Signature.C_GENERIC_START, typeName); if (genericStart > -1) typeName = CharOperation.subarray(typeName, 0, genericStart); return typeName; }
From source file:com.codenvy.ide.ext.java.server.internal.core.search.indexing.SourceIndexerRequestor.java
License:Open Source License
/** * @see org.eclipse.jdt.internal.compiler.ISourceElementRequestor#acceptConstructorReference(char[], int, int) *///from www.ja v a2s . com public void acceptConstructorReference(char[] typeName, int argCount, int sourcePosition) { if (CharOperation.indexOf(Signature.C_GENERIC_START, typeName) > 0) { typeName = Signature.toCharArray( Signature.getTypeErasure(Signature.createTypeSignature(typeName, false)).toCharArray()); } this.indexer.addConstructorReference(typeName, argCount); int lastDot = CharOperation.lastIndexOf('.', typeName); if (lastDot != -1) { char[][] qualification = CharOperation.splitOn('.', CharOperation.subarray(typeName, 0, lastDot)); for (int i = 0, length = qualification.length; i < length; i++) { this.indexer.addNameReference(qualification[i]); } } }
From source file:com.codenvy.ide.ext.java.server.internal.core.search.matching.ConstructorPattern.java
License:Open Source License
private static char[] getTypeErasure(char[] typeName) { int index;/* www .jav a 2 s.c o m*/ if ((index = CharOperation.indexOf('<', typeName)) == -1) return typeName; int length = typeName.length; char[] typeErasurename = new char[length - 2]; System.arraycopy(typeName, 0, typeErasurename, 0, index); int depth = 1; for (int i = index + 1; i < length; i++) { switch (typeName[i]) { case '<': depth++; break; case '>': depth--; break; default: if (depth == 0) { typeErasurename[index++] = typeName[i]; } break; } } System.arraycopy(typeErasurename, 0, typeErasurename = new char[index], 0, index); return typeErasurename; }
From source file:com.codenvy.ide.ext.java.server.internal.core.search.matching.SuperTypeNamesCollector.java
License:Open Source License
protected boolean matches(char[][] compoundName) { int length = compoundName.length; if (length == 0) return false; char[] simpleName = compoundName[length - 1]; int last = length - 1; if (this.typeSimpleName == null || this.pattern.matchesName(simpleName, this.typeSimpleName)) { // most frequent case: simple name equals last segment of compoundName char[][] qualification = new char[last][]; System.arraycopy(compoundName, 0, qualification, 0, last); return this.pattern.matchesName(this.typeQualification, CharOperation.concatWith(qualification, '.')); }// w w w. j a v a 2s.com if (!CharOperation.endsWith(simpleName, this.typeSimpleName)) return false; // member type -> transform A.B.C$D into A.B.C.D System.arraycopy(compoundName, 0, compoundName = new char[length + 1][], 0, last); int dollar = CharOperation.indexOf('$', simpleName); if (dollar == -1) return false; compoundName[last] = CharOperation.subarray(simpleName, 0, dollar); compoundName[length] = CharOperation.subarray(simpleName, dollar + 1, simpleName.length); return this.matches(compoundName); }
From source file:com.codenvy.ide.ext.java.server.internal.core.util.Util.java
License:Open Source License
/** Extracts the parameter types from a method signature. */ public static String[] extractParameterTypes(char[] sig) { int count = getParameterCount(sig); String[] result = new String[count]; if (count == 0) return result; int i = CharOperation.indexOf('(', sig) + 1; count = 0;//from w w w . j a v a2 s. co m int len = sig.length; int start = i; for (;;) { if (i == len) break; char c = sig[i]; if (c == ')') break; if (c == '[') { ++i; } else if (c == 'L') { i = CharOperation.indexOf(';', sig, i + 1) + 1; Assert.isTrue(i != 0); result[count++] = convertTypeSignature(sig, start, i - start); start = i; } else { ++i; result[count++] = convertTypeSignature(sig, start, i - start); start = i; } } return result; }
From source file:com.codenvy.ide.ext.java.server.internal.core.util.Util.java
License:Open Source License
/** Returns the number of parameter types in a method signature. */ public static int getParameterCount(char[] sig) { int i = CharOperation.indexOf('(', sig) + 1; Assert.isTrue(i != 0);//from www . j ava2 s.c o m int count = 0; int len = sig.length; for (;;) { if (i == len) break; char c = sig[i]; if (c == ')') break; if (c == '[') { ++i; } else if (c == 'L') { ++count; i = CharOperation.indexOf(';', sig, i + 1) + 1; Assert.isTrue(i != 0); } else { ++count; ++i; } } return count; }
From source file:com.codenvy.ide.ext.java.server.internal.core.util.Util.java
License:Open Source License
public static char[] toAnchor(int startingIndex, char[] methodSignature, char[] methodName, boolean isVargArgs) { int firstParen = CharOperation.indexOf(Signature.C_PARAM_START, methodSignature); if (firstParen == -1) { throw new IllegalArgumentException(); }// ww w . j a va2 s .c o m StringBuffer buffer = new StringBuffer(methodSignature.length + 10); // selector if (methodName != null) { buffer.append(methodName); } // parameters buffer.append('('); char[][] pts = Signature.getParameterTypes(methodSignature); for (int i = startingIndex, max = pts.length; i < max; i++) { if (i == max - 1) { appendTypeSignatureForAnchor(pts[i], 0, buffer, isVargArgs); } else { appendTypeSignatureForAnchor(pts[i], 0, buffer, false); } if (i != pts.length - 1) { buffer.append(','); buffer.append(' '); } } buffer.append(')'); char[] result = new char[buffer.length()]; buffer.getChars(0, buffer.length(), result, 0); return result; }
From source file:com.ibm.research.tours.content.url.Signature.java
License:Open Source License
/** * Returns the number of parameter types in the given method signature. * * @param methodSignature the method signature * @return the number of parameters/* ww w . j a va 2s. c o m*/ * @exception IllegalArgumentException if the signature is not syntactically * correct * @since 2.0 */ public static int getParameterCount(char[] methodSignature) throws IllegalArgumentException { try { int count = 0; int i = CharOperation.indexOf(C_PARAM_START, methodSignature); if (i < 0) { throw new IllegalArgumentException(); } else { i++; } for (;;) { if (methodSignature[i] == C_PARAM_END) { return count; } int e = Util.scanTypeSignature(methodSignature, i); if (e < 0) { throw new IllegalArgumentException(); } else { i = e + 1; } count++; } } catch (ArrayIndexOutOfBoundsException e) { throw new IllegalArgumentException(); } }