Java Code Examples for org.apache.bcel.classfile.Method#getAccessFlags()

The following examples show how to use org.apache.bcel.classfile.Method#getAccessFlags() . 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: UnreadFields.java    From spotbugs with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Override
public void visit(Method obj) {
    if (DEBUG) {
        System.out.println("Checking " + getClassName() + "." + obj.getName());
    }
    if (Const.CONSTRUCTOR_NAME.equals(getMethodName()) && (obj.isPublic() || obj.isProtected())) {
        publicOrProtectedConstructor = true;
    }
    pendingGetField = null;
    saState = 0;
    super.visit(obj);
    int flags = obj.getAccessFlags();
    if ((flags & Const.ACC_NATIVE) != 0) {
        hasNativeMethods = true;
    }
}
 
Example 2
Source File: UselessSubclassMethod.java    From spotbugs with GNU Lesser General Public License v2.1 6 votes vote down vote up
@SuppressWarnings("PMD.SimplifyBooleanReturns")
private boolean differentAttributes(Method m1, Method m2) {
    if (m1.getAnnotationEntries().length > 0 || m2.getAnnotationEntries().length > 0) {
        return true;
    }
    int access1 = m1.getAccessFlags()
            & (Const.ACC_PRIVATE | Const.ACC_PROTECTED | Const.ACC_PUBLIC | Const.ACC_FINAL);
    int access2 = m2.getAccessFlags()
            & (Const.ACC_PRIVATE | Const.ACC_PROTECTED | Const.ACC_PUBLIC | Const.ACC_FINAL);


    m1.getAnnotationEntries();
    if (access1 != access2) {
        return true;
    }
    if (!thrownExceptions(m1).equals(thrownExceptions(m2))) {
        return false;
    }
    return false;
}
 
Example 3
Source File: FindReturnRef.java    From spotbugs with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Override
public void visit(Method obj) {
    check = publicClass && (obj.getAccessFlags() & (Const.ACC_PUBLIC)) != 0;
    if (!check) {
        return;
    }
    staticMethod = (obj.getAccessFlags() & (Const.ACC_STATIC)) != 0;
    // variableNames = obj.getLocalVariableTable();
    parameterCount = getNumberMethodArguments();

    if (!staticMethod) {
        parameterCount++;
    }

    thisOnTOS = false;
    fieldOnTOS = false;
    super.visit(obj);
    thisOnTOS = false;
    fieldOnTOS = false;
}
 
Example 4
Source File: FindUnsyncGet.java    From spotbugs with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public void visit(Method obj) {
    int flags = obj.getAccessFlags();
    if ((flags & doNotConsider) != 0) {
        return;
    }
    String name = obj.getName();
    boolean isSynchronized = (flags & Const.ACC_SYNCHRONIZED) != 0;
    /*
     * String sig = obj.getSignature(); char firstArg = sig.charAt(1); char
     * returnValue = sig.charAt(1 + sig.indexOf(')')); boolean firstArgIsRef
     * = (firstArg == 'L') || (firstArg == '['); boolean returnValueIsRef =
     * (returnValue == 'L') || (returnValue == '[');
     *
     * System.out.println(className + "." + name + " " + firstArgIsRef + " "
     * + returnValueIsRef + " " + isSynchronized + " " + isNative );
     */
    if (name.startsWith("get") && !isSynchronized
    // && returnValueIsRef
    ) {
        getMethods.put(name.substring(3), MethodAnnotation.fromVisitedMethod(this));
    } else if (name.startsWith("set") && isSynchronized
    // && firstArgIsRef
    ) {
        setMethods.put(name.substring(3), MethodAnnotation.fromVisitedMethod(this));
    }
}
 
Example 5
Source File: FindUnrelatedTypesInGenericContainer.java    From spotbugs with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Methods marked with the "Synthetic" attribute do not appear in the source
 * code
 */
private boolean isSynthetic(Method m) {
    if ((m.getAccessFlags() & Const.ACC_SYNTHETIC) != 0) {
        return true;
    }
    Attribute[] attrs = m.getAttributes();
    for (Attribute attr : attrs) {
        if (attr instanceof Synthetic) {
            return true;
        }
    }
    return false;
}
 
Example 6
Source File: FindFinalizeInvocations.java    From spotbugs with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public void visit(Method obj) {
    if (DEBUG) {
        System.out.println("FFI: visiting " + getFullyQualifiedMethodName());
    }
    if ("finalize".equals(getMethodName()) && "()V".equals(getMethodSig()) && (obj.getAccessFlags() & (Const.ACC_PUBLIC)) != 0) {
        bugReporter
                .reportBug(new BugInstance(this, "FI_PUBLIC_SHOULD_BE_PROTECTED", NORMAL_PRIORITY).addClassAndMethod(this));
    }
}
 
Example 7
Source File: UselessSubclassMethod.java    From spotbugs with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public void visitMethod(Method obj) {
    if ((interfaceMethods != null) && ((obj.getAccessFlags() & Const.ACC_ABSTRACT) != 0)) {
        String curDetail = obj.getName() + obj.getSignature();
        for (String infMethodDetail : interfaceMethods) {
            if (curDetail.equals(infMethodDetail)) {
                bugReporter.reportBug(new BugInstance(this, "USM_USELESS_ABSTRACT_METHOD", LOW_PRIORITY).addClassAndMethod(
                        getClassContext().getJavaClass(), obj));
            }
        }
    }
    super.visitMethod(obj);
}
 
Example 8
Source File: ClassContext.java    From spotbugs with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Look up the Method represented by given MethodGen.
 *
 * @param methodGen
 *            a MethodGen
 * @return the Method represented by the MethodGen
 */
public Method getMethod(MethodGen methodGen) {
    Method[] methodList = jclass.getMethods();
    for (Method method : methodList) {
        if (method.getName().equals(methodGen.getName()) && method.getSignature().equals(methodGen.getSignature())
                && method.getAccessFlags() == methodGen.getAccessFlags()) {
            return method;
        }
    }
    return null;
}
 
Example 9
Source File: MethodGen.java    From commons-bcel with Apache License 2.0 4 votes vote down vote up
/**
 * Instantiate from existing method.
 *
 * @param method method
 * @param className class name containing this method
 * @param cp constant pool
 */
public MethodGen(final Method method, final String className, final ConstantPoolGen cp) {
    this(method.getAccessFlags(), Type.getReturnType(method.getSignature()),
        Type.getArgumentTypes(method.getSignature()), null /* may be overridden anyway */
        , method.getName(), className,
        ((method.getAccessFlags() & (Const.ACC_ABSTRACT | Const.ACC_NATIVE)) == 0)
            ? new InstructionList(getByteCodes(method))
            : null,
        cp);
    final Attribute[] attributes = method.getAttributes();
    for (final Attribute attribute : attributes) {
        Attribute a = attribute;
        if (a instanceof Code) {
            final Code c = (Code) a;
            setMaxStack(c.getMaxStack());
            setMaxLocals(c.getMaxLocals());
            final CodeException[] ces = c.getExceptionTable();
            if (ces != null) {
                for (final CodeException ce : ces) {
                    final int type = ce.getCatchType();
                    ObjectType c_type = null;
                    if (type > 0) {
                        final String cen = method.getConstantPool().getConstantString(type, Const.CONSTANT_Class);
                        c_type = ObjectType.getInstance(cen);
                    }
                    final int end_pc = ce.getEndPC();
                    final int length = getByteCodes(method).length;
                    InstructionHandle end;
                    if (length == end_pc) { // May happen, because end_pc is exclusive
                        end = il.getEnd();
                    } else {
                        end = il.findHandle(end_pc);
                        end = end.getPrev(); // Make it inclusive
                    }
                    addExceptionHandler(il.findHandle(ce.getStartPC()), end, il.findHandle(ce.getHandlerPC()),
                        c_type);
                }
            }
            final Attribute[] c_attributes = c.getAttributes();
            for (final Attribute c_attribute : c_attributes) {
                a = c_attribute;
                if (a instanceof LineNumberTable) {
                    final LineNumber[] ln = ((LineNumberTable) a).getLineNumberTable();
                    for (final LineNumber l : ln) {
                        final InstructionHandle ih = il.findHandle(l.getStartPC());
                        if (ih != null) {
                            addLineNumber(ih, l.getLineNumber());
                        }
                    }
                } else if (a instanceof LocalVariableTable) {
                    updateLocalVariableTable((LocalVariableTable) a);
                } else if (a instanceof LocalVariableTypeTable) {
                    this.localVariableTypeTable = (LocalVariableTypeTable) a.copy(cp.getConstantPool());
                } else {
                    addCodeAttribute(a);
                }
            }
        } else if (a instanceof ExceptionTable) {
            final String[] names = ((ExceptionTable) a).getExceptionNames();
            for (final String name2 : names) {
                addException(name2);
            }
        } else if (a instanceof Annotations) {
            final Annotations runtimeAnnotations = (Annotations) a;
            final AnnotationEntry[] aes = runtimeAnnotations.getAnnotationEntries();
            for (final AnnotationEntry element : aes) {
                addAnnotationEntry(new AnnotationEntryGen(element, cp, false));
            }
        } else {
            addAttribute(a);
        }
    }
}
 
Example 10
Source File: MethodsGeneralPane.java    From ApkToolPlus with Apache License 2.0 4 votes vote down vote up
public void actionPerformed(ActionEvent event) {
	if (event.getSource() == addButton) {
		Method method = new Method();
		if (staticCB.isSelected()) {
			method.isStatic(true);
		}
		if (finalCB.isSelected()) {
			method.isFinal(true);
		}
		if (synchronizedCB.isSelected()) {
			method.isSynchronized(true);
		}
		if (nativeCB.isSelected()) {
			method.isNative(true);
		}
		if (abstractCB.isSelected()) {
			method.isAbstract(true);
		}
		if (strictCB.isSelected()) {
			method.isStrictfp(true);
		}
		int selectedItem = dropdown.getSelectedIndex();

		switch (selectedItem) {
		case 1:
			method.isPublic(true);
			break;
		case 2:
			method.isPrivate(true);
			break;
		case 3:
			method.isProtected(true);
			break;
		}

		String fileName = internalFrame.getFileName();
		int accessFlags = method.getAccessFlags();
		String methodName = name.getText();
		String methodDescriptor = descriptor.getText();
		ClassSaver classSaver = new ClassSaver(ClassSaver.ADD_METHOD, fileName,accessFlags, 
				methodName, methodDescriptor);
		ProgressDialog progressDialog = new ProgressDialog(
				internalFrame.getParentFrame(), null,
				"Adding method...");
		progressDialog.setRunnable(classSaver);
		progressDialog.setVisible(true);
		if (classSaver.exceptionOccured()) {
			ErrorReportWindow er = new ErrorReportWindow(internalFrame
					.getParentFrame(), classSaver.getExceptionVerbose(), "Adding method failed");

			er.pack();
			GUIHelper.centerOnParentWindow(er, internalFrame
					.getParentFrame());
			er.setVisible(true);
		} else {

			internalFrame.getParentFrame().doReload();
		}

	}

}
 
Example 11
Source File: helloify.java    From commons-bcel with Apache License 2.0 4 votes vote down vote up
/**
 * Patch a method.
 */
private static Method helloifyMethod(Method m) {
    final Code code = m.getCode();
    final int flags = m.getAccessFlags();
    final String name = m.getName();

    // Sanity check
    if (m.isNative() || m.isAbstract() || (code == null)) {
        return m;
    }

    // Create instruction list to be inserted at method start.
    final String mesg = "Hello from " + Utility.methodSignatureToString(m.getSignature(),
            name,
            Utility.accessToString(flags));
    final InstructionList patch = new InstructionList();
    patch.append(new GETSTATIC(out));
    patch.append(new PUSH(cp, mesg));
    patch.append(new INVOKEVIRTUAL(println));

    final MethodGen mg = new MethodGen(m, class_name, cp);
    final InstructionList il = mg.getInstructionList();
    final InstructionHandle[] ihs = il.getInstructionHandles();

    if (name.equals("<init>")) { // First let the super or other constructor be called
        for (int j = 1; j < ihs.length; j++) {
            if (ihs[j].getInstruction() instanceof INVOKESPECIAL) {
                il.append(ihs[j], patch); // Should check: method name == "<init>"
                break;
            }
        }
    } else {
        il.insert(ihs[0], patch);
    }

    // Stack size must be at least 2, since the println method takes 2 argument.
    if (code.getMaxStack() < 2) {
        mg.setMaxStack(2);
    }

    m = mg.getMethod();

    il.dispose(); // Reuse instruction handles

    return m;
}
 
Example 12
Source File: Hierarchy.java    From spotbugs with GNU Lesser General Public License v2.1 4 votes vote down vote up
@Override
public boolean choose(JavaClassAndMethod javaClassAndMethod) {
    Method method = javaClassAndMethod.getMethod();
    int accessFlags = method.getAccessFlags();
    return accessFlagsAreConcrete(accessFlags);
}
 
Example 13
Source File: FindNullDeref.java    From spotbugs with GNU Lesser General Public License v2.1 4 votes vote down vote up
private void analyzeMethod(ClassContext classContext, Method method) throws DataflowAnalysisException, CFGBuilderException {
    if (DEBUG || DEBUG_NULLARG) {
        System.out.println("Pre FND ");
    }

    if ((method.getAccessFlags() & Const.ACC_BRIDGE) != 0) {
        return;
    }

    MethodGen methodGen = classContext.getMethodGen(method);

    if (methodGen == null) {
        return;
    }
    if (!checkedDatabases) {
        checkDatabases();
        checkedDatabases = true;
    }

    XMethod xMethod = XFactory.createXMethod(classContext.getJavaClass(), method);

    ClassDescriptor junitTestAnnotation = DescriptorFactory.createClassDescriptor("org/junit/Test");
    AnnotationValue av = xMethod.getAnnotation(junitTestAnnotation);
    if (av != null) {
        Object value = av.getValue("expected");

        if (value instanceof Type) {
            String className = ((Type) value).getClassName();
            if ("java.lang.NullPointerException".equals(className)) {
                return;
            }
        }
    }

    // UsagesRequiringNonNullValues uses =
    // classContext.getUsagesRequiringNonNullValues(method);
    this.method = method;
    this.methodAnnotation = getMethodNullnessAnnotation();

    if (DEBUG || DEBUG_NULLARG) {
        System.out.println("FND: " + SignatureConverter.convertMethodSignature(methodGen));
    }

    this.previouslyDeadBlocks = findPreviouslyDeadBlocks();

    // Get the IsNullValueDataflow for the method from the ClassContext
    invDataflow = classContext.getIsNullValueDataflow(method);

    vnaDataflow = classContext.getValueNumberDataflow(method);

    // Create a NullDerefAndRedundantComparisonFinder object to do the
    // actual
    // work. It will call back to report null derefs and redundant null
    // comparisons
    // through the NullDerefAndRedundantComparisonCollector interface we
    // implement.
    NullDerefAndRedundantComparisonFinder worker = new NullDerefAndRedundantComparisonFinder(classContext, method, this);
    worker.execute();

    checkCallSitesAndReturnInstructions();

}
 
Example 14
Source File: CallToUnconditionalThrower.java    From spotbugs with GNU Lesser General Public License v2.1 4 votes vote down vote up
private void analyzeMethod(ClassContext classContext, Method method) throws CFGBuilderException, DataflowAnalysisException {
    if (BCELUtil.isSynthetic(method) || (method.getAccessFlags() & Const.ACC_BRIDGE) == Const.ACC_BRIDGE) {
        return;
    }
    CFG cfg = classContext.getCFG(method);

    ConstantPoolGen cpg = classContext.getConstantPoolGen();
    TypeDataflow typeDataflow = classContext.getTypeDataflow(method);

    for (Iterator<BasicBlock> i = cfg.blockIterator(); i.hasNext();) {
        BasicBlock basicBlock = i.next();

        // Check if it's a method invocation.
        if (!basicBlock.isExceptionThrower()) {
            continue;
        }
        InstructionHandle thrower = basicBlock.getExceptionThrower();
        Instruction ins = thrower.getInstruction();
        if (!(ins instanceof InvokeInstruction)) {
            continue;
        }

        InvokeInstruction inv = (InvokeInstruction) ins;
        boolean foundThrower = false;
        boolean foundNonThrower = false;

        if (inv instanceof INVOKEINTERFACE || inv instanceof INVOKEDYNAMIC) {
            continue;
        }

        String className = inv.getClassName(cpg);

        Location loc = new Location(thrower, basicBlock);
        TypeFrame typeFrame = typeDataflow.getFactAtLocation(loc);
        XMethod primaryXMethod = XFactory.createXMethod(inv, cpg);
        // if (primaryXMethod.isAbstract()) continue;
        Set<XMethod> targetSet = null;
        try {

            if (className.startsWith("[")) {
                continue;
            }
            String methodSig = inv.getSignature(cpg);
            if (!methodSig.endsWith("V")) {
                continue;
            }

            targetSet = Hierarchy2.resolveMethodCallTargets(inv, typeFrame, cpg);

            for (XMethod xMethod : targetSet) {
                if (DEBUG) {
                    System.out.println("\tFound " + xMethod);
                }

                boolean isUnconditionalThrower = xMethod.isUnconditionalThrower() && !xMethod.isUnsupported()
                        && !xMethod.isSynthetic();
                if (isUnconditionalThrower) {
                    foundThrower = true;
                    if (DEBUG) {
                        System.out.println("Found thrower");
                    }
                } else {
                    foundNonThrower = true;
                    if (DEBUG) {
                        System.out.println("Found non thrower");
                    }
                }

            }
        } catch (ClassNotFoundException e) {
            analysisContext.getLookupFailureCallback().reportMissingClass(e);
        }
        boolean newResult = foundThrower && !foundNonThrower;
        if (newResult) {
            bugReporter.reportBug(new BugInstance(this, "TESTING", Priorities.NORMAL_PRIORITY)
                    .addClassAndMethod(classContext.getJavaClass(), method)
                    .addString("Call to method that always throws Exception").addMethod(primaryXMethod)
                    .describe(MethodAnnotation.METHOD_CALLED).addSourceLine(classContext, method, loc));
        }

    }

}
 
Example 15
Source File: FindNakedNotify.java    From spotbugs with GNU Lesser General Public License v2.1 4 votes vote down vote up
@Override
public void visit(Method obj) {
    int flags = obj.getAccessFlags();
    synchronizedMethod = (flags & Const.ACC_SYNCHRONIZED) != 0;
}
 
Example 16
Source File: SerializableIdiom.java    From spotbugs with GNU Lesser General Public License v2.1 4 votes vote down vote up
@Override
public void visit(Method obj) {

    int accessFlags = obj.getAccessFlags();
    boolean isSynchronized = (accessFlags & Const.ACC_SYNCHRONIZED) != 0;
    if (Const.CONSTRUCTOR_NAME.equals(getMethodName()) && "()V".equals(getMethodSig()) && (accessFlags & Const.ACC_PUBLIC) != 0) {
        hasPublicVoidConstructor = true;
    }
    if (!Const.CONSTRUCTOR_NAME.equals(getMethodName()) && isSynthetic(obj)) {
        foundSynthetic = true;
        // System.out.println(methodName + isSynchronized);
    }

    if ("readExternal".equals(getMethodName()) && "(Ljava/io/ObjectInput;)V".equals(getMethodSig())) {
        sawReadExternal = true;
        if (DEBUG && !obj.isPrivate()) {
            System.out.println("Non-private readExternal method in: " + getDottedClassName());
        }
    } else if ("writeExternal".equals(getMethodName()) && "(Ljava/io/Objectoutput;)V".equals(getMethodSig())) {
        sawWriteExternal = true;
        if (DEBUG && !obj.isPrivate()) {
            System.out.println("Non-private writeExternal method in: " + getDottedClassName());
        }
    } else if ("readResolve".equals(getMethodName()) && getMethodSig().startsWith("()") && isSerializable) {
        sawReadResolve = true;
        if (!"()Ljava/lang/Object;".equals(getMethodSig())) {
            bugReporter.reportBug(new BugInstance(this, "SE_READ_RESOLVE_MUST_RETURN_OBJECT", HIGH_PRIORITY)
                    .addClassAndMethod(this));
        } else if (obj.isStatic()) {
            bugReporter.reportBug(new BugInstance(this, "SE_READ_RESOLVE_IS_STATIC", HIGH_PRIORITY).addClassAndMethod(this));
        } else if (obj.isPrivate()) {
            try {
                Set<ClassDescriptor> subtypes = AnalysisContext.currentAnalysisContext().getSubtypes2()
                        .getSubtypes(getClassDescriptor());
                if (subtypes.size() > 1) {
                    BugInstance bug = new BugInstance(this, "SE_PRIVATE_READ_RESOLVE_NOT_INHERITED", NORMAL_PRIORITY)
                            .addClassAndMethod(this);
                    boolean nasty = false;
                    for (ClassDescriptor subclass : subtypes) {
                        if (!subclass.equals(getClassDescriptor())) {

                            XClass xSub = AnalysisContext.currentXFactory().getXClass(subclass);
                            if (xSub != null && xSub.findMethod("readResolve", "()Ljava/lang/Object;", false) == null
                                    && xSub.findMethod("writeReplace", "()Ljava/lang/Object;", false) == null) {
                                bug.addClass(subclass).describe(ClassAnnotation.SUBCLASS_ROLE);
                                nasty = true;
                            }
                        }
                    }
                    if (nasty) {
                        bug.setPriority(HIGH_PRIORITY);
                    } else if (!getThisClass().isPublic()) {
                        bug.setPriority(LOW_PRIORITY);
                    }
                    bugReporter.reportBug(bug);
                }

            } catch (ClassNotFoundException e) {
                bugReporter.reportMissingClass(e);
            }
        }

    } else if ("readObject".equals(getMethodName()) && "(Ljava/io/ObjectInputStream;)V".equals(getMethodSig())
            && isSerializable) {
        sawReadObject = true;
        if (!obj.isPrivate()) {
            bugReporter.reportBug(new BugInstance(this, "SE_METHOD_MUST_BE_PRIVATE", isExternalizable ? NORMAL_PRIORITY : HIGH_PRIORITY)
                    .addClassAndMethod(this));
        }

    } else if ("readObjectNoData".equals(getMethodName()) && "()V".equals(getMethodSig()) && isSerializable) {

        if (!obj.isPrivate()) {
            bugReporter.reportBug(new BugInstance(this, "SE_METHOD_MUST_BE_PRIVATE", isExternalizable ? NORMAL_PRIORITY : HIGH_PRIORITY)
                    .addClassAndMethod(this));
        }

    } else if ("writeObject".equals(getMethodName()) && "(Ljava/io/ObjectOutputStream;)V".equals(getMethodSig())
            && isSerializable) {
        sawWriteObject = true;
        if (!obj.isPrivate()) {
            bugReporter.reportBug(new BugInstance(this, "SE_METHOD_MUST_BE_PRIVATE", isExternalizable ? NORMAL_PRIORITY : HIGH_PRIORITY)
                    .addClassAndMethod(this));
        }
    }

    if (isSynchronized) {
        if ("readObject".equals(getMethodName()) && "(Ljava/io/ObjectInputStream;)V".equals(getMethodSig()) && isSerializable) {
            bugReporter.reportBug(new BugInstance(this, "RS_READOBJECT_SYNC", isExternalizable ? LOW_PRIORITY : NORMAL_PRIORITY)
                    .addClassAndMethod(this));
        } else if ("writeObject".equals(getMethodName()) && "(Ljava/io/ObjectOutputStream;)V".equals(getMethodSig())
                && isSerializable) {
            writeObjectIsSynchronized = true;
        } else {
            foundSynchronizedMethods = true;
        }
    }
    super.visit(obj);

}
 
Example 17
Source File: FieldsGeneralPane.java    From ApkToolPlus with Apache License 2.0 4 votes vote down vote up
public void actionPerformed(ActionEvent event) {
	if (event.getSource() == addButton) {
		Method method = new Method();
		if (staticCB.isSelected()) {
			method.isStatic(true);
		}
		if (finalCB.isSelected()) {
			method.isFinal(true);
		}
		if (volatileCB.isSelected()) {
			method.isSynchronized(true);
		}
		if (transientCB.isSelected()) {
			method.isNative(true);
		}
		int selectedItem = dropdown.getSelectedIndex();

		switch (selectedItem) {
		case 1:
			method.isPublic(true);
			break;
		case 2:
			method.isPrivate(true);
			break;
		case 3:
			method.isProtected(true);
			break;
		}

		String fileName = internalFrame.getFileName();
		String fieldName = name.getText();
		String fieldDescriptor = descriptor.getText();
		int accessFlags = method.getAccessFlags();
		ClassSaver classSaver = new ClassSaver(ClassSaver.ADD_FIELD, fileName, fieldName, fieldDescriptor, accessFlags);
		ProgressDialog progressDialog = new ProgressDialog(
				internalFrame.getParentFrame(), null,
				"Adding interface...");
		progressDialog.setRunnable(classSaver);
		progressDialog.setVisible(true);
		if (classSaver.exceptionOccured()) {
			ErrorReportWindow er = new ErrorReportWindow(internalFrame
					.getParentFrame(), classSaver.getExceptionVerbose(), "Adding field failed");

			er.pack();
			GUIHelper.centerOnParentWindow(er, internalFrame
					.getParentFrame());
			er.setVisible(true);
		} else {

			internalFrame.getParentFrame().doReload();
		}
	}

}
 
Example 18
Source File: XFactory.java    From spotbugs with GNU Lesser General Public License v2.1 3 votes vote down vote up
/**
 * Create an XMethod object from a BCEL Method.
 *
 * @param className
 *            the class to which the Method belongs
 * @param method
 *            the Method
 * @return an XMethod representing the Method
 */

public static XMethod createXMethod(String className, Method method) {
    String methodName = method.getName();
    String methodSig = method.getSignature();
    int accessFlags = method.getAccessFlags();

    return createXMethod(className, methodName, methodSig, accessFlags);
}