Refine search
private static CharSequence readSourceDeclaration(SourceTypeBinding binding) { TypeDeclaration referenceContext = binding.scope.referenceContext; char[] content = referenceContext.compilationResult.compilationUnit.getContents(); int start = referenceContext.declarationSourceStart; int end = referenceContext.declarationSourceEnd; StringBuilder declaration = new StringBuilder(); for (int p = start; p <= end; p++) { char c = content[p]; if (c == '{') { break; } declaration.append(c); } return declaration; }
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); }
static class IntArrayList { public int[] list = new int[5]; public int length = 0; public void add(int i) { if (this.list.length == this.length) { System.arraycopy(this.list, 0, this.list = new int[this.length*2], 0, this.length); } this.list[this.length++] = i; } }
public void acceptResult(CompilationResult result) { if (result.hasErrors()) { for (IProblem problem : result.getErrors()) { int line = problem.getSourceLineNumber(); String message = problem.getMessage(); throw CompileException.compilerException(String.valueOf(result.compilationUnit.getMainTypeName()), line, message); ClassFile[] clazzFiles = result.getClassFiles(); for (int i = 0; i < clazzFiles.length; i++) { final ClassFile clazzFile = clazzFiles[i];
private ReferenceExpression copy() { final Parser parser = new Parser(this.enclosingScope.problemReporter(), false); final ICompilationUnit compilationUnit = this.compilationResult.getCompilationUnit(); final char[] source = compilationUnit != null ? compilationUnit.getContents() : this.text; ReferenceExpression copy = (ReferenceExpression) parser.parseExpression(source, compilationUnit != null ? this.sourceStart : 0, this.sourceEnd - this.sourceStart + 1, this.enclosingScope.referenceCompilationUnit(), false /* record line separators */); copy.original = this; copy.sourceStart = this.sourceStart; copy.sourceEnd = this.sourceEnd; return copy; }
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(); } }
@Override public void acceptResult(CompilationResult compilationResult) { if (compilationResult.lineSeparatorPositions != null) { int unitLineCount = compilationResult.lineSeparatorPositions.length; this.lineDelta += unitLineCount; if (this.compiler.showProgress && this.lineDelta > 2000) { // in -log mode, dump a dot every 2000 lines compiled this.compiler.logger.logProgress(); this.lineDelta = 0; } } this.compiler.logger.startLoggingSource(compilationResult); if (compilationResult.hasProblems() || compilationResult.hasTasks()) { this.compiler.logger.logProblems(compilationResult.getAllProblems(), compilationResult.compilationUnit.getContents(), this.compiler); reportProblems(compilationResult); } this.compiler.outputClassFiles(compilationResult); this.compiler.logger.endLoggingSource(); }
filteredProblems[keep++] = problem; } else if (this.compilationUnit != null) { if (CharOperation.equals(this.compilationUnit.getMainTypeName(), TypeConstants.PACKAGE_INFO_NAME)) { filteredProblems[keep++] = problem; quickPrioritize(this.problems, 0, this.problemCount - 1); this.problemCount = this.maxProblemPerUnit; System.arraycopy(this.problems, 0, (this.problems = new CategorizedProblem[this.problemCount]), 0, this.problemCount);
/** * Add an additional compilation unit. * @param sourceUnit */ @Override public void accept(ICompilationUnit sourceUnit, AccessRestriction accessRestriction) { if (CharOperation.equals(TypeConstants.MODULE_INFO_NAME, sourceUnit.getMainTypeName())) { // module is needed for resolving, so parse and build it now: CompilationResult unitResult = new CompilationResult(sourceUnit, 1, 1, this.options.maxProblemsPerUnit); CompilationUnitDeclaration parsedUnit = basicParser().dietParse(sourceUnit, unitResult); this.lookupEnvironment.buildTypeBindings(parsedUnit, accessRestriction); this.lookupEnvironment.completeTypeBindings(parsedUnit, true); // work done inside checkAndSetImports() } else { //System.out.println("Cannot accept compilation units inside the HierarchyResolver."); this.lookupEnvironment.problemReporter.abortDueToInternalError( new StringBuffer(Messages.accept_cannot) .append(sourceUnit.getFileName()) .toString()); } } private Parser basicParser() {
protected static void copyCompilationUnitOverrides(final JavaEnvironmentWithJdt src, final JavaEnvironmentSpi dest) { for (final ICompilationUnit cu : src.m_nameEnv.overrideSupport().getCompilationUnits()) { dest.registerCompilationUnitOverride(CharOperation.toString(cu.getPackageName()), new String(cu.getFileName()), cu.getContents()); } }
/** * adds a compilation unit override * * @param cu * The override * @return {@code true} if there was a previous mapping which has been updated with this call. {@code false} if this is * the first override for this compilation unit or there was no change. */ public boolean addCompilationUnit(final ICompilationUnit cu) { final char[][] packageName0 = cu.getPackageName(); final CharBuffer key = CharBuffer.wrap(CharOperation.concatWith(packageName0, cu.getMainTypeName(), SEPARATOR)); boolean updatedExistingEntry = false; final ICompilationUnit existingIcu = m_overrideCompilationUnits.put(key, cu); if (existingIcu != null) { updatedExistingEntry = !Arrays.equals(existingIcu.getContents(), cu.getContents()); } //register additional packages if (packageName0 != null && packageName0.length > 0) { for (int i = 1; i <= packageName0.length; i++) { m_additionalPackages.add(CharBuffer.wrap(CharOperation.concatWith(CharOperation.subarray(packageName0, 0, i), SEPARATOR))); } } return updatedExistingEntry; }
public void packageIsNotExpectedPackage(CompilationUnitDeclaration compUnitDecl) { String[] arguments = new String[] { CharOperation.toString(compUnitDecl.compilationResult.compilationUnit.getPackageName()), compUnitDecl.currentPackage == null ? "" : CharOperation.toString(compUnitDecl.currentPackage.tokens), //$NON-NLS-1$ }; this.handle( IProblem.PackageIsNotExpectedPackage, arguments, arguments, compUnitDecl.currentPackage == null ? 0 : compUnitDecl.currentPackage.sourceStart, compUnitDecl.currentPackage == null ? 0 : compUnitDecl.currentPackage.sourceEnd); } public void parameterAssignment(LocalVariableBinding local, ASTNode location) {
protected static String getFqn(String packageName, ICompilationUnit cu) { StringBuilder fqnBuilder = new StringBuilder(); if (StringUtils.isNotBlank(packageName)) { fqnBuilder.append(packageName); fqnBuilder.append('.'); } fqnBuilder.append(cu.getMainTypeName()); return fqnBuilder.toString(); }
static class IntArrayList { public int[] list = new int[5]; public int length = 0; public void add(int i) { if (this.list.length == this.length) { System.arraycopy(this.list, 0, this.list = new int[this.length*2], 0, this.length); } this.list[this.length++] = i; } }
private ReferenceExpression copy() { final Parser parser = new Parser(this.enclosingScope.problemReporter(), false); final ICompilationUnit compilationUnit = this.compilationResult.getCompilationUnit(); final char[] source = compilationUnit != null ? compilationUnit.getContents() : this.text; parser.scanner = this.scanner; ReferenceExpression copy = (ReferenceExpression) parser.parseExpression(source, compilationUnit != null ? this.sourceStart : 0, this.sourceEnd - this.sourceStart + 1, this.enclosingScope.referenceCompilationUnit(), false /* record line separators */); copy.original = this; copy.sourceStart = this.sourceStart; copy.sourceEnd = this.sourceEnd; return copy; }
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(); } }
filteredProblems[keep++] = problem; } else if (this.compilationUnit != null) { if (CharOperation.equals(this.compilationUnit.getMainTypeName(), TypeConstants.PACKAGE_INFO_NAME)) { filteredProblems[keep++] = problem; quickPrioritize(this.problems, 0, this.problemCount - 1); this.problemCount = this.maxProblemPerUnit; System.arraycopy(this.problems, 0, (this.problems = new CategorizedProblem[this.problemCount]), 0, this.problemCount);
public void packageIsNotExpectedPackage(CompilationUnitDeclaration compUnitDecl) { String[] arguments = new String[] { CharOperation.toString(compUnitDecl.compilationResult.compilationUnit.getPackageName()), compUnitDecl.currentPackage == null ? "" : CharOperation.toString(compUnitDecl.currentPackage.tokens), //$NON-NLS-1$ }; this.handle( IProblem.PackageIsNotExpectedPackage, arguments, arguments, compUnitDecl.currentPackage == null ? 0 : compUnitDecl.currentPackage.sourceStart, compUnitDecl.currentPackage == null ? 0 : compUnitDecl.currentPackage.sourceEnd); } public void parameterAssignment(LocalVariableBinding local, ASTNode location) {
@Override public void accept(ICompilationUnit sourceUnit, AccessRestriction accessRestriction) { if (!CharOperation.equals(sourceUnit.getMainTypeName(), TypeConstants.PACKAGE_INFO_NAME)) { // do not accept package-info.java as a type for completion engine // because it contains no extra info that will help in completion // https://bugs.eclipse.org/bugs/show_bug.cgi?id=343865 // Required after the fix for https://bugs.eclipse.org/bugs/show_bug.cgi?id=337868 // because now we get a type corresponding to the package-info.java from the java model. super.accept(sourceUnit, accessRestriction); } }