List of usage examples for org.eclipse.jdt.core.compiler CharOperation charToString
public static String charToString(char[] charArray)
From source file:com.codenvy.ide.ext.java.server.internal.core.search.matching.MatchLocator.java
License:Open Source License
/** * Creates an IMethod from the given method declaration and type. *//*from ww w .ja v a2s . co m*/ protected IJavaElement createHandle(AbstractMethodDeclaration method, IJavaElement parent) { if (!(parent instanceof IType)) return parent; IType type = (IType) parent; Argument[] arguments = method.arguments; int argCount = arguments == null ? 0 : arguments.length; if (type.isBinary()) { // don't cache the methods of the binary type // fall thru if its a constructor with a synthetic argument... find it the slower way ClassFileReader reader = classFileReader(type); if (reader != null) { // build arguments names boolean firstIsSynthetic = false; if (reader.isMember() && method.isConstructor() && !Flags.isStatic(reader.getModifiers())) { // see https://bugs.eclipse.org/bugs/show_bug.cgi?id=48261 firstIsSynthetic = true; argCount++; } char[][] argumentTypeNames = new char[argCount][]; for (int i = 0; i < argCount; i++) { char[] typeName = null; if (i == 0 && firstIsSynthetic) { typeName = type.getDeclaringType().getFullyQualifiedName().toCharArray(); } else if (arguments != null) { TypeReference typeRef = arguments[firstIsSynthetic ? i - 1 : i].type; typeName = CharOperation.concatWith(typeRef.getTypeName(), '.'); for (int k = 0, dim = typeRef.dimensions(); k < dim; k++) typeName = CharOperation.concat(typeName, new char[] { '[', ']' }); } if (typeName == null) { // invalid type name return null; } argumentTypeNames[i] = typeName; } // return binary method IMethod binaryMethod = createBinaryMethodHandle(type, method.selector, argumentTypeNames); if (binaryMethod == null) { // when first attempt fails, try with similar matches if any... PossibleMatch similarMatch = this.currentPossibleMatch.getSimilarMatch(); while (similarMatch != null) { type = ((ClassFile) similarMatch.openable).getType(); binaryMethod = createBinaryMethodHandle(type, method.selector, argumentTypeNames); if (binaryMethod != null) { return binaryMethod; } similarMatch = similarMatch.getSimilarMatch(); } } return binaryMethod; } if (BasicSearchEngine.VERBOSE) { System.out.println("Not able to createHandle for the method " + //$NON-NLS-1$ CharOperation.charToString(method.selector) + " May miss some results"); //$NON-NLS-1$ } return null; } String[] parameterTypeSignatures = new String[argCount]; if (arguments != null) { for (int i = 0; i < argCount; i++) { TypeReference typeRef = arguments[i].type; char[] typeName = CharOperation.concatWith(typeRef.getParameterizedTypeName(), '.'); parameterTypeSignatures[i] = Signature.createTypeSignature(typeName, false); } } return createMethodHandle(type, new String(method.selector), parameterTypeSignatures); }
From source file:com.google.gwt.dev.javac.CompiledClass.java
License:Open Source License
CompiledClass(TypeDeclaration typeDeclaration, CompiledClass enclosingClass) {
this.enclosingClass = enclosingClass;
SourceTypeBinding binding = typeDeclaration.binding;
this.internalName = CharOperation.charToString(binding.constantPoolName());
this.isLocal = isLocalType(binding);
ClassFile classFile = getClassFile(typeDeclaration, internalName);
if (classFile != null) {
m_bytes = classFile.getBytes();/*from w ww. j a va 2s. c o m*/
} else {
m_bytes = ArrayUtils.EMPTY_BYTE_ARRAY;
}
}
From source file:com.google.gwt.dev.javac.JdtUtil.java
License:Apache License
public static String getSourceName(TypeBinding classBinding) { return Joiner.on(".").skipNulls() .join(new String[] { Strings.emptyToNull(CharOperation.charToString(classBinding.qualifiedPackageName())), CharOperation.charToString(classBinding.qualifiedSourceName()) }); }
From source file:com.redhat.ceylon.eclipse.core.model.JDTModelLoader.java
License:Open Source License
private JDTClass buildClassMirror(String name) { if (javaProject == null) { return null; }/*from w ww .j a v a 2 s.c o m*/ try { LookupEnvironment theLookupEnvironment = getLookupEnvironment(); char[][] uncertainCompoundName = CharOperation.splitOn('.', name.toCharArray()); int numberOfParts = uncertainCompoundName.length; char[][] compoundName = null; IType type = null; for (int i = numberOfParts - 1; i > 0; i--) { char[][] triedPackageName = new char[0][]; for (int j = 0; j < i; j++) { triedPackageName = CharOperation.arrayConcat(triedPackageName, uncertainCompoundName[j]); } char[] triedClassName = new char[0]; for (int k = i; k < numberOfParts; k++) { triedClassName = CharOperation.concat(triedClassName, uncertainCompoundName[k], '$'); } ModelLoaderNameEnvironment nameEnvironment = getNameEnvironment(); type = nameEnvironment.findTypeInNameLookup(CharOperation.charToString(triedClassName), CharOperation.toString(triedPackageName)); if (type != null) { compoundName = CharOperation.arrayConcat(triedPackageName, triedClassName); break; } } if (type == null) { return null; } ReferenceBinding binding = toBinding(type, theLookupEnvironment, compoundName); if (binding != null) { return new JDTClass(binding, type); } } catch (JavaModelException e) { e.printStackTrace(); } return null; }
From source file:com.redhat.ceylon.eclipse.core.model.mirror.JDTMethod.java
License:Open Source License
private boolean ignoreMethodInAncestorSearch(MethodBinding methodBinding) { String name = CharOperation.charToString(methodBinding.selector); if (name.equals("finalize") || name.equals("clone")) { if (methodBinding.declaringClass != null && CharOperation .toString(methodBinding.declaringClass.compoundName).equals("java.lang.Object")) { return true; }/* ww w . j a v a2 s .c o m*/ } // skip ignored methods too if (JDTUtils.hasAnnotation(methodBinding, AbstractModelLoader.CEYLON_IGNORE_ANNOTATION)) { return true; } return false; }
From source file:spoon.support.compiler.jdt.JDTCommentBuilder.java
License:Open Source License
/** * Creates a JDTCommentBuilder that will insert all comment of the declarationUnit into the Spoon AST * @param declarationUnit the declaration unit * @param factory the Spoon AST// w w w.j av a 2 s. c o m */ JDTCommentBuilder(CompilationUnitDeclaration declarationUnit, Factory factory) { this.declarationUnit = declarationUnit; if (declarationUnit.comments == null) { return; } this.factory = factory; this.sourceUnit = declarationUnit.compilationResult.compilationUnit; this.contents = sourceUnit.getContents(); this.filePath = CharOperation.charToString(sourceUnit.getFileName()); this.spoonUnit = factory.CompilationUnit().create(filePath); }
From source file:spoon.support.compiler.jdt.JDTImportBuilder.java
License:Open Source License
JDTImportBuilder(CompilationUnitDeclaration declarationUnit, Factory factory) {
this.declarationUnit = declarationUnit;
this.factory = factory;
this.sourceUnit = declarationUnit.compilationResult.compilationUnit;
this.filePath = CharOperation.charToString(sourceUnit.getFileName());
// get the CU: it has already been built during model building in JDTBasedSpoonCompiler
this.spoonUnit = JDTTreeBuilder.getOrCreateCompilationUnit(declarationUnit, factory);
this.imports = new HashSet<>();
}
From source file:spoon.support.compiler.jdt.JDTTreeBuilderHelper.java
License:Open Source License
/** * Computes the anonymous simple name from its fully qualified type name. * * @param anonymousQualifiedName// www. j a v a 2 s .c o m * Qualified name which contains the anonymous name. * @return Anonymous simple name. */ static String computeAnonymousName(char[] anonymousQualifiedName) { final String poolName = CharOperation.charToString(anonymousQualifiedName); return poolName.substring(poolName.lastIndexOf(CtType.INNERTTYPE_SEPARATOR) + 1); }
From source file:spoon.support.compiler.jdt.JDTTreeBuilderHelper.java
License:Open Source License
/** * Creates a qualified type name from a two-dimensional array. * * @param typeName/*from w w w . j a v a 2s . co m*/ * two-dimensional array which represents the qualified name expected. * @return Qualified name. */ static String createQualifiedTypeName(char[][] typeName) { StringBuilder s = new StringBuilder(); for (int i = 0; i < typeName.length - 1; i++) { s.append(CharOperation.charToString(typeName[i])).append("."); } s.append(CharOperation.charToString(typeName[typeName.length - 1])); return s.toString(); }
From source file:spoon.support.compiler.jdt.JDTTreeBuilderHelper.java
License:Open Source License
/** * Creates a catch variable from a type reference. * * @param typeReference//from w w w . jav a 2 s.c o m * Corresponds to the exception type declared in the catch. * @return a catch variable. */ CtCatchVariable<Throwable> createCatchVariable(TypeReference typeReference) { final Argument jdtCatch = (Argument) jdtTreeBuilder.getContextBuilder().stack.peekFirst().node; final Set<CtExtendedModifier> modifiers = getModifiers(jdtCatch.modifiers, false, false); CtCatchVariable<Throwable> result = jdtTreeBuilder.getFactory().Core().createCatchVariable(); result.<CtCatchVariable>setSimpleName(CharOperation.charToString(jdtCatch.name)) .setExtendedModifiers(modifiers); if (typeReference instanceof UnionTypeReference) { //do not set type of variable yet. It will be initialized later by visit of multiple types. Each call then ADDs one type return result; } else { CtTypeReference ctTypeReference = jdtTreeBuilder.getReferencesBuilder() .<Throwable>getTypeReference(typeReference.resolvedType); return result.<CtCatchVariable>setType(ctTypeReference); } }