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


Java IMember.getDeclaringType方法代码示例

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


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

示例1: addMemberBookmarkProperties

import org.eclipse.jdt.core.IMember; //导入方法依赖的package包/类
protected void addMemberBookmarkProperties(Map<String, String> bookmarkProperties, IMember member) {
	putIfAbsent(bookmarkProperties, PROP_JAVA_ELEMENT_NAME, member.getElementName());
	if (member.getDeclaringType() != null) {
		putIfAbsent(bookmarkProperties, PROP_JAVA_DECLARING_TYPE,
				member.getDeclaringType().getFullyQualifiedName());
	}
	putIfAbsent(bookmarkProperties, PROP_JAVA_ELEMENT_KIND, getKind(member));
	if (member instanceof IMethod) {
		putIfAbsent(bookmarkProperties, PROP_JAVA_METHOD_SIGNATURE,
				JavaEditorUtils.getMethodSimpleSignature((IMethod) member));
		putIfAbsent(bookmarkProperties, Bookmark.PROPERTY_NAME,
				bookmarkProperties.get(PROP_JAVA_DECLARING_TYPE) + '.' + member.getElementName() + "()");
	}
	if (member instanceof IType) {
		IType type = (IType) member;
		putIfAbsent(bookmarkProperties, PROP_JAVA_TYPE, type.getFullyQualifiedName());
		putIfAbsent(bookmarkProperties, Bookmark.PROPERTY_NAME, type.getFullyQualifiedName());
	}
	if (member instanceof IField) {
		putIfAbsent(bookmarkProperties, Bookmark.PROPERTY_NAME,
				bookmarkProperties.get(PROP_JAVA_DECLARING_TYPE) + '.' + member.getElementName());
	}
	putIfAbsent(bookmarkProperties, Bookmark.PROPERTY_NAME, member.getElementName());
}
 
开发者ID:cchabanois,项目名称:mesfavoris,代码行数:25,代码来源:JavaTypeMemberBookmarkPropertiesProvider.java

示例2: adjustOutgoingVisibilityChain

import org.eclipse.jdt.core.IMember; //导入方法依赖的package包/类
private void adjustOutgoingVisibilityChain(final IMember member, final IProgressMonitor monitor)
    throws JavaModelException {

  if (!Modifier.isPublic(member.getFlags())) {
    final ModifierKeyword threshold =
        computeOutgoingVisibilityThreshold(fReferencing, member, monitor);
    if (member instanceof IMethod) {
      adjustOutgoingVisibility(
          member,
          threshold,
          RefactoringCoreMessages.MemberVisibilityAdjustor_change_visibility_method_warning);
    } else if (member instanceof IField) {
      adjustOutgoingVisibility((IField) member, threshold);
    } else if (member instanceof IType) {
      adjustOutgoingVisibility(
          member,
          threshold,
          RefactoringCoreMessages.MemberVisibilityAdjustor_change_visibility_type_warning);
    }
  }

  if (member.getDeclaringType() != null)
    adjustOutgoingVisibilityChain(member.getDeclaringType(), monitor);
}
 
开发者ID:eclipse,项目名称:che,代码行数:25,代码来源:MemberVisibilityAdjustor.java

示例3: searchForOuterTypesOfReferences

import org.eclipse.jdt.core.IMember; //导入方法依赖的package包/类
private IType[] searchForOuterTypesOfReferences(IMethod[] newNameMethods, IProgressMonitor pm)
    throws CoreException {
  final Set<IType> outerTypesOfReferences = new HashSet<IType>();
  SearchPattern pattern =
      RefactoringSearchEngine.createOrPattern(newNameMethods, IJavaSearchConstants.REFERENCES);
  IJavaSearchScope scope = createRefactoringScope(getMethod());
  SearchRequestor requestor =
      new SearchRequestor() {
        @Override
        public void acceptSearchMatch(SearchMatch match) throws CoreException {
          Object element = match.getElement();
          if (!(element instanceof IMember))
            return; // e.g. an IImportDeclaration for a static method import
          IMember member = (IMember) element;
          IType declaring = member.getDeclaringType();
          if (declaring == null) return;
          IType outer = declaring.getDeclaringType();
          if (outer != null) outerTypesOfReferences.add(declaring);
        }
      };
  new SearchEngine()
      .search(pattern, SearchUtils.getDefaultSearchParticipants(), scope, requestor, pm);
  return outerTypesOfReferences.toArray(new IType[outerTypesOfReferences.size()]);
}
 
开发者ID:eclipse,项目名称:che,代码行数:25,代码来源:RenameMethodProcessor.java

示例4: isExtractSupertypeAvailable

import org.eclipse.jdt.core.IMember; //导入方法依赖的package包/类
public static boolean isExtractSupertypeAvailable(IMember member) throws JavaModelException {
  if (!member.exists()) return false;
  final int type = member.getElementType();
  if (type != IJavaElement.METHOD && type != IJavaElement.FIELD && type != IJavaElement.TYPE)
    return false;
  if (JdtFlags.isEnum(member) && type != IJavaElement.TYPE) return false;
  if (!Checks.isAvailable(member)) return false;
  if (member instanceof IMethod) {
    final IMethod method = (IMethod) member;
    if (method.isConstructor()) return false;
    if (JdtFlags.isNative(method)) return false;
    member = method.getDeclaringType();
  } else if (member instanceof IField) {
    member = member.getDeclaringType();
  }
  if (member instanceof IType) {
    if (JdtFlags.isEnum(member) || JdtFlags.isAnnotation(member)) return false;
    if (member.getDeclaringType() != null && !JdtFlags.isStatic(member)) return false;
    if (((IType) member).isAnonymous())
      return false; // see https://bugs.eclipse.org/bugs/show_bug.cgi?id=253727
    if (((IType) member).isLambda()) return false;
  }
  return true;
}
 
开发者ID:eclipse,项目名称:che,代码行数:25,代码来源:RefactoringAvailabilityTester.java

示例5: isMoveStaticAvailable

import org.eclipse.jdt.core.IMember; //导入方法依赖的package包/类
public static boolean isMoveStaticAvailable(final IMember member) throws JavaModelException {
  if (!member.exists()) return false;
  final int type = member.getElementType();
  if (type != IJavaElement.METHOD && type != IJavaElement.FIELD && type != IJavaElement.TYPE)
    return false;
  if (JdtFlags.isEnum(member) && type != IJavaElement.TYPE) return false;
  final IType declaring = member.getDeclaringType();
  if (declaring == null) return false;
  if (!Checks.isAvailable(member)) return false;
  if (type == IJavaElement.METHOD && declaring.isInterface()) {
    boolean is18OrHigher = JavaModelUtil.is18OrHigher(member.getJavaProject());
    if (!is18OrHigher || !Flags.isStatic(member.getFlags())) return false;
  }
  if (type == IJavaElement.METHOD && !JdtFlags.isStatic(member)) return false;
  if (type == IJavaElement.METHOD && ((IMethod) member).isConstructor()) return false;
  if (type == IJavaElement.TYPE && !JdtFlags.isStatic(member)) return false;
  if (!declaring.isInterface() && !JdtFlags.isStatic(member)) return false;
  return true;
}
 
开发者ID:eclipse,项目名称:che,代码行数:20,代码来源:RefactoringAvailabilityTester.java

示例6: isVisibleInHierarchy

import org.eclipse.jdt.core.IMember; //导入方法依赖的package包/类
/**
 * Evaluates if a member in the focus' element hierarchy is visible from elements in a package.
 *
 * @param member The member to test the visibility for
 * @param pack The package of the focus element focus
 * @return returns <code>true</code> if the member is visible from the package
 * @throws JavaModelException thrown when the member can not be accessed
 */
public static boolean isVisibleInHierarchy(IMember member, IPackageFragment pack)
    throws JavaModelException {
  int type = member.getElementType();
  if (type == IJavaElement.INITIALIZER
      || (type == IJavaElement.METHOD
          && member.getElementName().startsWith("<"))) { // $NON-NLS-1$
    return false;
  }

  int otherflags = member.getFlags();

  IType declaringType = member.getDeclaringType();
  if (Flags.isPublic(otherflags)
      || Flags.isProtected(otherflags)
      || (declaringType != null && isInterfaceOrAnnotation(declaringType))) {
    return true;
  } else if (Flags.isPrivate(otherflags)) {
    return false;
  }

  IPackageFragment otherpack =
      (IPackageFragment) member.getAncestor(IJavaElement.PACKAGE_FRAGMENT);
  return (pack != null && pack.equals(otherpack));
}
 
开发者ID:eclipse,项目名称:che,代码行数:33,代码来源:JavaModelUtil.java

示例7: isVisible

import org.eclipse.jdt.core.IMember; //导入方法依赖的package包/类
/**
 * Evaluates if a member (possible from another package) is visible from elements in a package.
 *
 * @param member The member to test the visibility for
 * @param pack The package in focus
 * @return returns <code>true</code> if the member is visible from the package
 * @throws JavaModelException thrown when the member can not be accessed
 */
public static boolean isVisible(IMember member, IPackageFragment pack) throws JavaModelException {

  int type = member.getElementType();
  if (type == IJavaElement.INITIALIZER
      || (type == IJavaElement.METHOD
          && member.getElementName().startsWith("<"))) { // $NON-NLS-1$
    return false;
  }

  int otherflags = member.getFlags();
  IType declaringType = member.getDeclaringType();
  if (Flags.isPublic(otherflags)
      || (declaringType != null && isInterfaceOrAnnotation(declaringType))) {
    return true;
  } else if (Flags.isPrivate(otherflags)) {
    return false;
  }

  IPackageFragment otherpack =
      (IPackageFragment) member.getAncestor(IJavaElement.PACKAGE_FRAGMENT);
  return (pack != null && otherpack != null && isSamePackage(pack, otherpack));
}
 
开发者ID:eclipse,项目名称:che,代码行数:31,代码来源:JavaModelUtil.java

示例8: isVisibleMember

import org.eclipse.jdt.core.IMember; //导入方法依赖的package包/类
static boolean isVisibleMember(IMember member) throws JavaModelException {
	int f = member.getFlags();
	IType jType = member.getDeclaringType();
	return 
		jType.getPackageFragment().isDefaultPackage() && (Flags.isPackageDefault(f) || Flags.isProtected(f) || Flags.isPublic(f))
	||
		Flags.isPublic(f);

}
 
开发者ID:andre-santos-pt,项目名称:pandionj,代码行数:10,代码来源:ObjectModel.java

示例9: isStatic

import org.eclipse.jdt.core.IMember; //导入方法依赖的package包/类
public static boolean isStatic(IMember member) throws JavaModelException {
  if (isNestedInterfaceOrAnnotation(member)) return true;
  if (member.getElementType() != IJavaElement.METHOD && isInterfaceOrAnnotationMember(member))
    return true;
  if (isEnum(member)
      && (member.getElementType() == IJavaElement.FIELD || member.getDeclaringType() != null))
    return true;
  return Flags.isStatic(member.getFlags());
}
 
开发者ID:eclipse,项目名称:che,代码行数:10,代码来源:JdtFlags.java

示例10: adjustIncomingVisibility

import org.eclipse.jdt.core.IMember; //导入方法依赖的package包/类
/**
 * Adjusts the visibility of the specified member.
 *
 * @param element the "source" point from which to calculate the visibility
 * @param referencedMovedElement the moved element which may be adjusted in visibility
 * @param monitor the progress monitor to use
 * @throws JavaModelException if the visibility adjustment could not be computed
 */
private void adjustIncomingVisibility(
    final IJavaElement element, IMember referencedMovedElement, final IProgressMonitor monitor)
    throws JavaModelException {
  final ModifierKeyword threshold =
      getVisibilityThreshold(element, referencedMovedElement, monitor);
  int flags = referencedMovedElement.getFlags();
  IType declaring = referencedMovedElement.getDeclaringType();
  if (declaring != null && declaring.isInterface()
      || referencedMovedElement instanceof IField
          && Flags.isEnum(referencedMovedElement.getFlags())) return;
  if (hasLowerVisibility(flags, threshold == null ? Modifier.NONE : threshold.toFlagValue())
      && needsVisibilityAdjustment(referencedMovedElement, threshold))
    fAdjustments.put(
        referencedMovedElement,
        new IncomingMemberVisibilityAdjustment(
            referencedMovedElement,
            threshold,
            RefactoringStatus.createStatus(
                fVisibilitySeverity,
                Messages.format(
                    getMessage(referencedMovedElement),
                    new String[] {getLabel(referencedMovedElement), getLabel(threshold)}),
                JavaStatusContext.create(referencedMovedElement),
                null,
                RefactoringStatusEntry.NO_CODE,
                null)));
}
 
开发者ID:eclipse,项目名称:che,代码行数:36,代码来源:MemberVisibilityAdjustor.java

示例11: adjustOutgoingVisibility

import org.eclipse.jdt.core.IMember; //导入方法依赖的package包/类
/**
 * Adjusts the visibility of the referenced body declaration.
 *
 * @param member the member where to adjust the visibility
 * @param threshold the visibility keyword representing the required visibility, or <code>null
 *     </code> for default visibility
 * @param template the message template to use
 * @throws JavaModelException if an error occurs
 */
private void adjustOutgoingVisibility(
    final IMember member, final ModifierKeyword threshold, final String template)
    throws JavaModelException {
  Assert.isTrue(!member.isBinary() && !member.isReadOnly());
  boolean adjust = true;
  final IType declaring = member.getDeclaringType();
  if (declaring != null
      && (JavaModelUtil.isInterfaceOrAnnotation(declaring)
          || (member instanceof IField) && Flags.isEnum(member.getFlags())
          || declaring.equals(fReferenced))) adjust = false;
  if (adjust
      && hasLowerVisibility(member.getFlags(), keywordToVisibility(threshold))
      && needsVisibilityAdjustment(member, threshold))
    fAdjustments.put(
        member,
        new OutgoingMemberVisibilityAdjustment(
            member,
            threshold,
            RefactoringStatus.createStatus(
                fVisibilitySeverity,
                Messages.format(
                    template,
                    new String[] {
                      JavaElementLabels.getTextLabel(
                          member,
                          JavaElementLabels.M_PARAMETER_TYPES
                              | JavaElementLabels.ALL_FULLY_QUALIFIED),
                      getLabel(threshold)
                    }),
                JavaStatusContext.create(member),
                null,
                RefactoringStatusEntry.NO_CODE,
                null)));
}
 
开发者ID:eclipse,项目名称:che,代码行数:44,代码来源:MemberVisibilityAdjustor.java

示例12: isInterfaceOrAnnotationFieldOrType

import org.eclipse.jdt.core.IMember; //导入方法依赖的package包/类
private static boolean isInterfaceOrAnnotationFieldOrType(IMember element)
    throws JavaModelException {
  // always show the static symbol on interface fields and types
  if (element.getElementType() == IJavaElement.FIELD) {
    return JavaModelUtil.isInterfaceOrAnnotation(element.getDeclaringType());
  } else if (element.getElementType() == IJavaElement.TYPE
      && element.getDeclaringType() != null) {
    return JavaModelUtil.isInterfaceOrAnnotation(element.getDeclaringType());
  }
  return false;
}
 
开发者ID:eclipse,项目名称:che,代码行数:12,代码来源:JavaElementImageProvider.java

示例13: acceptSearchMatch

import org.eclipse.jdt.core.IMember; //导入方法依赖的package包/类
@Override
public void acceptSearchMatch(SearchMatch match) throws CoreException {
  if (match.getAccuracy() == SearchMatch.A_ACCURATE && !match.isInsideDocComment()) {
    Object element = match.getElement();
    if (element instanceof IType || element instanceof IMethod) {
      IMember member = (IMember) element;
      IType type =
          member.getElementType() == IJavaElement.TYPE
              ? (IType) member
              : member.getDeclaringType();
      addTypeAndSubtypes(type);
    }
  }
}
 
开发者ID:eclipse,项目名称:che,代码行数:15,代码来源:AnnotationSearchRequestor.java

示例14: canBeAccessedFrom

import org.eclipse.jdt.core.IMember; //导入方法依赖的package包/类
private boolean canBeAccessedFrom(IMethod sourceMethod, final IMember member, final IType target,
		final ITypeHierarchy hierarchy) throws JavaModelException {
	Assert.isTrue(!(member instanceof IInitializer));
	if (member.exists()) {
		if (target.equals(member.getDeclaringType()))
			return true;
		if (target.equals(member))
			return true;
		// NOTE: We are not creating stubs (for now).
		// Related to https://bugs.eclipse.org/bugs/show_bug.cgi?id=495439.
		/*
		 * if (member instanceof IMethod) { final IMethod method = (IMethod)
		 * member; final IMethod stub =
		 * target.getMethod(method.getElementName(),
		 * method.getParameterTypes()); if (stub.exists()) return true; }
		 */
		if (member.getDeclaringType() == null) {
			if (!(member instanceof IType))
				return false;
			if (JdtFlags.isPublic(member))
				return true;
			if (!JdtFlags.isPackageVisible(member))
				return false;
			if (JavaModelUtil.isSamePackage(((IType) member).getPackageFragment(), target.getPackageFragment()))
				return true;
			final IType type = member.getDeclaringType();
			if (type != null)
				return hierarchy.contains(type);
			return false;
		}
		final IType declaringType = member.getDeclaringType();
		// if the member's declaring type isn't accessible from the target
		// type.
		if (!canBeAccessedFrom(sourceMethod, declaringType, target, hierarchy))
			return false; // then, the member isn't accessible from the
							// target type.
		// otherwise, the member's declaring type is accessible from the
		// target type.
		// We are going to be moving the source method from it's
		// declaring type.
		// We know that the member's declaring type is accessible from
		// the target.
		// We also know that the member's declaring type and the target
		// type are different.
		// The question now is if the target type can access the
		// particular member given that
		// the target type can access the member's declaring type.
		// if it's public, the answer is yes.
		if (JdtFlags.isPublic(member))
			return true;
		// if the member is private, the answer is no.
		else if (JdtFlags.isPrivate(member))
			return false;
		// if it's package-private or protected.
		else if (JdtFlags.isPackageVisible(member) || JdtFlags.isProtected(member)) {
			// then, if the member's declaring type in the same package
			// as the target's declaring type, the answer is yes.
			if (JavaModelUtil.isVisible(member, target.getPackageFragment()))
				return true;
			// otherwise, if it's protected.
			else if (JdtFlags.isProtected(member))
				// then, the answer is yes if the target type is a
				// sub-type of the member's declaring type. Otherwise,
				// the answer is no.
				return hierarchy.contains(declaringType);
			else
				return false; // not accessible.
		} else
			throw new IllegalStateException("Member: " + member + " has no known visibility.");
	}
	return false;
}
 
开发者ID:ponder-lab,项目名称:Migrate-Skeletal-Implementation-to-Interface-Refactoring,代码行数:73,代码来源:MigrateSkeletalImplementationToInterfaceRefactoringProcessor.java

示例15: isInterfaceOrAnnotationMember

import org.eclipse.jdt.core.IMember; //导入方法依赖的package包/类
private static boolean isInterfaceOrAnnotationMember(IMember member) throws JavaModelException {
  return member.getDeclaringType() != null
      && JavaModelUtil.isInterfaceOrAnnotation(member.getDeclaringType());
}
 
开发者ID:eclipse,项目名称:che,代码行数:5,代码来源:JdtFlags.java


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