本文整理汇总了Java中org.eclipse.jdt.internal.compiler.ClassFile类的典型用法代码示例。如果您正苦于以下问题:Java ClassFile类的具体用法?Java ClassFile怎么用?Java ClassFile使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ClassFile类属于org.eclipse.jdt.internal.compiler包,在下文中一共展示了ClassFile类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: acceptClassFiles
import org.eclipse.jdt.internal.compiler.ClassFile; //导入依赖的package包/类
/**
* @see ICodeSnippetRequestor
*/
public boolean acceptClassFiles(ClassFile[] classFiles, char[] codeSnippetClassName) {
int length = classFiles.length;
byte[][] classFileBytes = new byte[length][];
String[][] compoundNames = new String[length][];
for (int i = 0; i < length; i++) {
ClassFile classFile = classFiles[i];
classFileBytes[i] = classFile.getBytes();
char[][] classFileCompundName = classFile.getCompoundName();
int length2 = classFileCompundName.length;
String[] compoundName = new String[length2];
for (int j = 0; j < length2; j++){
compoundName[j] = new String(classFileCompundName[j]);
}
compoundNames[i] = compoundName;
}
return this.requestor.acceptClassFiles(classFileBytes, compoundNames, codeSnippetClassName == null ? null : new String(codeSnippetClassName));
}
示例2: deployCodeSnippetClassIfNeeded
import org.eclipse.jdt.internal.compiler.ClassFile; //导入依赖的package包/类
private void deployCodeSnippetClassIfNeeded(IRequestor requestor) throws InstallException {
if (this.codeSnippetBinary == null) {
// Deploy CodeSnippet class (only once)
if (!requestor.acceptClassFiles(
new ClassFile[] {
new ClassFile() {
public byte[] getBytes() {
return getCodeSnippetBytes();
}
public char[][] getCompoundName() {
return EvaluationConstants.ROOT_COMPOUND_NAME;
}
}
},
null))
throw new InstallException();
}
}
示例3: init
import org.eclipse.jdt.internal.compiler.ClassFile; //导入依赖的package包/类
public void init(ClassFile targetClassFile) {
super.init(targetClassFile);
this.stateIndexesCounter = 0;
if (this.framePositions != null) {
this.framePositions.clear();
}
if (this.exceptionMarkers != null) {
this.exceptionMarkers.clear();
}
if (this.stackDepthMarkers != null) {
this.stackDepthMarkers.clear();
}
if (this.stackMarkers != null) {
this.stackMarkers.clear();
}
}
示例4: reset
import org.eclipse.jdt.internal.compiler.ClassFile; //导入依赖的package包/类
public void reset(ClassFile givenClassFile) {
super.reset(givenClassFile);
this.stateIndexesCounter = 0;
if (this.framePositions != null) {
this.framePositions.clear();
}
if (this.exceptionMarkers != null) {
this.exceptionMarkers.clear();
}
if (this.stackDepthMarkers != null) {
this.stackDepthMarkers.clear();
}
if (this.stackMarkers != null) {
this.stackMarkers.clear();
}
}
示例5: reset
import org.eclipse.jdt.internal.compiler.ClassFile; //导入依赖的package包/类
public void reset(LambdaExpression lambda, ClassFile targetClassFile) {
init(targetClassFile);
this.lambdaExpression = lambda;
this.methodDeclaration = null;
int[] lineSeparatorPositions2 = this.lineSeparatorPositions;
if (lineSeparatorPositions2 != null) {
int length = lineSeparatorPositions2.length;
int lineSeparatorPositionsEnd = length - 1;
int start = Util.getLineNumber(lambda.body().sourceStart, lineSeparatorPositions2, 0, lineSeparatorPositionsEnd);
this.lineNumberStart = start;
if (start > lineSeparatorPositionsEnd) {
this.lineNumberEnd = start;
} else {
int end = Util.getLineNumber(lambda.body().sourceEnd, lineSeparatorPositions2, start - 1, lineSeparatorPositionsEnd);
if (end >= lineSeparatorPositionsEnd) {
end = length;
}
this.lineNumberEnd = end == 0 ? 1 : end;
}
}
this.preserveUnusedLocals = lambda.scope.compilerOptions().preserveAllLocalVariables;
initializeMaxLocals(lambda.binding);
}
示例6: acceptResult
import org.eclipse.jdt.internal.compiler.ClassFile; //导入依赖的package包/类
public void acceptResult(final org.eclipse.jdt.internal.compiler.CompilationResult result) {
if (result.hasProblems()) {
// Store compilation problems
for (IProblem iproblem : result.getProblems()) {
problems.add(new EclipseCompilationProblem(iproblem));
}
}
if (!result.hasErrors()) {
final ClassFile[] classFiles = result.getClassFiles();
for (ClassFile classFile : classFiles) {
// Write class file to store
String className = NameUtils.getClassName(classFile.getCompoundName());
String resourceName = NameUtils.toBinaryName(className);
byte[] classBytes = classFile.getBytes();
getBinaryStore().write(resourceName, classBytes);
// Add to compiled resources
compiled.put(className, classBytes);
}
}
}
示例7: getCachedClass
import org.eclipse.jdt.internal.compiler.ClassFile; //导入依赖的package包/类
protected Class<?> getCachedClass(String name) {
Class<?> c = null;
if (classCache != null) {
c = classCache.get(name);
}
// the class could be compiled but not yet define()d
if (c == null && resultAccumulator != null) {
ClassFile cf = resultAccumulator.get(name);
if (cf != null) {
c = defineClass(name, cf);
resultAccumulator.remove(cf);
}
}
return c;
}
示例8: outputClassFiles
import org.eclipse.jdt.internal.compiler.ClassFile; //导入依赖的package包/类
@Override
public void outputClassFiles(CompilationResult result) {
super.outputClassFiles(result);
if (result == null || result.hasErrors() && !proceedOnError) {
return;
}
List<String> classFiles = new ArrayList<String>();
for (ClassFile file : result.getClassFiles()) {
classFiles.add(new String(file.fileName()) + ".class");
}
myOutputs.put(new String(result.getFileName()), classFiles);
}
示例9: acceptResult
import org.eclipse.jdt.internal.compiler.ClassFile; //导入依赖的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());
}
}
}
示例10: VariablesInfo
import org.eclipse.jdt.internal.compiler.ClassFile; //导入依赖的package包/类
/**
* Creates a new variables info.
* The name of the global variable class is the simple name of this class.
* The package name can be null if the variables have been defined in the default package.
*/
public VariablesInfo(char[] packageName, char[] className, ClassFile[] classFiles, GlobalVariable[] variables, int variableCount) {
this.packageName = packageName;
this.className = className;
this.classFiles = classFiles;
this.variables = variables;
this.variableCount = variableCount;
}
示例11: evaluateVariables
import org.eclipse.jdt.internal.compiler.ClassFile; //导入依赖的package包/类
/**
* @see org.eclipse.jdt.core.eval.IEvaluationContext
* @exception org.eclipse.jdt.internal.eval.InstallException if the code snippet class files could not be deployed.
*/
public void evaluateVariables(INameEnvironment environment, Map options, IRequestor requestor, IProblemFactory problemFactory) throws InstallException {
deployCodeSnippetClassIfNeeded(requestor);
VariablesEvaluator evaluator = new VariablesEvaluator(this, environment, options, requestor, problemFactory);
ClassFile[] classes = evaluator.getClasses();
if (classes != null) {
if (classes.length > 0) {
// Sort classes so that enclosing types are cached before nested types
// otherwise an AbortCompilation is thrown in 1.5 mode since the enclosing type
// is needed to resolve a nested type
Util.sort(classes, new Util.Comparer() {
public int compare(Object a, Object b) {
if (a == b) return 0;
ClassFile enclosing = ((ClassFile) a).enclosingClassFile;
while (enclosing != null) {
if (enclosing == b)
return 1;
enclosing = enclosing.enclosingClassFile;
}
return -1;
}
});
// Send classes
if (!requestor.acceptClassFiles(classes, null)) {
throw new InstallException();
}
// Remember that the variables have been installed
int count = this.variableCount;
GlobalVariable[] variablesCopy = new GlobalVariable[count];
System.arraycopy(this.variables, 0, variablesCopy, 0, count);
this.installedVars = new VariablesInfo(evaluator.getPackageName(), evaluator.getClassName(), classes, variablesCopy, count);
VAR_CLASS_COUNTER++;
}
this.varsChanged = false;
}
}
示例12: generateCode
import org.eclipse.jdt.internal.compiler.ClassFile; //导入依赖的package包/类
public void generateCode(ClassScope classScope, ClassFile classFile) {
int problemResetPC = 0;
classFile.codeStream.wideMode = false;
boolean restart = false;
do {
try {
problemResetPC = classFile.contentsOffset;
this.generateCode(classFile);
restart = false;
} catch (AbortMethod e) {
// Restart code generation if possible ...
if (e.compilationResult == CodeStream.RESTART_IN_WIDE_MODE) {
// a branch target required a goto_w, restart code generation in wide mode.
classFile.contentsOffset = problemResetPC;
classFile.methodCount--;
classFile.codeStream.resetInWideMode(); // request wide mode
restart = true;
} else if (e.compilationResult == CodeStream.RESTART_CODE_GEN_FOR_UNUSED_LOCALS_MODE) {
classFile.contentsOffset = problemResetPC;
classFile.methodCount--;
classFile.codeStream.resetForCodeGenUnusedLocals();
restart = true;
} else {
throw new AbortType(this.compilationResult, e.problem);
}
}
} while (restart);
}
示例13: cleanUp
import org.eclipse.jdt.internal.compiler.ClassFile; //导入依赖的package包/类
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.bootstrapMethods = null;
classFile.missingTypes = null;
classFile.visitedTypes = null;
}
this.suppressWarningAnnotations = null;
}
示例14: writeToDisk
import org.eclipse.jdt.internal.compiler.ClassFile; //导入依赖的package包/类
/**
* outputPath is formed like:
* c:\temp\ the last character is a file separator
* relativeFileName is formed like:
* java\lang\String.class
* @param generatePackagesStructure a flag to know if the packages structure has to be generated.
* @param outputPath the given output directory
* @param relativeFileName the given relative file name
* @param classFile the given classFile to write
*
*/
public static void writeToDisk(boolean generatePackagesStructure, String outputPath, String relativeFileName, ClassFile classFile) throws IOException {
FileOutputStream file = getFileOutputStream(generatePackagesStructure, outputPath, relativeFileName);
/* use java.nio to write
if (true) {
FileChannel ch = file.getChannel();
try {
ByteBuffer buffer = ByteBuffer.allocate(classFile.headerOffset + classFile.contentsOffset);
buffer.put(classFile.header, 0, classFile.headerOffset);
buffer.put(classFile.contents, 0, classFile.contentsOffset);
buffer.flip();
while (true) {
if (ch.write(buffer) == 0) break;
}
} finally {
ch.close();
}
return;
}
*/
BufferedOutputStream output = new BufferedOutputStream(file, DEFAULT_WRITING_SIZE);
// BufferedOutputStream output = new BufferedOutputStream(file);
try {
// if no IOException occured, output cannot be null
output.write(classFile.header, 0, classFile.headerOffset);
output.write(classFile.contents, 0, classFile.contentsOffset);
output.flush();
} catch(IOException e) {
throw e;
} finally {
output.close();
}
}
示例15: ConstantPool
import org.eclipse.jdt.internal.compiler.ClassFile; //导入依赖的package包/类
/**
* ConstantPool constructor comment.
*/
public ConstantPool(ClassFile classFile) {
this.UTF8Cache = new CharArrayCache(UTF8_INITIAL_SIZE);
this.stringCache = new CharArrayCache(STRING_INITIAL_SIZE);
this.methodsAndFieldsCache = new HashtableOfObject(METHODS_AND_FIELDS_INITIAL_SIZE);
this.classCache = new CharArrayCache(CLASS_INITIAL_SIZE);
this.nameAndTypeCacheForFieldsAndMethods = new HashtableOfObject(NAMEANDTYPE_INITIAL_SIZE);
this.offsets = new int[5];
initialize(classFile);
}