List of usage examples for org.eclipse.jdt.core.compiler CharOperation charArrayToStringArray
public static String[] charArrayToStringArray(char[][] charArrays)
From source file:spoon.support.compiler.jdt.ReferenceBuilder.java
License:Open Source License
/** * In no classpath, the model of the super interface isn't always correct. *///from w ww. ja v a 2 s.c om private boolean isCorrectTypeReference(TypeReference ref) { if (ref.resolvedType == null) { return false; } if (!(ref.resolvedType instanceof ProblemReferenceBinding)) { return true; } final String[] compoundName = CharOperation .charArrayToStringArray(((ProblemReferenceBinding) ref.resolvedType).compoundName); final String[] typeName = CharOperation.charArrayToStringArray(ref.getTypeName()); if (compoundName.length == 0 || typeName.length == 0) { return false; } return compoundName[compoundName.length - 1].equals(typeName[typeName.length - 1]); }
From source file:spoon.support.compiler.jdt.ReferenceBuilder.java
License:Open Source License
/** * JDT doesn't return a correct AST with the resolved type of the reference. * This method try to build a correct Spoon AST from the name of the JDT * reference, thanks to the parsing of the string, the name parameterized from * the JDT reference and java convention. * Returns a complete Spoon AST when the name is correct, otherwise a spoon type * reference with a name that correspond to the name of the JDT type reference. *///from www . j a va2s . c o m <T> CtTypeReference<T> getTypeReference(TypeReference ref) { if (ref == null) { return null; } CtTypeReference<T> res = null; CtTypeReference inner = null; final String[] namesParameterized = CharOperation.charArrayToStringArray(ref.getParameterizedTypeName()); String nameParameterized = CharOperation.toString(ref.getParameterizedTypeName()); String typeName = CharOperation.toString(ref.getTypeName()); int index = namesParameterized.length - 1; for (; index >= 0; index--) { // Start at the end to get the class name first. CtTypeReference main = getTypeReference(namesParameterized[index]); if (main == null) { break; } if (res == null) { res = (CtTypeReference<T>) main; } else { inner.setDeclaringType((CtTypeReference<?>) main); } inner = main; } if (res == null) { return this.jdtTreeBuilder.getFactory().Type().createReference(nameParameterized); } if (inner.getPackage() == null) { PackageFactory packageFactory = this.jdtTreeBuilder.getFactory().Package(); CtPackageReference packageReference = index >= 0 ? packageFactory.getOrCreate(concatSubArray(namesParameterized, index)).getReference() : packageFactory.topLevel(); inner.setPackage(packageReference); } if (!res.toString().replace(", ?", ",?").endsWith(nameParameterized)) { // verify that we did not match a class that have the same name in a different package return this.jdtTreeBuilder.getFactory().Type().createReference(typeName); } return res; }