本文整理汇总了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;
}
示例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;
}
示例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;
}
示例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);
}
示例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;
}
示例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;
}