本文整理汇总了Java中org.eclipse.jdt.internal.compiler.env.ICompilationUnit.getContents方法的典型用法代码示例。如果您正苦于以下问题:Java ICompilationUnit.getContents方法的具体用法?Java ICompilationUnit.getContents怎么用?Java ICompilationUnit.getContents使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.eclipse.jdt.internal.compiler.env.ICompilationUnit
的用法示例。
在下文中一共展示了ICompilationUnit.getContents方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: retrieveClosingAngleBracketPosition
import org.eclipse.jdt.internal.compiler.env.ICompilationUnit; //导入方法依赖的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;
}
示例2: retrieveEndingPositionAfterOpeningParenthesis
import org.eclipse.jdt.internal.compiler.env.ICompilationUnit; //导入方法依赖的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;
}
示例3: retrieveStartingPositionAfterOpeningParenthesis
import org.eclipse.jdt.internal.compiler.env.ICompilationUnit; //导入方法依赖的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;
}
示例4: parse
import org.eclipse.jdt.internal.compiler.env.ICompilationUnit; //导入方法依赖的package包/类
public CompilationUnitDeclaration parse(
ICompilationUnit sourceUnit,
CompilationResult compilationResult,
int start,
int end) {
// parses a compilation unit and manages error handling (even bugs....)
CompilationUnitDeclaration unit;
try {
/* automaton initialization */
initialize(true);
goForCompilationUnit();
/* unit creation */
this.referenceContext =
this.compilationUnit =
new CompilationUnitDeclaration(
this.problemReporter,
compilationResult,
0);
/* scanners initialization */
char[] contents;
try {
contents = this.readManager != null ? this.readManager.getContents(sourceUnit) : sourceUnit.getContents();
} catch(AbortCompilationUnit abortException) {
problemReporter().cannotReadSource(this.compilationUnit, abortException, this.options.verbose);
contents = CharOperation.NO_CHAR; // pretend empty from thereon
}
this.scanner.setSource(contents);
this.compilationUnit.sourceEnd = this.scanner.source.length - 1;
if (end != -1) this.scanner.resetTo(start, end);
if (this.javadocParser != null && this.javadocParser.checkDocComment) {
this.javadocParser.scanner.setSource(contents);
if (end != -1) {
this.javadocParser.scanner.resetTo(start, end);
}
}
/* run automaton */
parse();
} finally {
unit = this.compilationUnit;
this.compilationUnit = null; // reset parser
// tag unit has having read bodies
if (!this.diet) unit.bits |= ASTNode.HasAllMethodBodies;
}
return unit;
}
示例5: getContents
import org.eclipse.jdt.internal.compiler.env.ICompilationUnit; //导入方法依赖的package包/类
public char[] getContents(ICompilationUnit unit) throws Error {
if (this.readingThreads == null || this.units.length == 0) {
if (this.caughtException != null) {
// rethrow the caught exception from the readingThreads in the main compiler thread
if (this.caughtException instanceof Error)
throw (Error) this.caughtException;
throw (RuntimeException) this.caughtException;
}
return unit.getContents();
}
boolean yield = false;
char[] result = null;
synchronized (this) {
if (unit == this.filesRead[this.readyToReadPosition]) {
result = this.contentsRead[this.readyToReadPosition];
while (result == this.readInProcessMarker || result == null) {
// let the readingThread know we're waiting
//System.out.print('|');
this.contentsRead[this.readyToReadPosition] = null;
try {
wait(250);
} catch (InterruptedException ignore) { // ignore
}
if (this.caughtException != null) {
// rethrow the caught exception from the readingThreads in the main compiler thread
if (this.caughtException instanceof Error)
throw (Error) this.caughtException;
throw (RuntimeException) this.caughtException;
}
result = this.contentsRead[this.readyToReadPosition];
}
// free spot for next file
this.filesRead[this.readyToReadPosition] = null;
this.contentsRead[this.readyToReadPosition] = null;
if (++this.readyToReadPosition >= this.contentsRead.length)
this.readyToReadPosition = 0;
if (this.sleepingThreadCount > 0) {
//System.out.print('+');
//System.out.print(this.nextFileToRead);
notify();
yield = this.sleepingThreadCount == this.readingThreads.length;
}
} else {
// must make sure we're reading ahead of the unit
int unitIndex = 0;
for (int l = this.units.length; unitIndex < l; unitIndex++)
if (this.units[unitIndex] == unit) break;
if (unitIndex == this.units.length) {
// attempting to read a unit that was not included in the initial files - should not happen
this.units = new ICompilationUnit[0]; // stop looking for more
} else if (unitIndex >= this.nextFileToRead) {
// start over
//System.out.println(unitIndex + " vs " + this.nextFileToRead);
this.nextFileToRead = unitIndex + START_CUSHION;
this.readyToReadPosition = 0;
this.nextAvailablePosition = 0;
this.filesRead = new ICompilationUnit[CACHE_SIZE];
this.contentsRead = new char[CACHE_SIZE][];
notifyAll();
}
}
}
if (yield)
Thread.yield(); // ensure other threads get a chance
if (result != null)
return result;
//System.out.print('-');
return unit.getContents();
}