public static TypeTag typeTag(Type t) { if (t == null) return Javac.CTC_VOID; try { return new TypeTag(getFieldCached(FIELD_CACHE, t, "tag")); } catch (NoSuchFieldException e) { if (TYPE_TYPETAG_METHOD == null) throw new IllegalStateException("Type " + t.getClass() + " has neither 'tag' nor getTag()"); try { return new TypeTag(TYPE_TYPETAG_METHOD.invoke(t)); } catch (IllegalAccessException ex) { throw Javac.sneakyThrow(ex); } catch (InvocationTargetException ex) { throw Javac.sneakyThrow(ex.getCause()); } } }
public static Type createVoidType(Symtab symbolTable, TypeTag tag) { if (symtabVoidType != null) try { return (Type) symtabVoidType.get(symbolTable); } catch (IllegalAccessException ignore) {} if (Javac.getJavaCompilerVersion() < 8) { return new JCNoType(((Integer) tag.value).intValue()); } else { try { if (CTC_VOID.equals(tag)) { return (Type) JC_VOID_TYPE.newInstance(); } else { return (Type) JC_NO_TYPE.newInstance(); } } catch (IllegalAccessException e) { throw sneakyThrow(e); } catch (InstantiationException e) { throw sneakyThrow(e); } } }
@Override public JCTree visitVariable(VariableTree node, Void p) { JCVariableDecl original = node instanceof JCVariableDecl ? (JCVariableDecl) node : null; JCVariableDecl copy = (JCVariableDecl) super.visitVariable(node, p); if (original == null) return copy; copy.sym = original.sym; if (copy.sym != null) copy.type = original.type; if (copy.type != null) { boolean wipeSymAndType = copy.type.isErroneous(); if (!wipeSymAndType) { TypeTag typeTag = TypeTag.typeTag(copy.type); wipeSymAndType = (CTC_NONE.equals(typeTag) || CTC_ERROR.equals(typeTag) || CTC_UNKNOWN.equals(typeTag) || CTC_UNDETVAR.equals(typeTag)); } if (wipeSymAndType) { copy.sym = null; copy.type = null; } } return copy; }
public static TypeTag typeTag(String identifier) { return new TypeTag(getFieldCached(TYPE_TAG_CACHE, Javac.getJavaCompilerVersion() < 8 ? "com.sun.tools.javac.code.TypeTags" : "com.sun.tools.javac.code.TypeTag", identifier)); } }
public static TypeTag typeTag(JCTree o) { try { return new TypeTag(getFieldCached(FIELD_CACHE, o, "typetag")); } catch (NoSuchFieldException e) { throw Javac.sneakyThrow(e); } }