Java Code Examples for org.eclipse.jdt.internal.compiler.classfmt.ClassFileReader#read()
The following examples show how to use
org.eclipse.jdt.internal.compiler.classfmt.ClassFileReader#read() .
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: InMemoryJavaCompiler.java From xtext-extras with Eclipse Public License 2.0 | 6 votes |
@Override public NameEnvironmentAnswer findType(final char[][] compoundTypeName) { try { final Function1<char[], String> _function = (char[] it) -> { return String.valueOf(it); }; String _join = IterableExtensions.join(ListExtensions.<char[], String>map(((List<char[]>)Conversions.doWrapArray(compoundTypeName)), _function), "/"); final String fileName = (_join + ".class"); boolean _containsKey = this.cache.containsKey(fileName); if (_containsKey) { return this.cache.get(fileName); } final URL url = this.classLoader.getResource(fileName); if ((url == null)) { this.cache.put(fileName, null); return null; } final ClassFileReader reader = ClassFileReader.read(url.openStream(), fileName); final NameEnvironmentAnswer result = new NameEnvironmentAnswer(reader, null); this.cache.put(fileName, result); return result; } catch (Throwable _e) { throw Exceptions.sneakyThrow(_e); } }
Example 2
Source File: InMemoryJavaCompiler.java From xtext-eclipse with Eclipse Public License 2.0 | 6 votes |
@Override public NameEnvironmentAnswer findType(final char[][] compoundTypeName) { try { final Function1<char[], String> _function = (char[] it) -> { return String.valueOf(it); }; String _join = IterableExtensions.join(ListExtensions.<char[], String>map(((List<char[]>)Conversions.doWrapArray(compoundTypeName)), _function), "/"); final String fileName = (_join + ".class"); boolean _containsKey = this.cache.containsKey(fileName); if (_containsKey) { return this.cache.get(fileName); } final URL url = this.classLoader.getResource(fileName); if ((url == null)) { this.cache.put(fileName, null); return null; } final ClassFileReader reader = ClassFileReader.read(url.openStream(), fileName); final NameEnvironmentAnswer result = new NameEnvironmentAnswer(reader, null); this.cache.put(fileName, result); return result; } catch (Throwable _e) { throw Exceptions.sneakyThrow(_e); } }
Example 3
Source File: AbstractSisuIndexMojo.java From takari-lifecycle with Eclipse Public License 1.0 | 6 votes |
Map<String, String> gleanNamedType(File classfile) throws IOException { // use jdt class reader to avoid extra runtime dependency, otherwise could use asm try { ClassFileReader type = ClassFileReader.read(classfile); IBinaryAnnotation[] annotations = type.getAnnotations(); if (annotations != null) { for (IBinaryAnnotation annotation : annotations) { if ("Ljavax/inject/Named;".equals(new String(annotation.getTypeName()))) { return Collections.singletonMap(new String(type.getName()).replace('/', '.'), null); } } } } catch (ClassFormatException e) { // silently ignore classes we can't read/parse } return null; }
Example 4
Source File: InMemoryJavaCompiler.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
@Override public NameEnvironmentAnswer findType(final char[] typeName, final char[][] packageName) { try { final Function1<char[], String> _function = (char[] it) -> { return String.valueOf(it); }; String _join = IterableExtensions.join(ListExtensions.<char[], String>map(((List<char[]>)Conversions.doWrapArray(packageName)), _function), "/"); String _plus = (_join + "/"); String _valueOf = String.valueOf(typeName); String _plus_1 = (_plus + _valueOf); final String fileName = (_plus_1 + ".class"); boolean _containsKey = this.cache.containsKey(fileName); if (_containsKey) { return this.cache.get(fileName); } final URL url = this.classLoader.getResource(fileName); if ((url == null)) { this.cache.put(fileName, null); return null; } final ClassFileReader reader = ClassFileReader.read(url.openStream(), fileName); final NameEnvironmentAnswer result = new NameEnvironmentAnswer(reader, null); this.cache.put(fileName, result); return result; } catch (Throwable _e) { throw Exceptions.sneakyThrow(_e); } }
Example 5
Source File: InMemoryJavaCompiler.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
@Override public NameEnvironmentAnswer findType(final char[] typeName, final char[][] packageName) { try { final Function1<char[], String> _function = (char[] it) -> { return String.valueOf(it); }; String _join = IterableExtensions.join(ListExtensions.<char[], String>map(((List<char[]>)Conversions.doWrapArray(packageName)), _function), "/"); String _plus = (_join + "/"); String _valueOf = String.valueOf(typeName); String _plus_1 = (_plus + _valueOf); final String fileName = (_plus_1 + ".class"); boolean _containsKey = this.cache.containsKey(fileName); if (_containsKey) { return this.cache.get(fileName); } final URL url = this.classLoader.getResource(fileName); if ((url == null)) { this.cache.put(fileName, null); return null; } final ClassFileReader reader = ClassFileReader.read(url.openStream(), fileName); final NameEnvironmentAnswer result = new NameEnvironmentAnswer(reader, null); this.cache.put(fileName, result); return result; } catch (Throwable _e) { throw Exceptions.sneakyThrow(_e); } }
Example 6
Source File: Util.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
public static ClassFileReader newClassFileReader(IResource resource) throws CoreException, ClassFormatException, IOException { InputStream in = null; try { in = ((IFile) resource).getContents(true); return ClassFileReader.read(in, resource.getFullPath().toString()); } finally { if (in != null) in.close(); } }
Example 7
Source File: ClasspathJar.java From takari-lifecycle with Eclipse Public License 1.0 | 5 votes |
@Override public NameEnvironmentAnswer findType(String packageName, String typeName, AccessRestriction accessRestriction) { try { String qualifiedFileName = packageName + "/" + typeName + SUFFIX_STRING_class; ClassFileReader reader = ClassFileReader.read(this.zipFile, qualifiedFileName); if (reader != null) { return new NameEnvironmentAnswer(reader, accessRestriction); } } catch (ClassFormatException | IOException e) { // treat as if class file is missing } return null; }
Example 8
Source File: ClasspathDirectory.java From takari-lifecycle with Eclipse Public License 1.0 | 5 votes |
@Override public NameEnvironmentAnswer findType(String packageName, String typeName, AccessRestriction accessRestriction) { try { Path classFile = getFile(packageName, typeName); if (classFile != null) { try (InputStream is = Files.newInputStream(classFile)) { return new NameEnvironmentAnswer(ClassFileReader.read(is, classFile.getFileName().toString(), false), accessRestriction); } } } catch (ClassFormatException | IOException e) { // treat as if type is missing } return null; }