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


Java CompilationResult类代码示例

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


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

示例1: addProblemToCompilationResult

import org.eclipse.jdt.internal.compiler.CompilationResult; //导入依赖的package包/类
/**
 * Adds a problem to the provided CompilationResult object so that it will show up
 * in the Problems/Warnings view.
 */
public static void addProblemToCompilationResult(char[] fileNameArray, CompilationResult result,
		boolean isWarning, String message, int sourceStart, int sourceEnd) {
	if (result == null) return;
	if (fileNameArray == null) fileNameArray = "(unknown).java".toCharArray();
	int lineNumber = 0;
	int columnNumber = 1;
	int[] lineEnds = null;
	lineNumber = sourceStart >= 0
			? Util.getLineNumber(sourceStart, lineEnds = result.getLineSeparatorPositions(), 0, lineEnds.length-1)
			: 0;
	columnNumber = sourceStart >= 0
			? Util.searchColumnNumber(result.getLineSeparatorPositions(), lineNumber,sourceStart)
			: 0;
	
	CategorizedProblem ecProblem = new LombokProblem(
			fileNameArray, message, 0, new String[0],
			isWarning ? ProblemSeverities.Warning : ProblemSeverities.Error,
			sourceStart, sourceEnd, lineNumber, columnNumber);
	result.record(ecProblem, null);
}
 
开发者ID:git03394538,项目名称:lombok-ianchiu,代码行数:25,代码来源:EclipseAstProblemView.java

示例2: parse

import org.eclipse.jdt.internal.compiler.CompilationResult; //导入依赖的package包/类
@Nullable
private static Node parse(String code) {
  CompilerOptions options = new CompilerOptions();
  options.complianceLevel = options.sourceLevel = options.targetJDK = ClassFileConstants.JDK1_7;
  options.parseLiteralExpressionsAsConstants = true;
  ProblemReporter problemReporter = new ProblemReporter(
    DefaultErrorHandlingPolicies.exitOnFirstError(), options, new DefaultProblemFactory());
  Parser parser = new Parser(problemReporter, options.parseLiteralExpressionsAsConstants);
  parser.javadocParser.checkDocComment = false;
  EcjTreeConverter converter = new EcjTreeConverter();
  org.eclipse.jdt.internal.compiler.batch.CompilationUnit sourceUnit =
    new org.eclipse.jdt.internal.compiler.batch.CompilationUnit(code.toCharArray(), "unitTest", "UTF-8");
  CompilationResult compilationResult = new CompilationResult(sourceUnit, 0, 0, 0);
  CompilationUnitDeclaration unit = parser.parse(sourceUnit, compilationResult);
  if (unit == null) {
    return null;
  }
  converter.visit(code, unit);
  List<? extends Node> nodes = converter.getAll();
  for (lombok.ast.Node node : nodes) {
    if (node instanceof lombok.ast.CompilationUnit) {
      return node;
    }
  }
  return null;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:27,代码来源:LombokPsiConverterTest.java

示例3: safeGetProblems

import org.eclipse.jdt.internal.compiler.CompilationResult; //导入依赖的package包/类
/**
 * Invoke CompilationResult#getProblems safely so that it works with
 * 3.1.1 and more recent versions of the eclipse java compiler.
 * See https://jsp.dev.java.net/issues/show_bug.cgi?id=13
 * 
 * @param result The compilation result.
 * @return The same object than CompilationResult#getProblems
 */
private static final IProblem[] safeGetProblems(CompilationResult result) {
    if (!USE_INTROSPECTION_TO_INVOKE_GET_PROBLEM) {
        try {
            return result.getProblems();
        } catch (NoSuchMethodError re) {
            USE_INTROSPECTION_TO_INVOKE_GET_PROBLEM = true;
        }
    }
    try {
        if (GET_PROBLEM_METH == null) {
            GET_PROBLEM_METH = result.getClass()
                    .getDeclaredMethod("getProblems", new Class[] {});
        }
        //an array of a particular type can be casted into an array of a super type.
        return (IProblem[]) GET_PROBLEM_METH.invoke(result, null);
    } catch (Throwable e) {
        if (e instanceof RuntimeException) {
            throw (RuntimeException)e;
        } else {
            throw new RuntimeException(e);
        }
    }
}
 
开发者ID:eclipse,项目名称:packagedrone,代码行数:32,代码来源:JDTJavaCompiler.java

示例4: buildCompilationUnit

import org.eclipse.jdt.internal.compiler.CompilationResult; //导入依赖的package包/类
public static CompilationUnitDeclaration buildCompilationUnit(
    ISourceType[] sourceTypes,
    int flags,
    ProblemReporter problemReporter,
    CompilationResult compilationResult) {

  //		long start = System.currentTimeMillis();
  SourceTypeConverter converter = new SourceTypeConverter(flags, problemReporter);
  try {
    return converter.convert(sourceTypes, compilationResult);
  } catch (JavaModelException e) {
    return null;
    /*		} finally {
    			System.out.println("Spent " + (System.currentTimeMillis() - start) + "ms to convert " + ((JavaElement) converter.cu)
    			.toStringWithAncestors());
    */
  }
}
 
开发者ID:eclipse,项目名称:che,代码行数:19,代码来源:SourceTypeConverter.java

示例5: convert

import org.eclipse.jdt.internal.compiler.CompilationResult; //导入依赖的package包/类
private QualifiedAllocationExpression convert(
    IJavaElement localType, FieldDeclaration enumConstant, CompilationResult compilationResult)
    throws JavaModelException {
  TypeDeclaration anonymousLocalTypeDeclaration =
      convert((SourceType) localType, compilationResult);
  QualifiedAllocationExpression expression =
      new QualifiedAllocationExpression(anonymousLocalTypeDeclaration);
  expression.type = anonymousLocalTypeDeclaration.superclass;
  anonymousLocalTypeDeclaration.superclass = null;
  anonymousLocalTypeDeclaration.superInterfaces = null;
  anonymousLocalTypeDeclaration.allocation = expression;
  if (enumConstant != null) {
    anonymousLocalTypeDeclaration.modifiers &= ~ClassFileConstants.AccEnum;
    expression.enumConstant = enumConstant;
    expression.type = null;
  }
  return expression;
}
 
开发者ID:eclipse,项目名称:che,代码行数:19,代码来源:SourceTypeConverter.java

示例6: process

import org.eclipse.jdt.internal.compiler.CompilationResult; //导入依赖的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

示例7: parseWithLombok

import org.eclipse.jdt.internal.compiler.CompilationResult; //导入依赖的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

示例8: parseWithTargetCompiler

import org.eclipse.jdt.internal.compiler.CompilationResult; //导入依赖的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

示例9: parseWithTargetCompiler

import org.eclipse.jdt.internal.compiler.CompilationResult; //导入依赖的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

示例10: parseWithTargetCompiler

import org.eclipse.jdt.internal.compiler.CompilationResult; //导入依赖的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

示例11: getJavaCompilationErrors

import org.eclipse.jdt.internal.compiler.CompilationResult; //导入依赖的package包/类
/**
 * 
 */
protected IProblem[] getJavaCompilationErrors(CompilationResult result) {
	return result.getErrors();
	//
	// try {
	// Method getErrorsMethod = result.getClass().getMethod("getErrors",
	// (Class[]) null);
	// return (IProblem[]) getErrorsMethod.invoke(result, (Object[]) null);
	// } catch (SecurityException e) {
	// throw new JRRuntimeException("Error resolving JDT methods", e);
	// } catch (NoSuchMethodException e) {
	// throw new JRRuntimeException("Error resolving JDT methods", e);
	// } catch (IllegalArgumentException e) {
	// throw new JRRuntimeException("Error invoking JDT methods", e);
	// } catch (IllegalAccessException e) {
	// throw new JRRuntimeException("Error invoking JDT methods", e);
	// } catch (InvocationTargetException e) {
	// throw new JRRuntimeException("Error invoking JDT methods", e);
	// }
}
 
开发者ID:OpenSoftwareSolutions,项目名称:PDFReporter-Studio,代码行数:23,代码来源:JRJdtCompiler.java

示例12: accept

import org.eclipse.jdt.internal.compiler.CompilationResult; //导入依赖的package包/类
/**
 * Add additional source types
 */
public void accept(ISourceType[] sourceTypes, PackageBinding packageBinding, AccessRestriction accessRestriction) {
	// case of SearchableEnvironment of an IJavaProject is used
	ISourceType sourceType = sourceTypes[0];
	while (sourceType.getEnclosingType() != null)
		sourceType = sourceType.getEnclosingType();
	if (sourceType instanceof SourceTypeElementInfo) {
		// get source
		SourceTypeElementInfo elementInfo = (SourceTypeElementInfo) sourceType;
		IType type = elementInfo.getHandle();
		ICompilationUnit sourceUnit = (ICompilationUnit) type.getCompilationUnit();
		accept(sourceUnit, accessRestriction);
	} else {
		CompilationResult result = new CompilationResult(sourceType.getFileName(), 1, 1, 0);
		CompilationUnitDeclaration unit =
			SourceTypeConverter.buildCompilationUnit(
				sourceTypes,
				SourceTypeConverter.FIELD_AND_METHOD // need field and methods
				| SourceTypeConverter.MEMBER_TYPE, // need member types
				// no need for field initialization
				this.lookupEnvironment.problemReporter,
				result);
		this.lookupEnvironment.buildTypeBindings(unit, accessRestriction);
		this.lookupEnvironment.completeTypeBindings(unit, true);
	}
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:29,代码来源:MatchLocator.java

示例13: getBatchRequestor

import org.eclipse.jdt.internal.compiler.CompilationResult; //导入依赖的package包/类
public ICompilerRequestor getBatchRequestor() {
	return new ICompilerRequestor() {
		int lineDelta = 0;
		public void acceptResult(CompilationResult compilationResult) {
			if (compilationResult.lineSeparatorPositions != null) {
				int unitLineCount = compilationResult.lineSeparatorPositions.length;
				this.lineDelta += unitLineCount;
				if (Main.this.showProgress && this.lineDelta > 2000) {
					// in -log mode, dump a dot every 2000 lines compiled
					Main.this.logger.logProgress();
					this.lineDelta = 0;
				}
			}
			Main.this.logger.startLoggingSource(compilationResult);
			if (compilationResult.hasProblems() || compilationResult.hasTasks()) {
				Main.this.logger.logProblems(compilationResult.getAllProblems(), compilationResult.compilationUnit.getContents(), Main.this);
			}
			outputClassFiles(compilationResult);
			Main.this.logger.endLoggingSource();
		}
	};
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion-Juno38,代码行数:23,代码来源:Main.java

示例14: buildCompilationUnit

import org.eclipse.jdt.internal.compiler.CompilationResult; //导入依赖的package包/类
public static CompilationUnitDeclaration buildCompilationUnit(
		ISourceType[] sourceTypes,
		int flags,
		ProblemReporter problemReporter,
		CompilationResult compilationResult) {

//		long start = System.currentTimeMillis();
		SourceTypeConverter converter = new SourceTypeConverter(flags, problemReporter);
		try {
			return converter.convert(sourceTypes, compilationResult);
		} catch (JavaModelException e) {
			return null;
/*		} finally {
			System.out.println("Spent " + (System.currentTimeMillis() - start) + "ms to convert " + ((JavaElement) converter.cu).toStringWithAncestors());
*/		}
	}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:17,代码来源:SourceTypeConverter.java

示例15: evaluationResultsForCompilationProblems

import org.eclipse.jdt.internal.compiler.CompilationResult; //导入依赖的package包/类
/**
 * Returns the evaluation results that converts the given compilation result that has problems.
 * If the compilation result has more than one problem, then the problems are broken down so that
 * each evaluation result has the same evaluation id.
 */
protected EvaluationResult[] evaluationResultsForCompilationProblems(CompilationResult result, char[] cuSource) {
	// Break down the problems and group them by ids in evaluation results
	CategorizedProblem[] problems = result.getAllProblems();
	HashMap resultsByIDs = new HashMap(5);
	for (int i = 0; i < problems.length; i++) {
		addEvaluationResultForCompilationProblem(resultsByIDs, problems[i], cuSource);
	}

	// Copy results
	int size = resultsByIDs.size();
	EvaluationResult[] evalResults = new EvaluationResult[size];
	Iterator results = resultsByIDs.values().iterator();
	for (int i = 0; i < size; i++) {
		evalResults[i] = (EvaluationResult)results.next();
	}

	return evalResults;
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:24,代码来源:Evaluator.java


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