类javax.annotation.processing.FilerException源码实例Demo

下面列出了怎么用javax.annotation.processing.FilerException的API类实例代码及写法,或者点击链接到github查看源代码。

@Override
public FileObject getResource(Location location, CharSequence pkg,
		CharSequence relativeName) throws IOException {
	validateName(relativeName);
	FileObject fo = _fileManager.getFileForInput(
			location, pkg.toString(), relativeName.toString());
	if (fo == null) {
		throw new FileNotFoundException("Resource does not exist : " + location + '/' + pkg + '/' + relativeName); //$NON-NLS-1$
	}
	URI uri = fo.toUri();
	if (_createdFiles.contains(uri)) {
		throw new FilerException("Resource already created : " + location + '/' + pkg + '/' + relativeName); //$NON-NLS-1$
	}

	_createdFiles.add(uri);
	return fo;
}
 
源代码2 项目: takari-lifecycle   文件: FilerImpl.java
@Override
public JavaFileObject createSourceFile(CharSequence name, Element... originatingElements) throws IOException {
  JavaFileObject sourceFile = fileManager.getJavaFileForOutput(StandardLocation.SOURCE_OUTPUT, name.toString(), JavaFileObject.Kind.SOURCE, null);
  if (!createdResources.add(sourceFile.toUri())) {
    throw new FilerException("Attempt to recreate file for type " + name);
  }
  return new JavaFileObjectImpl(sourceFile, new FileObjectDelegate() {

    private boolean closed = false;

    @Override
    protected void onClose(Output<File> generatedSource) {
      if (!closed) {
        closed = true;
        // TODO optimize if the regenerated sources didn't change compared the previous build
        CompilationUnit unit = new CompilationUnit(null, generatedSource.getResource().getAbsolutePath(), null /* encoding */);
        processingEnv.addNewUnit(unit);
        incrementalCompiler.addGeneratedSource(generatedSource);
      }
    }
  });
}
 
源代码3 项目: takari-lifecycle   文件: FilerImplTest.java
@Test
public void testRecreateSourceFile() throws Exception {
  EclipseFileManager fileManager = new EclipseFileManager(null, Charsets.UTF_8);

  File outputDir = temp.newFolder();
  fileManager.setLocation(StandardLocation.SOURCE_OUTPUT, Collections.singleton(outputDir));

  FilerImpl filer = new FilerImpl(null /* context */, fileManager, null /* compiler */, null /* env */);

  filer.createSourceFile("test.Source");
  try {
    filer.createSourceFile("test.Source");
    Assert.fail();
  } catch (FilerException expected) {
    // From Filer javadoc:
    // @throws FilerException if the same pathname has already been
    // created, the same type has already been created, or the name is
    // not valid for a type
  }
}
 
源代码4 项目: java-n-IDE-for-Android   文件: JavacFiler.java
private void checkName(String name, boolean allowUnnamedPackageInfo) throws FilerException {
    if (!SourceVersion.isName(name) && !isPackageInfo(name, allowUnnamedPackageInfo)) {
        if (lint)
            log.warning("proc.illegal.file.name", name);
        throw new FilerException("Illegal name " + name);
    }
}
 
源代码5 项目: java-n-IDE-for-Android   文件: JavacFiler.java
private void checkNameAndExistence(String typename, boolean allowUnnamedPackageInfo) throws FilerException {
    // TODO: Check if type already exists on source or class path?
    // If so, use warning message key proc.type.already.exists
    checkName(typename, allowUnnamedPackageInfo);
    if (aggregateGeneratedSourceNames.contains(typename) ||
        aggregateGeneratedClassNames.contains(typename)) {
        if (lint)
            log.warning("proc.type.recreate", typename);
        throw new FilerException("Attempt to recreate a file for type " + typename);
    }
}
 
源代码6 项目: java-n-IDE-for-Android   文件: JavacFiler.java
/**
 * Check to see if the file has already been opened; if so, throw
 * an exception, otherwise add it to the set of files.
 */
private void checkFileReopening(FileObject fileObject, boolean addToHistory) throws FilerException {
    for(FileObject veteran : fileObjectHistory) {
        if (fileManager.isSameFile(veteran, fileObject)) {
            if (lint)
                log.warning("proc.file.reopening", fileObject.getName());
            throw new FilerException("Attempt to reopen a file for path " + fileObject.getName());
        }
    }
    if (addToHistory)
        fileObjectHistory.add(fileObject);
}
 
源代码7 项目: javaide   文件: JavacFiler.java
private void checkName(String name, boolean allowUnnamedPackageInfo) throws FilerException {
    if (!SourceVersion.isName(name) && !isPackageInfo(name, allowUnnamedPackageInfo)) {
        if (lint)
            log.warning("proc.illegal.file.name", name);
        throw new FilerException("Illegal name " + name);
    }
}
 
源代码8 项目: javaide   文件: JavacFiler.java
private void checkNameAndExistence(String typename, boolean allowUnnamedPackageInfo) throws FilerException {
    // TODO: Check if type already exists on source or class path?
    // If so, use warning message key proc.type.already.exists
    checkName(typename, allowUnnamedPackageInfo);
    if (aggregateGeneratedSourceNames.contains(typename) ||
        aggregateGeneratedClassNames.contains(typename)) {
        if (lint)
            log.warning("proc.type.recreate", typename);
        throw new FilerException("Attempt to recreate a file for type " + typename);
    }
}
 
源代码9 项目: javaide   文件: JavacFiler.java
/**
 * Check to see if the file has already been opened; if so, throw
 * an exception, otherwise add it to the set of files.
 */
private void checkFileReopening(FileObject fileObject, boolean addToHistory) throws FilerException {
    for(FileObject veteran : fileObjectHistory) {
        if (fileManager.isSameFile(veteran, fileObject)) {
            if (lint)
                log.warning("proc.file.reopening", fileObject.getName());
            throw new FilerException("Attempt to reopen a file for path " + fileObject.getName());
        }
    }
    if (addToHistory)
        fileObjectHistory.add(fileObject);
}
 
源代码10 项目: openjdk-jdk9   文件: GraphNodeProcessor.java
/**
 * Determines if a given exception is (most likely) caused by
 * <a href="https://bugs.eclipse.org/bugs/show_bug.cgi?id=367599">Bug 367599</a>.
 */
public static boolean isBug367599(Throwable t) {
    if (t instanceof FilerException) {
        for (StackTraceElement ste : t.getStackTrace()) {
            if (ste.toString().contains("org.eclipse.jdt.internal.apt.pluggable.core.filer.IdeFilerImpl.create")) {
                // See: https://bugs.eclipse.org/bugs/show_bug.cgi?id=367599
                return true;
            }
        }
    }
    if (t.getCause() != null) {
        return isBug367599(t.getCause());
    }
    return false;
}
 
源代码11 项目: openjdk-jdk9   文件: ServiceProviderProcessor.java
/**
 * Determines if a given exception is (most likely) caused by
 * <a href="https://bugs.eclipse.org/bugs/show_bug.cgi?id=367599">Bug 367599</a>.
 */
public static boolean isBug367599(Throwable t) {
    if (t instanceof FilerException) {
        for (StackTraceElement ste : t.getStackTrace()) {
            if (ste.toString().contains("org.eclipse.jdt.internal.apt.pluggable.core.filer.IdeFilerImpl.create")) {
                // See: https://bugs.eclipse.org/bugs/show_bug.cgi?id=367599
                return true;
            }
        }
    }
    if (t.getCause() != null) {
        return isBug367599(t.getCause());
    }
    return false;
}
 
源代码12 项目: turbine   文件: TurbineFiler.java
private JavaFileObject create(StandardLocation location, Kind kind, String path)
    throws FilerException {
  checkArgument(location.isOutputLocation());
  if (!seen.add(path)) {
    throw new FilerException("already created " + path);
  }
  TurbineJavaFileObject result = new TurbineJavaFileObject(location, kind, path);
  files.add(result);
  return result;
}
 
源代码13 项目: sundrio   文件: JavaGeneratingProcessor.java
/**
 * Generates a source file from the specified {@link io.sundr.codegen.model.TypeDef}.
 * @param model                     The model of the class to generate.
 * @param resourceName              The template to use.
 * @throws IOException              If it fails to create the source file.
 */
public void generateFromResources(TypeDef model, String resourceName) throws IOException {
    try {
        generateFromResources(model, processingEnv
                .getFiler()
                .createSourceFile(model.getFullyQualifiedName()), resourceName);
    } catch (FilerException e) {
        //TODO: Need to avoid dublicate interfaces here.
    }
}
 
@Override
public JavaFileObject createClassFile(CharSequence name,
		Element... originatingElements) throws IOException {
	JavaFileObject jfo = _fileManager.getJavaFileForOutput(
			StandardLocation.CLASS_OUTPUT, name.toString(), JavaFileObject.Kind.CLASS, null);
	URI uri = jfo.toUri();
	if (_createdFiles.contains(uri)) {
		throw new FilerException("Class file already created : " + name); //$NON-NLS-1$
	}

	_createdFiles.add(uri);
	return new HookedJavaFileObject(jfo, jfo.getName(), name.toString(), this);
}
 
@Override
public FileObject createResource(Location location, CharSequence pkg,
		CharSequence relativeName, Element... originatingElements)
		throws IOException {
	validateName(relativeName);
	FileObject fo = _fileManager.getFileForOutput(
			location, pkg.toString(), relativeName.toString(), null);
	URI uri = fo.toUri();
	if (_createdFiles.contains(uri)) {
		throw new FilerException("Resource already created : " + location + '/' + pkg + '/' + relativeName); //$NON-NLS-1$
	}

	_createdFiles.add(uri);
	return fo;
}
 
@Override
public JavaFileObject createSourceFile(CharSequence name,
		Element... originatingElements) throws IOException {
	JavaFileObject jfo = _fileManager.getJavaFileForOutput(
			StandardLocation.SOURCE_OUTPUT, name.toString(), JavaFileObject.Kind.SOURCE, null);
	URI uri = jfo.toUri();
	if (_createdFiles.contains(uri)) {
		throw new FilerException("Source file already created : " + name); //$NON-NLS-1$
	}

	_createdFiles.add(uri);
	// hook the file object's writers to create compilation unit and add to addedUnits()
	return new HookedJavaFileObject(jfo, jfo.getName(), name.toString(), this);
}
 
源代码17 项目: takari-lifecycle   文件: FilerImpl.java
@Override
public JavaFileObject createClassFile(CharSequence name, Element... originatingElements) throws IOException {
  JavaFileObject classFile = fileManager.getJavaFileForOutput(StandardLocation.CLASS_OUTPUT, name.toString(), JavaFileObject.Kind.CLASS, null);
  if (!createdResources.add(classFile.toUri())) {
    throw new FilerException("Attempt to recreate file for class " + name);
  }
  return new JavaFileObjectImpl(classFile, new FileObjectDelegate() {
    @Override
    protected void onClose(Output<File> generatedClass) {
      // TODO processingEnv.addNewClassFile
      throw new UnsupportedOperationException();
    }
  });
}
 
源代码18 项目: takari-lifecycle   文件: FilerImpl.java
@Override
public FileObject createResource(Location location, CharSequence pkg, CharSequence relativeName, Element... originatingElements) throws IOException {
  FileObject file = fileManager.getFileForOutput(location, pkg.toString(), relativeName.toString(), null);
  if (!createdResources.add(file.toUri())) {
    throw new FilerException("Attempt to recreate file for resource " + pkg + "." + relativeName);
  }
  return new FileObjectImpl(file, new FileObjectDelegate());
}
 
源代码19 项目: takari-lifecycle   文件: FilerImpl.java
@Override
public FileObject getResource(Location location, CharSequence pkg, CharSequence relativeName) throws IOException {
  FileObject file = fileManager.getFileForInput(location, pkg.toString(), relativeName.toString());
  if (file == null) {
    throw new FileNotFoundException("Resource does not exist " + location + '/' + pkg + '/' + relativeName);
  }
  if (createdResources.contains(file.toUri())) {
    throw new FilerException("Resource already created " + pkg + "." + relativeName);
  }
  return file;
}
 
源代码20 项目: java-n-IDE-for-Android   文件: JavacFiler.java
private void checkName(String name) throws FilerException {
    checkName(name, false);
}
 
源代码21 项目: javaide   文件: JavacFiler.java
private void checkName(String name) throws FilerException {
    checkName(name, false);
}
 
 类所在包
 同包方法