private String getValue(QualifiedName name, ASTNode astNode, final JstType jstType) { TranslateInfo tInfo = TranslateCtx.ctx().getTranslateInfo(jstType); String typeName = name.getQualifier().getFullyQualifiedName(); String fullName = tInfo.getImported(typeName); try { Class<?> toClass = Class.forName(fullName); Field field = toClass.getField(name.getName().toString()); return (String) field.get(toClass); } catch (SecurityException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (NoSuchFieldException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (ClassNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IllegalArgumentException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IllegalAccessException e) { // TODO Auto-generated catch block e.printStackTrace(); } return null; }
/* * @see ASTVisitor#visit(QualifiedName) */ @Override public boolean visit(QualifiedName node) { node.getQualifier().accept(this); this.fBuffer.append("."); // $NON-NLS-1$ node.getName().accept(this); return false; }
/* * Must be one of: * <ul> * <li>[result].length</li> * </ul> */ private boolean validateLengthQuery(Expression lengthQuery) { if (lengthQuery instanceof QualifiedName) { QualifiedName qualifiedName = (QualifiedName) lengthQuery; SimpleName name = qualifiedName.getName(); if (!LENGTH_QUERY.equals(name.getIdentifier())) return false; Name arrayAccess = qualifiedName.getQualifier(); ITypeBinding accessType = arrayAccess.resolveTypeBinding(); if (accessType == null) return false; if (!accessType.isArray()) return false; IBinding arrayBinding = arrayAccess.resolveBinding(); if (arrayBinding == null) return false; fArrayBinding = arrayBinding; fArrayAccess = arrayAccess; return true; } else if (lengthQuery instanceof FieldAccess) { FieldAccess fieldAccess = (FieldAccess) lengthQuery; SimpleName name = fieldAccess.getName(); if (!LENGTH_QUERY.equals(name.getIdentifier())) return false; Expression arrayAccess = fieldAccess.getExpression(); ITypeBinding accessType = arrayAccess.resolveTypeBinding(); if (accessType == null) return false; if (!accessType.isArray()) return false; IBinding arrayBinding = getBinding(arrayAccess); if (arrayBinding == null) return false; fArrayBinding = arrayBinding; fArrayAccess = arrayAccess; return true; } return false; }