Java Code Examples for org.eclipse.jdt.core.Flags#isAbstract()

The following examples show how to use org.eclipse.jdt.core.Flags#isAbstract() . 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: DialogFactoryHelperImpl.java    From jenerate with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public boolean isOverriddenInSuperclass(IType objectClass, String methodName, String[] methodParameterTypes,
        String originalClassFullyQualifiedName) throws JavaModelException {
    ITypeHierarchy typeHierarchy = objectClass.newSupertypeHierarchy(null);
    IType[] superclasses = typeHierarchy.getAllSuperclasses(objectClass);

    if (superclasses.length == 0) {
        return false;
    }

    for (IType superclass : superclasses) {
        if (superclass.getFullyQualifiedName().equals(originalClassFullyQualifiedName)) {
            return false;
        }

        IMethod method = methodFinder.findMethodWithNameAndParameters(superclass, methodName, methodParameterTypes);
        if (method != null) {
            return !Flags.isAbstract(method.getFlags());
        }
    }

    return false;
}
 
Example 2
Source File: NewTypeWizardPage.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Sets the modifiers.
 *
 * @param modifiers <code>F_PUBLIC</code>, <code>F_PRIVATE</code>,
 * <code>F_PROTECTED</code>, <code>F_ABSTRACT</code>, <code>F_FINAL</code>
 * or <code>F_STATIC</code> or a valid combination.
 * @param canBeModified if <code>true</code> the modifier fields are
 * editable; otherwise they are read-only
 * @see Flags
 */
public void setModifiers(int modifiers, boolean canBeModified) {
	if (Flags.isPublic(modifiers)) {
		fAccMdfButtons.setSelection(PUBLIC_INDEX, true);
	} else if (Flags.isPrivate(modifiers)) {
		fAccMdfButtons.setSelection(PRIVATE_INDEX, true);
	} else if (Flags.isProtected(modifiers)) {
		fAccMdfButtons.setSelection(PROTECTED_INDEX, true);
	} else {
		fAccMdfButtons.setSelection(DEFAULT_INDEX, true);
	}
	if (Flags.isAbstract(modifiers)) {
		fOtherMdfButtons.setSelection(ABSTRACT_INDEX, true);
	}
	if (Flags.isFinal(modifiers)) {
		fOtherMdfButtons.setSelection(FINAL_INDEX, true);
	}
	if (Flags.isStatic(modifiers)) {
		fOtherMdfButtons.setSelection(STATIC_INDEX, true);
	}

	fAccMdfButtons.setEnabled(canBeModified);
	fOtherMdfButtons.setEnabled(canBeModified);
}
 
Example 3
Source File: IJUnitMethodTester.java    From jdt-codemining with Eclipse Public License 1.0 5 votes vote down vote up
public static boolean isMethod(IMethod method, boolean onlyPublicMethod) {
	try {
		int flags = method.getFlags();
		if (onlyPublicMethod && !Flags.isPublic(flags)) {
			return false;
		}
		// 'V' is void signature
		return !(method.isConstructor() || Flags.isAbstract(flags) || Flags.isStatic(flags)
				|| !"V".equals(method.getReturnType()));
	} catch (JavaModelException e) {
		// ignore
		return false;
	}
}
 
Example 4
Source File: TypeMatchFilters.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public boolean accept(int modifiers, char[] packageName, char[] simpleTypeName,
		char[][] enclosingTypeNames, String path) {
	if (isInternalClass(simpleTypeName, enclosingTypeNames)) {
		return false;
	}
	return !Flags.isAbstract(modifiers) && !Flags.isInterface(modifiers);
}
 
Example 5
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 6
Source File: MoveInstanceMethodProcessor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Checks whether the instance method declaration is compatible with this
 * refactoring.
 *
 * @param monitor
 *            the progress monitor to display progress
 * @param status
 *            the status of the condition checking
 * @throws JavaModelException
 *             if the method does not exist
 */
protected void checkMethodDeclaration(final IProgressMonitor monitor, final RefactoringStatus status) throws JavaModelException {
	Assert.isNotNull(monitor);
	Assert.isNotNull(status);
	try {
		monitor.beginTask("", 5); //$NON-NLS-1$
		monitor.setTaskName(RefactoringCoreMessages.MoveInstanceMethodProcessor_checking);
		final int flags= fMethod.getFlags();
		if (Flags.isStatic(flags))
			status.merge(RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.MoveInstanceMethodProcessor_no_static_methods, JavaStatusContext.create(fMethod)));
		else if (Flags.isAbstract(flags))
			status.merge(RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.MoveInstanceMethodProcessor_single_implementation, JavaStatusContext.create(fMethod)));
		monitor.worked(1);
		if (Flags.isNative(flags))
			status.merge(RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.MoveInstanceMethodProcessor_no_native_methods, JavaStatusContext.create(fMethod)));
		monitor.worked(1);
		if (Flags.isSynchronized(flags))
			status.merge(RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.MoveInstanceMethodProcessor_no_synchronized_methods, JavaStatusContext.create(fMethod)));
		monitor.worked(1);
		if (fMethod.isConstructor())
			status.merge(RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.MoveInstanceMethodProcessor_no_constructors, JavaStatusContext.create(fMethod)));
		monitor.worked(1);
		if (fMethod.getDeclaringType().isAnnotation())
			status.merge(RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.MoveInstanceMethodProcessor_no_annotation, JavaStatusContext.create(fMethod)));
		else if (fMethod.getDeclaringType().isInterface() && !Flags.isDefaultMethod(flags))
			status.merge(RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.MoveInstanceMethodProcessor_no_interface, JavaStatusContext.create(fMethod)));
		monitor.worked(1);
	} finally {
		monitor.done();
	}
}
 
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: TypeNameMatchLabelProvider.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public static ImageDescriptor getImageDescriptor(TypeNameMatch typeRef, int flags) {
	if (isSet(SHOW_TYPE_CONTAINER_ONLY, flags)) {
		if (typeRef.getPackageName().equals(typeRef.getTypeContainerName()))
			return JavaPluginImages.DESC_OBJS_PACKAGE;

		// XXX cannot check outer type for interface efficiently (5887)
		return JavaPluginImages.DESC_OBJS_CLASS;

	} else if (isSet(SHOW_PACKAGE_ONLY, flags)) {
		return JavaPluginImages.DESC_OBJS_PACKAGE;
	} else {
		boolean isInner= typeRef.getTypeContainerName().indexOf('.') != -1;
		int modifiers= typeRef.getModifiers();

		ImageDescriptor desc= JavaElementImageProvider.getTypeImageDescriptor(isInner, false, modifiers, false);
		int adornmentFlags= 0;
		if (Flags.isFinal(modifiers)) {
			adornmentFlags |= JavaElementImageDescriptor.FINAL;
		}
		if (Flags.isAbstract(modifiers) && !Flags.isInterface(modifiers)) {
			adornmentFlags |= JavaElementImageDescriptor.ABSTRACT;
		}
		if (Flags.isStatic(modifiers)) {
			adornmentFlags |= JavaElementImageDescriptor.STATIC;
		}
		if (Flags.isDeprecated(modifiers)) {
			adornmentFlags |= JavaElementImageDescriptor.DEPRECATED;
		}

		return new JavaElementImageDescriptor(desc, adornmentFlags, JavaElementImageProvider.BIG_SIZE);
	}
}
 
Example 9
Source File: InterfaceIndicatorLabelDecorator.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private void addOverlaysFromFlags(int flags, IDecoration decoration) {
	ImageDescriptor type;
	if (Flags.isAnnotation(flags)) {
		type= JavaPluginImages.DESC_OVR_ANNOTATION;
	} else if (Flags.isEnum(flags)) {
		type= JavaPluginImages.DESC_OVR_ENUM;
	} else if (Flags.isInterface(flags)) {
		type= JavaPluginImages.DESC_OVR_INTERFACE;
	} else if (/* is class */ Flags.isAbstract(flags)) {
		type= JavaPluginImages.DESC_OVR_ABSTRACT_CLASS;
	} else {
		type= null;
	}
	
	boolean deprecated= Flags.isDeprecated(flags);
	boolean packageDefault= Flags.isPackageDefault(flags);
	
	/* Each decoration position can only be used once. Since we don't want to take all positions
	 * away from other decorators, we confine ourselves to only use the top right position. */
	
	if (type != null && !deprecated && !packageDefault) {
		decoration.addOverlay(type, IDecoration.TOP_RIGHT);
		
	} else if (type == null && deprecated && !packageDefault) {
		decoration.addOverlay(JavaPluginImages.DESC_OVR_DEPRECATED, IDecoration.TOP_RIGHT);
		
	} else if (type != null || deprecated || packageDefault) {
		decoration.addOverlay(new TypeIndicatorOverlay(type, deprecated, packageDefault), IDecoration.TOP_RIGHT);
	}
}
 
Example 10
Source File: ClassFinder.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
private boolean hasValidModifiers( IType type ) throws JavaModelException
{
	if ( Flags.isAbstract( type.getFlags( ) ) )
		return false;
	if ( !Flags.isPublic( type.getFlags( ) ) )
		return false;
	return true;
}
 
Example 11
Source File: AbstractMethodCorrectionProposal.java    From eclipse.jdt.ls with Eclipse Public License 2.0 4 votes vote down vote up
private MethodDeclaration getStub(ASTRewrite rewrite, ASTNode targetTypeDecl) throws CoreException {
	ImportRewriteContext context=new ContextSensitiveImportRewriteContext(targetTypeDecl, getImportRewrite());

	AST ast= targetTypeDecl.getAST();
	MethodDeclaration decl= ast.newMethodDeclaration();

	SimpleName newNameNode= getNewName(rewrite);

	decl.setConstructor(isConstructor());

	addNewModifiers(rewrite, targetTypeDecl, decl.modifiers());

	ArrayList<String> takenNames= new ArrayList<>();
	addNewTypeParameters(rewrite, takenNames, decl.typeParameters(), context);

	decl.setName(newNameNode);

	IVariableBinding[] declaredFields= fSenderBinding.getDeclaredFields();
	for (int i= 0; i < declaredFields.length; i++) { // avoid to take parameter names that are equal to field names
		takenNames.add(declaredFields[i].getName());
	}

	String bodyStatement= ""; //$NON-NLS-1$
	boolean isAbstractMethod= Modifier.isAbstract(decl.getModifiers()) || (fSenderBinding.isInterface() && !Modifier.isStatic(decl.getModifiers()) && !Modifier.isDefault(decl.getModifiers()));
	if (!isConstructor()) {
		Type returnType= getNewMethodType(rewrite, context);
		decl.setReturnType2(returnType);

		boolean isVoid= returnType instanceof PrimitiveType && PrimitiveType.VOID.equals(((PrimitiveType)returnType).getPrimitiveTypeCode());
		if (!isAbstractMethod && !isVoid) {
			ReturnStatement returnStatement= ast.newReturnStatement();
			returnStatement.setExpression(ASTNodeFactory.newDefaultExpression(ast, returnType, 0));
			bodyStatement= ASTNodes.asFormattedString(returnStatement, 0, String.valueOf('\n'), getCompilationUnit().getJavaProject().getOptions(true));
		}
	}

	addNewParameters(rewrite, takenNames, decl.parameters(), context);
	addNewExceptions(rewrite, decl.thrownExceptionTypes(), context);

	Block body= null;
	if (!isAbstractMethod && !Flags.isAbstract(decl.getModifiers())) {
		body= ast.newBlock();
		if (bodyStatement.length() > 0) {
			ReturnStatement todoNode = (ReturnStatement) rewrite.createStringPlaceholder(bodyStatement,
					ASTNode.RETURN_STATEMENT);
			body.statements().add(todoNode);
		}
	}
	decl.setBody(body);

	CodeGenerationSettings settings = PreferenceManager.getCodeGenerationSettings(getCompilationUnit().getResource());
	if (settings.createComments && !fSenderBinding.isAnonymous()) {
		String string = CodeGeneration.getMethodComment(getCompilationUnit(), fSenderBinding.getName(), decl, null,
				String.valueOf('\n'));
		if (string != null) {
			Javadoc javadoc= (Javadoc) rewrite.createStringPlaceholder(string, ASTNode.JAVADOC);
			decl.setJavadoc(javadoc);
		}
	}
	return decl;
}
 
Example 12
Source File: CompletionProposalLabelProvider.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Returns a version of <code>descriptor</code> decorated according to
 * the passed <code>modifier</code> flags.
 *
 * @param descriptor the image descriptor to decorate
 * @param proposal the proposal
 * @return an image descriptor for a method proposal
 * @see Flags
 */
private ImageDescriptor decorateImageDescriptor(ImageDescriptor descriptor, CompletionProposal proposal) {
	int adornments= 0;
	int flags= proposal.getFlags();
	int kind= proposal.getKind();

	boolean deprecated= Flags.isDeprecated(flags);
	if (!deprecated) {
		CompletionProposal[] requiredProposals= proposal.getRequiredProposals();
		if (requiredProposals != null) {
			for (int i= 0; i < requiredProposals.length; i++) {
				CompletionProposal requiredProposal= requiredProposals[i];
				if (requiredProposal.getKind() == CompletionProposal.TYPE_REF) {
					deprecated |= Flags.isDeprecated(requiredProposal.getFlags());
				}
			}
		}
	}
	if (deprecated)
		adornments |= JavaElementImageDescriptor.DEPRECATED;

	if (kind == CompletionProposal.FIELD_REF || kind == CompletionProposal.METHOD_DECLARATION || kind == CompletionProposal.METHOD_NAME_REFERENCE
			|| kind == CompletionProposal.METHOD_REF || kind == CompletionProposal.CONSTRUCTOR_INVOCATION)
		if (Flags.isStatic(flags))
			adornments |= JavaElementImageDescriptor.STATIC;

	if (kind == CompletionProposal.METHOD_DECLARATION || kind == CompletionProposal.METHOD_NAME_REFERENCE || kind == CompletionProposal.METHOD_REF
			|| kind == CompletionProposal.CONSTRUCTOR_INVOCATION)
		if (Flags.isSynchronized(flags))
			adornments |= JavaElementImageDescriptor.SYNCHRONIZED;
	if (kind == CompletionProposal.METHOD_DECLARATION || kind == CompletionProposal.METHOD_NAME_REFERENCE || kind == CompletionProposal.METHOD_REF)
		if (Flags.isDefaultMethod(flags))
			adornments|= JavaElementImageDescriptor.DEFAULT_METHOD;
	if (kind == CompletionProposal.ANNOTATION_ATTRIBUTE_REF)
		if (Flags.isAnnnotationDefault(flags))
			adornments|= JavaElementImageDescriptor.ANNOTATION_DEFAULT;

	if (kind == CompletionProposal.TYPE_REF && Flags.isAbstract(flags) && !Flags.isInterface(flags))
		adornments |= JavaElementImageDescriptor.ABSTRACT;

	if (kind == CompletionProposal.FIELD_REF) {
		if (Flags.isFinal(flags))
			adornments |= JavaElementImageDescriptor.FINAL;
		if (Flags.isTransient(flags))
			adornments |= JavaElementImageDescriptor.TRANSIENT;
		if (Flags.isVolatile(flags))
			adornments |= JavaElementImageDescriptor.VOLATILE;
	}

	return new JavaElementImageDescriptor(descriptor, adornments, JavaElementImageProvider.SMALL_SIZE);
}
 
Example 13
Source File: HierarchyLabelProvider.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
private ImageDescriptor getTypeImageDescriptor(IType type) {
	ITypeHierarchy hierarchy= fHierarchy.getHierarchy();
	if (hierarchy == null) {
		return new JavaElementImageDescriptor(JavaPluginImages.DESC_OBJS_CLASS, 0, JavaElementImageProvider.BIG_SIZE);
	}

	int flags= hierarchy.getCachedFlags(type);
	if (flags == -1) {
		return new JavaElementImageDescriptor(JavaPluginImages.DESC_OBJS_CLASS, 0, JavaElementImageProvider.BIG_SIZE);
	}

	boolean isInterface= Flags.isInterface(flags);
	IType declaringType= type.getDeclaringType();
	boolean isInner= declaringType != null;
	boolean isInInterfaceOrAnnotation= false;
	if (isInner) {
		int declaringTypeFlags= hierarchy.getCachedFlags(declaringType);
		if (declaringTypeFlags != -1) {
			isInInterfaceOrAnnotation= Flags.isInterface(declaringTypeFlags);
		} else {
			// declaring type is not in hierarchy, so we have to pay the price for resolving here
			try {
				isInInterfaceOrAnnotation= declaringType.isInterface();
			} catch (JavaModelException e) {
			}
		}
	}

	ImageDescriptor desc= JavaElementImageProvider.getTypeImageDescriptor(isInner, isInInterfaceOrAnnotation, flags, isInDifferentHierarchyScope(type));

	int adornmentFlags= 0;
	if (Flags.isFinal(flags)) {
		adornmentFlags |= JavaElementImageDescriptor.FINAL;
	}
	if (Flags.isAbstract(flags) && !isInterface) {
		adornmentFlags |= JavaElementImageDescriptor.ABSTRACT;
	}
	if (Flags.isStatic(flags)) {
		adornmentFlags |= JavaElementImageDescriptor.STATIC;
	}
	if (Flags.isDeprecated(flags)) {
		adornmentFlags |= JavaElementImageDescriptor.DEPRECATED;
	}

	return new JavaElementImageDescriptor(desc, adornmentFlags, JavaElementImageProvider.BIG_SIZE);
}
 
Example 14
Source File: ContentAssistHistory.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
private boolean isCacheableRHS(IType type) throws JavaModelException {
	return !type.isInterface() && !Flags.isAbstract(type.getFlags());
}
 
Example 15
Source File: NewTypeWizardPage.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 3 votes vote down vote up
/**
 * Hook method that gets called when the modifiers have changed. The method validates
 * the modifiers and returns the status of the validation.
 * <p>
 * Subclasses may extend this method to perform their own validation.
 * </p>
 *
 * @return the status of the validation
 */
protected IStatus modifiersChanged() {
	StatusInfo status= new StatusInfo();
	int modifiers= getModifiers();
	if (Flags.isFinal(modifiers) && Flags.isAbstract(modifiers)) {
		status.setError(NewWizardMessages.NewTypeWizardPage_error_ModifiersFinalAndAbstract);
	}
	return status;
}