Java Code Examples for javax.tools.JavaFileObject#getName()

The following examples show how to use javax.tools.JavaFileObject#getName() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: EclipseFileManager.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public String inferBinaryName(Location location, JavaFileObject file) {
	String name = file.getName();
	JavaFileObject javaFileObject = null;
	int index = name.lastIndexOf('.');
	if (index != -1) {
		name = name.substring(0, index);
	}
	try {
		javaFileObject = getJavaFileForInput(location, name, file.getKind());
	} catch (IOException e) {
		// ignore
	} catch (IllegalArgumentException iae) {
		return null; // Either unknown kind or location not present
	}
	if (javaFileObject == null) {
		return null;
	}
	return normalized(name);
}
 
Example 2
Source File: JdkCompiler.java    From jprotobuf with Apache License 2.0 5 votes vote down vote up
@Override
public String inferBinaryName(Location loc, JavaFileObject file) {
    if (file instanceof JavaFileObjectImpl) {
        return file.getName();
    }
    return super.inferBinaryName(loc, file);
}
 
Example 3
Source File: T6411310.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
void test(String... args) throws IOException {
    JavaFileObject file = fm.getJavaFileForInput(PLATFORM_CLASS_PATH,
                                                 "java.lang.Object",
                                                 CLASS);
    String fileName = file.getName();
    if (!fileName.matches(".*java/lang/Object.class\\)?")) {
        System.err.println(fileName);
        throw new AssertionError(file);
    }
}
 
Example 4
Source File: ReflectionTest.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
private static void printTestSrc(Iterable<? extends JavaFileObject> files) {
    for (JavaFileObject f : files) {
        System.out.println("Test file " + f.getName() + ":");
        try {
            System.out.println("" + f.getCharContent(true));
        } catch (IOException e) {
            throw new RuntimeException(
                    "Exception when printing test src contents for class " +
                            f.getName(), e);
        }
    }

}
 
Example 5
Source File: ElementUtil.java    From j2objc with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the source file name for a type element. Returns null if the element
 * isn't a javac ClassSymbol, or if it is defined by a classfile which was compiled
 * without a source attribute.
 */
public static String getSourceFile(TypeElement type) {
  if (type instanceof ClassSymbol) {
    JavaFileObject srcFile = ((ClassSymbol) type).sourcefile;
    if (srcFile != null) {
      return srcFile.getName();
    }
  }
  return null;
}
 
Example 6
Source File: AbstractDiagnosticFormatter.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
public String formatSource(JCDiagnostic d, boolean fullname, Locale l) {
    JavaFileObject fo = d.getSource();
    if (fo == null)
        throw new IllegalArgumentException(); // d should have source set
    if (fullname)
        return fo.getName();
    else if (fo instanceof BaseFileObject)
        return ((BaseFileObject) fo).getShortName();
    else
        return BaseFileObject.getSimpleName(fo);
}
 
Example 7
Source File: AbstractDiagnosticFormatter.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
public String formatSource(JCDiagnostic d, boolean fullname, Locale l) {
    JavaFileObject fo = d.getSource();
    if (fo == null)
        throw new IllegalArgumentException(); // d should have source set
    if (fullname)
        return fo.getName();
    else if (fo instanceof BaseFileObject)
        return ((BaseFileObject) fo).getShortName();
    else
        return BaseFileObject.getSimpleName(fo);
}
 
Example 8
Source File: EclipseCompilerImpl.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public CompilationUnit[] getCompilationUnits() {
	if (this.compilationUnits == null) return EclipseCompilerImpl.NO_UNITS;
	ArrayList<CompilationUnit> units = new ArrayList<CompilationUnit>();
	for (final JavaFileObject javaFileObject : this.compilationUnits) {
		if (javaFileObject.getKind() != JavaFileObject.Kind.SOURCE) {
			throw new IllegalArgumentException();
		}
		String name = javaFileObject.getName();
		name = name.replace('\\', '/');
		CompilationUnit compilationUnit = new CompilationUnit(null,
			name,
			null) {

			@Override
			public char[] getContents() {
				try {
					return javaFileObject.getCharContent(true).toString().toCharArray();
				} catch(IOException e) {
					e.printStackTrace();
					throw new AbortCompilationUnit(null, e, null);
				}
			}
		};
		units.add(compilationUnit);
		this.javaFileObjectMap.put(compilationUnit, javaFileObject);
	}
	CompilationUnit[] result = new CompilationUnit[units.size()];
	units.toArray(result);
	return result;
}
 
Example 9
Source File: ReflectionTest.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
private static void printTestSrc(Iterable<? extends JavaFileObject> files) {
    for (JavaFileObject f : files) {
        System.out.println("Test file " + f.getName() + ":");
        try {
            System.out.println("" + f.getCharContent(true));
        } catch (IOException e) {
            throw new RuntimeException(
                    "Exception when printing test src contents for class " +
                            f.getName(), e);
        }
    }

}
 
Example 10
Source File: T6411310.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
void test(String... args) throws IOException {
    JavaFileObject file = fm.getJavaFileForInput(PLATFORM_CLASS_PATH,
                                                 "java.lang.Object",
                                                 CLASS);
    String fileName = file.getName();
    if (!fileName.matches(".*java/lang/Object.class\\)?")) {
        System.err.println(fileName);
        throw new AssertionError(file);
    }
}
 
Example 11
Source File: ReflectionTest.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
private static void printTestSrc(Iterable<? extends JavaFileObject> files) {
    for (JavaFileObject f : files) {
        System.out.println("Test file " + f.getName() + ":");
        try {
            System.out.println("" + f.getCharContent(true));
        } catch (IOException e) {
            throw new RuntimeException(
                    "Exception when printing test src contents for class " +
                            f.getName(), e);
        }
    }

}
 
Example 12
Source File: DynamicJavaFileManager.java    From oxygen with Apache License 2.0 5 votes vote down vote up
@Override
public String inferBinaryName(Location location, JavaFileObject file) {
  if (file instanceof ByteCode || file instanceof SourceCode) {
    return file.getName();
  }
  return super.inferBinaryName(location, file);
}
 
Example 13
Source File: Diagnostics.java    From FreeBuilder with Apache License 2.0 5 votes vote down vote up
/**
 * Appends a human-readable form of {@code diagnostic} to {@code appendable}.
 */
public static void appendTo(
    StringBuilder appendable,
    Diagnostic<? extends JavaFileObject> diagnostic,
    int indentLevel) {
  String indent = "\n" + Strings.repeat(" ", indentLevel);
  appendable.append(diagnostic.getMessage(Locale.getDefault()).replace("\n", indent));
  JavaFileObject source = diagnostic.getSource();
  long line = diagnostic.getLineNumber();
  if (source != null && line != Diagnostic.NOPOS) {
    File sourceFile = new File(source.getName());
    appendable.append(" (").append(sourceFile.getName()).append(":").append(line).append(")");
  }
}
 
Example 14
Source File: AbstractDiagnosticFormatter.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
public String formatSource(JCDiagnostic d, boolean fullname, Locale l) {
    JavaFileObject fo = d.getSource();
    if (fo == null)
        throw new IllegalArgumentException(); // d should have source set
    if (fullname)
        return fo.getName();
    else if (fo instanceof BaseFileObject)
        return ((BaseFileObject) fo).getShortName();
    else
        return BaseFileObject.getSimpleName(fo);
}
 
Example 15
Source File: ReflectionTest.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
private static void printTestSrc(Iterable<? extends JavaFileObject> files) {
    for (JavaFileObject f : files) {
        System.out.println("Test file " + f.getName() + ":");
        try {
            System.out.println("" + f.getCharContent(true));
        } catch (IOException e) {
            throw new RuntimeException(
                    "Exception when printing test src contents for class " +
                            f.getName(), e);
        }
    }

}
 
Example 16
Source File: T6411310.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
void test(String... args) throws IOException {
    JavaFileObject file = fm.getJavaFileForInput(PLATFORM_CLASS_PATH,
                                                 "java.lang.Object",
                                                 CLASS);
    String fileName = file.getName();
    if (!fileName.matches(".*java/lang/Object.class\\)?")) {
        System.err.println(fileName);
        throw new AssertionError(file);
    }
}
 
Example 17
Source File: CharSequenceCompiler.java    From openbd-core with GNU General Public License v3.0 5 votes vote down vote up
@Override
public String inferBinaryName(Location loc, JavaFileObject file) {
	String result;
	// For our JavaFileImpl instances, return the file's name, else
	// simply run the default implementation
	if (file instanceof JavaFileObjectImpl)
		result = file.getName();
	else
		result = super.inferBinaryName(loc, file);
	return result;
}
 
Example 18
Source File: AbstractDiagnosticFormatter.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public String formatSource(JCDiagnostic d, boolean fullname, Locale l) {
    JavaFileObject fo = d.getSource();
    if (fo == null)
        throw new IllegalArgumentException(); // d should have source set
    if (fullname)
        return fo.getName();
    else if (fo instanceof PathFileObject)
        return ((PathFileObject) fo).getShortName();
    else
        return PathFileObject.getSimpleName(fo);
}
 
Example 19
Source File: T6411310.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
void test(String... args) throws IOException {
    JavaFileObject file = fm.getJavaFileForInput(PLATFORM_CLASS_PATH,
                                                 "java.lang.Object",
                                                 CLASS);
    String fileName = file.getName();
    if (!fileName.matches(".*java/lang/Object.class\\)?")) {
        System.err.println(fileName);
        throw new AssertionError(file);
    }
}
 
Example 20
Source File: JdkCompiler.java    From jprotobuf with Apache License 2.0 5 votes vote down vote up
@Override
public String inferBinaryName(Location loc, JavaFileObject file) {
    if (file instanceof JavaFileObjectImpl) {
        return file.getName();
    }
    return super.inferBinaryName(loc, file);
}