本文整理汇总了Java中org.eclipse.jdt.internal.compiler.CompilationResult.getCompilationUnit方法的典型用法代码示例。如果您正苦于以下问题:Java CompilationResult.getCompilationUnit方法的具体用法?Java CompilationResult.getCompilationUnit怎么用?Java CompilationResult.getCompilationUnit使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.eclipse.jdt.internal.compiler.CompilationResult
的用法示例。
在下文中一共展示了CompilationResult.getCompilationUnit方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: acceptResult
import org.eclipse.jdt.internal.compiler.CompilationResult; //导入方法依赖的package包/类
public void acceptResult(CompilationResult result) {
String className = ((CompilationUnit) result.getCompilationUnit()).className;
int classIdx;
for (classIdx = 0; classIdx < units.length; ++classIdx) {
if (className.equals(units[classIdx].getName())) {
break;
}
}
if (result.hasErrors()) {
// IProblem[] problems = result.getErrors();
IProblem[] problems = getJavaCompilationErrors(result);
unitResults[classIdx].problems = problems;
String sourceCode = units[classIdx].getSourceCode();
for (int i = 0; i < problems.length; i++) {
IProblem problem = problems[i];
if (IProblem.UndefinedMethod == problem.getID()) {
if (problem.getSourceStart() >= 0 && problem.getSourceEnd() >= 0) {
String methodName = sourceCode.substring(problem.getSourceStart(), problem.getSourceEnd() + 1);
Method method = FunctionsUtil.getInstance(jasperReportsContext).getMethod4Function(methodName);
if (method != null) {
unitResults[classIdx].addMissingMethod(method);
// continue;
}
}
}
}
} else {
ClassFile[] resultClassFiles = result.getClassFiles();
for (int i = 0; i < resultClassFiles.length; i++) {
units[classIdx].setCompileData(resultClassFiles[i].getBytes());
}
}
}
示例2: retrieveClosingAngleBracketPosition
import org.eclipse.jdt.internal.compiler.CompilationResult; //导入方法依赖的package包/类
private int retrieveClosingAngleBracketPosition(int start) {
if (this.referenceContext == null) return start;
CompilationResult compilationResult = this.referenceContext.compilationResult();
if (compilationResult == null) return start;
ICompilationUnit compilationUnit = compilationResult.getCompilationUnit();
if (compilationUnit == null) return start;
char[] contents = compilationUnit.getContents();
if (contents.length == 0) return start;
if (this.positionScanner == null) {
this.positionScanner = new Scanner(false, false, false, this.options.sourceLevel, this.options.complianceLevel, null, null, false);
this.positionScanner.returnOnlyGreater = true;
}
this.positionScanner.setSource(contents);
this.positionScanner.resetTo(start, contents.length);
int end = start;
int count = 0;
try {
int token;
loop: while ((token = this.positionScanner.getNextToken()) != TerminalTokens.TokenNameEOF) {
switch(token) {
case TerminalTokens.TokenNameLESS:
count++;
break;
case TerminalTokens.TokenNameGREATER:
count--;
if (count == 0) {
end = this.positionScanner.currentPosition - 1;
break loop;
}
break;
case TerminalTokens.TokenNameLBRACE :
break loop;
}
}
} catch(InvalidInputException e) {
// ignore
}
return end;
}
示例3: retrieveEndingPositionAfterOpeningParenthesis
import org.eclipse.jdt.internal.compiler.CompilationResult; //导入方法依赖的package包/类
private int retrieveEndingPositionAfterOpeningParenthesis(int sourceStart, int sourceEnd, int numberOfParen) {
if (this.referenceContext == null) return sourceEnd;
CompilationResult compilationResult = this.referenceContext.compilationResult();
if (compilationResult == null) return sourceEnd;
ICompilationUnit compilationUnit = compilationResult.getCompilationUnit();
if (compilationUnit == null) return sourceEnd;
char[] contents = compilationUnit.getContents();
if (contents.length == 0) return sourceEnd;
if (this.positionScanner == null) {
this.positionScanner = new Scanner(false, false, false, this.options.sourceLevel, this.options.complianceLevel, null, null, false);
}
this.positionScanner.setSource(contents);
this.positionScanner.resetTo(sourceStart, sourceEnd);
try {
int token;
int previousSourceEnd = sourceEnd;
while ((token = this.positionScanner.getNextToken()) != TerminalTokens.TokenNameEOF) {
switch(token) {
case TerminalTokens.TokenNameRPAREN:
return previousSourceEnd;
default :
previousSourceEnd = this.positionScanner.currentPosition - 1;
}
}
} catch(InvalidInputException e) {
// ignore
}
return sourceEnd;
}
示例4: retrieveStartingPositionAfterOpeningParenthesis
import org.eclipse.jdt.internal.compiler.CompilationResult; //导入方法依赖的package包/类
private int retrieveStartingPositionAfterOpeningParenthesis(int sourceStart, int sourceEnd, int numberOfParen) {
if (this.referenceContext == null) return sourceStart;
CompilationResult compilationResult = this.referenceContext.compilationResult();
if (compilationResult == null) return sourceStart;
ICompilationUnit compilationUnit = compilationResult.getCompilationUnit();
if (compilationUnit == null) return sourceStart;
char[] contents = compilationUnit.getContents();
if (contents.length == 0) return sourceStart;
if (this.positionScanner == null) {
this.positionScanner = new Scanner(false, false, false, this.options.sourceLevel, this.options.complianceLevel, null, null, false);
}
this.positionScanner.setSource(contents);
this.positionScanner.resetTo(sourceStart, sourceEnd);
int count = 0;
try {
int token;
while ((token = this.positionScanner.getNextToken()) != TerminalTokens.TokenNameEOF) {
switch(token) {
case TerminalTokens.TokenNameLPAREN:
count++;
if (count == numberOfParen) {
this.positionScanner.getNextToken();
return this.positionScanner.startPosition;
}
}
}
} catch(InvalidInputException e) {
// ignore
}
return sourceStart;
}
示例5: acceptResult
import org.eclipse.jdt.internal.compiler.CompilationResult; //导入方法依赖的package包/类
@Override
public void acceptResult(CompilationResult result)
{
String className = ((CompilationUnit) result.getCompilationUnit()).className;
int classIdx;
for (classIdx = 0; classIdx < units.length; ++classIdx)
{
if (className.equals(units[classIdx].getName()))
{
break;
}
}
if (result.hasErrors())
{
//IProblem[] problems = result.getErrors();
IProblem[] problems = getJavaCompilationErrors(result);
unitResults[classIdx].problems = problems;
String sourceCode = units[classIdx].getSourceCode();
for (int i = 0; i < problems.length; i++)
{
IProblem problem = problems[i];
if (IProblem.UndefinedMethod == problem.getID())
{
if (
problem.getSourceStart() >= 0
&& problem.getSourceEnd() >= 0
)
{
String methodName =
sourceCode.substring(
problem.getSourceStart(),
problem.getSourceEnd() + 1
);
Method method = FunctionsUtil.getInstance(jasperReportsContext).getMethod4Function(methodName);
if (method != null)
{
unitResults[classIdx].addMissingMethod(method);
//continue;
}
}
}
}
}
else
{
ClassFile[] resultClassFiles = result.getClassFiles();
for (int i = 0; i < resultClassFiles.length; i++)
{
units[classIdx].setCompileData(resultClassFiles[i].getBytes());
}
}
}