Java Aspectj Usage resolveFileName(final String fileName)

Here you can find the source of resolveFileName(final String fileName)

Description

In the repository.xml class the file names of the fixed files are given, whereas cobertura prints the real java class names into the XML file.

License

Open Source License

Parameter

Parameter Description
fileName a parameter

Return

corresponding class name of the file name

Declaration

public static String resolveFileName(final String fileName) 

Method Source Code

//package com.java2s;
/*/*  w w w .j  a  v  a2s .  c  o  m*/
 * This file is part of the "STARDUST" project.
 *
 * (c) Fabian Keller <hello@fabian-keller.de>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

public class Main {
    /**
     * In the repository.xml class the file names of the fixed files are given,
     * whereas cobertura prints the real java
     * class names into the XML file. This method converts the file path into
     * its corresponding class name.
     * 
     * @param fileName
     * @return corresponding class name of the file name
     */
    public static String resolveFileName(final String fileName) {
        // remove prefix
        final String[] prefixes = new String[] {
                "org.aspectj/modules/weaver/src/",
                "org.aspectj/modules/org.aspectj.ajdt.core/src/",
                "org.aspectj/modules/tests/src/", };
        String file = null;
        for (final String prefix : prefixes) {
            if (fileName.startsWith(prefix)) {
                file = fileName.substring(prefix.length());
            }
        }
        if (file == null && fileName.startsWith("org/aspectj/")) {
            file = fileName;
        }
        if (file == null) {
            throw new RuntimeException(
                    "Filename cannot be resolved to a class name: "
                            + fileName);
        }

        // remove file ending .java
        if (!file.endsWith(".java")) {
            throw new RuntimeException(
                    "Expected filename to resolve to end with .java, but found: "
                            + fileName);
        }
        file = file.substring(0, file.length() - 5);

        // transform dashes to dots
        return file.replace("/", ".");
    }
}

Related

  1. proceedAroundCallAtAspectJ(JoinPoint thisJoinPoint)
  2. process(ProceedingJoinPoint point, Object[] args)
  3. readAjAttributes(String classname, Attribute[] as, ISourceContext context, World w, AjAttribute.WeaverVersionInfo version, ConstantPoolReader dataDecompressor)
  4. renderArgs(JoinPoint jp)
  5. renderJoinPoint(JoinPoint jp)
  6. setSourceLine(InstructionHandle ih, int lineNumber)
  7. strip(String[] src, String[] toStrip)
  8. type(final JoinPoint joinPoint)
  9. typeName(final JoinPoint joinPoint)