use of com.sun.tools.javac.code.Type.ArrayType in project lombok by rzwitserloot.
the class JavacResolution method typeToJCTree.
private static JCExpression typeToJCTree(Type type, JavacAST ast, boolean allowCompound, boolean allowVoid) throws TypeNotConvertibleException {
int dims = 0;
Type type0 = type;
while (type0 instanceof ArrayType) {
dims++;
type0 = ((ArrayType) type0).elemtype;
}
JCExpression result = typeToJCTree0(type0, ast, allowCompound, allowVoid);
while (dims > 0) {
result = ast.getTreeMaker().TypeArray(result);
dims--;
}
return result;
}
use of com.sun.tools.javac.code.Type.ArrayType in project checker-framework by typetools.
the class AnnotationConverter method getAnnotationFieldType.
/**
* Returns an AnnotationFieldType given an ExecutableElement or value.
*/
protected static AnnotationFieldType getAnnotationFieldType(ExecutableElement ee, Object value) {
if (value instanceof List<?>) {
AnnotationValue defaultValue = ee.getDefaultValue();
if (defaultValue == null || ((ArrayType) ((Array) defaultValue).type) == null) {
List<?> listV = (List<?>) value;
if (!listV.isEmpty()) {
ScalarAFT scalarAFT = (ScalarAFT) getAnnotationFieldType(ee, ((AnnotationValue) listV.get(0)).getValue());
if (scalarAFT != null) {
return new ArrayAFT(scalarAFT);
}
}
return null;
}
Type elemType = ((ArrayType) ((Array) defaultValue).type).elemtype;
try {
return new ArrayAFT(BasicAFT.forType(Class.forName(elemType.toString())));
} catch (ClassNotFoundException e) {
ErrorReporter.errorAbort(e.getMessage());
}
} else if (value instanceof Boolean) {
return BasicAFT.forType(boolean.class);
} else if (value instanceof Character) {
return BasicAFT.forType(char.class);
} else if (value instanceof Double) {
return BasicAFT.forType(double.class);
} else if (value instanceof Float) {
return BasicAFT.forType(float.class);
} else if (value instanceof Integer) {
return BasicAFT.forType(int.class);
} else if (value instanceof Long) {
return BasicAFT.forType(long.class);
} else if (value instanceof Short) {
return BasicAFT.forType(short.class);
} else if (value instanceof String) {
return BasicAFT.forType(String.class);
}
return null;
}
use of com.sun.tools.javac.code.Type.ArrayType in project checker-framework by typetools.
the class FlowExpressionParseUtil method parseArray.
private static Receiver parseArray(String s, FlowExpressionContext context, TreePath path) throws FlowExpressionParseException {
Pair<Pair<String, String>, String> array = parseArray(s);
if (array == null) {
return null;
}
String receiverStr = array.first.first;
String indexStr = array.first.second;
Receiver receiver = parseHelper(receiverStr, context, path);
FlowExpressionContext contextForIndex = context.copyAndUseOuterReceiver();
Receiver index = parseHelper(indexStr, contextForIndex, path);
TypeMirror receiverType = receiver.getType();
if (!(receiverType instanceof ArrayType)) {
throw constructParserException(s, String.format("receiver not an array: %s : %s", receiver, receiverType));
}
TypeMirror componentType = ((ArrayType) receiverType).getComponentType();
ArrayAccess result = new ArrayAccess(componentType, receiver, index);
return result;
}
use of com.sun.tools.javac.code.Type.ArrayType in project st-js by st-js.
the class NewArrayWriter method elementType.
private static Type elementType(NewArrayTree tree) {
try {
Field field = tree.getClass().getField("type");
Type elementType = (Type) field.get(tree);
while (elementType instanceof ArrayType) {
Type.ArrayType atype = (Type.ArrayType) elementType;
elementType = atype.elemtype;
}
return elementType;
} catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException e) {
return null;
}
}
use of com.sun.tools.javac.code.Type.ArrayType in project ceylon-compiler by ceylon.
the class Attr method visitSelect.
public void visitSelect(JCFieldAccess tree) {
// Determine the expected kind of the qualifier expression.
int skind = 0;
if (tree.name == names._this || tree.name == names._super || tree.name == names._class) {
skind = TYP;
} else {
if ((pkind & PCK) != 0)
skind = skind | PCK;
if ((pkind & TYP) != 0)
skind = skind | TYP | PCK;
if ((pkind & (VAL | MTH)) != 0)
skind = skind | VAL | TYP;
}
// Attribute the qualifier expression, and determine its symbol (if any).
Type site = attribTree(tree.selected, env, skind, Infer.anyPoly);
if ((pkind & (PCK | TYP)) == 0)
// Capture field access
site = capture(site);
// don't allow T.class T[].class, etc
if (skind == TYP) {
Type elt = site;
while (elt.tag == ARRAY) elt = ((ArrayType) elt).elemtype;
if (elt.tag == TYPEVAR) {
log.error(tree.pos(), "type.var.cant.be.deref");
result = types.createErrorType(tree.type);
return;
}
}
// If qualifier symbol is a type or `super', assert `selectSuper'
// for the selection. This is relevant for determining whether
// protected symbols are accessible.
Symbol sitesym = TreeInfo.symbol(tree.selected);
boolean selectSuperPrev = env.info.selectSuper;
env.info.selectSuper = sitesym != null && sitesym.name == names._super;
// they can be added later (in Attr.checkId and Infer.instantiateMethod).
if (tree.selected.type.tag == FORALL) {
ForAll pstype = (ForAll) tree.selected.type;
env.info.tvars = pstype.tvars;
site = tree.selected.type = pstype.qtype;
}
// Determine the symbol represented by the selection.
env.info.varArgs = false;
Symbol sym = selectSym(tree, sitesym, site, env, pt, pkind);
if (sym.exists() && !isType(sym) && (pkind & (PCK | TYP)) != 0) {
site = capture(site);
sym = selectSym(tree, sitesym, site, env, pt, pkind);
}
boolean varArgs = env.info.varArgs;
tree.sym = sym;
if (site.tag == TYPEVAR && !isType(sym) && sym.kind != ERR) {
while (site.tag == TYPEVAR) site = site.getUpperBound();
site = capture(site);
}
// If that symbol is a variable, ...
if (sym.kind == VAR) {
VarSymbol v = (VarSymbol) sym;
// ..., evaluate its initializer, if it has one, and check for
// illegal forward reference.
checkInit(tree, env, v, true);
// that the variable is assignable in the current environment.
if (pkind == VAR)
checkAssignable(tree.pos(), v, tree.selected, env);
}
if (sitesym != null && sitesym.kind == VAR && ((VarSymbol) sitesym).isResourceVariable() && sym.kind == MTH && sym.name.equals(names.close) && sym.overrides(syms.autoCloseableClose, sitesym.type.tsym, types, true) && env.info.lint.isEnabled(LintCategory.TRY)) {
log.warning(LintCategory.TRY, tree, "try.explicit.close.call");
}
// Disallow selecting a type from an expression
if (isType(sym) && (sitesym == null || (sitesym.kind & (TYP | PCK)) == 0)) {
tree.type = check(tree.selected, pt, sitesym == null ? VAL : sitesym.kind, TYP | PCK, pt);
}
if (isType(sitesym)) {
if (sym.name == names._this) {
// C.this' does not appear in a call to a super(...)
if (env.info.isSelfCall && site.tsym == env.enclClass.sym) {
chk.earlyRefError(tree.pos(), sym);
}
} else {
// Check if type-qualified fields or methods are static (JLS)
if ((sym.flags() & STATIC) == 0 && sym.name != names._super && (sym.kind == VAR || sym.kind == MTH)) {
rs.access(rs.new StaticError(sym), tree.pos(), site, sym.name, true);
}
}
} else if (sym.kind != ERR && (sym.flags() & STATIC) != 0 && sym.name != names._class) {
// If the qualified item is not a type and the selected item is static, report
// a warning. Make allowance for the class of an array type e.g. Object[].class)
chk.warnStatic(tree, "static.not.qualified.by.type", Kinds.kindName(sym.kind), sym.owner);
}
// If we are selecting an instance member via a `super', ...
if (env.info.selectSuper && (sym.flags() & STATIC) == 0) {
// Check that super-qualified symbols are not abstract (JLS)
rs.checkNonAbstract(tree.pos(), sym);
if (site.isRaw()) {
// Determine argument types for site.
Type site1 = types.asSuper(env.enclClass.sym.type, site.tsym);
if (site1 != null)
site = site1;
}
}
// Ceylon: error if we try to select an interface static in < 1.8
if (sym != null && sym.isStatic() && (sym.kind & Kinds.MTH) != 0 && sitesym != null && sitesym.isInterface()) {
chk.checkStaticInterfaceMethodCall(tree);
}
env.info.selectSuper = selectSuperPrev;
result = checkId(tree, site, sym, env, pkind, pt, varArgs);
env.info.tvars = List.nil();
}
Aggregations