コード例 #1
0
  /**
   * Get Item from {@link IField} <br>
   * DLTK Model => AST
   */
  public static Item getItem(IField field) {
    IModelElement parent = field.getParent();
    if (parent instanceof IType) {
      RecordTypeDef typeDef = (RecordTypeDef) getTypeDef((IType) parent);
      return typeDef.getFields().get(field.getElementName());
    } else if (parent instanceof ISourceModule) {
      LuaSourceRoot luaSourceRoot = getLuaSourceRoot((ISourceModule) parent);
      try {
        if (Flags.isPrivate(field.getFlags())) {
          List<LocalVar> localVars = luaSourceRoot.getInternalContent().getContent().getLocalVars();
          for (LocalVar localVar : localVars) {
            if (localVar.getVar().getName().equals(field.getElementName()))
              return localVar.getVar();
          }
        } else {

          return luaSourceRoot.getFileapi().getGlobalvars().get(field.getElementName());
        }
      } catch (ModelException e) {
        Activator.logError("unable to get item from field " + field, e); // $NON-NLS-1$
        return null;
      }
    }
    return null;
  }