当前位置: 首页>>代码示例>>Java>>正文


Java CompilationUnit类代码示例

本文整理汇总了Java中org.eclipse.jdt.internal.compiler.batch.CompilationUnit的典型用法代码示例。如果您正苦于以下问题:Java CompilationUnit类的具体用法?Java CompilationUnit怎么用?Java CompilationUnit使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


CompilationUnit类属于org.eclipse.jdt.internal.compiler.batch包,在下文中一共展示了CompilationUnit类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: process

import org.eclipse.jdt.internal.compiler.batch.CompilationUnit; //导入依赖的package包/类
@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;
}
 
开发者ID:evant,项目名称:android-retrolambda-lombok,代码行数:19,代码来源:Main.java

示例2: parseWithLombok

import org.eclipse.jdt.internal.compiler.batch.CompilationUnit; //导入依赖的package包/类
@Override
protected ASTNode parseWithLombok(Source source) {
	CompilerOptions compilerOptions = ecjCompilerOptions();
	Parser parser = new Parser(new ProblemReporter(
			DefaultErrorHandlingPolicies.proceedWithAllProblems(),
			compilerOptions,
			new DefaultProblemFactory()
		), compilerOptions.parseLiteralExpressionsAsConstants);
	parser.javadocParser.checkDocComment = true;
	CompilationUnit sourceUnit = new CompilationUnit(source.getRawInput().toCharArray(), source.getName(), "UTF-8");
	CompilationResult compilationResult = new CompilationResult(sourceUnit, 0, 0, 0);
	CompilationUnitDeclaration cud = parser.parse(sourceUnit, compilationResult);
	
	if (cud.hasErrors()) return null;
	
	EcjTreeConverter converter = new EcjTreeConverter();
	converter.visit(source.getRawInput(), cud);
	Node lombokized = converter.get();
	
	EcjTreeBuilder builder = new EcjTreeBuilder(source.getRawInput(), source.getName(), ecjCompilerOptions());
	builder.visit(lombokized);
	return builder.get();
}
 
开发者ID:evant,项目名称:android-retrolambda-lombok,代码行数:24,代码来源:EcjTreeConverterType2Test.java

示例3: parseWithTargetCompiler

import org.eclipse.jdt.internal.compiler.batch.CompilationUnit; //导入依赖的package包/类
@Override
protected ASTNode parseWithTargetCompiler(Source source) {
	CompilerOptions compilerOptions = ecjCompilerOptions();
	Parser parser = new Parser(new ProblemReporter(
			DefaultErrorHandlingPolicies.proceedWithAllProblems(),
			compilerOptions,
			new DefaultProblemFactory()
		), compilerOptions.parseLiteralExpressionsAsConstants);
	parser.javadocParser.checkDocComment = true;
	CompilationUnit sourceUnit = new CompilationUnit(source.getRawInput().toCharArray(), source.getName(), "UTF-8");
	CompilationResult compilationResult = new CompilationResult(sourceUnit, 0, 0, 0);
	CompilationUnitDeclaration cud = parser.parse(sourceUnit, compilationResult);
	
	if (cud.hasErrors()) return null;
	
	return cud;
}
 
开发者ID:evant,项目名称:android-retrolambda-lombok,代码行数:18,代码来源:EcjTreeConverterType2Test.java

示例4: parseWithTargetCompiler

import org.eclipse.jdt.internal.compiler.batch.CompilationUnit; //导入依赖的package包/类
@Override
protected ASTNode parseWithTargetCompiler(Source source) {
	CompilerOptions compilerOptions = ecjCompilerOptions();
	Parser parser = new Parser(new ProblemReporter(
			DefaultErrorHandlingPolicies.proceedWithAllProblems(),
			compilerOptions,
			new DefaultProblemFactory()
		), compilerOptions.parseLiteralExpressionsAsConstants);
	parser.javadocParser.checkDocComment = true;
	CompilationUnit sourceUnit = new CompilationUnit(source.getRawInput().toCharArray(), source.getName(), "UTF-8");
	CompilationResult compilationResult = new CompilationResult(sourceUnit, 0, 0, 0);
	CompilationUnitDeclaration cud = parser.parse(sourceUnit, compilationResult);
	
	if (cud.hasErrors()) return null;
	return cud;
}
 
开发者ID:evant,项目名称:android-retrolambda-lombok,代码行数:17,代码来源:EcjTreeBuilderTest.java

示例5: parseWithTargetCompiler

import org.eclipse.jdt.internal.compiler.batch.CompilationUnit; //导入依赖的package包/类
protected Node parseWithTargetCompiler(Source source) {
	CompilerOptions compilerOptions = ecjCompilerOptions();
	Parser parser = new Parser(new ProblemReporter(
			DefaultErrorHandlingPolicies.proceedWithAllProblems(),
			compilerOptions,
			new DefaultProblemFactory()
		), compilerOptions.parseLiteralExpressionsAsConstants);
	parser.javadocParser.checkDocComment = true;
	CompilationUnit sourceUnit = new CompilationUnit(source.getRawInput().toCharArray(), source.getName(), "UTF-8");
	CompilationResult compilationResult = new CompilationResult(sourceUnit, 0, 0, 0);
	CompilationUnitDeclaration cud = parser.parse(sourceUnit, compilationResult);
	
	if (cud.hasErrors()) return null;
	
	EcjTreeConverter converter = new EcjTreeConverter();
	converter.visit(source.getRawInput(), cud);
	return converter.get();
}
 
开发者ID:evant,项目名称:android-retrolambda-lombok,代码行数:19,代码来源:EcjTreeConverterType1Test.java

示例6: findType

import org.eclipse.jdt.internal.compiler.batch.CompilationUnit; //导入依赖的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);
    }
}
 
开发者ID:drxaos,项目名称:jvmvm,代码行数:19,代码来源:NameEnv.java

示例7: createSourceFile

import org.eclipse.jdt.internal.compiler.batch.CompilationUnit; //导入依赖的package包/类
@Override
public JavaFileObject createSourceFile(CharSequence name, Element... originatingElements) throws IOException {
  JavaFileObject sourceFile = fileManager.getJavaFileForOutput(StandardLocation.SOURCE_OUTPUT, name.toString(), JavaFileObject.Kind.SOURCE, null);
  if (!createdResources.add(sourceFile.toUri())) {
    throw new FilerException("Attempt to recreate file for type " + name);
  }
  return new JavaFileObjectImpl(sourceFile, new FileObjectDelegate() {

    private boolean closed = false;

    @Override
    protected void onClose(Output<File> generatedSource) {
      if (!closed) {
        closed = true;
        // TODO optimize if the regenerated sources didn't change compared the previous build
        CompilationUnit unit = new CompilationUnit(null, generatedSource.getResource().getAbsolutePath(), null /* encoding */);
        processingEnv.addNewUnit(unit);
        incrementalCompiler.addGeneratedSource(generatedSource);
      }
    }
  });
}
 
开发者ID:takari,项目名称:takari-lifecycle,代码行数:23,代码来源:FilerImpl.java

示例8: installStubs

import org.eclipse.jdt.internal.compiler.batch.CompilationUnit; //导入依赖的package包/类
public void installStubs(final Resource resource) {
  boolean _isInfoFile = this.isInfoFile(resource);
  if (_isInfoFile) {
    return;
  }
  final CompilationUnit compilationUnit = this.getCompilationUnit(resource);
  IErrorHandlingPolicy _proceedWithAllProblems = DefaultErrorHandlingPolicies.proceedWithAllProblems();
  CompilerOptions _compilerOptions = this.getCompilerOptions(resource);
  DefaultProblemFactory _defaultProblemFactory = new DefaultProblemFactory();
  ProblemReporter _problemReporter = new ProblemReporter(_proceedWithAllProblems, _compilerOptions, _defaultProblemFactory);
  final Parser parser = new Parser(_problemReporter, true);
  final CompilationResult compilationResult = new CompilationResult(compilationUnit, 0, 1, (-1));
  final CompilationUnitDeclaration result = parser.dietParse(compilationUnit, compilationResult);
  if ((result.types != null)) {
    for (final TypeDeclaration type : result.types) {
      {
        ImportReference _currentPackage = result.currentPackage;
        char[][] _importName = null;
        if (_currentPackage!=null) {
          _importName=_currentPackage.getImportName();
        }
        List<String> _map = null;
        if (((List<char[]>)Conversions.doWrapArray(_importName))!=null) {
          final Function1<char[], String> _function = (char[] it) -> {
            return String.valueOf(it);
          };
          _map=ListExtensions.<char[], String>map(((List<char[]>)Conversions.doWrapArray(_importName)), _function);
        }
        String _join = null;
        if (_map!=null) {
          _join=IterableExtensions.join(_map, ".");
        }
        final String packageName = _join;
        final JvmDeclaredType jvmType = this.createType(type, packageName);
        resource.getContents().add(jvmType);
      }
    }
  }
}
 
开发者ID:eclipse,项目名称:xtext-extras,代码行数:40,代码来源:JavaDerivedStateComputer.java

示例9: doLoad

import org.eclipse.jdt.internal.compiler.batch.CompilationUnit; //导入依赖的package包/类
@Override
protected void doLoad(final InputStream inputStream, final Map<?, ?> options) throws IOException {
  final String encoding = this.getEncoding(this.getURI(), options);
  InputStreamReader _inputStreamReader = new InputStreamReader(inputStream, encoding);
  final String contentsAsString = CharStreams.toString(_inputStreamReader);
  char[] _charArray = contentsAsString.toCharArray();
  String _lastSegment = this.getURI().lastSegment();
  CompilationUnit _compilationUnit = new CompilationUnit(_charArray, _lastSegment, encoding);
  this.compilationUnit = _compilationUnit;
}
 
开发者ID:eclipse,项目名称:xtext-extras,代码行数:11,代码来源:JavaResource.java

示例10: getCompilationUnits

import org.eclipse.jdt.internal.compiler.batch.CompilationUnit; //导入依赖的package包/类
@Override
public CompilationUnit[] getCompilationUnits() {
    int fileCount = this.filenames.length;
    CompilationUnit[] units = new CompilationUnit[fileCount];
    HashtableOfObject knownFileNames = new HashtableOfObject(fileCount);
    String defaultEncoding = (String)this.options.get("org.eclipse.jdt.core.encoding");
    if(Util.EMPTY_STRING.equals(defaultEncoding)) {
        defaultEncoding = null;
    }

    for(int i = 0; i < fileCount; ++i) {
        char[] charName = this.filenames[i].toCharArray();
        if(knownFileNames.get(charName) != null) {
            throw new IllegalArgumentException(this.bind("unit.more", this.filenames[i]));
        }

        knownFileNames.put(charName, charName);
        File file = new File(this.filenames[i]);
        if(!file.exists()) {
            throw new IllegalArgumentException(this.bind("unit.missing", this.filenames[i]));
        }

        String encoding = this.encodings[i];
        if(encoding == null) {
            encoding = defaultEncoding;
        }

        String fileName;
        try {
            fileName = file.getCanonicalPath();
        } catch (IOException var10) {
            fileName = this.filenames[i];
        }
        units[i] = new CompilationUnit((char[])null, fileName, encoding, this.destinationPaths[i], false, null);
    }
    return units;
}
 
开发者ID:STAMP-project,项目名称:dspot,代码行数:38,代码来源:DSpotJDTBatchCompiler.java

示例11: parseSources

import org.eclipse.jdt.internal.compiler.batch.CompilationUnit; //导入依赖的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);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:39,代码来源:ExtractAnnotationsDriver.java

示例12: parseJava

import org.eclipse.jdt.internal.compiler.batch.CompilationUnit; //导入依赖的package包/类
@Override
public Node parseJava(@NonNull JavaContext context) {
    String code = context.getContents();
    if (code == null) {
        return null;
    }

    CompilationUnitDeclaration unit = getParsedUnit(context, code);
    try {
        EcjTreeConverter converter = new EcjTreeConverter();
        converter.visit(code, unit);
        List<? extends Node> nodes = converter.getAll();

        if (nodes != null) {
            // There could be more than one node when there are errors; pick out the
            // compilation unit node
            for (Node node : nodes) {
                if (node instanceof lombok.ast.CompilationUnit) {
                    return node;
                }
            }
        }

        return null;
    } catch (Throwable t) {
        mClient.log(t, "Failed converting ECJ parse tree to Lombok for file %1$s",
                context.file.getPath());
        return null;
    }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:31,代码来源:EcjParser.java

示例13: parseWithEcj

import org.eclipse.jdt.internal.compiler.batch.CompilationUnit; //导入依赖的package包/类
private void parseWithEcj(Source source) {
	if (VERBOSE) {
		CompilerOptions compilerOptions = ecjCompilerOptions();
		Parser parser = new Parser(new ProblemReporter(
				DefaultErrorHandlingPolicies.proceedWithAllProblems(),
				compilerOptions,
				new DefaultProblemFactory()
			), compilerOptions.parseLiteralExpressionsAsConstants);
		parser.javadocParser.checkDocComment = true;
		CompilationUnit sourceUnit = new CompilationUnit(source.getRawInput().toCharArray(), source.getName(), "UTF-8");
		CompilationResult compilationResult = new CompilationResult(sourceUnit, 0, 0, 0);
		parser.parse(sourceUnit, compilationResult);
	}
}
 
开发者ID:evant,项目名称:android-retrolambda-lombok,代码行数:15,代码来源:PerformanceTest.java

示例14: getCompilationUnits

import org.eclipse.jdt.internal.compiler.batch.CompilationUnit; //导入依赖的package包/类
@Override
public CompilationUnit[] getCompilationUnits() {
	if (this.compilationUnits == null) return EclipseCompilerImpl.NO_UNITS;
	ArrayList<CompilationUnit> units = new ArrayList<CompilationUnit>();
	for (final JavaFileObject javaFileObject : this.compilationUnits) {
		if (javaFileObject.getKind() != JavaFileObject.Kind.SOURCE) {
			throw new IllegalArgumentException();
		}
		String name = javaFileObject.getName();
		name = name.replace('\\', '/');
		CompilationUnit compilationUnit = new CompilationUnit(null,
			name,
			null) {

			@Override
			public char[] getContents() {
				try {
					return javaFileObject.getCharContent(true).toString().toCharArray();
				} catch(IOException e) {
					e.printStackTrace();
					throw new AbortCompilationUnit(null, e, null);
				}
			}
		};
		units.add(compilationUnit);
		this.javaFileObjectMap.put(compilationUnit, javaFileObject);
	}
	CompilationUnit[] result = new CompilationUnit[units.size()];
	units.toArray(result);
	return result;
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:32,代码来源:EclipseCompilerImpl.java

示例15: parseClassBodyDeclarations

import org.eclipse.jdt.internal.compiler.batch.CompilationUnit; //导入依赖的package包/类
public ASTNode[] parseClassBodyDeclarations(
		char[] source,
		int offset,
		int length,
		Map settings,
		boolean recordParsingInformation,
		boolean enabledStatementRecovery) {
	if (source == null) {
		throw new IllegalArgumentException();
	}
	CompilerOptions compilerOptions = new CompilerOptions(settings);
	compilerOptions.ignoreMethodBodies = this.ignoreMethodBodies;
	final ProblemReporter problemReporter = new ProblemReporter(
				DefaultErrorHandlingPolicies.proceedWithAllProblems(),
				compilerOptions,
				new DefaultProblemFactory(Locale.getDefault()));

	CommentRecorderParser parser = new CommentRecorderParser(problemReporter, false);
	parser.setMethodsFullRecovery(false);
	parser.setStatementsRecovery(enabledStatementRecovery);

	ICompilationUnit sourceUnit =
		new CompilationUnit(
			source,
			"", //$NON-NLS-1$
			compilerOptions.defaultEncoding);

	CompilationResult compilationResult = new CompilationResult(sourceUnit, 0, 0, compilerOptions.maxProblemsPerUnit);
	final CompilationUnitDeclaration compilationUnitDeclaration = new CompilationUnitDeclaration(problemReporter, compilationResult, source.length);
	ASTNode[] result = parser.parseClassBodyDeclarations(source, offset, length, compilationUnitDeclaration);

	if (recordParsingInformation) {
		this.recordedParsingInformation = getRecordedParsingInformation(compilationResult, compilationUnitDeclaration.comments);
	}
	return result;
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:37,代码来源:CodeSnippetParsingUtil.java


注:本文中的org.eclipse.jdt.internal.compiler.batch.CompilationUnit类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。