Пример #1
0
 public static TypeInfo of(Set<? extends Type> types) {
   TypeInfo typeInfo = create();
   for (Type type : types) {
     typeInfo.add(type);
   }
   return typeInfo;
 }
  /** Updates the folder path to reflect the given type */
  private void updateFolderPath(TypeInfo type) {
    String wsFolderPath = mValues.folderPath;
    String newPath = null;
    FolderConfiguration config = mValues.configuration;
    ResourceQualifier qual = config.getInvalidQualifier();
    if (qual == null) {
      // The configuration is valid. Reformat the folder path using the canonical
      // value from the configuration.
      newPath = RES_FOLDER_ABS + config.getFolderName(type.getResFolderType());
    } else {
      // The configuration is invalid. We still update the path but this time
      // do it manually on the string.
      if (wsFolderPath.startsWith(RES_FOLDER_ABS)) {
        wsFolderPath =
            wsFolderPath.replaceFirst(
                "^(" + RES_FOLDER_ABS + ")[^-]*(.*)", // $NON-NLS-1$ //$NON-NLS-2$
                "\\1" + type.getResFolderName() + "\\2"); // $NON-NLS-1$ //$NON-NLS-2$
      } else {
        newPath = RES_FOLDER_ABS + config.getFolderName(type.getResFolderType());
      }
    }

    if (newPath != null && !newPath.equals(wsFolderPath)) {
      mValues.folderPath = newPath;
    }
  }
  /**
   * Validates the fields, displays errors and warnings. Enables the finish button if there are no
   * errors.
   */
  private void validatePage() {
    String error = null;
    String warning = null;

    // -- validate type
    TypeInfo type = mValues.type;
    if (error == null) {
      if (type == null) {
        error = "One of the types must be selected (e.g. layout, values, etc.)";
      }
    }

    // -- validate project
    if (mValues.project == null) {
      error = "Please select an Android project.";
    }

    // -- validate type API level
    if (error == null) {
      IAndroidTarget target = Sdk.getCurrent().getTarget(mValues.project);
      int currentApiLevel = 1;
      if (target != null) {
        currentApiLevel = target.getVersion().getApiLevel();
      }

      assert type != null;
      if (type.getTargetApiLevel() > currentApiLevel) {
        error =
            "The API level of the selected type (e.g. AppWidget, etc.) is not "
                + "compatible with the API level of the project.";
      }
    }

    // -- validate filename
    if (error == null) {
      String fileName = mValues.getFileName();
      assert type != null;
      ResourceFolderType folderType = type.getResFolderType();
      error = ResourceNameValidator.create(true, folderType).isValid(fileName);
    }

    // -- validate destination file doesn't exist
    if (error == null) {
      IFile file = mValues.getDestinationFile();
      if (file != null && file.exists()) {
        warning = "The destination file already exists";
      }
    }

    // -- update UI & enable finish if there's no error
    setPageComplete(error == null);
    if (error != null) {
      setMessage(error, IMessageProvider.ERROR);
    } else if (warning != null) {
      setMessage(warning, IMessageProvider.WARNING);
    } else {
      setErrorMessage(null);
      setMessage(null);
    }
  }
Пример #4
0
 public Class getClassByAlias(String alias) throws QueryParsingException {
   TypeInfo typeInfo = (TypeInfo) aliasToTypeInfo.get(alias);
   if (typeInfo != null) {
     return typeInfo.getClazz();
   }
   throw new QueryParsingException("Alias{0} not found", new Object[] {alias});
 }
  /** Given a folder name, such as "drawable", select the corresponding type in the dropdown. */
  void selectTypeFromFolder(String folderName) {
    List<TypeInfo> matches = new ArrayList<TypeInfo>();
    boolean selected = false;

    TypeInfo selectedType = getSelectedType();
    for (TypeInfo type : sTypes) {
      if (type.getResFolderName().equals(folderName)) {
        matches.add(type);
        selected |= type == selectedType;
      }
    }

    if (matches.size() == 1) {
      // If there's only one match, select it if it's not already selected
      if (!selected) {
        selectType(matches.get(0));
      }
    } else if (matches.size() > 1) {
      // There are multiple type candidates for this folder. This can happen
      // for /res/xml for example. Check to see if one of them is currently
      // selected. If yes, leave the selection unchanged. If not, deselect all type.
      if (!selected) {
        selectType(null);
      }
    } else {
      // Nothing valid was selected.
      selectType(null);
    }
  }
Пример #6
0
 /**
  * Ensure that a given property is not set as an xml-any-element.
  *
  * @param oldProperty
  * @param tInfo
  */
 private void unsetXmlAnyElement(Property oldProperty, TypeInfo tInfo) {
   oldProperty.setIsAny(false);
   if (tInfo.isSetAnyElementPropertyName()
       && tInfo.getAnyElementPropertyName().equals(oldProperty.getPropertyName())) {
     tInfo.setAnyElementPropertyName(null);
   }
 }
  /**
   * Helper method that fills the values of the "root element" combo box based on the currently
   * selected type radio button. Also disables the combo is there's only one choice. Always select
   * the first root element for the given type.
   *
   * @param type The currently selected {@link TypeInfo}, or null
   */
  private void updateRootCombo(TypeInfo type) {
    IBaseLabelProvider labelProvider =
        new ColumnLabelProvider() {
          @Override
          public Image getImage(Object element) {
            return IconFactory.getInstance().getIcon(element.toString());
          }
        };
    mRootTableViewer.setContentProvider(new ArrayContentProvider());
    mRootTableViewer.setLabelProvider(labelProvider);

    if (type != null) {
      // get the list of roots. The list can be empty but not null.
      ArrayList<String> roots = type.getRoots();
      mRootTableViewer.setInput(roots.toArray());

      int index = 0; // default is to select the first one
      String defaultRoot = type.getDefaultRoot(mValues.project);
      if (defaultRoot != null) {
        index = roots.indexOf(defaultRoot);
      }
      mRootTable.select(index < 0 ? 0 : index);
      mRootTable.showSelection();
    }
  }
Пример #8
0
 /**
  * Ensure that a given property is not set as an xml-value.
  *
  * @param oldProperty
  * @param tInfo
  */
 private void unsetXmlValue(Property oldProperty, TypeInfo tInfo) {
   oldProperty.setIsXmlValue(false);
   if (tInfo.isSetXmlValueProperty()
       && tInfo.getXmlValueProperty().getPropertyName().equals(oldProperty.getPropertyName())) {
     tInfo.setXmlValueProperty(null);
   }
 }
Пример #9
0
  public boolean matchesParams(String[] params, String[] dimensions, boolean varargs) {
    if (mParamStrings == null) {
      if (mParameters.size() != params.length) {
        return false;
      }
      int i = 0;
      for (ParameterInfo mine : mParameters) {
        if (!mine.matchesDimension(dimensions[i], varargs)) {
          return false;
        }
        TypeInfo myType = mine.type();
        String qualifiedName = myType.qualifiedTypeName();
        String realType = myType.isPrimitive() ? "" : myType.asClassInfo().qualifiedName();
        String s = params[i];
        int slen = s.length();
        int qnlen = qualifiedName.length();

        // Check for a matching generic name or best known type
        if (!matchesType(qualifiedName, s) && !matchesType(realType, s)) {
          return false;
        }
        i++;
      }
    }
    return true;
  }
Пример #10
0
 /**
  * Parses a type definition
  *
  * @param type
  * @return
  */
 protected static TypeInfo ParseType(Type type) {
   TypeInfo typeInfo = new TypeInfo();
   typeInfo.qualifiedName = type.qualifiedTypeName();
   typeInfo.dimension = type.dimension();
   typeInfo.wildcard = ParseWildCard(type.asWildcardType());
   typeInfo.generics = ParseGenerics(type.asParameterizedType());
   return typeInfo;
 }
Пример #11
0
 private TypeInfo findTypeInfo(String typeName) {
   for (Iterator it = aliasToTypeInfo.values().iterator(); it.hasNext(); ) {
     TypeInfo typeInfo = (TypeInfo) it.next();
     if (typeInfo.getTypeName().equals(typeName)) {
       return typeInfo;
     }
   }
   return null;
 }
Пример #12
0
 public boolean equals(Object other) {
   if (this == other) return true;
   if (!(other instanceof TypeInfo)) {
     return false;
   }
   TypeInfo o = (TypeInfo) other;
   return o.getCategory().equals(getCategory())
       && o.getPrimitiveClass().equals(getPrimitiveClass());
 }
Пример #13
0
 public TypeInfo typeCheck(TypeEnv tenv) throws TypeException {
   if (tenv.get(0, index) != null)
     throw new TypeException("duplicate variable: " + name(), this);
   varType = TypeInfo.get(type());
   tenv.put(0, index, varType);
   valueType = ((ASTreeTypeEx) initializer()).typeCheck(tenv);
   valueType.assertSubtypeOf(varType, tenv, this);
   return varType;
 }
  /**
   * Returns the {@link TypeInfo} for the given {@link ResourceFolderType}, or null if not found
   *
   * @param folderType the {@link ResourceFolderType} to look for
   * @return the corresponding {@link TypeInfo}
   */
  static TypeInfo getTypeInfo(ResourceFolderType folderType) {
    for (TypeInfo typeInfo : sTypes) {
      if (typeInfo.getResFolderType() == folderType) {
        return typeInfo;
      }
    }

    return null;
  }
Пример #15
0
 public TypeInfo typeCheck(TypeEnv tenv) throws TypeException {
   TypeInfo condType = ((ASTreeTypeEx) condition()).typeCheck(tenv);
   condType.assertSubtypeOf(TypeInfo.INT, tenv, this);
   TypeInfo thenType = ((ASTreeTypeEx) thenBlock()).typeCheck(tenv);
   TypeInfo elseType;
   ASTree elseBk = elseBlock();
   if (elseBk == null) elseType = TypeInfo.INT;
   else elseType = ((ASTreeTypeEx) elseBk).typeCheck(tenv);
   return thenType.union(elseType, tenv);
 }
Пример #16
0
  private static void intersectPropertySets(final List<TypeInfo> reducedTypeInfos) {

    // substract property set from type info with more than one
    // occurrence from type infos with the given superclass
    for (final TypeInfo info : reducedTypeInfos) {

      if (info.getHierarchyLevel() > 1) {

        final Set<String> supertypeKeySet = info.getPropertySet().keySet();

        for (final TypeInfo subType : reducedTypeInfos) {

          final Set<String> subtypeKeySet = subType.getPropertySet().keySet();

          // only substract property set if it is a true subtype (and not the same :))
          //					if ( subType.getUsages() == 1 && subType.hasSuperclass(info.getPrimaryType())) {
          if (subType.getHierarchyLevel() < info.getHierarchyLevel()
              && subType.hasSuperclass(info.getPrimaryType())) {

            subtypeKeySet.removeAll(supertypeKeySet);
          }
        }
      }
    }
  }
Пример #17
0
 /**
  * If name property is not found for the given type, try using the type's parent. If not found
  * using parent's type, try using top-level properties from hq-plugin.xml.
  */
 public String getTypeProperty(TypeInfo type, String name) {
   String value = getTypeProperty(type.getName(), name);
   if (value != null) {
     return value;
   }
   if (type.getType() == TypeInfo.TYPE_SERVICE) {
     ServiceTypeInfo service = (ServiceTypeInfo) type;
     return getTypeProperty(service.getServerName(), name);
   }
   return getPluginProperty(name);
 }
 private void initializeFromFixedType() {
   if (mInitialFolderType != null) {
     for (TypeInfo type : sTypes) {
       if (type.getResFolderType() == mInitialFolderType) {
         mValues.type = type;
         updateFolderPath(type);
         break;
       }
     }
   }
 }
Пример #19
0
    @Override
    public int compare(TypeInfo o1, TypeInfo o2) {

      if (reverse) {

        return Integer.valueOf(o1.getHierarchyLevel()).compareTo(o2.getHierarchyLevel());
      } else {

        return Integer.valueOf(o2.getHierarchyLevel()).compareTo(o1.getHierarchyLevel());
      }
    }
Пример #20
0
 public HashSet<String> typeVariables() {
   HashSet<String> result = TypeInfo.typeVariables(mTypeParameters);
   ClassInfo cl = containingClass();
   while (cl != null) {
     ArrayList<TypeInfo> types = cl.asTypeInfo().typeArguments();
     if (types != null) {
       TypeInfo.typeVariables(types, result);
     }
     cl = cl.containingClass();
   }
   return result;
 }
Пример #21
0
 public TypeInfo typeCheck(TypeEnv tenv) throws TypeException {
   TypeInfo[] params = ((ParamListEx2) parameters()).types();
   TypeInfo retType = TypeInfo.get(type());
   funcType = TypeInfo.function(retType, params);
   TypeInfo oldType = tenv.put(0, index, funcType);
   if (oldType != null) throw new TypeException("function redefinition: " + name(), this);
   bodyEnv = new TypeEnv(size, tenv);
   for (int i = 0; i < params.length; i++) bodyEnv.put(0, i, params[i]);
   TypeInfo bodyType = ((ASTreeTypeEx) revise(body())).typeCheck(bodyEnv);
   bodyType.assertSubtypeOf(retType, tenv, this);
   return funcType;
 }
Пример #22
0
    public TypeInfo typeCheck(TypeEnv tenv, TypeInfo target) throws TypeException {
      if (!(target instanceof TypeInfo.FunctionType)) throw new TypeException("bad function", this);
      funcType = (TypeInfo.FunctionType) target;
      TypeInfo[] params = funcType.parameterTypes;

      if (size() != params.length) throw new TypeException("bad number of arguments", this);
      argTypes = new TypeInfo[params.length];
      int num = 0;
      for (ASTree a : this) {
        TypeInfo t = argTypes[num] = ((ASTreeTypeEx) a).typeCheck(tenv);
        t.assertSubtypeOf(params[num++], tenv, this);
      }
      return funcType.returnType;
    }
Пример #23
0
  public TableInstance resolveByAlias(String alias) {
    resolvedClass = null;
    TypeInfo typeInfo = (TypeInfo) aliasToTypeInfo.get(alias);
    if (typeInfo != null) {
      resolvedClass = typeInfo.getClazz();
      return typeInfo.getTableInstance();
    }

    TableInstance tblInstance = null;
    if (superContext != null) {
      tblInstance = superContext.resolveByAlias(alias);
      resolvedClass = superContext.getResolvedClass();
    }
    return tblInstance;
  }
Пример #24
0
 private static void printJavaNativeStub(
     ProcessingEnvironment env,
     PrintWriter writer,
     ExecutableElement method,
     Mode mode,
     boolean generate_error_checks,
     boolean context_specific) {
   if (Utils.isMethodIndirect(generate_error_checks, context_specific, method)) {
     writer.print("\tstatic native ");
   } else {
     Utils.printDocComment(writer, method, env);
     writer.print("\tpublic static native ");
   }
   writer.print(getResultType(method, true));
   writer.print(
       " " + Utils.getSimpleNativeMethodName(method, generate_error_checks, context_specific));
   if (mode == Mode.BUFFEROBJECT) {
     writer.print(Utils.BUFFER_OBJECT_METHOD_POSTFIX);
   }
   writer.print("(");
   boolean first_parameter =
       generateParametersJava(
           writer, method, TypeInfo.getDefaultTypeInfoMap(method), true, true, mode);
   if (context_specific) {
     if (!first_parameter) {
       writer.print(", ");
     }
     writer.print("long " + Utils.FUNCTION_POINTER_VAR_NAME);
   }
   writer.println(");");
 }
Пример #25
0
 public String typeArgumentsName(HashSet<String> typeVars) {
   if (mTypeParameters == null || mTypeParameters.isEmpty()) {
     return "";
   } else {
     return TypeInfo.typeArgumentsName(mTypeParameters, typeVars);
   }
 }
Пример #26
0
    public TypeInfo typeCheck(TypeEnv tenv) throws TypeException {
      String op = operator();
      if ("=".equals(op)) return typeCheckForAssign(tenv);
      else {
        leftType = ((ASTreeTypeEx) left()).typeCheck(tenv);
        rightType = ((ASTreeTypeEx) right()).typeCheck(tenv);

        if ("+".equals(op)) return leftType.plus(rightType, tenv);
        else if ("==".equals(op)) return TypeInfo.INT;
        else {
          leftType.assertSubtypeOf(TypeInfo.INT, tenv, this);
          rightType.assertSubtypeOf(TypeInfo.INT, tenv, this);
          return TypeInfo.INT;
        }
      }
    }
Пример #27
0
 public TableInstance resolveByBEName(String beName) throws QueryParsingException {
   TypeInfo typeInfo = findTypeInfo(beName);
   if (typeInfo != null) {
     if (typeInfo.isUnconflict()) {
       resolvedClass = typeInfo.getClazz();
       return typeInfo.getTableInstance();
     }
     throw new QueryParsingException("{0}is an ambiguous type reference", new Object[] {beName});
   }
   if (superContext != null) {
     TableInstance tableInstance = superContext.resolveByBEName(beName);
     resolvedClass = superContext.getResolvedClass();
     return tableInstance;
   }
   throw new QueryParsingException("type {0} not found", new Object[] {beName});
 }
Пример #28
0
  private static void reduceTypeInfos(
      final Map<String, List<TypeInfo>> typeInfoTypeMap, final List<TypeInfo> reducedTypeInfos) {

    for (final Map.Entry<String, List<TypeInfo>> entry : typeInfoTypeMap.entrySet()) {

      final List<TypeInfo> listOfTypeInfosWithSamePrimaryType = entry.getValue();
      TypeInfo firstTypeInfo = null;

      for (final TypeInfo typeInfo : listOfTypeInfosWithSamePrimaryType) {

        if (firstTypeInfo == null) {

          firstTypeInfo = typeInfo;

        } else {

          firstTypeInfo.combinePropertySets(typeInfo.getPropertySet());

          // "save" node references for later use
          firstTypeInfo.getNodeIds().addAll(typeInfo.getNodeIds());
        }
      }

      // firstTypeInfo now contains the intersection of all type infos of a given type
      reducedTypeInfos.add(firstTypeInfo);

      // set hierarchy level
      firstTypeInfo.setHierarchyLevel(listOfTypeInfosWithSamePrimaryType.size());
    }
  }
Пример #29
0
  /**
   * Handle xml-any-element. If the property was annotated with @XmlAnyElement in code all values
   * will be overridden.
   *
   * @param xmlAnyElement
   * @param oldProperty
   * @param tInfo
   * @param javaType
   * @return
   */
  private Property processXmlAnyElement(
      XmlAnyElement xmlAnyElement, Property oldProperty, TypeInfo tInfo, JavaType javaType) {
    // reset any existing values
    resetProperty(oldProperty, tInfo);

    // set xml-any-element specific properties
    oldProperty.setIsAny(true);
    oldProperty.setDomHandlerClassName(xmlAnyElement.getDomHandler());
    oldProperty.setLax(xmlAnyElement.isLax());
    oldProperty.setMixedContent(xmlAnyElement.isXmlMixed());
    oldProperty.setXmlJavaTypeAdapter(xmlAnyElement.getXmlJavaTypeAdapter());

    // update TypeInfo
    tInfo.setMixed(xmlAnyElement.isXmlMixed());
    tInfo.setAnyElementPropertyName(oldProperty.getPropertyName());

    return oldProperty;
  }
Пример #30
0
  private Property processXmlValue(
      XmlValue xmlValue, Property oldProperty, TypeInfo info, JavaType javaType) {
    // reset any existing values
    resetProperty(oldProperty, info);

    oldProperty.setIsXmlValue(true);
    info.setXmlValueProperty(oldProperty);
    return oldProperty;
  }