Search in sources :

Example 6 with CompilationUnitDeclaration

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;
}
Also used : CompilationUnitDeclaration(org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration) TypeBinding(org.eclipse.jdt.internal.compiler.lookup.TypeBinding) ArrayList(java.util.ArrayList) ProblemMethodBinding(org.eclipse.jdt.internal.compiler.lookup.ProblemMethodBinding) MethodBinding(org.eclipse.jdt.internal.compiler.lookup.MethodBinding) CompilationUnitScope(org.eclipse.jdt.internal.compiler.lookup.CompilationUnitScope) ReferenceBinding(org.eclipse.jdt.internal.compiler.lookup.ReferenceBinding)

Example 7 with CompilationUnitDeclaration

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;
}
Also used : CompilationUnit(org.eclipse.jdt.internal.compiler.batch.CompilationUnit) ICompilationUnit(org.eclipse.jdt.internal.compiler.env.ICompilationUnit) Compiler(org.eclipse.jdt.internal.compiler.Compiler) ICompilationUnit(org.eclipse.jdt.internal.compiler.env.ICompilationUnit) CompilerMessage(lombok.javac.CapturingDiagnosticListener.CompilerMessage) ICompilerRequestor(org.eclipse.jdt.internal.compiler.ICompilerRequestor) AtomicReference(java.util.concurrent.atomic.AtomicReference) CategorizedProblem(org.eclipse.jdt.core.compiler.CategorizedProblem) CompilationUnitDeclaration(org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration) CompilationResult(org.eclipse.jdt.internal.compiler.CompilationResult) DefaultProblemFactory(org.eclipse.jdt.internal.compiler.problem.DefaultProblemFactory)

Example 8 with CompilationUnitDeclaration

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();
}
Also used : CompilationUnitDeclaration(org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration)

Example 9 with CompilationUnitDeclaration

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;
}
Also used : CompilationUnit(lombok.ast.CompilationUnit) ProblemReporter(org.eclipse.jdt.internal.compiler.problem.ProblemReporter) Node(lombok.ast.Node) Parser(org.eclipse.jdt.internal.compiler.parser.Parser) EcjTreeConverter(lombok.ast.ecj.EcjTreeConverter) CompilationUnitDeclaration(org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration) CompilerOptions(org.eclipse.jdt.internal.compiler.impl.CompilerOptions) DefaultProblemFactory(org.eclipse.jdt.internal.compiler.problem.DefaultProblemFactory) CompilationResult(org.eclipse.jdt.internal.compiler.CompilationResult) Nullable(com.android.annotations.Nullable)

Example 10 with CompilationUnitDeclaration

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);
}
Also used : ICompilationUnit(org.eclipse.jdt.internal.compiler.env.ICompilationUnit) IErrorHandlingPolicy(org.eclipse.jdt.internal.compiler.IErrorHandlingPolicy) ICompilationUnit(org.eclipse.jdt.internal.compiler.env.ICompilationUnit) Compiler(org.eclipse.jdt.internal.compiler.Compiler) ICompilerRequestor(org.eclipse.jdt.internal.compiler.ICompilerRequestor) ICompilerRequestor(org.eclipse.jdt.internal.compiler.ICompilerRequestor) CompilationUnitDeclaration(org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration) INameEnvironment(org.eclipse.jdt.internal.compiler.env.INameEnvironment) DefaultProblemFactory(org.eclipse.jdt.internal.compiler.problem.DefaultProblemFactory) CompilationResult(org.eclipse.jdt.internal.compiler.CompilationResult) IProblemFactory(org.eclipse.jdt.internal.compiler.IProblemFactory)

Aggregations

CompilationUnitDeclaration (org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration)17 CompilationResult (org.eclipse.jdt.internal.compiler.CompilationResult)4 DefaultProblemFactory (org.eclipse.jdt.internal.compiler.problem.DefaultProblemFactory)4 CategorizedProblem (org.eclipse.jdt.core.compiler.CategorizedProblem)3 Compiler (org.eclipse.jdt.internal.compiler.Compiler)3 ICompilerRequestor (org.eclipse.jdt.internal.compiler.ICompilerRequestor)3 AbstractMethodDeclaration (org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration)3 ICompilationUnit (org.eclipse.jdt.internal.compiler.env.ICompilationUnit)3 CompilerOptions (org.eclipse.jdt.internal.compiler.impl.CompilerOptions)3 ArrayList (java.util.ArrayList)2 EclipseAST (lombok.eclipse.EclipseAST)2 EclipseNode (lombok.eclipse.EclipseNode)2 TransformEclipseAST (lombok.eclipse.TransformEclipseAST)2 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)2 JavaModelException (org.eclipse.jdt.core.JavaModelException)2 IErrorHandlingPolicy (org.eclipse.jdt.internal.compiler.IErrorHandlingPolicy)2 IProblemFactory (org.eclipse.jdt.internal.compiler.IProblemFactory)2 TypeDeclaration (org.eclipse.jdt.internal.compiler.ast.TypeDeclaration)2 INameEnvironment (org.eclipse.jdt.internal.compiler.env.INameEnvironment)2 Parser (org.eclipse.jdt.internal.compiler.parser.Parser)2