Java Code Examples for org.eclipse.jdt.core.Flags#AccProtected

The following examples show how to use org.eclipse.jdt.core.Flags#AccProtected . 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: SelfEncapsulateFieldRefactoring.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public RefactoringStatus checkInitialConditions(IProgressMonitor pm) throws CoreException {
	if (fVisibility < 0)
		fVisibility= (fField.getFlags() & (Flags.AccPublic | Flags.AccProtected | Flags.AccPrivate));
	RefactoringStatus result=  new RefactoringStatus();
	result.merge(Checks.checkAvailability(fField));
	if (result.hasFatalError())
		return result;
	fRoot= new RefactoringASTParser(ASTProvider.SHARED_AST_LEVEL).parse(fField.getCompilationUnit(), true, pm);
	ISourceRange sourceRange= fField.getNameRange();
	ASTNode node= NodeFinder.perform(fRoot, sourceRange.getOffset(), sourceRange.getLength());
	if (node == null) {
		return mappingErrorFound(result, node);
	}
	fFieldDeclaration= (VariableDeclarationFragment)ASTNodes.getParent(node, VariableDeclarationFragment.class);
	if (fFieldDeclaration == null) {
		return mappingErrorFound(result, node);
	}
	if (fFieldDeclaration.resolveBinding() == null) {
		if (!processCompilerError(result, node))
			result.addFatalError(RefactoringCoreMessages.SelfEncapsulateField_type_not_resolveable);
		return result;
	}
	computeUsedNames();
	return result;
}
 
Example 2
Source File: SelfEncapsulateFieldInputPage.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private Object[] createData(int visibility) {
	String pub= RefactoringMessages.SelfEncapsulateFieldInputPage_public;
	String pro= RefactoringMessages.SelfEncapsulateFieldInputPage_protected;
	String def= RefactoringMessages.SelfEncapsulateFieldInputPage_default;
	String priv= RefactoringMessages.SelfEncapsulateFieldInputPage_private;

	String[] labels= null;
	Integer[] data= null;
	if (Flags.isPrivate(visibility)) {
		labels= new String[] { pub, pro, def, priv };
		data= new Integer[] {new Integer(Flags.AccPublic), new Integer(Flags.AccProtected), new Integer(0), new Integer(Flags.AccPrivate) };
	} else if (Flags.isProtected(visibility)) {
		labels= new String[] { pub, pro };
		data= new Integer[] {new Integer(Flags.AccPublic), new Integer(Flags.AccProtected)};
	} else {
		labels= new String[] { pub, def };
		data= new Integer[] {new Integer(Flags.AccPublic), new Integer(0)};
	}
	return new Object[] {labels, data};
}
 
Example 3
Source File: XbaseImages.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
protected int toFlags(JvmVisibility visibility) {
	switch (visibility) {
		case PRIVATE:
			return Flags.AccPrivate;
		case PROTECTED:
			return Flags.AccProtected;
		case PUBLIC:
			return Flags.AccPublic;
		default:
			return Flags.AccDefault;
	}
}
 
Example 4
Source File: XbaseImages2.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
protected int toFlags(JvmVisibility visibility) {
	switch (visibility) {
		case PRIVATE:
			return Flags.AccPrivate;
		case PROTECTED:
			return Flags.AccProtected;
		case PUBLIC:
			return Flags.AccPublic;
		default:
			return Flags.AccDefault;
	}
}
 
Example 5
Source File: SelfEncapsulateFieldRefactoring.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public RefactoringStatus checkInitialConditions(IProgressMonitor pm) throws CoreException {
	if (fVisibility < 0) {
		fVisibility = (fField.getFlags() & (Flags.AccPublic | Flags.AccProtected | Flags.AccPrivate));
	}
	RefactoringStatus result = new RefactoringStatus();
	result.merge(Checks.checkAvailability(fField));
	if (result.hasFatalError()) {
		return result;
	}
	fRoot = new RefactoringASTParser(IASTSharedValues.SHARED_AST_LEVEL).parse(fField.getCompilationUnit(), true, pm);
	ISourceRange sourceRange = fField.getNameRange();
	ASTNode node = NodeFinder.perform(fRoot, sourceRange.getOffset(), sourceRange.getLength());
	if (node == null) {
		return mappingErrorFound(result, node);
	}
	fFieldDeclaration = ASTNodes.getParent(node, VariableDeclarationFragment.class);
	if (fFieldDeclaration == null) {
		return mappingErrorFound(result, node);
	}
	if (fFieldDeclaration.resolveBinding() == null) {
		if (!processCompilerError(result, node)) {
			result.addFatalError(RefactoringCoreMessages.SelfEncapsulateField_type_not_resolveable);
		}
		return result;
	}
	computeUsedNames();
	return result;
}
 
Example 6
Source File: MemberVisibilityAdjustor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Converts a given modifier keyword into a visibility flag.
 *
 * @param keyword the keyword to convert
 * @return the visibility flag
 */
private static int keywordToVisibility(final ModifierKeyword keyword) {
	int visibility= 0;
	if (keyword == ModifierKeyword.PUBLIC_KEYWORD)
		visibility= Flags.AccPublic;
	else if (keyword == ModifierKeyword.PRIVATE_KEYWORD)
		visibility= Flags.AccPrivate;
	else if (keyword == ModifierKeyword.PROTECTED_KEYWORD)
		visibility= Flags.AccProtected;
	return visibility;
}
 
Example 7
Source File: XbaseReferenceProposalCreator.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
protected Image computeImage(JvmFeature feature) {
	int flags = 0;
	int decorator = 0;
	switch(feature.getVisibility()) {
		case PUBLIC: flags = Flags.AccPublic; break;
		case PROTECTED: flags = Flags.AccProtected; break;
		case PRIVATE: flags = Flags.AccPrivate; break;
		case DEFAULT: flags = Flags.AccDefault; break;
	}
	JvmDeclaredType declaringType = feature.getDeclaringType();
	boolean interfaceOrAnnotation = false;
	if (declaringType instanceof JvmGenericType) {
		interfaceOrAnnotation = ((JvmGenericType) declaringType).isInterface();
	} else if (declaringType instanceof JvmAnnotationType) {
		interfaceOrAnnotation = true;
	}
	if (feature instanceof JvmConstructor) {
		decorator = JavaElementImageDescriptor.CONSTRUCTOR;
		if (declaringType.isAbstract()) {
			flags |= Flags.AccAbstract;
			decorator |= JavaElementImageDescriptor.ABSTRACT;
		}
		return computeConstructorImage(declaringType.getDeclaringType() != null, interfaceOrAnnotation, flags, decorator);
	} else if (feature instanceof JvmOperation) {
		JvmOperation operation = (JvmOperation) feature;
		if (operation.isStatic()) {
			flags |= Flags.AccStatic;
			decorator |= JavaElementImageDescriptor.STATIC;
		}
		if (operation.isAbstract()) {
			flags |= Flags.AccAbstract;
			decorator |= JavaElementImageDescriptor.ABSTRACT;
		}
		if (operation.isFinal()) {
			flags |= Flags.AccFinal;
			decorator |= JavaElementImageDescriptor.FINAL;
		}
		return computeMethodImage(interfaceOrAnnotation, flags, decorator);
	} else if (feature instanceof JvmField) {
		JvmField field = (JvmField) feature;
		if (field.isStatic()) {
			flags |= Flags.AccStatic;
			decorator |= JavaElementImageDescriptor.STATIC;
		}
		if (field.isFinal()) {
			flags |= Flags.AccFinal;
			decorator |= JavaElementImageDescriptor.FINAL;
		}
		if (declaringType instanceof JvmEnumerationType)
			flags |= Flags.AccEnum;
		return computeFieldImage(interfaceOrAnnotation, flags, decorator);
	} 
	return null;
}
 
Example 8
Source File: JdtTypesProposalProvider.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
/**
 * Compute the JVM modifiers that corresponds to the given description.
 *
 * <p>This function fixes the issue related to the missed modifiers given to the content assist.
 *
 * @param context the current content assist context.
 * @param description the description.
 * @return the JVM modifiers.
 * @since 2.11
 */
protected int getDirtyStateModifiers(ContentAssistContext context, IEObjectDescription description) {
	EObject eobject = description.getEObjectOrProxy();
	if (eobject.eIsProxy()) {
		eobject = EcoreUtil.resolve(eobject, context.getResource().getResourceSet());
	}
	int accessModifiers = Flags.AccPublic;
	int otherModifiers = 0;
	if (eobject instanceof JvmMember) {
		final JvmMember member = (JvmMember) eobject;
		switch (member.getVisibility()) {
		case PUBLIC:
			accessModifiers = Flags.AccPublic;
			break;
		case PRIVATE:
			accessModifiers = Flags.AccPrivate;
			break;
		case PROTECTED:
			accessModifiers = Flags.AccProtected;
			break;
		case DEFAULT:
		default:
			accessModifiers = Flags.AccDefault;
			break;
		}
		if (DeprecationUtil.isDeprecated(member)) {
			otherModifiers |= Flags.AccDeprecated;
		}
		if (eobject instanceof JvmDeclaredType) {
			final JvmDeclaredType type = (JvmDeclaredType) eobject;
			if (type.isFinal()) {
				otherModifiers |= Flags.AccFinal;
			}
			if (type.isAbstract()) {
				otherModifiers |= Flags.AccAbstract;
			}
			if (type.isStatic()) {
				otherModifiers |= Flags.AccStatic;
			}
			if (type instanceof JvmEnumerationType) {
                otherModifiers |= Flags.AccEnum;
            } else  if (type instanceof JvmAnnotationType) {
                otherModifiers |= Flags.AccAnnotation;
            } else if (type instanceof JvmGenericType) {
                if (((JvmGenericType) type).isInterface()) {
                    otherModifiers |= Flags.AccInterface;
                }
            }
		}
	}
	return accessModifiers | otherModifiers;
}