Java Code Examples for org.eclipse.jdt.core.IMember#exists()

The following examples show how to use org.eclipse.jdt.core.IMember#exists() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RefactoringAvailabilityTester.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
public static boolean isPullUpAvailable(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 IType) {
		if (!JdtFlags.isStatic(member) && !JdtFlags.isEnum(member) && !JdtFlags.isAnnotation(member))
			return false;
	}
	if (member instanceof IMethod) {
		final IMethod method= (IMethod) member;
		if (method.isConstructor())
			return false;
		if (JdtFlags.isNative(method))
			return false;
		final IType declaring= method.getDeclaringType();
		if (declaring != null && declaring.isAnnotation())
			return false;
	}
	return true;
}
 
Example 2
Source File: RefactoringAvailabilityTester.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
public static boolean isPushDownAvailable(final IMember member) throws JavaModelException {
	if (!member.exists())
		return false;
	final int type= member.getElementType();
	if (type != IJavaElement.METHOD && type != IJavaElement.FIELD)
		return false;
	if (JdtFlags.isEnum(member))
		return false;
	if (!Checks.isAvailable(member))
		return false;
	if (JdtFlags.isStatic(member))
		return false;
	if (type == IJavaElement.METHOD) {
		final IMethod method= (IMethod) member;
		if (method.isConstructor())
			return false;
		if (JdtFlags.isNative(method))
			return false;
		final IType declaring= method.getDeclaringType();
		if (declaring != null && declaring.isAnnotation())
			return false;
	}
	return true;
}
 
Example 3
Source File: CalleeMethodWrapper.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
/**
    * Find callees called from the current method.
 * @see org.eclipse.jdt.internal.corext.callhierarchy.MethodWrapper#findChildren(org.eclipse.core.runtime.IProgressMonitor)
    */
   @Override
protected Map<String, MethodCall> findChildren(IProgressMonitor progressMonitor) {
   	IMember member= getMember();
	if (member.exists()) {
		CompilationUnit cu= CallHierarchy.getCompilationUnitNode(member, true);
	    if (progressMonitor != null) {
	        progressMonitor.worked(5);
	    }

		if (cu != null) {
			CalleeAnalyzerVisitor visitor = new CalleeAnalyzerVisitor(member, cu, progressMonitor);

			cu.accept(visitor);
			return visitor.getCallees();
		}
	}
       return new HashMap<String, MethodCall>(0);
   }
 
Example 4
Source File: JavaHistoryActionImpl.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Returns an IMember or null.
 */
final IMember getEditionElement(ISelection selection) {

	if (selection instanceof IStructuredSelection) {
		IStructuredSelection ss= (IStructuredSelection) selection;
		if (ss.size() == 1) {
			Object o= ss.getFirstElement();
			if (o instanceof IMember) {
				IMember m= (IMember) o;
				if (m.exists() && !m.isBinary() && JavaStructureCreator.hasEdition(m))
					return m;
			}
		}
	}
	return null;
}
 
Example 5
Source File: RefactoringAvailabilityTester.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
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;
}
 
Example 6
Source File: RefactoringAvailabilityTester.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
public static boolean isPullUpAvailable(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 IType) {
		if (!JdtFlags.isStatic(member) && !JdtFlags.isEnum(member) && !JdtFlags.isAnnotation(member)) {
			return false;
		}
	}
	if (member instanceof IMethod) {
		final IMethod method = (IMethod) member;
		if (method.isConstructor()) {
			return false;
		}
		if (JdtFlags.isNative(method)) {
			return false;
		}
		final IType declaring = method.getDeclaringType();
		if (declaring != null && declaring.isAnnotation()) {
			return false;
		}
	}
	return true;
}
 
Example 7
Source File: RefactoringAvailabilityTester.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
public static boolean isPushDownAvailable(final IMember member) throws JavaModelException {
	if (!member.exists()) {
		return false;
	}
	final int type = member.getElementType();
	if (type != IJavaElement.METHOD && type != IJavaElement.FIELD) {
		return false;
	}
	if (JdtFlags.isEnum(member)) {
		return false;
	}
	if (!Checks.isAvailable(member)) {
		return false;
	}
	if (JdtFlags.isStatic(member)) {
		return false;
	}
	if (type == IJavaElement.METHOD) {
		final IMethod method = (IMethod) member;
		if (method.isConstructor()) {
			return false;
		}
		if (JdtFlags.isNative(method)) {
			return false;
		}
		final IType declaring = method.getDeclaringType();
		if (declaring != null && declaring.isAnnotation()) {
			return false;
		}
	}
	return true;
}
 
Example 8
Source File: HierarchyProcessor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
protected RefactoringStatus checkIfMembersExist() {
	final RefactoringStatus result= new RefactoringStatus();
	IMember member= null;
	for (int index= 0; index < fMembersToMove.length; index++) {
		member= fMembersToMove[index];
		if (member == null || !member.exists())
			result.addFatalError(RefactoringCoreMessages.HierarchyRefactoring_does_not_exist);
	}
	return result;
}
 
Example 9
Source File: RefactoringAvailabilityTester.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
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;
}
 
Example 10
Source File: RefactoringAvailabilityTester.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
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;
}
 
Example 11
Source File: CallHierarchyViewPart.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private void updateHistoryEntries() {
     for (int i = getMethodHistory().size() - 1; i >= 0; i--) {
         IMember[] members = getMethodHistory().get(i);
         for (int j= 0; j < members.length; j++) {
	IMember member= members[j];
	if (! member.exists()) {
		getMethodHistory().remove(i);
		break;
	}
}
     }

     fHistoryDropDownAction.setEnabled(!getMethodHistory().isEmpty());
 }
 
Example 12
Source File: RefactoringAvailabilityTester.java    From eclipse.jdt.ls with Eclipse Public License 2.0 4 votes vote down vote up
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;
}
 
Example 13
Source File: HierarchyProcessor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
protected boolean canBeAccessedFrom(final IMember member, final IType target, final ITypeHierarchy hierarchy) throws JavaModelException {
	Assert.isTrue(!(member instanceof IInitializer));
	return member.exists();
}
 
Example 14
Source File: AddJavaDocStubAction.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
private IMember[] getSelectedMembers(IStructuredSelection selection) {
	List<?> elements= selection.toList();
	int nElements= elements.size();
	if (nElements > 0) {
		IMember[] res= new IMember[nElements];
		ICompilationUnit cu= null;
		for (int i= 0; i < nElements; i++) {
			Object curr= elements.get(i);
			if (curr instanceof IMethod || curr instanceof IType || curr instanceof IField) {
				IMember member= (IMember)curr; // limit to methods, types & fields
				if (! member.exists()) {
					return null;
				}
				if (i == 0) {
					cu= member.getCompilationUnit();
					if (cu == null) {
						return null;
					}
				} else if (!cu.equals(member.getCompilationUnit())) {
					return null;
				}
				if (member instanceof IMethod && ((IMethod) member).isLambdaMethod()) {
					return null;
				}
				try {
					if (member instanceof IType) {
						IType type= (IType) member;
						if (type.isAnonymous() || type.isLambda()) {
							return null;
						}
					}
				} catch (JavaModelException e) {
					return null;
				}
				res[i]= member;
			} else {
				return null;
			}
		}
		return res;
	}
	return null;
}
 
Example 15
Source File: JavaStatusContext.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 2 votes vote down vote up
/**
 * Creates an status entry context for the given member
 *
 * @param member the java member for which the context is supposed
 *  to be created
 * @return the status entry context or <code>null</code> if the
 * 	context cannot be created
 */
public static RefactoringStatusContext create(IMember member) {
	if (member == null || !member.exists())
		return null;
	return new MemberSourceContext(member);
}