use of org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration in project lombok by rzwitserloot.
the class PatchExtensionMethod method getApplicableExtensionMethodsDefinedInProvider.
private static List<MethodBinding> getApplicableExtensionMethodsDefinedInProvider(EclipseNode typeNode, ReferenceBinding extensionMethodProviderBinding, TypeBinding receiverType) {
List<MethodBinding> extensionMethods = new ArrayList<MethodBinding>();
CompilationUnitScope cuScope = ((CompilationUnitDeclaration) typeNode.top().get()).scope;
for (MethodBinding method : extensionMethodProviderBinding.methods()) {
if (!method.isStatic())
continue;
if (!method.isPublic())
continue;
if (method.parameters == null || method.parameters.length == 0)
continue;
TypeBinding firstArgType = method.parameters[0];
if (receiverType.isProvablyDistinct(firstArgType) && !receiverType.isCompatibleWith(firstArgType.erasure()))
continue;
TypeBinding[] argumentTypes = Arrays.copyOfRange(method.parameters, 1, method.parameters.length);
if ((receiverType instanceof ReferenceBinding) && ((ReferenceBinding) receiverType).getExactMethod(method.selector, argumentTypes, cuScope) != null)
continue;
extensionMethods.add(method);
}
return extensionMethods;
}
use of org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration in project lombok by rzwitserloot.
the class RunTestsViaEcj method transformCode.
@Override
public boolean transformCode(Collection<CompilerMessage> messages, StringWriter result, File file, String encoding, Map<String, String> formatPreferences) throws Throwable {
final AtomicReference<CompilationResult> compilationResult_ = new AtomicReference<CompilationResult>();
final AtomicReference<CompilationUnitDeclaration> compilationUnit_ = new AtomicReference<CompilationUnitDeclaration>();
ICompilerRequestor bitbucketRequestor = new ICompilerRequestor() {
@Override
public void acceptResult(CompilationResult result) {
compilationResult_.set(result);
}
};
String source = readFile(file);
final CompilationUnit sourceUnit = new CompilationUnit(source.toCharArray(), file.getName(), encoding == null ? "UTF-8" : encoding);
Compiler ecjCompiler = new Compiler(createFileSystem(file), ecjErrorHandlingPolicy(), ecjCompilerOptions(), bitbucketRequestor, new DefaultProblemFactory(Locale.ENGLISH)) {
@Override
protected synchronized void addCompilationUnit(ICompilationUnit inUnit, CompilationUnitDeclaration parsedUnit) {
if (inUnit == sourceUnit)
compilationUnit_.set(parsedUnit);
super.addCompilationUnit(inUnit, parsedUnit);
}
};
ecjCompiler.compile(new ICompilationUnit[] { sourceUnit });
CompilationResult compilationResult = compilationResult_.get();
CategorizedProblem[] problems = compilationResult.getAllProblems();
if (problems != null)
for (CategorizedProblem p : problems) {
messages.add(new CompilerMessage(p.getSourceLineNumber(), p.getSourceStart(), p.isError(), p.getMessage()));
}
CompilationUnitDeclaration cud = compilationUnit_.get();
if (cud == null)
result.append("---- NO CompilationUnit provided by ecj ----");
else
result.append(cud.toString());
return true;
}
use of org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration in project lombok by rzwitserloot.
the class EclipseAST method propagateProblems.
private void propagateProblems() {
if (queuedProblems.isEmpty())
return;
CompilationUnitDeclaration cud = (CompilationUnitDeclaration) top().get();
if (cud.compilationResult == null)
return;
for (ParseProblem problem : queuedProblems) problem.addToCompilationResult();
queuedProblems.clear();
}
use of org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration in project android by JetBrains.
the class LombokPsiConverterTest method parse.
@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;
}
use of org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration in project Japid by branaway.
the class RendererCompiler method compile.
/**
* Please compile this className and set the bytecode to the class holder
*/
@SuppressWarnings("deprecation")
public void compile(String[] classNames) {
ICompilationUnit[] compilationUnits = new CompilationUnit[classNames.length];
for (int i = 0; i < classNames.length; i++) {
compilationUnits[i] = new CompilationUnit(this, classNames[i]);
}
IErrorHandlingPolicy policy = DefaultErrorHandlingPolicies.exitOnFirstError();
IProblemFactory problemFactory = new DefaultProblemFactory(Locale.ENGLISH);
/**
* To find types ...
*/
INameEnvironment nameEnvironment = new NameEnv(this);
/**
* Compilation result
*/
ICompilerRequestor compilerRequestor = new CompilerRequestor(this);
/**
* The JDT compiler
*/
Compiler jdtCompiler = new Compiler(nameEnvironment, policy, settings, compilerRequestor, problemFactory) {
@Override
protected void handleInternalException(Throwable e, CompilationUnitDeclaration ud, CompilationResult result) {
}
};
// Go !
jdtCompiler.compile(compilationUnits);
}
Aggregations