蓝色天空.知识 · 实践 · 创造
我的收藏
在线代码实验室

运行 Eclipse 透视图生命周期、子菜单定制、另存为序列化与 Java/Debug 视图对比离线核验

PYTHONWindows x64、CPython 3.12.14、Playwright 与本地浏览器/标准库。explore-perspectives.py
explore-perspectives.py124 行
"""Offline Eclipse Perspective lifecycle, customization & serialization verifier for Ch07 (perspectives)."""
import json
import xml.etree.ElementTree as ET

VERSION = "CPython 3.12.14 offline Eclipse perspective-layout verifier (desktop Eclipse SWT GUI absent)"


def check(name, summary, expected, actual):
    return {
        "name": name,
        "summary": summary,
        "expected": expected,
        "actual": actual,
        "passed": actual == expected,
    }


def main():
    cases = []

    # Case 1: Perspective open, single-active switching, and close lifecycle
    opened = ["Java"]
    active = "Java"
    # Open Debug perspective
    opened.append("Debug")
    active = "Debug"
    # Switch back to Java
    active = "Java"
    # Close Debug perspective
    opened.remove("Debug")
    cases.append(
        check(
            "perspective_lifecycle_and_single_active",
            "Verify default Java perspective, opening Debug, single-active constraint, switching, and closing",
            {
                "default_perspective": "Java",
                "active_after_switch": "Java",
                "remaining_opened": ["Java"],
            },
            {
                "default_perspective": "Java",
                "active_after_switch": active,
                "remaining_opened": opened,
            },
        )
    )

    # Case 2: Customize Perspective submenus (New, Show Views, Open Perspective)
    submenus = {
        "New": ["Java Project", "Package", "Class", "Interface", "XML File"],
        "Show Views": ["Package Explorer", "Outline", "Console", "Problems"],
        "Open Perspective": ["Java", "Debug", "Git"],
    }
    submenus["New"].append("JUnit Test Case")
    submenus["Show Views"].remove("Outline")
    cases.append(
        check(
            "customize_perspective_submenus",
            "Verify customizing New, Show Views, and Open Perspective submenu entries",
            {
                "submenu_groups": ["New", "Open Perspective", "Show Views"],
                "has_junit_in_new": True,
                "outline_hidden": True,
            },
            {
                "submenu_groups": sorted(submenus.keys()),
                "has_junit_in_new": "JUnit Test Case" in submenus["New"],
                "outline_hidden": "Outline" not in submenus["Show Views"],
            },
        )
    )

    # Case 3: Save Perspective As... XML serialization and reload
    root = ET.Element("perspective", {"id": "custom.java.compact", "label": "Java Compact"})
    views_el = ET.SubElement(root, "views")
    for vid in ("org.eclipse.jdt.ui.PackageExplorer", "org.eclipse.ui.console.ConsoleView"):
        ET.SubElement(views_el, "view", {"id": vid})
    xml_bytes = ET.tostring(root, encoding="utf-8")
    reloaded = ET.fromstring(xml_bytes)
    reloaded_views = [v.attrib["id"] for v in reloaded.findall("views/view")]
    cases.append(
        check(
            "save_perspective_as_serialization",
            "Serialize custom perspective descriptor via Save Perspective As and reload cleanly",
            {
                "label": "Java Compact",
                "view_count": 2,
                "first_view": "org.eclipse.jdt.ui.PackageExplorer",
            },
            {
                "label": reloaded.attrib["label"],
                "view_count": len(reloaded_views),
                "first_view": reloaded_views[0],
            },
        )
    )

    # Case 4: Java vs Debug perspective view composition with shared editor area
    java_views = {"Package Explorer", "Outline", "Problems", "Console"}
    debug_views = {"Debug", "Variables", "Breakpoints", "Console"}
    shared_editors = ["OrderService.java", "App.java"]
    cases.append(
        check(
            "java_vs_debug_perspective_layout",
            "Compare Java and Debug perspective default view sets while confirming shared editor preservation",
            {
                "common_views": ["Console"],
                "debug_only_count": 3,
                "shared_editors_preserved": 2,
            },
            {
                "common_views": sorted(java_views & debug_views),
                "debug_only_count": len(debug_views - java_views),
                "shared_editors_preserved": len(shared_editors),
            },
        )
    )

    print(json.dumps({"version": VERSION, "cases": cases}, ensure_ascii=False, indent=2))


if __name__ == "__main__":
    main()
本例需在 Windows x64、CPython 3.12.14、Playwright 与本地浏览器/标准库。 中运行,请复制源码、保存文件或下载工程包后在本地执行验证。
运行说明与环境独立工程

运行环境:Windows x64、CPython 3.12.14、Playwright 与本地浏览器/标准库。

入口文件:projects/eclipse-perspectives-lab/explore-perspectives.py

本地运行步骤快速上手
  1. 点击上方“保存源码”保存为 explore-perspectives.py,或下载右侧课程工程包。
  2. 确认本地已准备 Windows x64、CPython 3.12.14、Playwright 与本地浏览器/标准库。。
  3. 按对应章节命令执行,结合正文核对实际输出。
附件与关联工程包下载

下载课程关联工程包:Eclipse

课程关联工程包(登记关联35章) · 含当前章节或实例 · mbskycom202612a2259.zip

下载课程关联工程包:Eclipse

课程关联工程包(登记关联1章) · 含当前章节或实例 · mbskycom202612a2281.zip
SITE SEARCH

搜索教程、工具与资讯

热门搜索

JavaScriptJSON格式化正则表达式AI 编程AI 翻译AI导航专题标签
Esc 关闭

欢迎登录蓝色天空网

使用会员账号,继续你的学习