/**
   * 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;
  }
  @SuppressWarnings({"rawtypes", "unchecked"})
  private Map getFields() throws ModelException {

    IField[] fields = type.getFields();
    Map result = new LinkedHashMap();
    for (int i = 0; i < fields.length; i++) {

      IField field = fields[i];

      int flags = field.getFlags();
      if (PHPFlags.isStatic(flags) || PHPFlags.isConstant(flags)) {
        continue;
      }

      String name = field.getElementName().replace("$", "");
      String getter = "get" + name.toLowerCase();
      String setter = "set" + name.toLowerCase();

      List l = new ArrayList(2);
      List<GetterSetterEntry> entries = new ArrayList<GetterSetterEntry>();

      boolean getterExists = false;
      boolean setterExists = false;

      for (IMethod method : type.getMethods()) {
        String methodName = method.getElementName().toLowerCase();
        if (methodName.startsWith("get")) {
          getterExists = methodName.equals(getter);
        } else if (methodName.startsWith("set")) {
          setterExists = methodName.equals(setter);
        }
      }

      if (!getterExists) {
        entries.add(new GetterSetterEntry(field, true));
      }

      if (!setterExists) {
        entries.add(new GetterSetterEntry(field, false));
      }

      if (!getterExists || !setterExists) {
        l.addAll(entries);
      }

      if (!l.isEmpty()) result.put(field, l.toArray(new GetterSetterEntry[l.size()]));
    }

    return result;
  }
    public String getName() {

      if (name != null) return name;

      if (isGetter) {
        return name = String.format("%s()", getIdentifier());
      } else {
        String elemName = field.getElementName();
        String type = getType();
        String param = "";
        if (type != null && type != "") {
          param += type + " ";
        }
        param += elemName;
        return name = String.format("%s(%s)", getIdentifier(), param);
      }
    }
Ejemplo n.º 4
0
 @Deprecated
 protected final String processFieldName(IField field, String token) {
   return field.getElementName();
 }
    public String getRawFieldName() {

      if (raw != null) return raw;

      return raw = field.getElementName().replace("$", "");
    }