Example usage for org.eclipse.jdt.internal.compiler.ast CompilationUnitDeclaration getMainTypeName

List of usage examples for org.eclipse.jdt.internal.compiler.ast CompilationUnitDeclaration getMainTypeName

Introduction

In this page you can find the example usage for org.eclipse.jdt.internal.compiler.ast CompilationUnitDeclaration getMainTypeName.

Prototype

public char[] getMainTypeName() 

Source Link

Usage

From source file:com.codenvy.ide.ext.java.server.internal.core.search.matching.MatchLocator.java

License:Open Source License

/**
 * Creates an IImportDeclaration from the given import statement
 *///from w  w  w.  jav a  2  s . com
protected IJavaElement createPackageDeclarationHandle(CompilationUnitDeclaration unit) {
    if (unit.isPackageInfo()) {
        char[] packName = CharOperation.concatWith(unit.currentPackage.getImportName(), '.');
        Openable openable = this.currentPossibleMatch.openable;
        if (openable instanceof CompilationUnit) {
            return ((CompilationUnit) openable).getPackageDeclaration(new String(packName));
        }
    }
    return createTypeHandle(new String(unit.getMainTypeName()));
}

From source file:com.google.gwt.dev.javac.CompilationUnitInvalidator.java

License:Open Source License

public static void reportErrors(TreeLogger logger, CompilationUnitDeclaration cud, String sourceForDump) {
    CategorizedProblem[] problems = cud.compilationResult().getProblems();
    String fileName = String.valueOf(cud.getFileName());
    boolean isError = cud.compilationResult().hasErrors();
    TreeLogger branch = reportErrors(logger, problems, fileName, isError);
    if (branch != null) {
        Util.maybeDumpSource(branch, fileName, sourceForDump, String.valueOf(cud.getMainTypeName()));
    }//from ww  w  .  jav a 2s.  c  o m
}

From source file:com.google.gwt.dev.jjs.JavaToJavaScriptCompiler.java

License:Apache License

/**
 * Look through the list of compiled units for errors and log them to the
 * console.//w  w w .  j  ava 2s .c o  m
 * 
 * @param logger logger to use for compilation errors
 * @param cuds compiled units to analyze for errors.
 * @param itemizeErrors log each error or simply log one message if the build
 *          failed.
 * @throws UnableToCompleteException if a compilation error is found in the
 *           cuds argument.
 */
static void checkForErrors(TreeLogger logger, CompilationUnitDeclaration[] cuds, boolean itemizeErrors)
        throws UnableToCompleteException {
    Event checkForErrorsEvent = SpeedTracerLogger.start(CompilerEventType.CHECK_FOR_ERRORS);
    boolean compilationFailed = false;
    if (cuds.length == 0) {
        compilationFailed = true;
    }
    for (CompilationUnitDeclaration cud : cuds) {
        final CompilationResult result = cud.compilationResult();
        if (result.hasErrors()) {
            compilationFailed = true;
            // Early out if we don't need to itemize.
            if (!itemizeErrors) {
                break;
            }
            String typeName = new String(cud.getMainTypeName());
            CompilationProblemReporter.reportErrors(logger, result.getErrors(), new String(cud.getFileName()),
                    true, new SourceFetcher() {
                        public String getSource() {
                            return new String(result.getCompilationUnit().getContents());
                        }
                    }, typeName, false);
        }
    }
    checkForErrorsEvent.end();
    if (compilationFailed) {
        logger.log(TreeLogger.ERROR, "Cannot proceed due to previous errors", null);
        throw new UnableToCompleteException();
    }
}

From source file:lombok.core.debug.DebugSnapshot.java

License:Open Source License

private String ownerName() {
    CompilationUnitDeclaration node = owner.get();
    if (node == null)
        return "--GCed--";
    char[] tn = node.getMainTypeName();
    char[] fs = node.getFileName();
    if (tn == null || tn.length == 0) {
        return (fs == null || fs.length == 0) ? "--UNKNOWN--" : new String(fs);
    }/*from   w  w w .ja v a  2 s. c o  m*/

    return new String(tn);
}

From source file:org.eclipse.objectteams.otdt.tests.compiler.smap.AbstractSourceMapGeneratorTest.java

License:Open Source License

public void callback(CompilationUnitDeclaration cuDecl) {
    String cuDeclName = String.valueOf(cuDecl.getMainTypeName());
    if (!_enclosingTypename.equals(cuDeclName))
        return;/*from www  . j  a va 2  s . c  om*/

    TypeDeclaration typeDecl = cuDecl.types[0];

    assertNotNull("TypeDeclaration should not be null.", typeDecl);

    assertTrue("Membertypes of TypeDeclaration should be greater than 0.", typeDecl.memberTypes.length > 0);

    TypeDeclaration[] members = typeDecl.memberTypes;
    for (int idx = 0; idx < members.length; idx++) {
        TypeDeclaration decl = members[idx];
        String typeName = String.valueOf(decl.name);

        if (decl.isRole() && !decl.isInterface() && typeName.equals(TYPENAME)) {
            RoleSmapGenerator rolefileSmapGenerator = new RoleSmapGenerator(decl);
            rolefileSmapGenerator.addStratum("OTJ");
            rolefileSmapGenerator.generate();
            List actualStrata = rolefileSmapGenerator.getStrata();

            assertEquals("Strata of type \"" + typeName + "\" should be equal.\n",
                    expectedStrata.get(typeName).toString(), actualStrata.toString());
        }
    }
}

From source file:org.eclipse.objectteams.otdt.tests.compiler.smap.OTJStratumGenerationTest003.java

License:Open Source License

public void callback(CompilationUnitDeclaration cuDecl) {
    if (_enclosingTypename != null) {
        super.callback(cuDecl);
        return;//  w w w.  ja  v  a2 s.  co  m
    }
    // testing the team itself 
    String cuDeclName = String.valueOf(cuDecl.getMainTypeName());
    if (!TYPENAME.equals(cuDeclName))
        return;

    TypeDeclaration typeDecl = cuDecl.types[0];

    assertNotNull("TypeDeclaration should not be null.", typeDecl);

    assertTrue("TypeDeclaration should be a team.", typeDecl.isTeam());

    TeamSmapGenerator teamSmapGenerator = new TeamSmapGenerator(typeDecl);
    teamSmapGenerator.addStratum("OTJ");
    teamSmapGenerator.generate();
    List actualStrata = teamSmapGenerator.getStrata();

    assertEquals("Strata of type \"" + TYPENAME + "\" should be equal.\n",
            expectedStrata.get(TYPENAME).toString(), actualStrata.toString());
}

From source file:org.eclipse.objectteams.otdt.tests.compiler.smap.OTJStratumGenerationTest007.java

License:Open Source License

public void callback(CompilationUnitDeclaration cuDecl) {
    String cuDeclName = String.valueOf(cuDecl.getMainTypeName());
    if (!_enclosingTypename.equals(cuDeclName))
        return;/*  w  w w .  ja va 2  s .  c om*/

    TypeDeclaration typeDecl = cuDecl.types[0];

    assertNotNull("TypeDeclaration should not be null.", typeDecl);

    assertTrue("Membertypes of TypeDeclaration should be greater than 0.", typeDecl.memberTypes.length > 0);

    TypeDeclaration[] members = typeDecl.memberTypes;
    for (int idx = 0; idx < members.length; idx++) {
        TypeDeclaration decl = members[idx];
        String typeName = String.valueOf(decl.name);

        if (decl.isRole() && !decl.isInterface() && typeName.equals(TYPENAME)) {
            RoleSmapGenerator rolefileSmapGenerator = new RoleSmapGenerator(decl);
            if (_buildPartially) {
                rolefileSmapGenerator.addStratum("OTJ");
                SmapStratum stratum = (SmapStratum) rolefileSmapGenerator.getStrata().get(0);
                rolefileSmapGenerator.generatePartialOTJSmap(stratum, new LineInfoCollector());
            } else {
                rolefileSmapGenerator.addStratum("OTJ");
                rolefileSmapGenerator.generate();
            }

            List actualStrata = rolefileSmapGenerator.getStrata();

            assertEquals("Strata of type \"" + typeName + "\" should be equal.\n",
                    expectedStrata.get(typeName).toString(), actualStrata.toString());
        }
    }
}

From source file:org.nabucco.framework.mda.model.java.JavaModelLoader.java

License:Open Source License

/**
 * Starts the basic compilation process. Fills the scopes of the java AST nodes.
 * /*from   w w  w .  ja v  a  2s.c o m*/
 * @param result
 *            the compilation result for compilation errors
 * @param parser
 *            the parser
 * @param unit
 *            the compilation unit to compile
 */
private void compile(CompilationResult result, Parser parser, CompilationUnitDeclaration unit) {
    try {

        LookupEnvironment environment = JavaModelSupport.createLookupEnvironment(unit, this.compilerOptions);

        this.beginCompile(environment, result, unit);
        this.process(environment, parser, unit);

    } catch (AbortCompilation e) {
        StringBuilder msg = new StringBuilder();
        msg.append("Skip compilation for ");
        msg.append(unit.getMainTypeName());
        msg.append(". ");
        msg.append(e.problem);
        logger.debug(msg.toString());
    }
}