List of usage examples for org.eclipse.jdt.internal.compiler.classfmt ClassFileReader read
public static ClassFileReader read(String fileName) throws ClassFormatException, java.io.IOException
From source file:io.gige.compiler.internal.HookedJavaFileObject.java
License:Open Source License
protected void closed() { if (!_closed) { _closed = true;/* ww w . ja v a 2s .co m*/ // TODO: support encoding switch (this.getKind()) { case SOURCE: CompilationUnit unit = new CompilationUnit(null, _fileName, null /* encoding */); _filer.addNewUnit(unit); break; case CLASS: IBinaryType binaryType = null; try { binaryType = ClassFileReader.read(_fileName); } catch (ClassFormatException e) { /* * When the annotation processor produces garbage, javac * seems to show some resilience, by hooking the source * type, which since is resolved can answer annotations * during discovery - Not sure if this sanctioned by the * spec, to be taken up with Oracle. Here we mimic the bug, * see that addNewClassFile is simply collecting * ReferenceBinding's, so adding a SourceTypeBinding works * just fine. */ ReferenceBinding type = this._filer._env.getCompiler().lookupEnvironment .getType(CharOperation.splitOn('.', _typeName.toCharArray())); if (type != null) _filer.addNewClassFile(type); } catch (IOException e) { // ignore } if (binaryType != null) { char[] name = binaryType.getName(); ReferenceBinding type = this._filer._env.getCompiler().lookupEnvironment .getType(CharOperation.splitOn('/', name)); if (type != null && type.isValidBinding()) { if (type.isBinaryBinding()) { _filer.addNewClassFile(type); } else { BinaryTypeBinding binaryBinding = new BinaryTypeBinding(type.getPackage(), binaryType, this._filer._env.getCompiler().lookupEnvironment, true); if (binaryBinding != null) _filer.addNewClassFile(binaryBinding); } } } break; case HTML: case OTHER: break; } } }
From source file:io.takari.maven.plugins.compile.jdt.ClasspathDigester.java
License:Open Source License
private Map<String, byte[]> digestDirectory(final File directory) throws IOException { Map<String, byte[]> digest = CACHE.get(directory); if (digest == null) { digest = new HashMap<String, byte[]>(); DirectoryScanner scanner = new DirectoryScanner(); scanner.setBasedir(directory);//from w w w . j a va 2 s.c o m scanner.setIncludes(new String[] { "**/*.class" }); scanner.scan(); for (String path : scanner.getIncludedFiles()) { String type = toJavaType(path); try { digest.put(type, digester.digest(ClassFileReader.read(new File(directory, path)))); } catch (ClassFormatException e) { // as far as jdt is concerned, the type does not exist } } CACHE.put(directory, digest); } return digest; }
From source file:org.eclipse.ajdt.internal.core.builder.ClasspathDirectory.java
License:Open Source License
public NameEnvironmentAnswer findClass(String binaryFileName, String qualifiedPackageName, String qualifiedBinaryFileName) { if (!doesFileExist(binaryFileName, qualifiedPackageName)) return null; // most common case try {/*from ww w . j av a2 s . co m*/ ClassFileReader reader = ClassFileReader.read(binaryLocation + qualifiedBinaryFileName); if (reader != null) { if (this.accessRuleSet == null) return new NameEnvironmentAnswer(reader, null); return new NameEnvironmentAnswer(reader, this.accessRuleSet.getViolatedRestriction(qualifiedBinaryFileName.toCharArray())); } } catch (Exception e) { // handle the case when the project is the output folder and the top-level package is a linked folder if (binaryFolder instanceof IProject) { IResource file = binaryFolder.findMember(qualifiedBinaryFileName); if (file instanceof IFile) { IPath location = file.getLocation(); if (location != null) { try { ClassFileReader reader = ClassFileReader.read(location.toString()); if (reader != null) { if (this.accessRuleSet == null) return new NameEnvironmentAnswer(reader, null); return new NameEnvironmentAnswer(reader, this.accessRuleSet .getViolatedRestriction(qualifiedBinaryFileName.toCharArray())); } } catch (Exception ignored) { // treat as if class file is missing } } } } } return null; }
From source file:org.eclipse.objectteams.otdt.internal.core.compiler.model.TypeModel.java
License:Open Source License
public ClassFileReader read() throws IOException, ClassFormatException { if (this._classFilePath != null) { FileNotFoundException fileNotFoundException = null; for (int i = 0; i < 5; i++) { // make <= 5 attempts thus waiting <= 500 ms try { return ClassFileReader.read(this._classFilePath); // not recording attributes } catch (FileNotFoundException ex) { fileNotFoundException = ex; try { Thread.sleep(100); } catch (InterruptedException e) { e.printStackTrace(); }/* www . j a v a 2 s. c o m*/ } } if (fileNotFoundException != null) throw fileNotFoundException; } return null; }
From source file:org.springframework.ide.eclipse.core.java.TypeStructureCache.java
License:Open Source License
private static ClassFileReader getClassFileReaderForClassName(String className, IProject project) throws JavaModelException, MalformedURLException { IJavaProject jp = JavaCore.create(project); File outputDirectory = convertPathToFile(project, jp.getOutputLocation()); File classFile = new File(outputDirectory, ClassUtils.getClassFileName(className)); if (classFile.exists() && classFile.canRead()) { try {/*from w ww.j a va 2 s . co m*/ return ClassFileReader.read(classFile); } catch (ClassFormatException e) { } catch (IOException e) { } } IClasspathEntry[] classpath = jp.getRawClasspath(); for (int i = 0; i < classpath.length; i++) { IClasspathEntry path = classpath[i]; if (path.getEntryKind() == IClasspathEntry.CPE_SOURCE) { outputDirectory = convertPathToFile(project, path.getOutputLocation()); classFile = new File(outputDirectory, ClassUtils.getClassFileName(className)); if (classFile.exists() && classFile.canRead()) { try { return ClassFileReader.read(classFile); } catch (ClassFormatException e) { } catch (IOException e) { } } } } return null; }