@Override public boolean onAccess(char[][] tokens, int index) { return !CharOperation.equals(tokens[index + 1], tokens[tokens.length - 1]); } });
@Override protected void report(Environment environment, CategorizedProblem problem) { if (problem.isError()) { throw new SnippetCompilationError(problem.getMessage() + "at line " + problem.getSourceLineNumber()); } }
/** * Computes the anonymous simple name from its fully qualified type name. * * @param anonymousQualifiedName * 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); }
/** * Checks if the qualified name reference is a problem field binding and have a valid field. * * @param qualifiedNameReference * Reference which should contains a problem field binding. * @return true if the qualified name reference is a valid problem field binding. */ static boolean isValidProblemBindingField(QualifiedNameReference qualifiedNameReference) { return qualifiedNameReference.binding instanceof ProblemFieldBinding && !((FieldBinding) qualifiedNameReference.binding).declaringClass.isAnonymousType() && qualifiedNameReference.tokens.length - 1 == ((FieldBinding) qualifiedNameReference.binding).declaringClass.compoundName.length && CharOperation .equals(CharOperation.subarray(qualifiedNameReference.tokens, 0, qualifiedNameReference.tokens.length - 1), ((FieldBinding) qualifiedNameReference.binding).declaringClass.compoundName); }
/** * report a compilation problem (callback for JDT) */ public void reportProblem(CategorizedProblem pb) { if (pb == null) { return; } // we can not accept this problem, even in noclasspath mode // otherwise a nasty null pointer exception occurs later if (pb.getID() == IProblem.DuplicateTypes) { if (getFactory().getEnvironment().isIgnoreDuplicateDeclarations() == false) { throw new ModelBuildingException(pb.getMessage()); } } else { probs.add(pb); } }
/** * Searches a type declared in imports. * * @param typeName * Expected type name. * @param imports * Search the type in imports. * @return qualified name of the expected type. */ static String searchType(String typeName, ImportReference[] imports) { if (typeName == null || imports == null) { return null; } for (ImportReference anImport : imports) { final String importType = CharOperation.charToString(anImport.getImportName()[anImport.getImportName().length - 1]); if (typeName.equals(importType)) { return CharOperation.toString(anImport.getImportName()); } } return null; }
private void sortModuleDeclarationsFirst(ICompilationUnit[] sourceUnits) { Arrays.sort(sourceUnits, (u1, u2) -> { char[] fn1 = u1.getFileName(); char[] fn2 = u2.getFileName(); boolean isMod1 = CharOperation.endsWith(fn1, TypeConstants.MODULE_INFO_FILE_NAME) || CharOperation.endsWith(fn1, TypeConstants.MODULE_INFO_CLASS_NAME); boolean isMod2 = CharOperation.endsWith(fn2, TypeConstants.MODULE_INFO_FILE_NAME) || CharOperation.endsWith(fn2, TypeConstants.MODULE_INFO_CLASS_NAME); if (isMod1 == isMod2) { return 0; } return isMod1 ? -1 : 1; }); }
/** * In no classpath, the model of the super interface isn't always correct. */ 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]); }
for (int i = 0; i < packageName.length; i++) { char[] chars = packageName[i]; if (!CharOperation.equals(chars, tokens[i])) { isFound = false; break;
/** * Creates a qualified type name from a two-dimensional array. * * @param typeName * 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(); }
<T> CtFieldReference<T> getVariableReference(FieldBinding fieldBinding, char[] tokens) { final CtFieldReference<T> ref = getVariableReference(fieldBinding); if (fieldBinding != null) { return ref; } ref.setSimpleName(CharOperation.charToString(tokens)); return ref; }
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<>(); }
/** * 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 */ 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 = JDTTreeBuilder.getOrCreateCompilationUnit(declarationUnit, factory); }
@Override public boolean visit(StringLiteral stringLiteral, BlockScope scope) { context.enter(factory.Code().createLiteral(CharOperation.charToString(stringLiteral.source())), stringLiteral); return true; }
@Override public boolean visit(AnnotationMethodDeclaration annotationTypeDeclaration, ClassScope classScope) { CtAnnotationMethod<Object> ctAnnotationMethod = factory.Core().createAnnotationMethod(); ctAnnotationMethod.setSimpleName(CharOperation.charToString(annotationTypeDeclaration.selector)); context.enter(ctAnnotationMethod, annotationTypeDeclaration); return true; }
private boolean visitTypeParameter(TypeParameter typeParameter, Scope scope) { final CtTypeParameter typeParameterRef = factory.Core().createTypeParameter(); typeParameterRef.setSimpleName(CharOperation.charToString(typeParameter.name)); context.enter(typeParameterRef, typeParameter); return true; }
@Override public boolean visit(ExtendedStringLiteral extendedStringLiteral, BlockScope scope) { context.enter(factory.Code().createLiteral(CharOperation.charToString(extendedStringLiteral.source())), extendedStringLiteral); return true; }
/** * Searches a type from an entry-point according to a simple name. * * @param type * Entry-point to search. * @param simpleName * Expected type name. * @return type binding. */ static TypeBinding searchTypeBinding(ReferenceBinding type, String simpleName) { if (simpleName == null || type == null) { return null; } if (type.memberTypes() != null) { for (ReferenceBinding memberType : type.memberTypes()) { if (simpleName.equals(CharOperation.charToString(memberType.sourceName()))) { return memberType; } } } return searchTypeBinding(type.superclass(), simpleName); }
@Override public boolean visit(LambdaExpression lambdaExpression, BlockScope blockScope) { CtLambda<?> lambda = factory.Core().createLambda(); final MethodBinding methodBinding = lambdaExpression.getMethodBinding(); if (methodBinding != null) { lambda.setSimpleName(CharOperation.charToString(methodBinding.constantPoolName())); } context.isBuildLambda = true; context.enter(lambda, lambdaExpression); return true; }