Refine search
public void acceptResult( org.eclipse.jdt.internal.compiler.CompilationResult result ) { if (result.hasProblems()) { if (result.hasErrors()) hasErrors = true; problems.addAll(Arrays.asList((IProblem[]) result.getProblems())); } if (!result.hasErrors()) { ClassFile[] clazzFiles = result.getClassFiles(); for (ClassFile clazzFile : clazzFiles) { char[][] compoundName = clazzFile.getCompoundName(); StringBuffer clazzName = new StringBuffer(); for (char[] part : compoundName) { if (clazzName.length() > 0) { clazzName.append('.'); } clazzName.append(part); } byteCode.put(clazzName.toString(), clazzFile.getBytes()); } } } }
@Override public void acceptResult(CompilationResult result) { if (result.hasErrors()) { errors = result.getErrors(); } else { classFiles = result.getClassFiles(); } }
@Override public void acceptResult(CompilationResult result) { if (result.hasErrors()) { IProblem[] problems = result.getProblems(); if (problemList == null) problemList = new ArrayList<>(problems.length); Collections.addAll(problemList, problems); } else { ClassFile[] classFiles = result.getClassFiles(); for (ClassFile classFile : classFiles) targetClassLoader.addClass(className, classFile.getBytes()); } }
private static Map<String, byte[]> classes(final CompilationResult result) { final Map<String, byte[]> classes = new HashMap<String, byte[]>(); if (!result.hasErrors()) { for (final ClassFile cls : result.getClassFiles()) { final String className = CharOperation .toString(cls.getCompoundName()); classes.put(className, cls.getBytes()); } } return classes; }
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 compilationResult) { if (compilationResult.lineSeparatorPositions != null) { int unitLineCount = compilationResult.lineSeparatorPositions.length; this.lineDelta += unitLineCount; if (Main.this.showProgress && this.lineDelta > 2000) { // in -log mode, dump a dot every 2000 lines compiled Main.this.logger.logProgress(); this.lineDelta = 0; } } Main.this.logger.startLoggingSource(compilationResult); if (compilationResult.hasProblems() || compilationResult.hasTasks()) { Main.this.logger.logProblems(compilationResult.getAllProblems(), compilationResult.compilationUnit.getContents(), Main.this); } outputClassFiles(compilationResult); Main.this.logger.endLoggingSource(); } };
@Override public void acceptResult(CompilationResult result) { String className = ((CompilationUnit) result.getCompilationUnit()).className; if (result.hasErrors()) { ClassFile[] resultClassFiles = result.getClassFiles(); for (int i = 0; i < resultClassFiles.length; i++) { units[classIdx].setCompileData(resultClassFiles[i].getBytes());
protected void backupAptProblems() { if (this.unitsToProcess == null) return; for (int i = 0; i < this.totalUnits; i++) { CompilationUnitDeclaration unitDecl = this.unitsToProcess[i]; CompilationResult result = unitDecl.compilationResult; if (result != null && result.hasErrors()) { CategorizedProblem[] errors = result.getErrors(); for (CategorizedProblem problem : errors) { if (problem.getCategoryID() == CategorizedProblem.CAT_UNSPECIFIED) { if (this.aptProblems == null) { this.aptProblems = new HashMap<>(); } APTProblem[] problems = this.aptProblems.get(new String(unitDecl.getFileName())); if (problems == null) { this.aptProblems.put( new String(unitDecl.getFileName()), new APTProblem[] { new APTProblem(problem, result.getContext(problem)) }); } else { APTProblem[] temp = new APTProblem[problems.length + 1]; System.arraycopy(problems, 0, temp, 0, problems.length); temp[problems.length] = new APTProblem(problem, result.getContext(problem)); this.aptProblems.put(new String(unitDecl.getFileName()), temp); } } } } } }
@Override public void acceptResult(CompilationResult result) { assert this.bytes == null : "duplicate result"; //$NON-NLS-1$ ClassFile[] classFiles = result.getClassFiles(); assert classFiles.length == 1; this.bytes = classFiles[0].getBytes(); } }
public boolean isSuccess() { for (final CompilationResult res : results) { if (res.getProblems() != null) { for (final CategorizedProblem problem : res.getProblems()) { if (problem.isError()) { return false; } } } } return true; }
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; }
@Override public List<Problem> validateSnippet(String snippet) { CodeSnippetParsingUtil codeSnippetParsingUtil = new CodeSnippetParsingUtil(false); ConstructorDeclaration constructorDeclaration = codeSnippetParsingUtil.parseStatements(snippet.toCharArray(), 0, snippet.length(), JDTOptions.getJDTOptions(), true, false); CompilationResult compilationResult = constructorDeclaration.compilationResult(); List<Problem> problems = new ArrayList<>(); if (compilationResult.hasErrors()) { for (CategorizedProblem problem : compilationResult.getErrors()) { Problem p = new Problem(problem.getMessage(), problem.getSourceStart(), problem.getSourceEnd(), problem.getSourceLineNumber()); problems.add(p); } } return problems; } }
@Override public ASTNode process(Source in, Void irrelevant) throws ConversionProblem { CompilerOptions compilerOptions = ecjCompilerOptions(); Parser parser = new Parser(new ProblemReporter( DefaultErrorHandlingPolicies.proceedWithAllProblems(), compilerOptions, new DefaultProblemFactory() ), compilerOptions.parseLiteralExpressionsAsConstants); parser.javadocParser.checkDocComment = true; CompilationUnit sourceUnit = new CompilationUnit(in.getRawInput().toCharArray(), in.getName(), charset.name()); CompilationResult compilationResult = new CompilationResult(sourceUnit, 0, 0, 0); CompilationUnitDeclaration cud = parser.parse(sourceUnit, compilationResult); if (cud.hasErrors()) { throw new ConversionProblem(String.format("Can't read file %s due to parse error: %s", in.getName(), compilationResult.getErrors()[0])); } return cud; } };
@Override public void acceptResult(CompilationResult result) { if (result.hasErrors()) { for (CategorizedProblem problem : result.problems) { this.jdtCompiler.reportProblem(problem); } } } }
public void cleanUp() { if (this.types != null) { for (int i = 0, max = this.types.length; i < max; i++) { cleanUp(this.types[i]); } for (int i = 0, max = this.localTypeCount; i < max; i++) { LocalTypeBinding localType = this.localTypes[i]; // null out the type's scope backpointers localType.scope = null; // local members are already in the list localType.enclosingCase = null; } } this.compilationResult.recoveryScannerData = null; // recovery is already done ClassFile[] classFiles = this.compilationResult.getClassFiles(); for (int i = 0, max = classFiles.length; i < max; i++) { // clear the classFile back pointer to the bindings ClassFile classFile = classFiles[i]; // null out the classfile backpointer to a type binding classFile.referenceBinding = null; classFile.innerClassesBindings = null; classFile.missingTypes = null; classFile.visitedTypes = null; } this.suppressWarningAnnotations = null; }
private static Parser makeDummyParser(ProblemReporter reporter, String mainTypeName) { Parser parser = new Parser(reporter, false); CompilationResult cr = new CompilationResult((mainTypeName + ".java").toCharArray(), 0, 1, 0); parser.compilationUnit = new CompilationUnitDeclaration(reporter, cr, 0); return parser; }
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(); } }
public void process(CompilationUnitDeclaration unit, int i) { // don't resolve a second time the same unit (this would create the same binding twice) char[] fileName = unit.compilationResult.getFileName(); if (this.requestedKeys.get(fileName) == null && this.requestedSources.get(fileName) == null) super.process(unit, i); } /*
/** * @return null when no errors */ public synchronized String getCompileErrors(CompilationUnitDeclaration unit) { process(unit, 0); CategorizedProblem[] errors = unit.compilationResult().getErrors(); if (errors != null && errors.length > 0) { StringBuilder sb = new StringBuilder(); for (CategorizedProblem p : errors) { sb.append(p.getMessage()).append('\n'); } sb.setLength(sb.length() - 1); return sb.toString(); } return null; }
protected void consumeReferenceExpression(ReferenceExpression referenceExpression) { pushOnExpressionStack(referenceExpression); if (!this.parsingJava8Plus) { problemReporter().referenceExpressionsNotBelow18(referenceExpression); } if (referenceExpression.compilationResult.getCompilationUnit() == null) { // unit built out of model. Stash a textual representation to enable RE.copy(). int length = referenceExpression.sourceEnd - referenceExpression.sourceStart + 1; System.arraycopy(this.scanner.getSource(), referenceExpression.sourceStart, referenceExpression.text = new char [length], 0, length); } this.referenceContext.compilationResult().hasFunctionalTypes = true; markEnclosingMemberWithLocalOrFunctionalType(LocalTypeKind.METHOD_REFERENCE); } protected void consumeReferenceExpressionTypeArgumentsAndTrunk(boolean qualified) {