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

The following examples show how to use org.eclipse.jdt.core.IMember#isBinary() . 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: ReorgPolicyFactory.java    From eclipse.jdt.ls with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public boolean canEnable() throws JavaModelException {
	if (!super.canEnable() || fJavaElements.length == 0) {
		return false;
	}

	for (int i= 0; i < fJavaElements.length; i++) {
		if (fJavaElements[i] instanceof IMember) {
			IMember member= (IMember) fJavaElements[i];
			// we can copy some binary members, but not all
			if (member.isBinary() && member.getSourceRange() == null) {
				return false;
			}
		}
	}

	return true;
}
 
Example 2
Source File: ReorgPolicyFactory.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public boolean canEnable() throws JavaModelException {
	if (!super.canEnable() || fJavaElements.length == 0)
		return false;

	for (int i= 0; i < fJavaElements.length; i++) {
		if (fJavaElements[i] instanceof IMember) {
			IMember member= (IMember) fJavaElements[i];
			// we can copy some binary members, but not all
			if (member.isBinary() && member.getSourceRange() == null)
				return false;
		}
	}

	return true;
}
 
Example 3
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 4
Source File: JdtFlags.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
public static boolean isAbstract(IMember member) throws JavaModelException{
	int flags= member.getFlags();
	if (!member.isBinary() && isInterfaceOrAnnotationMethod(member)) {
		return !Flags.isPrivate(flags) && !Flags.isStatic(flags) && !Flags.isDefaultMethod(flags);
	}
	return Flags.isAbstract(flags);
}
 
Example 5
Source File: DocumentSymbolHandler.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
private boolean isSyntheticElement(IJavaElement element) {
	if (!(element instanceof IMember)) {
		return false;
	}
	IMember member= (IMember)element;
	if (!(member.isBinary())) {
		return false;
	}
	try {
		return Flags.isSynthetic(member.getFlags());
	} catch (JavaModelException e) {
		return false;
	}
}
 
Example 6
Source File: MemberVisibilityAdjustor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Adjusts the visibilities of the referenced element from the search match found in a compilation unit.
 *
 * @param match the search match representing the element declaration
 * @param monitor the progress monitor to use
 * @throws JavaModelException if the visibility could not be determined
 */
private void adjustOutgoingVisibility(final SearchMatch match, final IProgressMonitor monitor) throws JavaModelException {
	final Object element= match.getElement();
	if (element instanceof IMember) {
		final IMember member= (IMember) element;
		if (!member.isBinary() && !member.isReadOnly() && !isInsideMovedMember(member)) {
			adjustOutgoingVisibilityChain(member, monitor);
		}
	}
}
 
Example 7
Source File: JdtFlags.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public static boolean isAbstract(IMember member) throws JavaModelException{
	int flags= member.getFlags();
	if (!member.isBinary() && isInterfaceOrAnnotationMethod(member)) {
		return !Flags.isStatic(flags) && !Flags.isDefaultMethod(flags);
	}
	return Flags.isAbstract(flags);
}
 
Example 8
Source File: SyntheticMembersFilter.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public boolean select(Viewer viewer, Object parent, Object element) {
	if (!(element instanceof IMember))
		return true;
	IMember member= (IMember)element;
	if (!(member.isBinary()))
		return true;
	try {
		return !Flags.isSynthetic(member.getFlags());
	} catch (JavaModelException e) {
		return true;
	}
}
 
Example 9
Source File: ReorgUtils.java    From eclipse.jdt.ls with Eclipse Public License 2.0 4 votes vote down vote up
public static boolean hasSourceAvailable(IMember member) throws JavaModelException{
	return ! member.isBinary() ||
			(member.getSourceRange() != null && ! fgUnknownRange.equals(member.getSourceRange()));
}
 
Example 10
Source File: IntroduceIndirectionRefactoring.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
private RefactoringStatus adjustVisibility(IMember whoToAdjust, ModifierKeyword neededVisibility, boolean alsoIncreaseEnclosing, IProgressMonitor monitor) throws CoreException {

		Map<IMember, IncomingMemberVisibilityAdjustment> adjustments;
		if (isRewriteKept(whoToAdjust.getCompilationUnit()))
			adjustments= fIntermediaryAdjustments;
		else
			adjustments= new HashMap<IMember, IncomingMemberVisibilityAdjustment>();

		int existingAdjustments= adjustments.size();
		addAdjustment(whoToAdjust, neededVisibility, adjustments);

		if (alsoIncreaseEnclosing)
			while (whoToAdjust.getDeclaringType() != null) {
				whoToAdjust= whoToAdjust.getDeclaringType();
				addAdjustment(whoToAdjust, neededVisibility, adjustments);
			}

		boolean hasNewAdjustments= (adjustments.size() - existingAdjustments) > 0;
		if (hasNewAdjustments && ( (whoToAdjust.isReadOnly() || whoToAdjust.isBinary())))
			return RefactoringStatus.createErrorStatus(Messages.format(RefactoringCoreMessages.IntroduceIndirectionRefactoring_cannot_update_binary_target_visibility, new String[] { JavaElementLabels
					.getElementLabel(whoToAdjust, JavaElementLabels.ALL_DEFAULT) }), JavaStatusContext.create(whoToAdjust));

		RefactoringStatus status= new RefactoringStatus();

		// Don't create a rewrite if it is not necessary
		if (!hasNewAdjustments)
			return status;

		try {
			monitor.beginTask(RefactoringCoreMessages.MemberVisibilityAdjustor_adjusting, 2);
			Map<ICompilationUnit, CompilationUnitRewrite> rewrites;
			if (!isRewriteKept(whoToAdjust.getCompilationUnit())) {
				CompilationUnitRewrite rewrite= new CompilationUnitRewrite(whoToAdjust.getCompilationUnit());
				rewrite.setResolveBindings(false);
				rewrites= new HashMap<ICompilationUnit, CompilationUnitRewrite>();
				rewrites.put(whoToAdjust.getCompilationUnit(), rewrite);
				status.merge(rewriteVisibility(adjustments, rewrites, new SubProgressMonitor(monitor, 1, SubProgressMonitor.SUPPRESS_SUBTASK_LABEL)));
				rewrite.attachChange((CompilationUnitChange) fTextChangeManager.get(whoToAdjust.getCompilationUnit()), true, new SubProgressMonitor(monitor, 1, SubProgressMonitor.SUPPRESS_SUBTASK_LABEL));
			}
		} finally {
			monitor.done();
		}
		return status;
	}
 
Example 11
Source File: ReorgUtils.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
public static boolean hasSourceAvailable(IMember member) throws JavaModelException{
	return ! member.isBinary() ||
			(member.getSourceRange() != null && ! fgUnknownRange.equals(member.getSourceRange()));
}
 
Example 12
Source File: HandleFactory.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Create handle by adding child to parent obtained by recursing into parent scopes.
 */
public IJavaElement createElement(Scope scope, int elementPosition, ICompilationUnit unit, HashSet existingElements, HashMap knownScopes) {
	IJavaElement newElement = (IJavaElement)knownScopes.get(scope);
	if (newElement != null) return newElement;

	switch(scope.kind) {
		case Scope.COMPILATION_UNIT_SCOPE :
			newElement = unit;
			break;
		case Scope.CLASS_SCOPE :
			IJavaElement parentElement = createElement(scope.parent, elementPosition, unit, existingElements, knownScopes);
			switch (parentElement.getElementType()) {
				case IJavaElement.COMPILATION_UNIT :
					newElement = ((ICompilationUnit)parentElement).getType(new String(scope.enclosingSourceType().sourceName));
					break;
				case IJavaElement.TYPE :
					newElement = ((IType)parentElement).getType(new String(scope.enclosingSourceType().sourceName));
					break;
				case IJavaElement.FIELD :
				case IJavaElement.INITIALIZER :
				case IJavaElement.METHOD :
				    IMember member = (IMember)parentElement;
				    if (member.isBinary()) {
				        return null;
				    } else {
						newElement = member.getType(new String(scope.enclosingSourceType().sourceName), 1);
						// increment occurrence count if collision is detected
						if (newElement != null) {
							while (!existingElements.add(newElement)) ((SourceRefElement)newElement).occurrenceCount++;
						}
				    }
					break;
			}
			if (newElement != null) {
				knownScopes.put(scope, newElement);
			}
			break;
		case Scope.METHOD_SCOPE :
			if (scope.isLambdaScope()) {
				parentElement = createElement(scope.parent, elementPosition, unit, existingElements, knownScopes);
				LambdaExpression expression = (LambdaExpression) scope.originalReferenceContext();
				if (expression.resolvedType != null && expression.resolvedType.isValidBinding() && 
						!(expression.descriptor instanceof ProblemMethodBinding)) { // chain in lambda element only if resolved properly.
					//newElement = new org.eclipse.jdt.internal.core.SourceLambdaExpression((JavaElement) parentElement, expression).getMethod();
					newElement = LambdaFactory.createLambdaExpression((JavaElement) parentElement, expression).getMethod();
					knownScopes.put(scope, newElement);
					return newElement;
				}
				return parentElement;
			}
			IType parentType = (IType) createElement(scope.parent, elementPosition, unit, existingElements, knownScopes);
			MethodScope methodScope = (MethodScope) scope;
			if (methodScope.isInsideInitializer()) {
				// inside field or initializer, must find proper one
				TypeDeclaration type = methodScope.referenceType();
				int occurenceCount = 1;
				int length = type.fields == null ? 0 : type.fields.length;
				for (int i = 0; i < length; i++) {
					FieldDeclaration field = type.fields[i];
					if (field.declarationSourceStart <= elementPosition && elementPosition <= field.declarationSourceEnd) {
						switch (field.getKind()) {
							case AbstractVariableDeclaration.FIELD :
							case AbstractVariableDeclaration.ENUM_CONSTANT :
								newElement = parentType.getField(new String(field.name));
								break;
							case AbstractVariableDeclaration.INITIALIZER :
								newElement = parentType.getInitializer(occurenceCount);
								break;
						}
						break;
					} else if (field.getKind() == AbstractVariableDeclaration.INITIALIZER) {
						occurenceCount++;
					}
				}
			} else {
				// method element
				AbstractMethodDeclaration method = methodScope.referenceMethod();
				newElement = parentType.getMethod(new String(method.selector), Util.typeParameterSignatures(method));
				if (newElement != null) {
					knownScopes.put(scope, newElement);
				}
			}
			break;
		case Scope.BLOCK_SCOPE :
			// standard block, no element per se
			newElement = createElement(scope.parent, elementPosition, unit, existingElements, knownScopes);
			break;
	}
	return newElement;
}