Java Code Examples for org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants#AccNative

The following examples show how to use org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants#AccNative . 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: ASTNode.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
public static StringBuffer printModifiers(int modifiers, StringBuffer output) {

		if ((modifiers & ClassFileConstants.AccPublic) != 0)
			output.append("public "); //$NON-NLS-1$
		if ((modifiers & ClassFileConstants.AccPrivate) != 0)
			output.append("private "); //$NON-NLS-1$
		if ((modifiers & ClassFileConstants.AccProtected) != 0)
			output.append("protected "); //$NON-NLS-1$
		if ((modifiers & ClassFileConstants.AccStatic) != 0)
			output.append("static "); //$NON-NLS-1$
		if ((modifiers & ClassFileConstants.AccFinal) != 0)
			output.append("final "); //$NON-NLS-1$
		if ((modifiers & ClassFileConstants.AccSynchronized) != 0)
			output.append("synchronized "); //$NON-NLS-1$
		if ((modifiers & ClassFileConstants.AccVolatile) != 0)
			output.append("volatile "); //$NON-NLS-1$
		if ((modifiers & ClassFileConstants.AccTransient) != 0)
			output.append("transient "); //$NON-NLS-1$
		if ((modifiers & ClassFileConstants.AccNative) != 0)
			output.append("native "); //$NON-NLS-1$
		if ((modifiers & ClassFileConstants.AccAbstract) != 0)
			output.append("abstract "); //$NON-NLS-1$
		if ((modifiers & ExtraCompilerModifiers.AccDefaultMethod) != 0)
			output.append("default "); //$NON-NLS-1$
		return output;
	}
 
Example 2
Source File: SyntheticMethodBinding.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Construct a bridge method
 */
public SyntheticMethodBinding(MethodBinding overridenMethodToBridge, MethodBinding targetMethod, SourceTypeBinding declaringClass) {

    this.declaringClass = declaringClass;
    this.selector = overridenMethodToBridge.selector;
    // amongst other, clear the AccGenericSignature, so as to ensure no remains of original inherited persist (101794)
    // also use the modifiers from the target method, as opposed to inherited one (147690)
    this.modifiers = (targetMethod.modifiers | ClassFileConstants.AccBridge | ClassFileConstants.AccSynthetic) & ~(ClassFileConstants.AccSynchronized | ClassFileConstants.AccAbstract | ClassFileConstants.AccNative  | ClassFileConstants.AccFinal | ExtraCompilerModifiers.AccGenericSignature);
	this.tagBits |= (TagBits.AnnotationResolved | TagBits.DeprecatedAnnotationResolved);
    this.returnType = overridenMethodToBridge.returnType;
    this.parameters = overridenMethodToBridge.parameters;
    this.thrownExceptions = overridenMethodToBridge.thrownExceptions;
    this.targetMethod = targetMethod;
    this.purpose = SyntheticMethodBinding.BridgeMethod;
	SyntheticMethodBinding[] knownAccessMethods = declaringClass.syntheticMethods();
	int methodId = knownAccessMethods == null ? 0 : knownAccessMethods.length;
	this.index = methodId;
}
 
Example 3
Source File: SyntheticMethodBinding.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
public SyntheticMethodBinding(MethodBinding overridenMethodToBridge, SourceTypeBinding declaringClass) {

	    this.declaringClass = declaringClass;
	    this.selector = overridenMethodToBridge.selector;
	    // amongst other, clear the AccGenericSignature, so as to ensure no remains of original inherited persist (101794)
	    this.modifiers = (overridenMethodToBridge.modifiers | ClassFileConstants.AccBridge | ClassFileConstants.AccSynthetic) & ~(ClassFileConstants.AccSynchronized | ClassFileConstants.AccAbstract | ClassFileConstants.AccNative  | ClassFileConstants.AccFinal | ExtraCompilerModifiers.AccGenericSignature);
		this.tagBits |= (TagBits.AnnotationResolved | TagBits.DeprecatedAnnotationResolved);
	    this.returnType = overridenMethodToBridge.returnType;
	    this.parameters = overridenMethodToBridge.parameters;
	    this.thrownExceptions = overridenMethodToBridge.thrownExceptions;
	    this.targetMethod = overridenMethodToBridge;
	    this.purpose = SyntheticMethodBinding.SuperMethodAccess;
		SyntheticMethodBinding[] knownAccessMethods = declaringClass.syntheticMethods();
		int methodId = knownAccessMethods == null ? 0 : knownAccessMethods.length;
		this.index = methodId;
	}
 
Example 4
Source File: Factory.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
private static void decodeModifiers(Set<Modifier> result, int modifiers, int[] checkBits) {
	if (checkBits == null) return;
	for (int i = 0, max = checkBits.length; i < max; i++) {
		switch(checkBits[i]) {
			case ClassFileConstants.AccPublic :
				appendModifier(result, modifiers, checkBits[i], Modifier.PUBLIC);
				break;
			case ClassFileConstants.AccProtected:
				appendModifier(result, modifiers, checkBits[i], Modifier.PROTECTED);
				break;
			case ClassFileConstants.AccPrivate :
				appendModifier(result, modifiers, checkBits[i], Modifier.PRIVATE);
				break;
			case ClassFileConstants.AccAbstract :
				appendModifier(result, modifiers, checkBits[i], Modifier.ABSTRACT);
				break;
			case ExtraCompilerModifiers.AccDefaultMethod :
				try {
					appendModifier(result, modifiers, checkBits[i], Modifier.valueOf("DEFAULT")); //$NON-NLS-1$
				} catch(IllegalArgumentException iae) {
					// Don't have JDK 1.8, just ignore and proceed.
				}
				break;
			case ClassFileConstants.AccStatic :
				appendModifier(result, modifiers, checkBits[i], Modifier.STATIC);
				break;
			case ClassFileConstants.AccFinal :
				appendModifier(result, modifiers, checkBits[i], Modifier.FINAL);
				break;
			case ClassFileConstants.AccSynchronized :
				appendModifier(result, modifiers, checkBits[i], Modifier.SYNCHRONIZED);
				break;
			case ClassFileConstants.AccNative :
				appendModifier(result, modifiers, checkBits[i], Modifier.NATIVE);
				break;
			case ClassFileConstants.AccStrictfp :
				appendModifier(result, modifiers, checkBits[i], Modifier.STRICTFP);
				break;
			case ClassFileConstants.AccTransient :
				appendModifier(result, modifiers, checkBits[i], Modifier.TRANSIENT);
				break;
			case ClassFileConstants.AccVolatile :
				appendModifier(result, modifiers, checkBits[i], Modifier.VOLATILE);
				break;
		}
	}
}
 
Example 5
Source File: AbstractMethodDeclaration.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
public boolean isNative() {

		if (this.binding != null)
			return this.binding.isNative();
		return (this.modifiers & ClassFileConstants.AccNative) != 0;
	}
 
Example 6
Source File: MethodBinding.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
public final boolean isNative() {
	return (this.modifiers & ClassFileConstants.AccNative) != 0;
}
 
Example 7
Source File: MethodScope.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Spec : 8.4.3 & 9.4
 */
private void checkAndSetModifiersForMethod(MethodBinding methodBinding) {
	int modifiers = methodBinding.modifiers;
	final ReferenceBinding declaringClass = methodBinding.declaringClass;
	if ((modifiers & ExtraCompilerModifiers.AccAlternateModifierProblem) != 0)
		problemReporter().duplicateModifierForMethod(declaringClass, (AbstractMethodDeclaration) this.referenceContext);

	// after this point, tests on the 16 bits reserved.
	int realModifiers = modifiers & ExtraCompilerModifiers.AccJustFlag;

	// set the requested modifiers for a method in an interface/annotation
	if (declaringClass.isInterface()) {
		int expectedModifiers = ClassFileConstants.AccPublic | ClassFileConstants.AccAbstract;
		boolean isDefaultMethod = (modifiers & ExtraCompilerModifiers.AccDefaultMethod) != 0; // no need to check validity, is done by the parser
		boolean reportIllegalModifierCombination = false;
		boolean isJDK18orGreater = false;
		if (compilerOptions().sourceLevel >= ClassFileConstants.JDK1_8 && !declaringClass.isAnnotationType()) {
			expectedModifiers |= ClassFileConstants.AccStrictfp
					| ExtraCompilerModifiers.AccDefaultMethod | ClassFileConstants.AccStatic;
			isJDK18orGreater = true;
			if (!methodBinding.isAbstract()) {
				reportIllegalModifierCombination = isDefaultMethod && methodBinding.isStatic();
			} else {
				reportIllegalModifierCombination = isDefaultMethod || methodBinding.isStatic();
				if (methodBinding.isStrictfp()) {
					problemReporter().illegalAbstractModifierCombinationForMethod((AbstractMethodDeclaration) this.referenceContext);
				}
			}
			if (reportIllegalModifierCombination) {
				problemReporter().illegalModifierCombinationForInterfaceMethod((AbstractMethodDeclaration) this.referenceContext);
			}
			// Kludge - The AccDefaultMethod bit is outside the lower 16 bits and got removed earlier. Putting it back.
			if (isDefaultMethod) {
				realModifiers |= ExtraCompilerModifiers.AccDefaultMethod;
			}
		}
		if ((realModifiers & ~expectedModifiers) != 0) {
			if ((declaringClass.modifiers & ClassFileConstants.AccAnnotation) != 0)
				problemReporter().illegalModifierForAnnotationMember((AbstractMethodDeclaration) this.referenceContext);
			else
				problemReporter().illegalModifierForInterfaceMethod((AbstractMethodDeclaration) this.referenceContext, isJDK18orGreater);
		}
		return;
	}

	// check for abnormal modifiers
	final int UNEXPECTED_MODIFIERS = ~(ClassFileConstants.AccPublic | ClassFileConstants.AccPrivate | ClassFileConstants.AccProtected
		| ClassFileConstants.AccAbstract | ClassFileConstants.AccStatic | ClassFileConstants.AccFinal | ClassFileConstants.AccSynchronized | ClassFileConstants.AccNative | ClassFileConstants.AccStrictfp);
	if ((realModifiers & UNEXPECTED_MODIFIERS) != 0) {
		problemReporter().illegalModifierForMethod((AbstractMethodDeclaration) this.referenceContext);
		modifiers &= ~ExtraCompilerModifiers.AccJustFlag | ~UNEXPECTED_MODIFIERS;
	}

	// check for incompatible modifiers in the visibility bits, isolate the visibility bits
	int accessorBits = realModifiers & (ClassFileConstants.AccPublic | ClassFileConstants.AccProtected | ClassFileConstants.AccPrivate);
	if ((accessorBits & (accessorBits - 1)) != 0) {
		problemReporter().illegalVisibilityModifierCombinationForMethod(declaringClass, (AbstractMethodDeclaration) this.referenceContext);

		// need to keep the less restrictive so disable Protected/Private as necessary
		if ((accessorBits & ClassFileConstants.AccPublic) != 0) {
			if ((accessorBits & ClassFileConstants.AccProtected) != 0)
				modifiers &= ~ClassFileConstants.AccProtected;
			if ((accessorBits & ClassFileConstants.AccPrivate) != 0)
				modifiers &= ~ClassFileConstants.AccPrivate;
		} else if ((accessorBits & ClassFileConstants.AccProtected) != 0 && (accessorBits & ClassFileConstants.AccPrivate) != 0) {
			modifiers &= ~ClassFileConstants.AccPrivate;
		}
	}

	// check for modifiers incompatible with abstract modifier
	if ((modifiers & ClassFileConstants.AccAbstract) != 0) {
		int incompatibleWithAbstract = ClassFileConstants.AccPrivate | ClassFileConstants.AccStatic | ClassFileConstants.AccFinal | ClassFileConstants.AccSynchronized | ClassFileConstants.AccNative | ClassFileConstants.AccStrictfp;
		if ((modifiers & incompatibleWithAbstract) != 0)
			problemReporter().illegalAbstractModifierCombinationForMethod(declaringClass, (AbstractMethodDeclaration) this.referenceContext);
		if (!methodBinding.declaringClass.isAbstract())
			problemReporter().abstractMethodInAbstractClass((SourceTypeBinding) declaringClass, (AbstractMethodDeclaration) this.referenceContext);
	}

	/* DISABLED for backward compatibility with javac (if enabled should also mark private methods as final)
	// methods from a final class are final : 8.4.3.3
	if (methodBinding.declaringClass.isFinal())
		modifiers |= AccFinal;
	*/
	// native methods cannot also be tagged as strictfp
	if ((modifiers & ClassFileConstants.AccNative) != 0 && (modifiers & ClassFileConstants.AccStrictfp) != 0)
		problemReporter().nativeMethodsCannotBeStrictfp(declaringClass, (AbstractMethodDeclaration) this.referenceContext);

	// static members are only authorized in a static member or top level type
	if (((realModifiers & ClassFileConstants.AccStatic) != 0) && declaringClass.isNestedType() && !declaringClass.isStatic())
		problemReporter().unexpectedStaticModifierForMethod(declaringClass, (AbstractMethodDeclaration) this.referenceContext);

	methodBinding.modifiers = modifiers;
}