Search in sources :

Example 26 with Label

use of com.googlecode.lanterna.gui2.Label in project jodd by oblac.

the class ProxyAspectData method readAdviceData.

// ---------------------------------------------------------------- read
/**
	 * Parse advice class to gather some advice data. Should be called before any advice use.
	 * Must be called only *once* per advice.
	 */
private void readAdviceData() {
    if (ready) {
        return;
    }
    adviceClassReader.accept(new EmptyClassVisitor() {

        /**
			 * Stores advice reference.
			 */
        @Override
        public void visit(int version, int access, String name, String signature, String superName, String[] interfaces) {
            adviceReference = name;
            super.visit(version, access, name, signature, superName, interfaces);
        }

        /**
			 * Prevents advice to have inner classes.
			 */
        @Override
        public void visitInnerClass(String name, String outerName, String innerName, int access) {
            if (outerName.equals(adviceReference)) {
                throw new ProxettaException("Proxetta doesn't allow inner classes in/for advice: " + advice.getName());
            }
            super.visitInnerClass(name, outerName, innerName, access);
        }

        /**
			 * Clones advices fields to destination.
			 */
        @Override
        public FieldVisitor visitField(int access, String name, String desc, String signature, Object value) {
            // [A5]
            wd.dest.visitField(access, adviceFieldName(name, aspectIndex), desc, signature, value);
            return super.visitField(access, name, desc, signature, value);
        }

        /**
			 * Copies advices methods to destination.
			 */
        @Override
        public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) {
            if (name.equals(CLINIT)) {
                // [A6]
                if (!desc.equals(DESC_VOID)) {
                    throw new ProxettaException("Invalid static initialization block description for advice: " + advice.getName());
                }
                name = clinitMethodName + methodDivider + aspectIndex;
                access |= AsmUtil.ACC_PRIVATE | AsmUtil.ACC_FINAL;
                wd.addAdviceClinitMethod(name);
                return new MethodAdapter(wd.dest.visitMethod(access, name, desc, signature, exceptions)) {

                    @Override
                    public void visitLocalVariable(String name, String desc, String signature, Label start, Label end, int index) {
                    }

                    @Override
                    public void visitLineNumber(int line, Label start) {
                    }

                    @Override
                    public void visitMethodInsn(int opcode, String owner, String name, String desc, boolean isInterface) {
                        if (opcode == INVOKESTATIC) {
                            if (owner.equals(adviceReference)) {
                                owner = wd.thisReference;
                                name = adviceMethodName(name, aspectIndex);
                            }
                        }
                        super.visitMethodInsn(opcode, owner, name, desc, isInterface);
                    }

                    @Override
                    public void visitFieldInsn(int opcode, String owner, String name, String desc) {
                        // [F6]
                        if (owner.equals(adviceReference)) {
                            // [F5]
                            owner = wd.thisReference;
                            name = adviceFieldName(name, aspectIndex);
                        }
                        super.visitFieldInsn(opcode, owner, name, desc);
                    }
                };
            } else if (name.equals(INIT)) {
                // [A7]
                if (!desc.equals(DESC_VOID)) {
                    throw new ProxettaException("Advices can have only default constructors. Invalid advice: " + advice.getName());
                }
                name = initMethodName + methodDivider + aspectIndex;
                access = ProxettaAsmUtil.makePrivateFinalAccess(access);
                wd.addAdviceInitMethod(name);
                return new MethodAdapter(wd.dest.visitMethod(access, name, desc, signature, exceptions)) {

                    @Override
                    public void visitLocalVariable(String name, String desc, String signature, Label start, Label end, int index) {
                    }

                    @Override
                    public void visitLineNumber(int line, Label start) {
                    }

                    // used to detect and to ignore the first super call()
                    int state;

                    @Override
                    public void visitVarInsn(int opcode, int var) {
                        // [F7]
                        if ((state == 0) && (opcode == ALOAD) && (var == 0)) {
                            state++;
                            return;
                        }
                        super.visitVarInsn(opcode, var);
                    }

                    @Override
                    public void visitMethodInsn(int opcode, String owner, String name, String desc, boolean isInterface) {
                        if ((state == 1) && (opcode == INVOKESPECIAL)) {
                            state++;
                            return;
                        }
                        if ((opcode == INVOKEVIRTUAL) || (opcode == INVOKEINTERFACE)) {
                            if (owner.equals(adviceReference)) {
                                owner = wd.thisReference;
                                name = adviceMethodName(name, aspectIndex);
                            }
                        } else if (opcode == INVOKESTATIC) {
                            if (owner.equals(adviceReference)) {
                                owner = wd.thisReference;
                                name = adviceMethodName(name, aspectIndex);
                            }
                        }
                        super.visitMethodInsn(opcode, owner, name, desc, isInterface);
                    }

                    @Override
                    public void visitFieldInsn(int opcode, String owner, String name, String desc) {
                        // [F7]
                        if (owner.equals(adviceReference)) {
                            // [F5]
                            owner = wd.thisReference;
                            name = adviceFieldName(name, aspectIndex);
                        }
                        super.visitFieldInsn(opcode, owner, name, desc);
                    }
                };
            } else // other methods
            if (!name.equals(executeMethodName)) {
                name = adviceMethodName(name, aspectIndex);
                return new MethodAdapter(wd.dest.visitMethod(access, name, desc, signature, exceptions)) {

                    @Override
                    public void visitLocalVariable(String name, String desc, String signature, Label start, Label end, int index) {
                    }

                    @Override
                    public void visitLineNumber(int line, Label start) {
                    }

                    @Override
                    public void visitMethodInsn(int opcode, String owner, String name, String desc, boolean isInterface) {
                        if ((opcode == INVOKEVIRTUAL) || (opcode == INVOKEINTERFACE)) {
                            if (owner.equals(adviceReference)) {
                                owner = wd.thisReference;
                                name = adviceMethodName(name, aspectIndex);
                            }
                        } else if (opcode == INVOKESTATIC || opcode == INVOKESPECIAL) {
                            if (owner.equals(adviceReference)) {
                                owner = wd.thisReference;
                                name = adviceMethodName(name, aspectIndex);
                            }
                        }
                        super.visitMethodInsn(opcode, owner, name, desc, isInterface);
                    }

                    @Override
                    public void visitFieldInsn(int opcode, String owner, String name, String desc) {
                        // replace field references
                        if (owner.equals(adviceReference)) {
                            owner = wd.thisReference;
                            name = adviceFieldName(name, aspectIndex);
                        }
                        super.visitFieldInsn(opcode, owner, name, desc);
                    }
                };
            }
            //return new MethodAdapter(new EmptyMethodVisitor()) {		// toask may we replace this with the following code?
            return new EmptyMethodVisitor() {

                @Override
                public void visitVarInsn(int opcode, int var) {
                    if (isStoreOpcode(opcode)) {
                        if (var > maxLocalVarOffset) {
                            // find max local var offset
                            maxLocalVarOffset = var;
                        }
                    }
                    super.visitVarInsn(opcode, var);
                }
            };
        //					return super.visitMethod(access, name, desc, signature, exceptions);
        }
    }, 0);
    // increment offset by 2 because var on last index may be a dword value
    maxLocalVarOffset += 2;
    ready = true;
}
Also used : ProxettaException(jodd.proxetta.ProxettaException) Label(jodd.asm5.Label) FieldVisitor(jodd.asm5.FieldVisitor) EmptyClassVisitor(jodd.asm.EmptyClassVisitor) EmptyMethodVisitor(jodd.asm.EmptyMethodVisitor) MethodVisitor(jodd.asm5.MethodVisitor) MethodAdapter(jodd.asm.MethodAdapter) EmptyMethodVisitor(jodd.asm.EmptyMethodVisitor)

Example 27 with Label

use of com.googlecode.lanterna.gui2.Label in project intellij-community by JetBrains.

the class AdvancedEnhancer method emitMethods.

private void emitMethods(final ClassEmitter ce, Map<Method, MethodInfo> methodMap, final Map<Method, Method> covariantMethods) {
    CallbackGenerator[] generators = CallbackInfo.getGenerators(callbackTypes);
    Map<MethodInfo, MethodInfo> covariantInfoMap = new HashMap<>();
    for (Method method : methodMap.keySet()) {
        final Method delegate = covariantMethods.get(method);
        if (delegate != null) {
            covariantInfoMap.put(methodMap.get(method), ReflectUtils.getMethodInfo(delegate, delegate.getModifiers()));
        }
    }
    BridgeMethodGenerator bridgeMethodGenerator = new BridgeMethodGenerator(covariantInfoMap);
    Map<CallbackGenerator, List<MethodInfo>> groups = new HashMap<>();
    final Map<MethodInfo, Integer> indexes = new HashMap<>();
    final Map<MethodInfo, Integer> originalModifiers = new HashMap<>();
    final Map positions = CollectionUtils.getIndexMap(new ArrayList<>(methodMap.values()));
    for (Method actualMethod : methodMap.keySet()) {
        MethodInfo method = methodMap.get(actualMethod);
        int index = filter.accept(actualMethod);
        if (index >= callbackTypes.length) {
            throw new IllegalArgumentException("Callback filter returned an index that is too large: " + index);
        }
        originalModifiers.put(method, (actualMethod != null) ? actualMethod.getModifiers() : method.getModifiers());
        indexes.put(method, index);
        final CallbackGenerator generator = covariantMethods.containsKey(actualMethod) ? bridgeMethodGenerator : generators[index];
        List<MethodInfo> group = groups.get(generator);
        if (group == null) {
            groups.put(generator, group = new ArrayList<>(methodMap.size()));
        }
        group.add(method);
    }
    CodeEmitter se = ce.getStaticHook();
    se.new_instance(THREAD_LOCAL);
    se.dup();
    se.invoke_constructor(THREAD_LOCAL, CSTRUCT_NULL);
    se.putfield(THREAD_CALLBACKS_FIELD);
    CallbackGenerator.Context context = new CallbackGenerator.Context() {

        public ClassLoader getClassLoader() {
            return AdvancedEnhancer.this.getClassLoader();
        }

        public int getOriginalModifiers(MethodInfo method) {
            return originalModifiers.get(method);
        }

        public int getIndex(MethodInfo method) {
            return indexes.get(method);
        }

        public void emitCallback(CodeEmitter e, int index) {
            emitCurrentCallback(e, index);
        }

        public Signature getImplSignature(MethodInfo method) {
            return rename(method.getSignature(), (Integer) positions.get(method));
        }

        @Override
        public void emitInvoke(CodeEmitter codeEmitter, MethodInfo methodInfo) {
            codeEmitter.super_invoke(methodInfo.getSignature());
        }

        public CodeEmitter beginMethod(ClassEmitter ce, MethodInfo method) {
            CodeEmitter e = EmitUtils.begin_method(ce, method);
            if (!interceptDuringConstruction && !TypeUtils.isAbstract(method.getModifiers())) {
                $Label constructed = e.make_label();
                e.load_this();
                e.getfield(CONSTRUCTED_FIELD);
                e.if_jump(e.NE, constructed);
                e.load_this();
                e.load_args();
                e.super_invoke();
                e.return_value();
                e.mark(constructed);
            }
            return e;
        }
    };
    Set<CallbackGenerator> seenGen = new HashSet<>();
    for (int i = 0; i < callbackTypes.length + 1; i++) {
        CallbackGenerator gen = i == callbackTypes.length ? bridgeMethodGenerator : generators[i];
        if (!seenGen.contains(gen)) {
            seenGen.add(gen);
            final List<MethodInfo> fmethods = groups.get(gen);
            if (fmethods != null) {
                try {
                    gen.generate(ce, context, fmethods);
                    gen.generateStatic(se, context, fmethods);
                } catch (RuntimeException x) {
                    throw x;
                } catch (Exception x) {
                    throw new CodeGenerationException(x);
                }
            }
        }
    }
    se.return_value();
    se.end_method();
}
Also used : Method(java.lang.reflect.Method) InvocationTargetException(java.lang.reflect.InvocationTargetException) net.sf.cglib.asm.$Label(net.sf.cglib.asm.$Label)

Example 28 with Label

use of com.googlecode.lanterna.gui2.Label in project intellij-community by JetBrains.

the class AdvancedEnhancer method emitCurrentCallback.

private static void emitCurrentCallback(CodeEmitter e, int index) {
    e.load_this();
    e.getfield(getCallbackField(index));
    e.dup();
    $Label end = e.make_label();
    e.ifnonnull(end);
    // stack height
    e.pop();
    e.load_this();
    e.invoke_static_this(BIND_CALLBACKS);
    e.load_this();
    e.getfield(getCallbackField(index));
    e.mark(end);
}
Also used : net.sf.cglib.asm.$Label(net.sf.cglib.asm.$Label)

Example 29 with Label

use of com.googlecode.lanterna.gui2.Label in project sirix by sirixdb.

the class AbstractSunburstGUI method style.

/**
 * Style menu.
 */
protected void style() {
    final Group ctrl = mControlP5.addGroup("menu", 15, 25, 35);
    ctrl.setColorLabel(mParent.color(255));
    ctrl.setColorBackground(mParent.color(100));
    ctrl.close();
    mParent.colorMode(PConstants.RGB, 255, 255, 255);
    final int backgroundColor = 0x99ffffff;
    int i = 0;
    for (final Slider slider : mSliders) {
        slider.setGroup(ctrl);
        slider.setId(i);
        final Label label = slider.getCaptionLabel();
        label.toUpperCase(true);
        label.setColor(mParent.color(0));
        label.setColorBackground(backgroundColor);
        final ControllerStyle style = label.getStyle();
        style.padding(4, 0, 1, 3);
        style.marginTop = -4;
        style.marginLeft = 0;
        style.marginRight = -14;
        slider.plugTo(mControl);
        i++;
    }
    i = 0;
    for (final Range range : mRanges) {
        range.setGroup(ctrl);
        range.setId(i);
        final Label label = range.getCaptionLabel();
        label.toUpperCase(true);
        label.setColor(mParent.color(0));
        label.setColorBackground(backgroundColor);
        final ControllerStyle style = label.getStyle();
        style.padding(4, 0, 1, 3);
        style.marginTop = -4;
        range.plugTo(mControl);
        i++;
    }
    i = 0;
    for (final Toggle toggle : mToggles) {
        toggle.setGroup(ctrl);
        toggle.setId(i);
        final Label label = toggle.getCaptionLabel();
        label.setColor(mParent.color(0));
        label.setColorBackground(backgroundColor);
        final ControllerStyle style = label.getStyle();
        style.padding(4, 3, 1, 3);
        style.marginTop = -19;
        style.marginLeft = 18;
        style.marginRight = 5;
        toggle.plugTo(mControl);
        i++;
    }
    mParent.colorMode(PConstants.HSB, 360, 100, 100);
    mParent.textLeading(14);
    mParent.textAlign(PConstants.LEFT, PConstants.TOP);
    mParent.cursor(PConstants.CROSS);
}
Also used : Group(controlP5.Group) ControllerStyle(controlP5.ControllerStyle) Slider(controlP5.Slider) Toggle(controlP5.Toggle) Label(controlP5.Label) Range(controlP5.Range)

Example 30 with Label

use of com.googlecode.lanterna.gui2.Label in project googleads-java-lib by googleads.

the class CreateLabels method runExample.

/**
 * Runs the example.
 *
 * @param adManagerServices the services factory.
 * @param session the session.
 * @throws ApiException if the API request failed with one or more service errors.
 * @throws RemoteException if the API request failed due to other errors.
 */
public static void runExample(AdManagerServices adManagerServices, AdManagerSession session) throws RemoteException {
    // Get the LabelService.
    LabelServiceInterface labelService = adManagerServices.get(session, LabelServiceInterface.class);
    // Create a competitive exclusion label.
    Label competitiveExclusionLabel = new Label();
    competitiveExclusionLabel.setName("Car company label #" + new Random().nextInt(Integer.MAX_VALUE));
    competitiveExclusionLabel.setTypes(new LabelType[] { LabelType.COMPETITIVE_EXCLUSION });
    // Create an ad unit frequency cap label.
    Label adUnitFrequencyCapLabel = new Label();
    adUnitFrequencyCapLabel.setName("Don't run too often label #" + new Random().nextInt(Integer.MAX_VALUE));
    adUnitFrequencyCapLabel.setTypes(new LabelType[] { LabelType.AD_UNIT_FREQUENCY_CAP });
    // Create the labels on the server.
    Label[] labels = labelService.createLabels(new Label[] { competitiveExclusionLabel, adUnitFrequencyCapLabel });
    for (Label createdLabel : labels) {
        System.out.printf("A label with ID %d and name '%s' was created.%n", createdLabel.getId(), createdLabel.getName());
    }
}
Also used : Random(java.util.Random) LabelServiceInterface(com.google.api.ads.admanager.axis.v202108.LabelServiceInterface) Label(com.google.api.ads.admanager.axis.v202108.Label)

Aggregations

Label (org.apache.xbean.asm9.Label)9 MethodVisitor (org.apache.xbean.asm9.MethodVisitor)7 Label (com.google.api.ads.admanager.axis.v202108.Label)5 LabelServiceInterface (com.google.api.ads.admanager.axis.v202108.LabelServiceInterface)5 Label (com.google.api.ads.admanager.axis.v202111.Label)5 LabelServiceInterface (com.google.api.ads.admanager.axis.v202111.LabelServiceInterface)5 Label (com.google.api.ads.admanager.axis.v202202.Label)5 LabelServiceInterface (com.google.api.ads.admanager.axis.v202202.LabelServiceInterface)5 Label (com.google.api.ads.admanager.axis.v202205.Label)5 LabelServiceInterface (com.google.api.ads.admanager.axis.v202205.LabelServiceInterface)5 StatementBuilder (com.google.api.ads.admanager.axis.utils.v202108.StatementBuilder)4 StatementBuilder (com.google.api.ads.admanager.axis.utils.v202111.StatementBuilder)4 StatementBuilder (com.google.api.ads.admanager.axis.utils.v202202.StatementBuilder)4 StatementBuilder (com.google.api.ads.admanager.axis.utils.v202205.StatementBuilder)4 LabelPage (com.google.api.ads.admanager.axis.v202108.LabelPage)4 LabelPage (com.google.api.ads.admanager.axis.v202111.LabelPage)4 LabelPage (com.google.api.ads.admanager.axis.v202202.LabelPage)4 LabelPage (com.google.api.ads.admanager.axis.v202205.LabelPage)4 ArrayList (java.util.ArrayList)4 Random (java.util.Random)4