当前位置: 首页>>代码示例>>Java>>正文


Java IField.getConstant方法代码示例

本文整理汇总了Java中org.eclipse.jdt.core.IField.getConstant方法的典型用法代码示例。如果您正苦于以下问题:Java IField.getConstant方法的具体用法?Java IField.getConstant怎么用?Java IField.getConstant使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.eclipse.jdt.core.IField的用法示例。


在下文中一共展示了IField.getConstant方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getDistinctSets

import org.eclipse.jdt.core.IField; //导入方法依赖的package包/类
public static Collection getDistinctSets(Collection elementSets)
		throws JavaModelException {
	final Collection ret = new LinkedHashSet(elementSets);
	for (final Iterator it = elementSets.iterator(); it.hasNext();) {
		final Collection set = (Collection) it.next();
		final Collection constValues = new ArrayList();
		for (final Iterator jit = set.iterator(); jit.hasNext();) {
			final IJavaElement elem = (IJavaElement) jit.next();
			if (elem.getElementType() == IJavaElement.FIELD) {
				final IField field = (IField) elem;
				final Object constValue = field.getConstant();
				if (constValue != null)
					constValues.add(constValue);
			}
		}

		if (!distinct(constValues))
			ret.remove(set);
	}
	return ret;
}
 
开发者ID:ponder-lab,项目名称:Constants-to-Enum-Eclipse-Plugin,代码行数:22,代码来源:Util.java

示例2: getUniquelyNamedSets

import org.eclipse.jdt.core.IField; //导入方法依赖的package包/类
public static Collection getUniquelyNamedSets(Collection elementSets)
		throws JavaModelException {
	final Collection ret = new LinkedHashSet(elementSets);
	for (final Iterator it = elementSets.iterator(); it.hasNext();) {
		final Collection set = (Collection) it.next();
		final Collection constNames = new ArrayList();
		for (final Iterator jit = set.iterator(); jit.hasNext();) {
			final IJavaElement elem = (IJavaElement) jit.next();
			if (elem.getElementType() == IJavaElement.FIELD) {
				final IField field = (IField) elem;
				final Object constValue = field.getConstant();
				if (constValue != null)
					constNames.add(field.getElementName());
			}
		}
		if (!distinct(constNames))
			ret.remove(set);
	}
	return ret;
}
 
开发者ID:ponder-lab,项目名称:Constants-to-Enum-Eclipse-Plugin,代码行数:21,代码来源:Util.java

示例3: getConsistentlyVisibleSets

import org.eclipse.jdt.core.IField; //导入方法依赖的package包/类
public static Collection getConsistentlyVisibleSets(Collection elementSets)
		throws JavaModelException {
	final Collection ret = new LinkedHashSet(elementSets);
	for (final Iterator it = elementSets.iterator(); it.hasNext();) {
		final Collection set = (Collection) it.next();

		boolean allPublic = true;
		boolean allPrivate = true;
		boolean allPackage = true;
		boolean allProtected = true;

		for (final Iterator jit = set.iterator(); jit.hasNext();) {
			final IJavaElement elem = (IJavaElement) jit.next();
			if (elem.getElementType() == IJavaElement.FIELD) {
				final IField field = (IField) elem;
				final Object constValue = field.getConstant();
				if (constValue != null) {
					allPublic &= Flags.isPublic(field.getFlags());
					allPrivate &= Flags.isPrivate(field.getFlags());
					allProtected &= Flags.isProtected(field.getFlags());
					allPackage &= Flags.isPackageDefault(field.getFlags());
				}
			}
		}
		if (!(allPublic || allPrivate || allPackage || allProtected))
			ret.remove(set);
	}
	return ret;
}
 
开发者ID:ponder-lab,项目名称:Constants-to-Enum-Eclipse-Plugin,代码行数:30,代码来源:Util.java

示例4: compare

import org.eclipse.jdt.core.IField; //导入方法依赖的package包/类
public int compare(Object o1, Object o2) {
	if (!(o2 instanceof EnumConstantDeclaration && o2 instanceof EnumConstantDeclaration)) {
		String message = Messages.EnumConstantComparator_BothObjectsMustMatch;
		throw new IllegalArgumentException(MessageFormat.format(message, new Object[]{EnumConstantDeclaration.class.getName()}));
	}

	final IField f1 = (IField) this.newEnumConstantToOldConstantFieldMap.get(o1);
	final IField f2 = (IField) this.newEnumConstantToOldConstantFieldMap.get(o2);

	Object v1 = null;
	Object v2 = null;

	try {
		v1 = f1.getConstant();
		v2 = f2.getConstant();
	} catch (final JavaModelException E) {
		final ClassCastException ce = new ClassCastException(
				Messages.EnumConstantComparator_CannotCompare);
		ce.initCause(E);
		throw ce;
	}

	if (v1 == null || v2 == null) // no constant value.
		throw new ClassCastException(
				Messages.EnumConstantComparator_CannotCompareWithoutPrimitives);
	else
		return ((Comparable) v1).compareTo(v2);
}
 
开发者ID:ponder-lab,项目名称:Constants-to-Enum-Eclipse-Plugin,代码行数:29,代码来源:EnumConstantComparator.java

示例5: isConstantField

import org.eclipse.jdt.core.IField; //导入方法依赖的package包/类
public static boolean isConstantField(IField field)
		throws JavaModelException {
	if (field.getConstant() == null)
		return false;
	return true;
}
 
开发者ID:ponder-lab,项目名称:Constants-to-Enum-Eclipse-Plugin,代码行数:7,代码来源:Util.java

示例6: handleConstantValue

import org.eclipse.jdt.core.IField; //导入方法依赖的package包/类
private boolean handleConstantValue(IField field, boolean link) throws JavaModelException {
  String text = null;

  ISourceRange nameRange = field.getNameRange();
  if (SourceRange.isAvailable(nameRange)) {
    CompilationUnit cuNode = ASTProvider.createAST(field.getTypeRoot(), null);
    if (cuNode != null) {
      ASTNode nameNode = NodeFinder.perform(cuNode, nameRange);
      if (nameNode instanceof SimpleName) {
        IBinding binding = ((SimpleName) nameNode).resolveBinding();
        if (binding instanceof IVariableBinding) {
          IVariableBinding variableBinding = (IVariableBinding) binding;
          Object constantValue = variableBinding.getConstantValue();
          if (constantValue != null) {
            if (constantValue instanceof String) {
              text = ASTNodes.getEscapedStringLiteral((String) constantValue);
            } else {
              text = constantValue.toString(); // Javadoc tool is even worse for chars...
            }
          }
        }
      }
    }
  }

  if (text == null) {
    Object constant = field.getConstant();
    if (constant != null) {
      text = constant.toString();
    }
  }

  if (text != null) {
    text = HTMLPrinter.convertToHTMLContentWithWhitespace(text);
    if (link) {
      String uri;
      try {
        uri = JavaElementLinks.createURI(urlPrefix, field);
        fBuf.append(JavaElementLinks.createLink(uri, text));
      } catch (URISyntaxException e) {
        LOG.error(e.getMessage(), e);
        return false;
      }
    } else {
      handleText(text);
    }
    return true;
  }
  return false;
}
 
开发者ID:eclipse,项目名称:che,代码行数:51,代码来源:JavadocContentAccess2.java


注:本文中的org.eclipse.jdt.core.IField.getConstant方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。