This commit is contained in:
2026-01-11 23:31:17 +00:00
parent 80cec51597
commit 77da48b6ad
504 changed files with 1923 additions and 1094 deletions

104
scripts/fix_all_constructors.py Executable file
View File

@@ -0,0 +1,104 @@
#!/usr/bin/env python3
"""
Fix all constructor declaration errors in Java files.
This script finds lowercase method names that should be constructors
and fixes them to use the proper class name.
"""
import re
import os
import sys
from pathlib import Path
def fix_constructors_in_file(file_path):
"""Fix constructor declarations in a single Java file."""
with open(file_path, 'r', encoding='utf-8', errors='ignore') as f:
content = f.read()
original_content = content
# Extract class name from the file
class_match = re.search(r'\bclass\s+(\w+)', content)
if not class_match:
return False
class_name = class_match.group(1)
# Pattern to find lowercase method declarations that look like constructors
# These have no return type and are at the class level
# Pattern: lowercase_identifier(parameters) {
pattern = r'\b([a-z]\w*)\s*\(([^)]*)\)\s*\{'
def replacer(match):
method_name = match.group(1)
params = match.group(2)
# Skip known keywords and common method names
skip_keywords = ['if', 'for', 'while', 'switch', 'catch', 'synchronized',
'assert', 'return', 'throw', 'try']
if method_name in skip_keywords:
return match.group(0)
# Look backwards to see if there's a type declaration (return type)
# If there is, it's a regular method, not a constructor
start_pos = match.start()
# Get 100 chars before to check context
context_start = max(0, start_pos - 100)
context = content[context_start:start_pos]
# Check if there's a type declaration right before (like "public void method(")
# Split by common boundaries
last_statement = context.split(';')[-1].split('}')[-1].strip()
# If there's a clear return type, skip it
if re.search(r'\b(void|int|boolean|String|double|float|long|byte|char|short)\s+$', last_statement):
return match.group(0)
# If it's a visibility modifier followed by lowercase, it's likely a constructor
if re.search(r'\b(public|private|protected)\s+$', last_statement):
return f'{class_name}({params}) {{'
# Check if it's at the start of the file (after class declaration)
# and has no return type
if not re.search(r'\w\s+$', last_statement):
# Likely a constructor
return f'{class_name}({params}) {{'
return match.group(0)
# Apply the fix
content = re.sub(pattern, replacer, content)
if content != original_content:
with open(file_path, 'w', encoding='utf-8') as f:
f.write(content)
return True
return False
def main():
# Get the source directory
script_dir = Path(__file__).parent
src_dir = script_dir.parent / 'app' / 'src' / 'main' / 'java'
if not src_dir.exists():
print(f"Error: Source directory not found: {src_dir}")
sys.exit(1)
# Find all Java files
java_files = list(src_dir.rglob('*.java'))
print(f"Found {len(java_files)} Java files")
fixed_count = 0
for java_file in java_files:
try:
if fix_constructors_in_file(java_file):
fixed_count += 1
print(f"Fixed: {java_file.relative_to(src_dir)}")
except Exception as e:
print(f"Error processing {java_file}: {e}")
print(f"\nFixed {fixed_count} files")
if __name__ == '__main__':
main()

View File

@@ -0,0 +1,110 @@
#!/usr/bin/env python3
"""
Fix constructor errors by reading the compilation output.
Finds files with "invalid method declaration; return type required"
and fixes the lowercase method to be a proper constructor.
"""
import re
import subprocess
from pathlib import Path
def get_class_name_from_file(file_path):
"""Extract the class name from a Java file."""
try:
with open(file_path, 'r', encoding='utf-8', errors='ignore') as f:
content = f.read()
# Look for class declaration
match = re.search(r'\b(public\s+|private\s+|protected\s+)?class\s+(\w+)', content)
if match:
return match.group(2)
except Exception as e:
print(f"Error reading {file_path}: {e}")
return None
def fix_constructor_at_line(file_path, line_num, class_name):
"""Fix a constructor error at a specific line."""
try:
with open(file_path, 'r', encoding='utf-8', errors='ignore') as f:
lines = f.readlines()
# Line numbers are 1-based
if line_num < 1 or line_num > len(lines):
return False
line = lines[line_num - 1]
# Pattern: lowercase_name(params) {
pattern = r'\b([a-z]\w*)\s*\('
match = re.search(pattern, line)
if match:
# Replace with class name
old_name = match.group(1)
new_line = line.replace(f'{old_name}(', f'{class_name}(', 1)
lines[line_num - 1] = new_line
with open(file_path, 'w', encoding='utf-8') as f:
f.writelines(lines)
return True
except Exception as e:
print(f"Error fixing {file_path}:{line_num}: {e}")
return False
def main():
# Compile and get errors
print("Running compilation to get errors...")
result = subprocess.run(
['./gradlew', ':app:compileJava', '--no-build-cache'],
cwd='/home/rewrich/Documents/GitHub/tustu',
capture_output=True,
text=True
)
output = result.stdout + result.stderr
# Parse errors: "invalid method declaration; return type required"
error_pattern = r'^(.+\.java):(\d+):\s*error:\s*invalid method declaration'
errors = []
for line in output.split('\n'):
match = re.match(error_pattern, line)
if match:
file_path = match.group(1)
line_num = int(match.group(2))
errors.append((file_path, line_num))
# Debug: show some lines
if not errors:
print("Debug: Checking output for errors...")
for line in output.split('\n'):
if 'error:' in line and '.java:' in line:
print(f"Error line: {line[:150]}")
if len([e for e in errors if e[0] in line]) < 5:
# Try to parse it differently
match2 = re.search(r'(/[^:]+\.java):(\d+):', line)
if match2:
file_path = match2.group(1)
line_num = int(match2.group(2))
errors.append((file_path, line_num))
print(f" Parsed: {file_path}:{line_num}")
print(f"Found {len(errors)} constructor errors")
# Fix each error
fixed_count = 0
for file_path, line_num in errors:
class_name = get_class_name_from_file(file_path)
if class_name:
if fix_constructor_at_line(file_path, line_num, class_name):
fixed_count += 1
print(f"Fixed: {file_path}:{line_num}")
print(f"\nFixed {fixed_count} constructor errors")
if __name__ == '__main__':
main()

45
scripts/fix_constructors.sh Executable file
View File

@@ -0,0 +1,45 @@
#!/bin/bash
# Fix all constructor errors by matching class names with lowercase method declarations
# Read the list of files from the compile error output
FILES=$(grep "error: invalid method declaration" /tmp/compile_output3.txt | sed 's/:.*error.*//' | sort -u)
count=0
for file in $FILES; do
if [ ! -f "$file" ]; then
continue
fi
# Extract class name from file
classname=$(basename "$file" .java)
# Find lines with lowercase method that looks like constructor
# Pattern: lowercase_name(params) {
# Replace with: ClassName(params) {
# Use awk to find and fix constructor declarations
awk -v classname="$classname" '
{
# Match lines like: lowercase_name(params) {
# But not lines with return types like: void lowercase_name(params) {
if (match($0, /^[[:space:]]*(public|private|protected)?[[:space:]]+([a-z][a-zA-Z0-9_]*)[[:space:]]*\(/)) {
# Extract the method name
line = $0
# Check if there is NO return type keyword before
if (!match($0, /[[:space:]]+(void|int|boolean|String|double|float|long|short|byte|char|Object|List|Map)[[:space:]]+[a-z]/)) {
# Replace lowercase method name with class name
gsub(/([[:space:]]+|^)(public|private|protected)?[[:space:]]+([a-z][a-zA-Z0-9_]*)[[:space:]]*\(/, "\\1\\2 " classname "(")
count++
}
}
print
}
' "$file" > "$file.tmp" && mv "$file.tmp" "$file"
if [ $? -eq 0 ]; then
((count++))
echo "Fixed: $file"
fi
done
echo "Processed $count files"

154
scripts/fix_simple.py Normal file
View File

@@ -0,0 +1,154 @@
#!/usr/bin/env python3
"""
Simple constructor fixer - reads file list and fixes lowercase constructors.
"""
import re
from pathlib import Path
# Files with constructor errors
files = """
/home/rewrich/Documents/GitHub/tustu/app/src/main/java/com/efiAnalytics/ui/ArrowButton.java
/home/rewrich/Documents/GitHub/tustu/app/src/main/java/com/efiAnalytics/ui/ChartDataPoint.java
/home/rewrich/Documents/GitHub/tustu/app/src/main/java/com/efiAnalytics/ui/CurveDataPoint.java
/home/rewrich/Documents/GitHub/tustu/app/src/main/java/com/efiAnalytics/ui/DataGapRange.java
/home/rewrich/Documents/GitHub/tustu/app/src/main/java/com/efiAnalytics/ui/FloatPolygon.java
/home/rewrich/Documents/GitHub/tustu/app/src/main/java/com/efiAnalytics/ui/CustomGridLayout.java
/home/rewrich/Documents/GitHub/tustu/app/src/main/java/com/efiAnalytics/ui/TableSizeSelectorCell.java
/home/rewrich/Documents/GitHub/tustu/app/src/main/java/com/efiAnalytics/ui/TableStatisticsData.java
/home/rewrich/Documents/GitHub/tustu/app/src/main/java/com/efiAnalytics/ui/TableStatisticsOverlay.java
/home/rewrich/Documents/GitHub/tustu/app/src/main/java/com/efiAnalytics/ui/PagedNavigationPanel.java
/home/rewrich/Documents/GitHub/tustu/app/src/main/java/com/efiAnalytics/ui/RowHeaderCellRenderer.java
/home/rewrich/Documents/GitHub/tustu/app/src/main/java/com/efiAnalytics/ui/FileSelectorListModel.java
/home/rewrich/Documents/GitHub/tustu/app/src/main/java/com/efiAnalytics/ui/ThreeDimensionalViewPanel.java
/home/rewrich/Documents/GitHub/tustu/app/src/main/java/com/efiAnalytics/ui/Table3DColorMapPanel.java
/home/rewrich/Documents/GitHub/tustu/app/src/main/java/com/efiAnalytics/ui/Table3DDataModel.java
/home/rewrich/Documents/GitHub/tustu/app/src/main/java/com/efiAnalytics/ui/Table3DPaintThrottle.java
/home/rewrich/Documents/GitHub/tustu/app/src/main/java/com/efiAnalytics/ui/Table3DProjection.java
""".strip().split('\n')
# Listener classes
listeners = """
AxisSelectorMouseAdapter
ChartMouseHandler
ColorClearActionListener
ColorSetActionListener
CommentBoxCloseListener
CommentBoxDismissListener
CommentBoxFocusListener
CommentBoxHyperlinkListener
CommentBoxMouseListener
CommIndicatorActionListenerA
CommIndicatorActionListenerB
CommIndicatorMouseListener
FileSelectorActionListenerC
FileSelectorActionListenerD
FileSelectorActionListenerE
InputFieldFocusListener
ListAddItemListener
RegistrationDialogCountdownThread
SpinnerDownActionListener
SpinnerUpActionListener
TableSizeSelectorMouseAdapter
ThreeDViewAntialiasingListener
ThreeDViewColorShadeListener
ThreeDViewEvenSpacingListener
ThreeDViewFollowModeListener
ThreeDViewHorizontalSliderListener
ThreeDViewResetActionListener
TimestampUpdateTask
WaitBarThread
YAxisSelectorLayoutRunnable
""".strip().split('\n')
# Add listener files
for listener in listeners:
files.append(f"/home/rewrich/Documents/GitHub/tustu/app/src/main/java/com/efiAnalytics/ui/{listener}.java")
# Add panel files
panels = [
"/home/rewrich/Documents/GitHub/tustu/app/src/main/java/com/efiAnalytics/tunerStudio/panels/CalibrationTablePanel.java",
"/home/rewrich/Documents/GitHub/tustu/app/src/main/java/com/efiAnalytics/tunerStudio/panels/CanDeviceConfigPanel.java",
"/home/rewrich/Documents/GitHub/tustu/app/src/main/java/com/efiAnalytics/tunerStudio/panels/ProtocolStatsPanel.java",
"/home/rewrich/Documents/GitHub/tustu/app/src/main/java/com/efiAnalytics/tunerStudio/panels/RealTimeDisplayPanel.java",
"/home/rewrich/Documents/GitHub/tustu/app/src/main/java/com/efiAnalytics/tuningwidgets/panels/AutoLoggingTriggerPanel.java",
"/home/rewrich/Documents/GitHub/tustu/app/src/main/java/com/efiAnalytics/tuningwidgets/panels/InjectorControlPanel.java",
"/home/rewrich/Documents/GitHub/tustu/app/src/main/java/com/efiAnalytics/tuningwidgets/panels/ProfileDatalogFieldsPanel.java",
"/home/rewrich/Documents/GitHub/tustu/app/src/main/java/com/efiAnalytics/tuningwidgets/panels/ProjectArchiveOptionsPanel.java",
"/home/rewrich/Documents/GitHub/tustu/app/src/main/java/com/efiAnalytics/tuningwidgets/panels/RequiredFuelPanel.java",
"/home/rewrich/Documents/GitHub/tustu/app/src/main/java/com/efiAnalytics/tuningwidgets/panels/RestorePointDetailsPanel.java",
"/home/rewrich/Documents/GitHub/tustu/app/src/main/java/com/efiAnalytics/tuningwidgets/panels/ScalarDataLogListener.java",
"/home/rewrich/Documents/GitHub/tustu/app/src/main/java/com/efiAnalytics/tuningwidgets/panels/Table2DDataLogListener.java",
]
files.extend(panels)
# Add other files
others = [
"/home/rewrich/Documents/GitHub/tustu/app/src/main/java/com/efiAnalytics/tuningwidgets/portEditor/OutputChannelComboBox.java",
"/home/rewrich/Documents/GitHub/tustu/app/src/main/java/com/efiAnalytics/tunerStudio/search/SearchDelayThread.java",
"/home/rewrich/Documents/GitHub/tustu/app/src/main/java/com/efiAnalytics/tunerStudio/search/SearchResultItemMouseAdapter.java",
"/home/rewrich/Documents/GitHub/tustu/app/src/main/java/com/efiAnalytics/tunerStudio/search/SearchResultItemPanel.java",
"/home/rewrich/Documents/GitHub/tustu/app/src/main/java/com/efiAnalytics/apps/ts/tuningViews/EcuConfigDelegate.java",
"/home/rewrich/Documents/GitHub/tustu/app/src/main/java/com/efiAnalytics/apps/ts/tuningViews/TuningViewController.java",
"/home/rewrich/Documents/GitHub/tustu/app/src/main/java/com/efiAnalytics/apps/ts/tuningViews/TuningViewFileLoadThread.java",
"/home/rewrich/Documents/GitHub/tustu/app/src/main/java/com/efiAnalytics/apps/ts/tuningViews/TuningViewPanel.java",
"/home/rewrich/Documents/GitHub/tustu/app/src/main/java/com/efiAnalytics/apps/ts/tuningViews/TuningViewTabbedPane.java",
"/home/rewrich/Documents/GitHub/tustu/app/src/main/java/com/efiAnalytics/apps/ts/tuningViews/TuningViewWindow.java",
"/home/rewrich/Documents/GitHub/tustu/app/src/main/java/ui/ui_dialogs/AfInterfaceIndia.java",
]
files.extend(others)
def fix_file(filepath):
"""Fix constructors in a single file."""
path = Path(filepath)
if not path.exists():
print(f"SKIP: {filepath} - doesn't exist")
return False
classname = path.stem
try:
with open(path, 'r', encoding='utf-8', errors='ignore') as f:
content = f.read()
original = content
# Pattern: Find lowercase method declarations that are likely constructors
# Match: public|private|protected lowercase_name(
# Not match: type lowercase_name(
pattern = r'(\s+)(public\s+|private\s+|protected\s+|)([a-z]\w*)\s*\('
def replacer(match):
indent = match.group(1)
modifier = match.group(2)
name = match.group(3)
# Skip common keywords
if name in ['if', 'for', 'while', 'switch', 'return', 'throw', 'super']:
return match.group(0)
# Replace with class name
return f'{indent}{modifier}{classname}('
content = re.sub(pattern, replacer, content)
if content != original:
with open(path, 'w', encoding='utf-8') as f:
f.write(content)
print(f"FIXED: {classname}")
return True
else:
print(f"UNCHANGED: {classname}")
return False
except Exception as e:
print(f"ERROR: {filepath} - {e}")
return False
# Fix all files
fixed = 0
for filepath in files:
if filepath.strip():
if fix_file(filepath.strip()):
fixed += 1
print(f"\nFixed {fixed} files")

View File

@@ -0,0 +1,65 @@
#!/usr/bin/env python3
"""
Fix single-letter constructor names to match class names.
"""
import re
from pathlib import Path
# Map of files that need fixing
files_to_fix = {
"/home/rewrich/Documents/GitHub/tustu/app/src/main/java/com/efiAnalytics/apps/ts/tuningViews/TuningViewPanel.java": "TuningViewPanel",
"/home/rewrich/Documents/GitHub/tustu/app/src/main/java/com/efiAnalytics/apps/ts/tuningViews/TuningViewWindow.java": "TuningViewWindow",
"/home/rewrich/Documents/GitHub/tustu/app/src/main/java/com/efiAnalytics/tunerStudio/panels/ProtocolStatsPanel.java": "ProtocolStatsPanel",
"/home/rewrich/Documents/GitHub/tustu/app/src/main/java/com/efiAnalytics/tunerStudio/panels/RealTimeDisplayPanel.java": "RealTimeDisplayPanel",
"/home/rewrich/Documents/GitHub/tustu/app/src/main/java/com/efiAnalytics/tunerStudio/panels/CalibrationTablePanel.java": "CalibrationTablePanel",
"/home/rewrich/Documents/GitHub/tustu/app/src/main/java/com/efiAnalytics/tunerStudio/search/SearchResultItemPanel.java": "SearchResultItemPanel",
"/home/rewrich/Documents/GitHub/tustu/app/src/main/java/com/efiAnalytics/tunerStudio/search/SearchResultItemMouseAdapter.java": "SearchResultItemMouseAdapter",
"/home/rewrich/Documents/GitHub/tustu/app/src/main/java/com/efiAnalytics/tuningwidgets/panels/ProfileDatalogFieldsPanel.java": "ProfileDatalogFieldsPanel",
}
def fix_single_letter_constructors(filepath, classname):
"""Fix single-letter constructors in a file."""
path = Path(filepath)
if not path.exists():
print(f"SKIP: {filepath}")
return False
try:
with open(path, 'r', encoding='utf-8', errors='ignore') as f:
content = f.read()
original = content
# Pattern: public X( where X is a single uppercase letter
pattern = r'(\s+)(public\s+|private\s+|protected\s+|)([A-Z])\s*\('
def replacer(match):
indent = match.group(1)
modifier = match.group(2)
letter = match.group(3)
# Replace with class name
return f'{indent}{modifier}{classname}('
content = re.sub(pattern, replacer, content)
if content != original:
with open(path, 'w', encoding='utf-8') as f:
f.write(content)
print(f"FIXED: {classname}")
return True
else:
print(f"UNCHANGED: {classname}")
return False
except Exception as e:
print(f"ERROR: {filepath} - {e}")
return False
# Fix all files
fixed = 0
for filepath, classname in files_to_fix.items():
if fix_single_letter_constructors(filepath, classname):
fixed += 1
print(f"\nFixed {fixed} files with single-letter constructors")