Java Code Examples for org.eclipse.jdt.core.compiler.CharOperation#lastIndexOf()

The following examples show how to use org.eclipse.jdt.core.compiler.CharOperation#lastIndexOf() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CompilationUnitDeclaration.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
public char[] getMainTypeName() {
	if (this.compilationResult.compilationUnit == null) {
		char[] fileName = this.compilationResult.getFileName();

		int start = CharOperation.lastIndexOf('/', fileName) + 1;
		if (start == 0 || start < CharOperation.lastIndexOf('\\', fileName))
			start = CharOperation.lastIndexOf('\\', fileName) + 1;

		int end = CharOperation.lastIndexOf('.', fileName);
		if (end == -1)
			end = fileName.length;

		return CharOperation.subarray(fileName, start, end);
	} else {
		return this.compilationResult.compilationUnit.getMainTypeName();
	}
}
 
Example 2
Source File: ClassFileReader.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
public char[] getSourceName() {
	if (this.sourceName != null)
		return this.sourceName;

	char[] name = getInnerSourceName(); // member or local scenario
	if (name == null) {
		name = getName(); // extract from full name
		int start;
		if (isAnonymous()) {
			start = CharOperation.indexOf('$', name, CharOperation.lastIndexOf('/', name) + 1) + 1;
		} else {
			start = CharOperation.lastIndexOf('/', name) + 1;
		}
		if (start > 0) {
			char[] newName = new char[name.length - start];
			System.arraycopy(name, start, newName, 0, newName.length);
			name = newName;
		}
	}
	return this.sourceName = name;
}
 
Example 3
Source File: BasicCompilationUnit.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
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;

		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;
}
 
Example 4
Source File: Util.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private static ICompilationUnit getCompilationUnit(char[] fileName, WorkingCopyOwner workingCopyOwner) {
	char[] slashSeparatedFileName = CharOperation.replaceOnCopy(fileName, File.separatorChar, '/');
	int pkgEnd = CharOperation.lastIndexOf('/', slashSeparatedFileName); // pkgEnd is exclusive
	if (pkgEnd == -1)
		return null;
	IPackageFragment pkg = getPackageFragment(slashSeparatedFileName, pkgEnd, -1/*no jar separator for .java files*/);
	if (pkg == null) return null;
	int start;
	ICompilationUnit cu = pkg.getCompilationUnit(new String(slashSeparatedFileName, start =  pkgEnd+1, slashSeparatedFileName.length - start));
	if (workingCopyOwner != null) {
		ICompilationUnit workingCopy = cu.findWorkingCopy(workingCopyOwner);
		if (workingCopy != null)
			return workingCopy;
	}
	return cu;
}
 
Example 5
Source File: LocalTypeBinding.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public char[] computeUniqueKey(boolean isLeaf) {
	if (!isPrototype())
		return this.prototype.computeUniqueKey(isLeaf);
	
	char[] outerKey = outermostEnclosingType().computeUniqueKey(isLeaf);
	int semicolon = CharOperation.lastIndexOf(';', outerKey);

	StringBuffer sig = new StringBuffer();
	sig.append(outerKey, 0, semicolon);

	// insert $sourceStart
	sig.append('$');
	sig.append(String.valueOf(this.sourceStart));

	// insert $LocalName if local
	if (!isAnonymousType()) {
		sig.append('$');
		sig.append(this.sourceName);
	}

	// insert remaining from outer key
	sig.append(outerKey, semicolon, outerKey.length-semicolon);

	int sigLength = sig.length();
	char[] uniqueKey = new char[sigLength];
	sig.getChars(0, sigLength, uniqueKey, 0);
	return uniqueKey;
}
 
Example 6
Source File: DefaultBytecodeVisitor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private String returnClassName(char[] classInfoName) {
	if (classInfoName.length == 0) {
		return EMPTY_CLASS_NAME;
	} else if (isCompact()) {
		int lastIndexOfSlash = CharOperation.lastIndexOf('/', classInfoName);
		if (lastIndexOfSlash != -1) {
			return new String(classInfoName, lastIndexOfSlash + 1, classInfoName.length - lastIndexOfSlash - 1);
		}
	}
	CharOperation.replace(classInfoName, '/', '.');
	return new String(classInfoName);
}
 
Example 7
Source File: Util.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private static IClassFile getClassFile(char[] fileName) {
	int jarSeparator = CharOperation.indexOf(IDependent.JAR_FILE_ENTRY_SEPARATOR, fileName);
	int pkgEnd = CharOperation.lastIndexOf('/', fileName); // pkgEnd is exclusive
	if (pkgEnd == -1)
		pkgEnd = CharOperation.lastIndexOf(File.separatorChar, fileName);
	if (jarSeparator != -1 && pkgEnd < jarSeparator) // if in a jar and no slash, it is a default package -> pkgEnd should be equal to jarSeparator
		pkgEnd = jarSeparator;
	if (pkgEnd == -1)
		return null;
	IPackageFragment pkg = getPackageFragment(fileName, pkgEnd, jarSeparator);
	if (pkg == null) return null;
	int start;
	return pkg.getClassFile(new String(fileName, start = pkgEnd + 1, fileName.length - start));
}
 
Example 8
Source File: Main.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public String extractDestinationPathFromSourceFile(CompilationResult result) {
	ICompilationUnit compilationUnit = result.compilationUnit;
	if (compilationUnit != null) {
		char[] fileName = compilationUnit.getFileName();
		int lastIndex = CharOperation.lastIndexOf(java.io.File.separatorChar, fileName);
		if (lastIndex != -1) {
			final String outputPathName = new String(fileName, 0, lastIndex);
			final File output = new File(outputPathName);
			if (output.exists() && output.isDirectory()) {
				return outputPathName;
			}
		}
	}
	return System.getProperty("user.dir"); //$NON-NLS-1$
}
 
Example 9
Source File: Disassembler.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private char[] returnClassName(char[] classInfoName, char separator, int mode) {
	if (classInfoName.length == 0) {
		return CharOperation.NO_CHAR;
	} else if (isCompact(mode)) {
		int lastIndexOfSlash = CharOperation.lastIndexOf(separator, classInfoName);
		if (lastIndexOfSlash != -1) {
			return CharOperation.subarray(classInfoName, lastIndexOfSlash + 1, classInfoName.length);
		}
	}
	return classInfoName;
}
 
Example 10
Source File: CompilationUnit.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public CompilationUnit(char[] contents, String fileName, String encoding,
		String destinationPath, boolean ignoreOptionalProblems) {
	this.contents = contents;
	char[] fileNameCharArray = fileName.toCharArray();
	switch(File.separatorChar) {
		case '/' :
			if (CharOperation.indexOf('\\', fileNameCharArray) != -1) {
				CharOperation.replace(fileNameCharArray, '\\', '/');
			}
			break;
		case '\\' :
			if (CharOperation.indexOf('/', fileNameCharArray) != -1) {
				CharOperation.replace(fileNameCharArray, '/', '\\');
			}
	}
	this.fileName = fileNameCharArray;
	int start = CharOperation.lastIndexOf(File.separatorChar, fileNameCharArray) + 1;

	int end = CharOperation.lastIndexOf('.', fileNameCharArray);
	if (end == -1) {
		end = fileNameCharArray.length;
	}

	this.mainTypeName = CharOperation.subarray(fileNameCharArray, start, end);
	this.encoding = encoding;
	this.destinationPath = destinationPath;
	this.ignoreOptionalProblems = ignoreOptionalProblems;
}
 
Example 11
Source File: SourceFile.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
public char[] getMainTypeName() {
	char[] typeName = this.initialTypeName.toCharArray();
	int lastIndex = CharOperation.lastIndexOf('/', typeName);
	return CharOperation.subarray(typeName, lastIndex + 1, -1);
}
 
Example 12
Source File: FileSystem.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
private void initializeKnownFileNames(String[] initialFileNames) {
	if (initialFileNames == null) {
		this.knownFileNames = new HashSet(0);
		return;
	}
	this.knownFileNames = new HashSet(initialFileNames.length * 2);
	for (int i = initialFileNames.length; --i >= 0;) {
		File compilationUnitFile = new File(initialFileNames[i]);
		char[] fileName = null;
		try {
			fileName = compilationUnitFile.getCanonicalPath().toCharArray();
		} catch (IOException e) {
			// this should not happen as the file exists
			continue;
		}
		char[] matchingPathName = null;
		final int lastIndexOf = CharOperation.lastIndexOf('.', fileName);
		if (lastIndexOf != -1) {
			fileName = CharOperation.subarray(fileName, 0, lastIndexOf);
		}
		CharOperation.replace(fileName, '\\', '/');
		boolean globalPathMatches = false;
		// the most nested path should be the selected one
		for (int j = 0, max = this.classpaths.length; j < max; j++) {
			char[] matchCandidate = this.classpaths[j].normalizedPath();
			boolean currentPathMatch = false;
			if (this.classpaths[j] instanceof ClasspathDirectory
					&& CharOperation.prefixEquals(matchCandidate, fileName)) {
				currentPathMatch = true;
				if (matchingPathName == null) {
					matchingPathName = matchCandidate;
				} else {
					if (currentPathMatch) {
						// we have a second source folder that matches the path of the source file
						if (matchCandidate.length > matchingPathName.length) {
							// we want to preserve the shortest possible path
							matchingPathName = matchCandidate;
						}
					} else {
						// we want to preserve the shortest possible path
						if (!globalPathMatches && matchCandidate.length < matchingPathName.length) {
							matchingPathName = matchCandidate;
						}
					}
				}
				if (currentPathMatch) {
					globalPathMatches = true;
				}
			}
		}
		if (matchingPathName == null) {
			this.knownFileNames.add(new String(fileName)); // leave as is...
		} else {
			this.knownFileNames.add(new String(CharOperation.subarray(fileName, matchingPathName.length, fileName.length)));
		}
		matchingPathName = null;
	}
}
 
Example 13
Source File: SourceFile.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
public char[][] getPackageName() {
	char[] typeName = this.initialTypeName.toCharArray();
	int lastIndex = CharOperation.lastIndexOf('/', typeName);
	return CharOperation.splitOn('/', typeName, 0, lastIndex);
}
 
Example 14
Source File: JDTCompilerAdapter.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * 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.
 * @param args compiler arguments to process
 */
private void checkCompilerArgs(String[] args) {
	for (int i = 0; i < args.length; i++) {
		if (args[i].charAt(0) == '@') {
			try {
				char[] content = Util.getFileCharContent(new File(args[i].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 (this.fileEncodings == null)
									this.fileEncodings = new HashMap();
								//use File to translate the string into a path with the correct File.seperator
								this.fileEncodings.put(str, enc);
							} else {
								if (this.dirEncodings == null)
									this.dirEncodings = new HashMap();
								this.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 (this.accessRules == null)
								this.accessRules = new ArrayList();
							this.accessRules.add(path);
							this.accessRules.add(access);
						}
					}
					offset = end;
				}
			} catch (IOException e) {
				//ignore
			}
		}
	}

}
 
Example 15
Source File: Util.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
public static String toString(char[] declaringClass, char[] methodName, char[] methodSignature, boolean includeReturnType, boolean compact) {
	final boolean isConstructor = CharOperation.equals(methodName, INIT);
	int firstParen = CharOperation.indexOf(Signature.C_PARAM_START, methodSignature);
	if (firstParen == -1) {
		return ""; //$NON-NLS-1$
	}

	StringBuffer buffer = new StringBuffer(methodSignature.length + 10);

	// decode declaring class name
	// it can be either an array signature or a type signature
	if (declaringClass != null && declaringClass.length > 0) {
		char[] declaringClassSignature = null;
		if (declaringClass[0] == Signature.C_ARRAY) {
			CharOperation.replace(declaringClass, '/', '.');
			declaringClassSignature = Signature.toCharArray(declaringClass);
		} else {
			CharOperation.replace(declaringClass, '/', '.');
			declaringClassSignature = declaringClass;
		}
		int lastIndexOfSlash = CharOperation.lastIndexOf('.', declaringClassSignature);
		if (compact && lastIndexOfSlash != -1) {
			buffer.append(declaringClassSignature, lastIndexOfSlash + 1, declaringClassSignature.length - lastIndexOfSlash - 1);
		} else {
			buffer.append(declaringClassSignature);
		}
		if (!isConstructor) {
			buffer.append('.');
		}
	}

	// selector
	if (!isConstructor && methodName != null) {
		buffer.append(methodName);
	}

	// parameters
	buffer.append('(');
	char[][] pts = Signature.getParameterTypes(methodSignature);
	for (int i = 0, max = pts.length; i < max; i++) {
		appendTypeSignature(pts[i], 0 , buffer, compact);
		if (i != pts.length - 1) {
			buffer.append(',');
			buffer.append(' ');
		}
	}
	buffer.append(')');

	if (!isConstructor) {
		buffer.append(" : "); //$NON-NLS-1$
		// return type
		if (includeReturnType) {
			char[] rts = Signature.getReturnType(methodSignature);
			appendTypeSignature(rts, 0 , buffer, compact);
		}
	}
	return String.valueOf(buffer);
}
 
Example 16
Source File: HierarchyResolver.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
private IType findSuperClass(IGenericType type, ReferenceBinding typeBinding) {
	ReferenceBinding superBinding = typeBinding.superclass();

	if (superBinding != null) {
		superBinding = (ReferenceBinding) superBinding.erasure();
		if (typeBinding.isHierarchyInconsistent()) {
			if (superBinding.problemId() == ProblemReasons.NotFound) {
				this.hasMissingSuperClass = true;
				this.builder.hierarchy.missingTypes.add(new String(superBinding.sourceName)); // note: this could be Map$Entry
				return null;
			} else if ((superBinding.id == TypeIds.T_JavaLangObject)) {
				char[] superclassName;
				char separator;
				if (type instanceof IBinaryType) {
					superclassName = ((IBinaryType)type).getSuperclassName();
					separator = '/';
				} else if (type instanceof ISourceType) {
					superclassName = ((ISourceType)type).getSuperclassName();
					separator = '.';
				} else if (type instanceof HierarchyType) {
					superclassName = ((HierarchyType)type).superclassName;
					separator = '.';
				} else {
					return null;
				}

				if (superclassName != null) { // check whether subclass of Object due to broken hierarchy (as opposed to explicitly extending it)
					int lastSeparator = CharOperation.lastIndexOf(separator, superclassName);
					char[] simpleName = lastSeparator == -1 ? superclassName : CharOperation.subarray(superclassName, lastSeparator+1, superclassName.length);
					if (!CharOperation.equals(simpleName, TypeConstants.OBJECT)) {
						this.hasMissingSuperClass = true;
						this.builder.hierarchy.missingTypes.add(new String(simpleName));
						return null;
					}
				}
			}
		}
		for (int t = this.typeIndex; t >= 0; t--) {
			if (TypeBinding.equalsEquals(this.typeBindings[t], superBinding)) {
				return this.builder.getHandle(this.typeModels[t], superBinding);
			}
		}
	}
	return null;
}
 
Example 17
Source File: BinaryIndexer.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
private int extractArgCount(char[] signature, char[] className) throws ClassFormatException {
	int indexOfClosingParen = CharOperation.lastIndexOf(')', signature);
	if (indexOfClosingParen == 1) {
		// there is no parameter
		return 0;
	}
	if (indexOfClosingParen == -1) {
		throw new ClassFormatException(ClassFormatException.ErrInvalidMethodSignature);
	}
	int parameterTypesCounter = 0;
	for (int i = 1; i < indexOfClosingParen; i++) {
		switch(signature[i]) {
			case 'B':
			case 'C':
			case 'D':
			case 'F':
			case 'I':
			case 'J':
			case 'S':
			case 'Z':
				parameterTypesCounter++;
				break;
			case 'L':
				int indexOfSemiColon = CharOperation.indexOf(';', signature, i+1);
				if (indexOfSemiColon == -1) throw new ClassFormatException(ClassFormatException.ErrInvalidMethodSignature);
				// verify if first parameter is synthetic
				if (className != null && parameterTypesCounter == 0) {
					char[] classSignature = Signature.createCharArrayTypeSignature(className, true);
					int length = indexOfSemiColon-i+1;
					if (classSignature.length > (length+1)) {
						// synthetic means that parameter type has same signature than given class
						for (int j=i, k=0; j<indexOfSemiColon; j++, k++) {
							if (!(signature[j] == classSignature[k] || (signature[j] == '/' && classSignature[k] == '.' ))) {
								parameterTypesCounter++;
								break;
							}
						}
					} else {
						parameterTypesCounter++;
					}
					className = null; // do not verify following parameters
				} else {
					parameterTypesCounter++;
				}
				i = indexOfSemiColon;
				break;
			case '[':
				break;
			default:
				throw new ClassFormatException(ClassFormatException.ErrInvalidMethodSignature);
		}
	}
	return parameterTypesCounter;
}
 
Example 18
Source File: BinaryIndexer.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
private char[] decodeReturnType(char[] signature) throws ClassFormatException {
	if (signature == null) return null;
	int indexOfClosingParen = CharOperation.lastIndexOf(')', signature);
	if (indexOfClosingParen == -1) throw new ClassFormatException(ClassFormatException.ErrInvalidMethodSignature);
	int arrayDim = 0;
	for (int i = indexOfClosingParen + 1, max = signature.length; i < max; i++) {
		switch(signature[i]) {
			case 'B':
				if (arrayDim > 0)
					return convertToArrayType(BYTE, arrayDim);
				return BYTE;

			case 'C':
				if (arrayDim > 0)
					return convertToArrayType(CHAR, arrayDim);
				return CHAR;

			case 'D':
				if (arrayDim > 0)
					return convertToArrayType(DOUBLE, arrayDim);
				return DOUBLE;

			case 'F':
				if (arrayDim > 0)
					return convertToArrayType(FLOAT, arrayDim);
				return FLOAT;

			case 'I':
				if (arrayDim > 0)
					return convertToArrayType(INT, arrayDim);
				return INT;

			case 'J':
				if (arrayDim > 0)
					return convertToArrayType(LONG, arrayDim);
				return LONG;

			case 'L':
				int indexOfSemiColon = CharOperation.indexOf(';', signature, i+1);
				if (indexOfSemiColon == -1) throw new ClassFormatException(ClassFormatException.ErrInvalidMethodSignature);
				if (arrayDim > 0) {
					return convertToArrayType(replace('/','.',CharOperation.subarray(signature, i + 1, indexOfSemiColon)), arrayDim);
				}
				return replace('/','.',CharOperation.subarray(signature, i + 1, indexOfSemiColon));

			case 'S':
				if (arrayDim > 0)
					return convertToArrayType(SHORT, arrayDim);
				return SHORT;

			case 'Z':
				if (arrayDim > 0)
					return convertToArrayType(BOOLEAN, arrayDim);
				return BOOLEAN;

			case 'V':
				return VOID;

			case '[':
				arrayDim++;
				break;

			default:
				throw new ClassFormatException(ClassFormatException.ErrInvalidMethodSignature);
		}
	}
	return null;
}
 
Example 19
Source File: Signature.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 3 votes vote down vote up
/**
 * 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>
 * 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);
}
 
Example 20
Source File: Signature.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 3 votes vote down vote up
/**
 * Extracts the return type from the given method signature. The method signature is
 * expected to be dot-based.
 *
 * @param methodSignature the method signature
 * @return the type signature of the return type
 * @exception IllegalArgumentException if the signature is syntactically
 *   incorrect
 *
 * @since 2.0
 */
public static char[] getReturnType(char[] methodSignature) throws IllegalArgumentException {
	// skip type parameters
	int paren = CharOperation.lastIndexOf(C_PARAM_END, methodSignature);
	if (paren == -1) {
		throw new IllegalArgumentException();
	}
	// there could be thrown exceptions behind, thus scan one type exactly
	int last = Util.scanTypeSignature(methodSignature, paren+1);
	return CharOperation.subarray(methodSignature, paren + 1, last+1);
}