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


Java IField.exists方法代码示例

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


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

示例1: resolveMember

import org.eclipse.jdt.core.IField; //导入方法依赖的package包/类
/**
 * Resolves the member described by the receiver and returns it if found. Returns <code>null
 * </code> if no corresponding member can be found.
 *
 * @return the resolved member or <code>null</code> if none is found
 * @throws org.eclipse.jdt.core.JavaModelException if accessing the java model fails
 */
@Override
protected IMember resolveMember() throws JavaModelException {
  char[] declarationSignature = fProposal.getDeclarationSignature();
  // for synthetic fields on arrays, declaration signatures may be null
  // TODO remove when https://bugs.eclipse.org/bugs/show_bug.cgi?id=84690 gets fixed
  if (declarationSignature == null) return null;
  String typeName = SignatureUtil.stripSignatureToFQN(String.valueOf(declarationSignature));
  IType type = fJavaProject.findType(typeName);
  if (type != null) {
    String name = String.valueOf(fProposal.getName());
    IField field = type.getField(name);
    if (field.exists()) return field;
  }

  return null;
}
 
开发者ID:eclipse,项目名称:che,代码行数:24,代码来源:FieldProposalInfo.java

示例2: getMemberCandidates

import org.eclipse.jdt.core.IField; //导入方法依赖的package包/类
private List<IMember> getMemberCandidates(IType type, Bookmark javaBookmark) {
	String elementKind = javaBookmark.getPropertyValue(PROP_JAVA_ELEMENT_KIND);
	String elementName = javaBookmark.getPropertyValue(PROP_JAVA_ELEMENT_NAME);
	if (KIND_FIELD.equals(elementKind)) {
		IField field = type.getField(elementName);
		return field.exists() ? Lists.newArrayList(field) : Collections.emptyList();
	}
	if (KIND_METHOD.equals(elementKind)) {
		String signature = javaBookmark.getPropertyValue(PROP_JAVA_METHOD_SIGNATURE);
		IMethod method = null;
		if (signature != null) {
			method = getMethod(type, elementName, signature);
		}
		if (method == null) {
			List<IMethod> candidates = getMethodsWithName(type, elementName);
			return Lists.newArrayList(candidates);
		}
		return Lists.newArrayList(method);
	}
	if (JavaEditorUtils.isType(elementKind) && elementName != null) {
		IType memberType = type.getType(elementName);
		return memberType.exists() ? Lists.newArrayList(memberType) : Collections.emptyList();
	}
	return Collections.emptyList();
}
 
开发者ID:cchabanois,项目名称:mesfavoris,代码行数:26,代码来源:JavaTypeMemberBookmarkLocationProvider.java

示例3: checkNestedHierarchy

import org.eclipse.jdt.core.IField; //导入方法依赖的package包/类
private RefactoringStatus checkNestedHierarchy(IType type) throws CoreException {
  IType[] nestedTypes = type.getTypes();
  if (nestedTypes == null) return null;
  RefactoringStatus result = new RefactoringStatus();
  for (int i = 0; i < nestedTypes.length; i++) {
    IField otherField = nestedTypes[i].getField(getNewElementName());
    if (otherField.exists()) {
      String msg =
          Messages.format(
              RefactoringCoreMessages.RenameFieldRefactoring_hiding,
              new String[] {
                BasicElementLabels.getJavaElementName(fField.getElementName()),
                BasicElementLabels.getJavaElementName(getNewElementName()),
                BasicElementLabels.getJavaElementName(nestedTypes[i].getFullyQualifiedName('.'))
              });
      result.addWarning(msg, JavaStatusContext.create(otherField));
    }
    result.merge(checkNestedHierarchy(nestedTypes[i]));
  }
  return result;
}
 
开发者ID:eclipse,项目名称:che,代码行数:22,代码来源:RenameFieldProcessor.java

示例4: checkEnclosingHierarchy

import org.eclipse.jdt.core.IField; //导入方法依赖的package包/类
private RefactoringStatus checkEnclosingHierarchy() {
  IType current = fField.getDeclaringType();
  if (Checks.isTopLevel(current)) return null;
  RefactoringStatus result = new RefactoringStatus();
  while (current != null) {
    IField otherField = current.getField(getNewElementName());
    if (otherField.exists()) {
      String msg =
          Messages.format(
              RefactoringCoreMessages.RenameFieldRefactoring_hiding2,
              new String[] {
                BasicElementLabels.getJavaElementName(getNewElementName()),
                BasicElementLabels.getJavaElementName(current.getFullyQualifiedName('.')),
                BasicElementLabels.getJavaElementName(otherField.getElementName())
              });
      result.addWarning(msg, JavaStatusContext.create(otherField));
    }
    current = current.getDeclaringType();
  }
  return result;
}
 
开发者ID:eclipse,项目名称:che,代码行数:22,代码来源:RenameFieldProcessor.java

示例5: isGeneralizeTypeAvailable

import org.eclipse.jdt.core.IField; //导入方法依赖的package包/类
public static boolean isGeneralizeTypeAvailable(final IStructuredSelection selection)
    throws JavaModelException {
  if (selection.size() == 1) {
    final Object element = selection.getFirstElement();
    if (element instanceof IMethod) {
      final IMethod method = (IMethod) element;
      if (!method.exists()) return false;
      final String type = method.getReturnType();
      if (PrimitiveType.toCode(Signature.toString(type)) == null)
        return Checks.isAvailable(method);
    } else if (element instanceof IField) {
      final IField field = (IField) element;
      if (!field.exists()) return false;
      if (!JdtFlags.isEnum(field)) return Checks.isAvailable(field);
    }
  }
  return false;
}
 
开发者ID:eclipse,项目名称:che,代码行数:19,代码来源:RefactoringAvailabilityTester.java

示例6: createField

import org.eclipse.jdt.core.IField; //导入方法依赖的package包/类
/**
 * Create a transient field with a certain name and type in the {@link IType} objectClass. It checks first if the
 * cache property allows this field to be created. If the field with the same name exists, it is deleted prior to
 * the new field creation.
 * 
 * @param objectClass the {@link IType} where the field will be created
 * @param data the data used for the code generation
 * @param cacheProperty {@code true} if the field caching is allowed, {@code false} otherwise.
 * @param cachingFieldName the name of the field to be created
 * @param cachingFieldType the type of the field to be created
 * @return {@code true} if the field was created, {@code false} otherwise
 * @throws JavaModelException if a problem occurs during the code generation.
 */
public static boolean createField(IType objectClass, MethodGenerationData data, boolean cacheProperty,
        String cachingFieldName, Class<?> cachingFieldType) throws JavaModelException {
    IField field = objectClass.getField(cachingFieldName);
    if (field.exists()) {
        field.delete(true, null);
    }
    boolean isCacheable = cacheProperty && areAllFinalFields(data.getCheckedFields());
    if (isCacheable) {
        IJavaElement currentPosition = data.getElementPosition();
        String fieldSrc = "private transient " + cachingFieldType.getSimpleName() + " " + cachingFieldName
                + ";\n\n";
        objectClass.createField(fieldSrc, currentPosition, true, null);
    }
    return isCacheable;
}
 
开发者ID:maximeAudrain,项目名称:jenerate,代码行数:29,代码来源:MethodContentGenerations.java

示例7: addTypes

import org.eclipse.jdt.core.IField; //导入方法依赖的package包/类
private void addTypes(IType[] allSubtypes, HashSet<ICompilationUnit> cus, List<IType> types) throws JavaModelException {
	for (int i = 0; i < allSubtypes.length; i++) {
		IType type = allSubtypes[i];

		IField field = type.getField(NAME_FIELD);
		if (!field.exists()) {
			if (type.isClass() && cus.contains(type.getCompilationUnit())) {
				types.add(type);
			}
		}
	}
}
 
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:13,代码来源:PotentialProgrammingProblemsFix.java

示例8: collectChildrenWithMissingSerialVersionId

import org.eclipse.jdt.core.IField; //导入方法依赖的package包/类
private void collectChildrenWithMissingSerialVersionId(IJavaElement[] children, IType serializable, List<IType> result) throws JavaModelException {
	for (int i = 0; i < children.length; i++) {
		IJavaElement child = children[i];
		if (child instanceof IType) {
			IType type = (IType) child;

			if (type.isClass()) {
				IField field = type.getField(NAME_FIELD);
				if (!field.exists()) {
					ITypeHierarchy hierarchy = type.newSupertypeHierarchy(new NullProgressMonitor());
					IType[] interfaces = hierarchy.getAllSuperInterfaces(type);
					for (int j = 0; j < interfaces.length; j++) {
						if (interfaces[j].equals(serializable)) {
							result.add(type);
							break;
						}
					}
				}
			}

			collectChildrenWithMissingSerialVersionId(type.getChildren(), serializable, result);
		} else if (child instanceof IMethod) {
			collectChildrenWithMissingSerialVersionId(((IMethod) child).getChildren(), serializable, result);
		} else if (child instanceof IField) {
			collectChildrenWithMissingSerialVersionId(((IField) child).getChildren(), serializable, result);
		}
	}
}
 
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:29,代码来源:PotentialProgrammingProblemsFix.java

示例9: appendFieldLabel

import org.eclipse.jdt.core.IField; //导入方法依赖的package包/类
/**
 * Appends the style label for a field. Considers the F_* flags.
 *
 * @param field the element to render
 * @param flags the rendering flags. Flags with names starting with 'F_' are considered.
 */
public void appendFieldLabel(IField field, long flags) {
	try {

		if (getFlag(flags, JavaElementLabels.F_PRE_TYPE_SIGNATURE) && field.exists() && !Flags.isEnum(field.getFlags())) {
			if (getFlag(flags, JavaElementLabels.USE_RESOLVED) && field.isResolved()) {
				appendTypeSignatureLabel(field, new BindingKey(field.getKey()).toSignature(), flags);
			} else {
				appendTypeSignatureLabel(field, field.getTypeSignature(), flags);
			}
			fBuilder.append(' ');
		}

		// qualification
		if (getFlag(flags, JavaElementLabels.F_FULLY_QUALIFIED)) {
			appendTypeLabel(field.getDeclaringType(), JavaElementLabels.T_FULLY_QUALIFIED | (flags & QUALIFIER_FLAGS));
			fBuilder.append('.');
		}
		fBuilder.append(getElementName(field));

		if (getFlag(flags, JavaElementLabels.F_APP_TYPE_SIGNATURE) && field.exists() && !Flags.isEnum(field.getFlags())) {
			fBuilder.append(JavaElementLabels.DECL_STRING);
			if (getFlag(flags, JavaElementLabels.USE_RESOLVED) && field.isResolved()) {
				appendTypeSignatureLabel(field, new BindingKey(field.getKey()).toSignature(), flags);
			} else {
				appendTypeSignatureLabel(field, field.getTypeSignature(), flags);
			}
		}

		// post qualification
		if (getFlag(flags, JavaElementLabels.F_POST_QUALIFIED)) {
			fBuilder.append(JavaElementLabels.CONCAT_STRING);
			appendTypeLabel(field.getDeclaringType(), JavaElementLabels.T_FULLY_QUALIFIED | (flags & QUALIFIER_FLAGS));
		}

	} catch (JavaModelException e) {
		JavaLanguageServerPlugin.logException("", e); // NotExistsException will not reach this point
	}
}
 
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:45,代码来源:JavaElementLabelComposer.java

示例10: addTypes

import org.eclipse.jdt.core.IField; //导入方法依赖的package包/类
private void addTypes(IType[] allSubtypes, HashSet<ICompilationUnit> cus, List<IType> types)
    throws JavaModelException {
  for (int i = 0; i < allSubtypes.length; i++) {
    IType type = allSubtypes[i];

    IField field = type.getField(NAME_FIELD);
    if (!field.exists()) {
      if (type.isClass() && cus.contains(type.getCompilationUnit())) {
        types.add(type);
      }
    }
  }
}
 
开发者ID:eclipse,项目名称:che,代码行数:14,代码来源:PotentialProgrammingProblemsFix.java

示例11: collectChildrenWithMissingSerialVersionId

import org.eclipse.jdt.core.IField; //导入方法依赖的package包/类
private void collectChildrenWithMissingSerialVersionId(
    IJavaElement[] children, IType serializable, List<IType> result) throws JavaModelException {
  for (int i = 0; i < children.length; i++) {
    IJavaElement child = children[i];
    if (child instanceof IType) {
      IType type = (IType) child;

      if (type.isClass()) {
        IField field = type.getField(NAME_FIELD);
        if (!field.exists()) {
          ITypeHierarchy hierarchy = type.newSupertypeHierarchy(new NullProgressMonitor());
          IType[] interfaces = hierarchy.getAllSuperInterfaces(type);
          for (int j = 0; j < interfaces.length; j++) {
            if (interfaces[j].equals(serializable)) {
              result.add(type);
              break;
            }
          }
        }
      }

      collectChildrenWithMissingSerialVersionId(type.getChildren(), serializable, result);
    } else if (child instanceof IMethod) {
      collectChildrenWithMissingSerialVersionId(
          ((IMethod) child).getChildren(), serializable, result);
    } else if (child instanceof IField) {
      collectChildrenWithMissingSerialVersionId(
          ((IField) child).getChildren(), serializable, result);
    }
  }
}
 
开发者ID:eclipse,项目名称:che,代码行数:32,代码来源:PotentialProgrammingProblemsFix.java

示例12: checkInitialConditions

import org.eclipse.jdt.core.IField; //导入方法依赖的package包/类
@Override
public RefactoringStatus checkInitialConditions(IProgressMonitor pm) throws CoreException {
  IField primary = (IField) fField.getPrimaryElement();
  if (primary == null || !primary.exists()) {
    String message =
        Messages.format(
            RefactoringCoreMessages.RenameFieldRefactoring_deleted,
            BasicElementLabels.getFileName(fField.getCompilationUnit()));
    return RefactoringStatus.createFatalErrorStatus(message);
  }
  fField = primary;

  return Checks.checkIfCuBroken(fField);
}
 
开发者ID:eclipse,项目名称:che,代码行数:15,代码来源:RenameFieldProcessor.java

示例13: isDelegateCreationAvailable

import org.eclipse.jdt.core.IField; //导入方法依赖的package包/类
public static boolean isDelegateCreationAvailable(final IField field) throws JavaModelException {
  return field.exists()
      && (Flags.isStatic(field.getFlags()) && Flags.isFinal(field.getFlags()) /*
 * &&
 * hasInitializer(field)
 */);
}
 
开发者ID:eclipse,项目名称:che,代码行数:8,代码来源:RefactoringAvailabilityTester.java

示例14: findField

import org.eclipse.jdt.core.IField; //导入方法依赖的package包/类
private RefactoringStatus findField() {
  fField = (IField) ((IVariableBinding) fSelectedConstantName.resolveBinding()).getJavaElement();
  if (fField != null && !fField.exists())
    return RefactoringStatus.createStatus(
        RefactoringStatus.FATAL,
        RefactoringCoreMessages.InlineConstantRefactoring_local_anonymous_unsupported,
        null,
        Corext.getPluginId(),
        RefactoringStatusCodes.LOCAL_AND_ANONYMOUS_NOT_SUPPORTED,
        null);

  return null;
}
 
开发者ID:eclipse,项目名称:che,代码行数:14,代码来源:InlineConstantRefactoring.java

示例15: findField

import org.eclipse.jdt.core.IField; //导入方法依赖的package包/类
public static IField findField(IType type, String fieldName) {
  IField field = type.getField(fieldName);
  if (field.exists()) {
    return field;
  }

  return null;
}
 
开发者ID:gwt-plugins,项目名称:gwt-eclipse-plugin,代码行数:9,代码来源:JavaModelSearch.java


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