本文整理汇总了Java中org.eclipse.jdt.internal.compiler.env.ICompilationUnit类的典型用法代码示例。如果您正苦于以下问题:Java ICompilationUnit类的具体用法?Java ICompilationUnit怎么用?Java ICompilationUnit使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ICompilationUnit类属于org.eclipse.jdt.internal.compiler.env包,在下文中一共展示了ICompilationUnit类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: JavaSearchNameEnvironment
import org.eclipse.jdt.internal.compiler.env.ICompilationUnit; //导入依赖的package包/类
public JavaSearchNameEnvironment(IJavaProject javaProject, org.eclipse.jdt.core.ICompilationUnit[] copies) {
computeClasspathLocations(javaProject.getProject().getWorkspace().getRoot(), (JavaProject) javaProject);
try {
int length = copies == null ? 0 : copies.length;
this.workingCopies = new HashMap(length);
if (copies != null) {
for (int i = 0; i < length; i++) {
org.eclipse.jdt.core.ICompilationUnit workingCopy = copies[i];
IPackageDeclaration[] pkgs = workingCopy.getPackageDeclarations();
String pkg = pkgs.length > 0 ? pkgs[0].getElementName() : ""; //$NON-NLS-1$
String cuName = workingCopy.getElementName();
String mainTypeName = Util.getNameWithoutJavaLikeExtension(cuName);
String qualifiedMainTypeName = pkg.length() == 0 ? mainTypeName : pkg.replace('.', '/') + '/' + mainTypeName;
this.workingCopies.put(qualifiedMainTypeName, workingCopy);
}
}
} catch (JavaModelException e) {
// working copy doesn't exist: cannot happen
}
}
示例2: compile
import org.eclipse.jdt.internal.compiler.env.ICompilationUnit; //导入依赖的package包/类
public void compile(Collection<Source> sources) {
Timer timer = metric.startTimer("act:classload:compile:_all");
int len = sources.size();
ICompilationUnit[] compilationUnits = new ICompilationUnit[len];
int i = 0;
for (Source source: sources) {
compilationUnits[i++] = source.compilationUnit();
}
IErrorHandlingPolicy policy = DefaultErrorHandlingPolicies.exitOnFirstError();
IProblemFactory problemFactory = new DefaultProblemFactory(Locale.ENGLISH);
org.eclipse.jdt.internal.compiler.Compiler jdtCompiler = new Compiler(
nameEnv, policy, compilerOptions, requestor, problemFactory) {
@Override
protected void handleInternalException(Throwable e, CompilationUnitDeclaration ud, CompilationResult result) {
}
};
jdtCompiler.compile(compilationUnits);
timer.stop();
}
示例3: findType
import org.eclipse.jdt.internal.compiler.env.ICompilationUnit; //导入依赖的package包/类
private NameEnvironmentAnswer findType(final String name) {
try {
byte[] bytecode = classpath.get(name.replace(".", "/") + ".class");
String source = files.get(name.replace(".", "/") + ".java");
if (bytecode != null) {
char[] fileName = name.toCharArray();
ClassFileReader classFileReader = new ClassFileReader(bytecode, fileName, true);
return new NameEnvironmentAnswer(classFileReader, null);
} else if (source != null) {
ICompilationUnit compilationUnit = new CompilationUnit(source.toCharArray(), name, "UTF-8");
return new NameEnvironmentAnswer(compilationUnit, null);
}
return null;
} catch (ClassFormatException e) {
// Something very very bad
throw new ProjectCompilerException("compiler error", e);
}
}
示例4: rememberAllTypes
import org.eclipse.jdt.internal.compiler.env.ICompilationUnit; //导入依赖的package包/类
private void rememberAllTypes(CompilationUnitDeclaration parsedUnit, org.eclipse.jdt.core.ICompilationUnit cu, boolean includeLocalTypes) {
TypeDeclaration[] types = parsedUnit.types;
if (types != null) {
for (int i = 0, length = types.length; i < length; i++) {
TypeDeclaration type = types[i];
rememberWithMemberTypes(type, cu.getType(new String(type.name)));
}
}
if (includeLocalTypes && parsedUnit.localTypes != null) {
HandleFactory factory = new HandleFactory();
HashSet existingElements = new HashSet(parsedUnit.localTypeCount);
HashMap knownScopes = new HashMap(parsedUnit.localTypeCount);
for (int i = 0; i < parsedUnit.localTypeCount; i++) {
LocalTypeBinding localType = parsedUnit.localTypes[i];
ClassScope classScope = localType.scope;
TypeDeclaration typeDecl = classScope.referenceType();
IType typeHandle = (IType)factory.createElement(classScope, cu, existingElements, knownScopes);
rememberWithMemberTypes(typeDecl, typeHandle);
}
}
}
示例5: incrementalCompilationLoop
import org.eclipse.jdt.internal.compiler.env.ICompilationUnit; //导入依赖的package包/类
/**
* This loop handles the incremental compilation of classes in the compileQueue. Regular apt rounds may occur in this loop, but the apt final round will not.
*
* This loop will be called once after the apt final round is processed to compile all effected types. All prior error/warn/info messages, referenced types, generated outputs and other per-input
* information tracked by in build context are ignored when a type is recompiled.
*/
private void incrementalCompilationLoop(Classpath namingEnvironment, Compiler compiler, AnnotationProcessorManager aptmanager) throws IOException {
while (!compileQueue.isEmpty() || !staleOutputs.isEmpty()) {
processedQueue.clear();
processedQueue.addAll(compileQueue.keySet());
// All prior error/warn/info messages, referenced types, generated outputs and other per-input information tracked by in build context are wiped away within.
processSources();
// invoke the compiler
ICompilationUnit[] compilationUnits = compileQueue.values().toArray(new ICompilationUnit[compileQueue.size()]);
compileQueue.clear();
compiler.compile(compilationUnits);
namingEnvironment.reset();
if (aptmanager != null) {
aptmanager.incrementalIterationReset();
}
deleteStaleOutputs(); // delete stale outputs and enqueue affected sources
enqueueAffectedSources();
}
}
示例6: compile
import org.eclipse.jdt.internal.compiler.env.ICompilationUnit; //导入依赖的package包/类
@Override
public int compile(Classpath namingEnvironment, Compiler compiler) throws IOException {
processSources();
if (aptstate != null) {
staleOutputs.addAll(aptstate.writtenOutputs);
aptstate = null;
}
if (!compileQueue.isEmpty()) {
ICompilationUnit[] compilationUnits = compileQueue.values().toArray(new ICompilationUnit[compileQueue.size()]);
compiler.compile(compilationUnits);
}
persistAnnotationProcessingState(compiler, null);
deleteStaleOutputs();
return compileQueue.size();
}
示例7: compile
import org.eclipse.jdt.internal.compiler.env.ICompilationUnit; //导入依赖的package包/类
@Override
public CompilationResult compile(final Collection<String> sourceNames) {
final Map<String, byte[]> compiled = new HashMap<String, byte[]>();
final List<CompilationProblem> problems = new ArrayList<CompilationProblem>();
final List<ICompilationUnit> compilationUnits = collectCompilationUnits(sourceNames, problems);
// Exit if problems
if (! problems.isEmpty()) {
return new CompilationResult(problems);
}
// Setup compiler environment
final IErrorHandlingPolicy policy = DefaultErrorHandlingPolicies.proceedWithAllProblems();
final IProblemFactory problemFactory = new DefaultProblemFactory(Locale.getDefault());
final INameEnvironment nameEnvironment = new NameEnvironment();
final ICompilerRequestor compilerRequestor = new CompilerRequestor(problems, compiled);
// Compile
final Compiler compiler = new Compiler(nameEnvironment, policy, new CompilerOptions(STANDARD_OPTIONS),
compilerRequestor, problemFactory);
compiler.compile(compilationUnits.toArray(new ICompilationUnit[0]));
return new CompilationResult(problems, compiled);
}
示例8: parseSources
import org.eclipse.jdt.internal.compiler.env.ICompilationUnit; //导入依赖的package包/类
@NonNull
private static Pair<Collection<CompilationUnitDeclaration>,INameEnvironment> parseSources(
@NonNull List<File> sourcePaths,
@NonNull List<String> classpath,
@NonNull String encoding,
long languageLevel)
throws IOException {
List<ICompilationUnit> sourceUnits = Lists.newArrayListWithExpectedSize(100);
for (File source : gatherJavaSources(sourcePaths)) {
char[] contents = Util.getFileCharContent(source, encoding);
ICompilationUnit unit = new CompilationUnit(contents, source.getPath(), encoding);
sourceUnits.add(unit);
}
Map<ICompilationUnit, CompilationUnitDeclaration> outputMap = Maps.newHashMapWithExpectedSize(
sourceUnits.size());
CompilerOptions options = EcjParser.createCompilerOptions();
options.docCommentSupport = true; // So I can find @hide
// Note: We can *not* set options.ignoreMethodBodies=true because it disables
// type attribution!
options.sourceLevel = languageLevel;
options.complianceLevel = options.sourceLevel;
// We don't generate code, but just in case the parser consults this flag
// and makes sure that it's not greater than the source level:
options.targetJDK = options.sourceLevel;
options.originalComplianceLevel = options.sourceLevel;
options.originalSourceLevel = options.sourceLevel;
options.inlineJsrBytecode = true; // >= 1.5
INameEnvironment environment = EcjParser.parse(options, sourceUnits, classpath,
outputMap, null);
Collection<CompilationUnitDeclaration> parsedUnits = outputMap.values();
return Pair.of(parsedUnits, environment);
}
示例9: dispose
import org.eclipse.jdt.internal.compiler.env.ICompilationUnit; //导入依赖的package包/类
@Override
public void dispose(@NonNull JavaContext context,
@NonNull Node compilationUnit) {
if (mSourceUnits != null && mCompiled != null) {
ICompilationUnit sourceUnit = mSourceUnits.get(context.file);
if (sourceUnit != null) {
mSourceUnits.remove(context.file);
mCompiled.remove(sourceUnit);
}
}
}
示例10: NonGeneratingCompiler
import org.eclipse.jdt.internal.compiler.env.ICompilationUnit; //导入依赖的package包/类
public NonGeneratingCompiler(INameEnvironment environment, IErrorHandlingPolicy policy,
CompilerOptions options, ICompilerRequestor requestor,
IProblemFactory problemFactory,
Map<ICompilationUnit, CompilationUnitDeclaration> units) {
super(environment, policy, options, requestor, problemFactory, null, null);
mUnits = units;
}
示例11: getCompilationUnit
import org.eclipse.jdt.internal.compiler.env.ICompilationUnit; //导入依赖的package包/类
public static NameEnvironmentAnswer getCompilationUnit(ICompilationUnit compilationUnit) throws IllegalArgumentException, InstantiationException, IllegalAccessException, InvocationTargetException {
return new NameEnvironmentAnswer(compilationUnit, null);
//
// if (constrNameEnvAnsCompUnit2Args != null)
// return constrNameEnvAnsCompUnit2Args.newInstance(new Object[] {
// compilationUnit, null });
// return constrNameEnvAnsCompUnit.newInstance(new Object[] {
// compilationUnit });
}
示例12: BaseProcessingEnvImpl
import org.eclipse.jdt.internal.compiler.env.ICompilationUnit; //导入依赖的package包/类
public BaseProcessingEnvImpl() {
_addedUnits = new ArrayList<ICompilationUnit>();
_addedClassFiles = new ArrayList<ReferenceBinding>();
_deletedUnits = new ArrayList<ICompilationUnit>();
_elementUtils = new ElementsImpl(this);
_typeUtils = new TypesImpl(this);
_factory = new Factory(this);
_errorRaised = false;
}
示例13: dietParse
import org.eclipse.jdt.internal.compiler.env.ICompilationUnit; //导入依赖的package包/类
public CompilationUnitDeclaration dietParse(ICompilationUnit sourceUnit, CompilationResult compilationResult, int start, int end) {
this.selectionStart = start;
this.selectionEnd = end;
SelectionScanner selectionScanner = (SelectionScanner)this.scanner;
selectionScanner.selectionIdentifier = null;
selectionScanner.selectionStart = start;
selectionScanner.selectionEnd = end;
return this.dietParse(sourceUnit, compilationResult);
}
示例14: parse
import org.eclipse.jdt.internal.compiler.env.ICompilationUnit; //导入依赖的package包/类
public CompilationUnitDeclaration parse(ICompilationUnit sourceUnit, CompilationResult compilationResult, int start, int end) {
if (end == -1) return super.parse(sourceUnit, compilationResult, start, end);
this.selectionStart = start;
this.selectionEnd = end;
SelectionScanner selectionScanner = (SelectionScanner)this.scanner;
selectionScanner.selectionIdentifier = null;
selectionScanner.selectionStart = start;
selectionScanner.selectionEnd = end;
return super.parse(sourceUnit, compilationResult, -1, -1/*parse without reseting the scanner*/);
}
示例15: accept
import org.eclipse.jdt.internal.compiler.env.ICompilationUnit; //导入依赖的package包/类
public void accept(ISourceType[] sourceTypes, PackageBinding packageBinding, AccessRestriction accessRestriction) {
ISourceType sourceType = sourceTypes[0];
while (sourceType.getEnclosingType() != null)
sourceType = sourceType.getEnclosingType();
SourceTypeElementInfo elementInfo = (SourceTypeElementInfo) sourceType;
IType type = elementInfo.getHandle();
ICompilationUnit sourceUnit = (ICompilationUnit) type.getCompilationUnit();
accept(sourceUnit, accessRestriction);
}