OC.L10N.register( "files", { "Added to favorites" : "Dodano med priljubljene", "Removed from favorites" : "Odstranjeno iz priljubljenih", "You added {file} to your favorites" : "Med priljubljene dodate datoteko {file}", "You removed {file} from your favorites" : "Odstranite datoteko {file} od priljubljenih", "Favorites" : "Priljubljene", "File changes" : "Spremembe datoteke", "Created by {user}" : "{user} ustvari predmet", "Changed by {user}" : "{user} spremeni predmet", "Deleted by {user}" : "{user} izbriše predmet", "Restored by {user}" : "{user} obnovi predmet", "Renamed by {user}" : "{user} preimenuje predmet", "Moved by {user}" : "{user} premakne predmet", "\"remote account\"" : "»oddaljeni račun«", "You created {file}" : "Ustvarite datoteko ali mapo {file}", "You created an encrypted file in {file}" : "Ustvarite šifrirano datoteko v {file}", "{user} created {file}" : "{user} ustvari datoteko {file}", "{user} created an encrypted file in {file}" : "{user} ustvari šifrirano datoteko v {file}", "{file} was created in a public folder" : "Datoteka {file} je ustvarjena v javni mapi", "You changed {file}" : "Spremenite {file}", "You changed an encrypted file in {file}" : "Spremenite šifrirano datoteko v {file}", "{user} changed {file}" : "{user} spremeni datoteko {file}", "{user} changed an encrypted file in {file}" : "Uporabnik {user} spremeni šifrirano datoteko {file}", "You deleted {file}" : "Izbrišete datoteko {file}", "You deleted an encrypted file in {file}" : "Izbrišete šifrirano datoteko {file}", "{user} deleted {file}" : "{user} izbriše datoteko {file}", "{user} deleted an encrypted file in {file}" : "{user} izbriše šifrirano datoteko {file}", "You restored {file}" : "Obnovite datoteko {file}", "{user} restored {file}" : "{user} obnovi datoteko {file}", "You renamed {oldfile} (hidden) to {newfile} (hidden)" : "Preimenujete datoteko {oldfile} (skrito) v {newfile} (skrito)", "You renamed {oldfile} (hidden) to {newfile}" : "Preimenujete {oldfile} (skrito) v {newfile}", "You renamed {oldfile} to {newfile} (hidden)" : "Preimenujete datoteko {oldfile} v {newfile} (skrito)", "You renamed {oldfile} to {newfile}" : "Preimenujete datoteko {oldfile} v {newfile}", "{user} renamed {oldfile} (hidden) to {newfile} (hidden)" : "{user} preimenuje datoteko {oldfile} (skrito) v {newfile} (skrito)", "{user} renamed {oldfile} (hidden) to {newfile}" : "{user} preimenuje {oldfile} (skrito) v {newfile}", "{user} renamed {oldfile} to {newfile} (hidden)" : "{user} preimenuje datoteko {oldfile} v {newfile} (skrito)", "{user} renamed {oldfile} to {newfile}" : "{user} preimenuje datoteko {oldfile} v {newfile}", "You moved {oldfile} to {newfile}" : "Premaknete datoteko {oldfile} v {newfile}", "{user} moved {oldfile} to {newfile}" : "{user} premakne datoteko {oldfile} v {newfile}", "A file has been added to or removed from your favorites" : "Datoteka je bila, ali dodana ali umaknjena iz priljubljenih", "Files" : "Datoteke", "A file or folder has been changed" : "Spremenjena je bila datoteka ali mapa", "A favorite file or folder has been changed" : "Spremenjena je bila priljubljena datoteka ali mapa", "Failed to authorize" : "Overitev je spodletela", "Invalid folder path" : "Neveljavna pot mape", "Folder not found" : "Mape ni mogoče najti", "The file cannot be found" : "Datoteke ni mogoče najti.", "The destination path does not exist: %1$s" : "Cilja pot ne obstaja: %1$s", "You do not have permission to create a file at the specified location" : "Nimate pravice za stvarjenje datoteke na podani lokaciji", "The file could not be converted." : "Datoteke ni mogoče pretvoriti.", "Could not get relative path to converted file" : "Ni mogoče pridobiti relativne poti do pretvorjene datoteke.", "Favorite files" : "Priljubljene datoteke", "No favorites" : "Ni priljubljenih datotek", "More favorites" : "Več priljubljenih", "Accept" : "Sprejmi", "Reject" : "Zavrni", "Incoming ownership transfer from {user}" : "Vpisana je zahteva za prenos lastništva uporabnika {user}", "Do you want to accept {path}?\n\nNote: The transfer process after accepting may take up to 1 hour." : "Ali želite sprejeti pot {path}?\n\nOpomba: po sprejetju lahko prenos traja tudi več kot 1 uro.", "Ownership transfer denied" : "Prenos lastništva je spodletel", "Your ownership transfer of {path} was denied by {user}." : "Prenos lastništva za {path} je onemogočil {user}.", "Ownership transfer failed" : "Prenos lastništva je spodletel", "Your ownership transfer of {path} to {user} failed." : "Prenos lastništva mesta {path} na uporabnika {user} je spodletel.", "The ownership transfer of {path} from {user} failed." : "Prenos lastništva mesta {path} na uporabnika {user} je spodletel.", "Ownership transfer done" : "Prenos lastništva je uspešno končan", "Your ownership transfer of {path} to {user} has completed." : "Prenos lastništva poti {path} na uporabnika {user} je končan.", "The ownership transfer of {path} from {user} has completed." : "Prenos lastništva poti {path} z uporabnika {user} je končan.", "in %s" : "v %s", "Transferred from %1$s on %2$s" : "Preneseno iz %1$s na %2$s", "Files compatibility" : "Skladnost datotek", "Allow to restrict filenames to ensure files can be synced with all clients. By default all filenames valid on POSIX (e.g. Linux or macOS) are allowed." : "Dovoli omejitev imen datotek za zagotovitev sinhronizacije datotek z vsemi odjemalci. Privzeto je dovoljenje za vsa imena datotek na POSIX (tj. Linux ali macOS).", "After enabling the Windows compatible filenames, existing files cannot be modified anymore but can be renamed to valid new names by their owner." : "Po vklopu imen, ki so združljiva z WIndows, obstoječih datotek ni več mogoče spreminjati, jih pa lahko lastnik preimenuje v ustrezno ime.", "It is also possible to migrate files automatically after enabling this setting, please refer to the documentation about the occ command." : "Datoteke lahko po vklopu te možnosti tudi same migrirajo. Preverite dokumentacijo o ukazu occ.", "Enforce Windows compatibility" : "Vsili skladnost s sistemom Windows", "This will block filenames not valid on Windows systems, like using reserved names or special characters. But this will not enforce compatibility of case sensitivity." : "To bo blokiralo imena datotek, ki niso ustrezna za Windows sisteme, kot so rezervirana imena ali posebni znaki, ne bo pa to vsililo združljivosti pri razlikovanju velikih in malih črk imena.", "File Management" : "Upravljanje datotek", "Home" : "Začetni pogled", "Target folder does not exist any more" : "Ciljna mapa ne obstaja več", "Reload current directory" : "Ponovno naloži trenutno mapo", "Go to the \"{dir}\" directory" : "Pojdi v mapo »{dir}«", "Current directory path" : "Trenutna pot mape", "Your have used your space quota and cannot upload files anymore" : "Porabili ste svojo količino prostora in datotek več ne morete nalagati", "You do not have permission to upload or create files here." : "Nimate pravic za ustvarjanje ali nalaganje datotek na to mesto.", "Drag and drop files here to upload" : "Za pošiljanje potegnite in spustite datoteke na to mesto", "Favorite" : "Priljubljene", "Back" : "Nazaj", "Toggle selection for file \"{displayName}\"" : "Preklopi izbor za datoteko \"{displayName}\"", "Toggle selection for folder \"{displayName}\"" : "Preklopi izbor za mapo \"{displayName}\"", "File is loading" : "Poteka nalaganje datoteke", "Folder is loading" : "mape", "Filename" : "Ime datoteke", "Folder name" : "Ime mape", "This node is unavailable" : "To vozlišče ni na voljo.", "Another entry with the same name already exists." : "Vpis z istim imenom že obstaja.", "Invalid filename." : "Neveljavno ime datoteke", "Renamed \"{oldName}\" to \"{newName}\"" : "Preimenuj »{oldName}« to »{newName}«", "Rename file" : "Preimenuj datoteke", "Folder" : "Mapa", "Pending" : "Na čakanju ...", "Unknown date" : "Neznani datum", "Clear filter" : "Počisti filter", "Modified" : "Spremenjeno", "Search everywhere" : "Išči povsod", "Type" : "Vrsta", "Active filters" : "Dejavni filtri", "Remove filter" : "Odstrani filter", "Total rows summary" : "Skupni povzetek vrstic", "Toggle selection for all files and folders" : "Preklopi izbor za vse datoteke in mape", "Name" : "Ime", "Size" : "Velikost", "\"{displayName}\" failed on some elements" : "\"{displayName}\" ni uspel za nekatere elemente", "\"{displayName}\" batch action executed successfully" : "Paketno dejanje »{displayName}« je uspešno izvedeno", "\"{displayName}\" action failed" : "Dejanje »{displayName}« je spodletelo", "Actions" : "Dejanja", "(selected)" : "(izbrano)", "List of files and folders." : "Seznam datotek in map", "You have used your space quota and cannot upload files anymore." : "Porabili ste svojo količino prostora in datotek več ne morete nalagati", "Column headers with buttons are sortable." : "Naslove stolpcev z gumbi je mogoče sortirati.", "This list is not fully rendered for performance reasons. The files will be rendered as you navigate through the list." : "Seznam datotek ni v celoti izpisan zaradi zagotavljanja hitrosti in odzivnosti sistema. Predmeti se bodo dopolnjevali med brskanjem.", "File not found" : "Datoteke ni mogoče najti", "Search globally" : "Splošno iskanje", "{usedQuotaByte} used" : "Zasedeno {usedQuotaByte}", "{used} of {quota} used" : "V uporabi je {used} od {quota}", "{relative}% used" : "Zasedeno {relative} %", "Could not refresh storage stats" : "Ni mogoče osvežiti podatkov shrambe", "Your storage is full, files can not be updated or synced anymore!" : "Shramba je povsem napolnjena. Datotek ni več mogoče posodabljati in usklajevati!", "Storage information" : "Podrobnosti shrambe", "Storage quota" : "Omejitev shrambe", "New folder" : "Nova mapa", "Create new folder" : "Ustvari novo mapo", "This name is already in use." : "Vpisano uporabniško ime je že v uporabi", "Create" : "Ustvari", "Fill template fields" : "Zapolni polja predloge", "Submitting fields …" : "Pošiljanje polj ...", "Submit" : "Pošlji", "Choose a file or folder to transfer" : "Izbor datoteke ali mape za prenos", "Transfer" : "Prenos", "Transfer {path} to {userid}" : "Prenesi pot {path} k uporabniku {userid}", "Invalid path selected" : "Izbrana je neveljavna pot", "Unknown error" : "Neznana napaka", "Ownership transfer request sent" : "Zahteva za prenos lastništva je poslana", "Cannot transfer ownership of a file or folder you do not own" : "Ni mogoče prenesti lastništva datotek in map, katerih niste lastnik", "Transfer ownership of a file or folder" : "Prenos lastništva datoteke ali mape", "Choose file or folder to transfer" : "Izbor datoteke ali mape za prenos", "Change" : "Spremeni", "New owner" : "Nov lastnik", "Keep {old}" : "Ohrani {old}", "Keep without extension" : "Ohrani brez pripone", "Use {new}" : "Uporabi {new}", "Remove extension" : "Odstrani pripono", "Change file extension" : "Spremeni pripono datoteke", "Changing the file extension from \"{old}\" to \"{new}\" may render the file unreadable." : "Sprememba končnice datoteke iz \"{old}\" v \"{new}\" lahko naredi datoteko neberljivo.", "Removing the file extension \"{old}\" may render the file unreadable." : "Odstranitev končnice datoteke \"{old}\" lahko naredi datoteko neberljivo.", "Adding the file extension \"{new}\" may render the file unreadable." : "Dadajanje končnice datoteke \"{new}\" lahko naredi datoteko neberljivo.", "Do not show this dialog again." : "Pogovornega okna ne pokaži več.", "Select file or folder to link to" : "Izbor datoteke ali mape za povezavo", "Choose {file}" : "Izberite datoteko {file}", "Share" : "·Souporaba·", "Shared by link" : "V souporabi sk povezavo", "Shared" : "V souporabi", "Switch to list view" : "Preklopi na seznamski pogled", "Switch to grid view" : "Preklopi na mrežni pogled", "The file could not be found" : "Datoteke ni mogoče najti.", "Upload was cancelled by user" : "Uporabnik je pošiljanje preklical", "Not enough free space" : "Ni dovolj prostora", "Operation is blocked by access control" : "Opravilo je zaustavljeno prek nadzora dostopa", "Error during upload: {message}" : "Napaka med nalaganjem: {message}", "Error during upload, status code {status}" : "Napaka med nalaganje s kodo stanja {status}", "Unknown error during upload" : "Med pošiljanjem je prišlo do neznane napake", "\"{displayName}\" action executed successfully" : "Dejanje »{displayName}« je uspešno izvedeno", "Loading current folder" : "Poteka nalaganje trenutne mape", "Retry" : "Poskusi znova ", "No files in here" : "V mapi ni datotek", "Upload some content or sync with your devices!" : "Uvozite vsebino, ali pa omogočite usklajevanje z napravami!", "Go back" : "Skoči nazaj", "Views" : "Pogledi", "Files settings" : "Nastavitve datotek", "Your files" : "Osebne datoteke", "Open in files" : "Odpri datoteko v mapi", "File cannot be accessed" : "Do datoteke dostop ni mogoč", "The file could not be found or you do not have permissions to view it. Ask the sender to share it." : "Datoteke ni bilo mogoče najti ali pa nimate ustreznih dovoljenj za ogled. Prosite pošiljatelja, da jo deli.", "Clipboard is not available" : "Odložišče ni na voljo", "WebDAV URL copied to clipboard" : "Naslov URL WebDAV je kopiran v odložišče", "All files" : "Vse datoteke", "Personal files" : "Osebne datoteke", "Sort favorites first" : "Razvrsti najprej priljubljene", "Sort folders before files" : "Razvrsti mape pred datotekami", "Enable folder tree" : "Omogoči drevesno strukturo map", "Show hidden files" : "Pokaži skrite datoteke", "Crop image previews" : "Obreži slike predogleda", "Additional settings" : "Dodatne nastavitve", "WebDAV" : "WebDAV", "WebDAV URL" : "Naslov URL WebDAV", "Copy to clipboard" : "Kopiraj v odložišče", "Warnings" : "Opozorila", "Prevent warning dialogs from open or reenable them." : "Preprečite odpiranje dialogov z opozorili ali jih ponovno omogočite.", "Show a warning dialog when changing a file extension." : "Prikaži opozorilo ob spreminjanju končnice datoteke.", "Keyboard shortcuts" : "Tipkovne bližnjice", "Speed up your Files experience with these quick shortcuts." : "Pospešite uporabo upravljalnika Files s temi bližnjicami.", "Open the actions menu for a file" : "Odpri meni dejanj za datoteko", "Rename a file" : "Preimenuj datoteko", "Delete a file" : "Izbriši datoteko", "Favorite or remove a file from favorites" : "Označi ali odstrani koz priljubljeno", "Manage tags for a file" : "Upravljanje oznak datoteke", "Selection" : "Izbor", "Select all files" : "Izberi vse datoteke", "Deselect all files" : "Ostrani izbor vseh datotek", "Select or deselect a file" : "Izberi ali odstrani izbor datoteke", "Select a range of files" : "Izbor obsega datotek", "Navigation" : "Krmarjenje", "Navigate to the parent folder" : "Pojdi na nadrejeni imenik", "Navigate to the file above" : "Pojdi na datoteko zgoraj", "Navigate to the file below" : "Pojdi na doatoteko spodaj", "Navigate to the file on the left (in grid mode)" : "Pojdi na datoteko na levi (v mrežnem načinu)", "Navigate to the file on the right (in grid mode)" : "Pojdi na datoteko na desni (v mrežnem načinu)", "View" : "Pogled", "Toggle the grid view" : "Preklopi mrežni način", "Open the sidebar for a file" : "Odpri stranski pano datoteke", "Show those shortcuts" : "Pokaži tipkovne bližnjice", "You" : "Jaz", "Shared multiple times with different people" : "V več souporabah z različnimi uporabniki", "Error while loading the file data" : "Prišlo je do napake med nalaganjem podatkov računa", "Owner" : "Lastnik", "Remove from favorites" : "Odstrani iz priljubljenih", "Add to favorites" : "Dodaj med priljubljene", "Tags" : "Oznake", "Blank" : "Prazno", "Unable to create new file from template" : "Nove datoteke iz predloge ni mogoče ustvariti", "Pick a template for {name}" : "Izbor predloge za {name}", "Create a new file with the selected template" : "Ustvari novo datoteko z izbrano predlogo", "Creating file" : "Poteka ustvarjanje datoteke", "Save as {displayName}" : "Shrani kot {displayName}", "Save as …" : "Shrani kot ...", "Converting files …" : "Poteka pretvarjanje datotek ...", "Failed to convert files: {message}" : "Pretvarjanje datotek je spodletelo: {message}", "All files failed to be converted" : "Spodletelo je pretvarjanje vseh datotek.", "One file could not be converted: {message}" : "Ene datoteke ni mogoče pretvoriti: {message}", "_One file could not be converted_::_%n files could not be converted_" : ["%n datoteke ni mogoče pretvoriti","%n datotek ni mogoče pretvoriti","%n datotek ni mogoče pretvoriti","%n datotek ni mogoče pretvoriti"], "_One file successfully converted_::_%n files successfully converted_" : ["%n datoteka je uspešno pretvorjena","%n datoteki sta uspešno pretvorjeni","%n datoteke so uspešno pretvorjene","%n datotek je uspešno pretvorjenih"], "Files successfully converted" : "Datoteke so uspešno pretvorjene", "Failed to convert files" : "Pretvarjanje datotek je spodletelo", "Converting file …" : "Poteka pretvarjanje datoteke ...", "File successfully converted" : "Datoteka je uspešno pretvorjena", "Failed to convert file: {message}" : "Pretvarjanje datoteek je spodletelo: {message}", "Failed to convert file" : "Pretvarjanje datoteke je spodletelo", "Deletion cancelled" : "Brisanje je bilo preklicano", "Leave this share" : "Prekini to souporabo", "Leave these shares" : "Prekini to souporabo", "Disconnect storage" : "Odklopi shrambo", "Disconnect storages" : "Odklopi shrambo", "Delete permanently" : "Izbriši trajno", "Delete and unshare" : "Izbriši in prekini souporabo", "Delete file" : "Izbriši datoteko", "Delete files" : "Izbriši datoteke", "Delete folder" : "Izbriši mapo", "Delete folders" : "Izbriši mape", "Delete" : "Izbriši", "_You are about to permanently delete {count} item_::_You are about to permanently delete {count} items_" : ["Za stalno boste izbrisali {count} predmet","Za stalno boste izbrisali {count} predmeta","Za stalno boste izbrisali {count} predmete","Za stalno boste izbrisali {count} predmetov"], "_You are about to delete {count} item_::_You are about to delete {count} items_" : ["Izbrisali boste {count} predmet","Izbrisali boste {count} predmeta","Izbrisali boste {count} predmete","Izbrisali boste {count} predmetov"], "Confirm deletion" : "Potrdi brisanje", "Cancel" : "Prekliči", "Download" : "Prejmi", "Moving \"{source}\" to \"{destination}\" …" : "Premik \"{source}\" v \"{destination}\"...", "Copying \"{source}\" to \"{destination}\" …" : "Kopiranje \"{source}\" v \"{destination}\"...", "Destination is not a folder" : "Ciljno mesto ni mapa", "This file/folder is already in that directory" : "Ta datoteka oziroma mapa je že v določeni mapi", "You cannot move a file/folder onto itself or into a subfolder of itself" : "Mape ali datoteke ni mogoče premakniti samo vase oziroma v podmapo same sebe", "(copy)" : "(kopija)", "(copy %n)" : "(kopija %n)", "Move cancelled" : "Premikanje je bilo preklicano", "A file or folder with that name already exists in this folder" : "Datoteka oziroma mapa s tem imenom v tej mapi že obstaja", "The files are locked" : "Datoteke so zaklenjene", "The file does not exist anymore" : "Datoteka ne obstaja več", "Choose destination" : "Izbor ciljnega mesta", "Copy to {target}" : "Kopiraj na {target}", "Copy" : "Kopiraj", "Move to {target}" : "Premakni na {target}", "Move" : "Premakni", "Move or copy operation failed" : "Opravilo kopiranja oziroma premikanja je spodletelo", "Move or copy" : "Premakni ali kopiraj", "Cancelled move or copy of \"{filename}\"." : "Prekinjeno premikanje ali kopiranje za \"{filename}\".", "Cancelled move or copy operation" : "Opravilo kopiranje in premikanja je preklicano", "Open folder {displayName}" : "Odpri mapo {displayName}", "Open in Files" : "Open in Files", "Open locally" : "Odpri krajevno", "Failed to redirect to client" : "Preusmerjanje odjemalca je spodletelo", "Open file locally" : "Odpri datoteko krajevno", "The file should now open on your device. If it doesn't, please check that you have the desktop app installed." : "Datoteka bi se sedaj morala odpreti z vaše naprave. Če se to ne zgodi, preverite namestitev namizne aplikacije.", "Retry and close" : "Ponovno poskusi in zapri", "Open online" : "Odpri v brskalniku", "Rename" : "Preimenuj", "Open details" : "Odpri podrobnosti", "View in folder" : "Pokaži v mapi", "Today" : "Danes", "Last 7 days" : "Zadnjih 7 dni", "Last 30 days" : "Zadnjih 30 dni", "This year ({year})" : "Letos ({year})", "Last year ({year})" : "Lansko leto ({year})", "Documents" : "Dokumenti", "Spreadsheets" : "Preglednice", "Presentations" : "Predstavitve", "PDFs" : "Dokumenti PDF", "Folders" : "Mape", "Audio" : "Zvočni posnetek", "Photos and images" : "Slike in fotografije", "Videos" : "Video posnetki", "New folder creation cancelled" : "Ustvarjanje nove mape je bilo preklicano", "Created new folder \"{name}\"" : "Ustvarjena je nova mapa »{name}«.", "Unable to initialize the templates directory" : "Ni mogoče začeti mape predlog", "Create templates folder" : "Ustvari mapo predlog", "Templates" : "Predloge", "New template folder" : "Nova mapa predlog", "In folder" : "V mapi", "Search in folder: {folder}" : "Išči v mapi: {folder}", "One of the dropped files could not be processed" : "Eno od podanih datotek ni bilo mogoče obdelati", "Your browser does not support the Filesystem API. Directories will not be uploaded" : "Brskalnik ne podpira API datotečnega sistema. Mape ne bodo naložene", "No files to upload" : "Ni datotek za pošiljanje", "Unable to create the directory {directory}" : "Mape {directory} ni mogoče ustvariti", "Some files could not be uploaded" : "Nekaterih datotek ni bilo mogoče poslati", "Files uploaded successfully" : "Datoteke so uspešno poslane v oblak", "No files to process" : "Ni datotek za obdelavo", "Some files could not be copied" : "Nekaterih datotek ni bilo mogoče kopirati", "Some files could not be moved" : "Nekaterih datotek ni mogoče premakniti", "Files copied successfully" : "Datoteke so uspešno kopirane", "Files moved successfully" : "Datoteke so uspešno premaknjene", "Conflicts resolution skipped" : "Razreševanje sporov je preklicano", "Upload cancelled" : "Pošiljanje je bilo preklicano", "Could not rename \"{oldName}\", it does not exist any more" : "Datoteke »{oldName}« ni mogoče preimenovati, ker ne obstaja več.", "The name \"{newName}\" is already used in the folder \"{dir}\". Please choose a different name." : "Ime »{newName}« je v mapi »{dir}« že v uporabi. Izbrati je treba drugačno ime.", "Could not rename \"{oldName}\"" : "Datoteke »{oldName}« ni mogoče preimenovati", "This operation is forbidden" : "To dejanje ni dovoljeno!", "This directory is unavailable, please check the logs or contact the administrator" : "Mapa ni na voljo. Preverite dnevnik in stopite v stik s skrbnikom sistema.", "Storage is temporarily not available" : "Shramba trenutno ni na voljo", "Unexpected error: {error}" : "Nepričakovana napaka: {error}", "_%n file_::_%n files_" : ["%n datoteka","%n datoteki","%n datoteke","%n datotek"], "_%n folder_::_%n folders_" : ["%n mapa","%n mapi","%n mape","%n mape"], "_%n hidden_::_%n hidden_" : ["%n skrita","%n skriti","%n skrite","%n skritih"], "Filename must not be empty." : "Ime datoteke ne sme biti prazno.", "\"{char}\" is not allowed inside a filename." : "Znak \"{char}\" ni dovoljen v imenu datotek.", "\"{segment}\" is a reserved name and not allowed for filenames." : "\"{segment}\" je rezervirano ime in ni dovoljeno za ime datoteke.", "\"{extension}\" is not an allowed filetype." : "\"{extension}\" ni dovoljena vrsta končnice.", "Filenames must not end with \"{extension}\"." : "Imena datotek naj nimajo končnice \"{extension}\".", "List of favorite files and folders." : "Seznam priljubljenih datotek in map.", "No favorites yet" : "Ni še dodanih priljubljenih predmetov", "Files and folders you mark as favorite will show up here" : "Datoteke ali mape, ki so označene kot priljubljene, bodo zbrane na tem mestu.", "List of your files and folders." : "Seznam datotek in map.", "All folders" : "Vse mape", "List of your files and folders that are not shared." : "Seznam datotek in map, ki niso v skupni rabi.", "No personal files found" : "Ni najdenih zasebnih datotek", "Files that are not shared will show up here." : "Datoteke, ki niso v skupni rabi, bodo prikazane tukaj.", "Recent" : "Nedavne", "List of recently modified files and folders." : "Seznam nedavno spremenjenih datotek in map.", "No recently modified files" : "Ni nedavno spremenjenih datotek", "Files and folders you recently modified will show up here." : "Nedavno spremenjene datoteke ali mape, bodo zbrane na tem mestu.", "Search" : "Poišči", "No entries found in this folder" : "V tej mapi ni najdenih predmetov.", "Select all" : "izberi vse", "Upload too large" : "Prekoračena je omejitev dovoljene velikosti", "The files you are trying to upload exceed the maximum size for file uploads on this server." : "Datoteke, ki jih želite poslati, presegajo največjo dovoljeno velikost na strežniku.", "File could not be found" : "Datoteke ni mogoče najti", "Show list view" : "Pokaži seznamski pogled", "Show grid view" : "Pokaži mrežni pogled", "Close" : "Zapri", "Could not create folder \"{dir}\"" : "Mape »{dir}« ni mogoče ustvariti.", "This will stop your current uploads." : "S tem bodo zaustavljena vsa pošiljanja v oblak.", "Upload cancelled." : "Pošiljanje je preklicano.", "Processing files …" : "Poteka obdelava datotek ...", "…" : "...", "Unable to upload {filename} as it is a directory or has 0 bytes" : "Datoteke {filename} ni mogoče poslati, saj je to mapa, ali pa je velikost datoteke 0 bajtov.", "Not enough free space, you are uploading {size1} but only {size2} is left" : "Ni dovolj prostora. Velikost poslane datoteke je {size1}, na voljo pa je le {size2}.", "Target folder \"{dir}\" does not exist any more" : "Ciljna mapa »{dir}« ne obstaja več.", "An unknown error has occurred" : "Prišlo je do neznane napake!", "File could not be uploaded" : "Datoteke ni mogoče poslati", "Uploading …" : "Poteka pošiljanje ...", "{remainingTime} ({currentNumber}/{total})" : "{remainingTime} ({currentNumber}/{total})", "Uploading … ({currentNumber}/{total})" : "Pošiljanje … ({currentNumber}/{total})", "{loadedSize} of {totalSize} ({bitrate})" : "{loadedSize} od {totalSize} ({bitrate})", "Uploading that item is not supported" : "Pošiljate te vrste predmeta ni podprto.", "Error when assembling chunks, status code {status}" : "Napaka pri sestavljanju kosov datoteke, koda stanja je {status}", "Choose target folder" : "Izbor ciljne mape", "Set reminder" : "Nastavi opomnik", "Edit locally" : "Uredi krajevno", "Open" : "Odpri", "Could not load info for file \"{file}\"" : "Ni mogoče naložiti podatkov za datoteko »{file}«.", "Details" : "Podrobnosti", "Please select tag(s) to add to the selection" : "Izbrati je treba oznake za dodajanje k izbiri", "Apply tag(s) to selection" : "Poteka uveljavljanje oznak za izbiro", "Select directory \"{dirName}\"" : "Izberi mapo »{dirName}«", "Select file \"{fileName}\"" : "Izberi datoteko »{fileName}«.", "Unable to determine date" : "Ni mogoče določiti datuma", "Could not move \"{file}\", target exists" : "Datoteke »{file}« ni mogoče premakniti, ker na ciljnem mestu z istim imenom že obstaja.", "Could not move \"{file}\"" : "Datoteke »{file}« ni mogoče premakniti", "copy" : "kopija", "Could not copy \"{file}\", target exists" : "Datoteke »{file}« ni mogoče kopirati, ker ta že obstaja.", "Could not copy \"{file}\"" : "Datoteke »{file}« ni mogoče kopirati.", "Copied {origin} inside {destination}" : "Kopirano {origin} v {destination}", "Copied {origin} and {nbfiles} other files inside {destination}" : "Kopirano {origin} in {nbfiles} ostale datoteke v {destination}", "{newName} already exists" : "Ime {newName} že obstaja", "Could not create file \"{file}\"" : "Datoteke »{file}« ni mogoče ustvariti.", "Could not create file \"{file}\" because it already exists" : "Datoteke »{file}« ni mogoče ustvariti, ker datoteka z istim imenom že obstaja.", "Could not create folder \"{dir}\" because it already exists" : "Ni mogoče ustvariti mape »{dir}«, ker ta že obstaja", "Could not fetch file details \"{file}\"" : "Ni mogoče pridobiti podrobnosti datoteke »{file}«.", "Error deleting file \"{fileName}\"." : "Prišli je do napake med brisanjem datoteke »{fileName}«.", "No search results in other folders for {tag}{filter}{endtag}" : "Za iskalni niz {tag}{filter}{endtag} ni zadetkov v nobeni mapi", "Enter more than two characters to search in other folders" : "Vpišite več kot dva znaka za iskanje po drugih mapah", "{dirs} and {files}" : "{dirs} in {files}", "_including %n hidden_::_including %n hidden_" : ["vključujoč %n skrito","vključujoč %n skriti","vključujoč %n skrite","vključujoč %n skritih"], "You do not have permission to upload or create files here" : "Ni ustreznih dovoljenja za pošiljanje ali ustvarjanje novih datotek", "_Uploading %n file_::_Uploading %n files_" : ["Posodabljanje %n datoteke","Posodabljanje %n datotek","Posodabljanje %n datotek","Poteka posodabljanje %n datotek"], "New" : "Novo", "New file/folder menu" : "Nov meni datoteke/mape", "Select file range" : "Izbor obsega datotek", "{used}%" : "{used} %", "{used} used" : "V uporabi je {used}", "\"{name}\" is an invalid file name." : "Ime »{name}« ni veljavno ime datoteke.", "File name cannot be empty." : "Ime datoteke ne sme biti prazno polje.", "\"/\" is not allowed inside a file name." : "znak » / « v imenu datoteke ni dovoljen.", "\"{name}\" is not an allowed filetype" : "Ime »{name}« ni dovoljena vrsta datoteke.", "Storage of {owner} is full, files cannot be updated or synced anymore!" : "Shramba uporabnika {owner} je polna, zato datotek ni več mogoče posodabljati in usklajevati!", "Group folder \"{mountPoint}\" is full, files cannot be updated or synced anymore!" : "Skupinska mapa »{mountPoint}« je do konca zasedena, zato datotek ni mogoče več posodobiti in usklajevati!", "External storage \"{mountPoint}\" is full, files cannot be updated or synced anymore!" : "Zunanja shramba »{mountPoint}« je do konca zasedena, zato datotek ni mogoče več posodobiti in usklajevati!", "Your storage is full, files cannot be updated or synced anymore!" : "Shramba je povsem napolnjena. Datotek ni več mogoče posodabljati in usklajevati!", "Storage of {owner} is almost full ({usedSpacePercent}%)." : "Shramba uporabnika {owner} je do konca zasedena ({usedSpacePercent}%).", "Group folder \"{mountPoint}\" is almost full ({usedSpacePercent}%)." : "Skupinska mapa »{mountPoint}« je skoraj do konca zasedena ({usedSpacePercent}%).", "External storage \"{mountPoint}\" is almost full ({usedSpacePercent}%)." : "Zunanja shramba »{mountPoint}« je skoraj do konca zasedena ({usedSpacePercent}%).", "Your storage is almost full ({usedSpacePercent}%)." : "Vaša shramba je skoraj do konca zasedena ({usedSpacePercent}%).", "_matches \"{filter}\"_::_match \"{filter}\"_" : ["se skladajo s filtrom »{filter}«","se skladajo s filtroma »{filter}«","se skladajo s filtri »{filter}«","se skladajo s filtri »{filter}«"], "Direct link was copied (only works for people who have access to this file/folder)" : "Kopirana je neposredna povezava (za uporabnike, ki imajo dostop do datoteke ali mape)", "Path" : "Pot", "_%n byte_::_%n bytes_" : ["%n bajt","%n bajta","%n bajti","%n bajtov"], "Favored" : "Priljubljeno", "Copy direct link (only works for people who have access to this file/folder)" : "Kopiraj neposredno povezavo (za uporabnike, ki imajo dostop do datoteke ali mape)", "Upload file" : "Pošlji datoteko", "An error occurred while trying to update the tags" : "Prišlo je do napake med posodabljanjem oznak", "Upload (max. %s)" : "Pošiljanje (omejitev %s)", "Submitting fields…" : "Poteka objavljanje vsebine polj ...", "Filter filenames…" : "Filtriraj imena datotek ...", "Enable the grid view" : "Omogoči mrežni pogled", "Use this address to access your Files via WebDAV" : "Uporabite ta naslov za dostop do datotek z uporabo WebDAV", "If you have enabled 2FA, you must create and use a new app password by clicking here." : "Če je omogočen sistem dvostopenjskega overjanja 2FA, je treba ustvariti in uporabiti novo geslo programa s klikom na to mesto.", "_{folderCount} folder_::_{folderCount} folders_" : ["{folderCount} mapa","{folderCount} mapi","{folderCount} mape","{folderCount} map"], "_{fileCount} file_::_{fileCount} files_" : ["{fileCount} datoteka","{fileCount} datoteki","{fileCount} datoteke","{fileCount} datotek"], "_1 file and {folderCount} folder_::_1 file and {folderCount} folders_" : ["1 datoteka in {folderCount} mapa","1 datoteka in {folderCount} mapi","1 datoteka in {folderCount} mape","1 datoteka in {folderCount} map"], "_{fileCount} file and 1 folder_::_{fileCount} files and 1 folder_" : ["{fileCount} datoteka in 1 mapa","{fileCount} datoteki in 1 mapa","{fileCount} datoteke in 1 mapa","{fileCount} datotek in 1 mapa"], "{fileCount} files and {folderCount} folders" : "{fileCount} datotek in {folderCount} map", "Personal Files" : "Osebne datoteke", "Text file" : "Besedilna datoteka", "New text file.txt" : "nova_datoteka.txt", "Filter file names …" : "Filtriraj imena datotek..." }, "nplurals=4; plural=(n%100==1 ? 0 : n%100==2 ? 1 : n%100==3 || n%100==4 ? 2 : 3);"); 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Javassist Tutorial</title>
<link rel="stylesheet" type="text/css" href="brown.css">
</head>
<body>
<div align="right">Getting Started with Javassist</div>
<div align="left"><a href="tutorial.html">Previous page</a></div>
<div align="right"><a href="tutorial3.html">Next page</a></div>
<p>
<a href="#intro">4. Introspection and customization</a>
<ul>
<li><a href="#before">Inserting source text at the beginning/end of a method body</a>
<br><li><a href="#alter">Altering a method body</a>
<br><li><a href="#add">Adding a new method or field</a>
<br><li><a href="#runtime">Runtime support classes</a>
<br><li><a href="#annotation">Annotations</a>
<br><li><a href="#import">Import</a>
<br><li><a href="#limit">Limitations</a>
</ul>
<p><br>
<a name="intro">
<h2>4. Introspection and customization</h2>
<p><code>CtClass</code> provides methods for introspection. The
introspective ability of Javassist is compatible with that of
the Java reflection API. <code>CtClass</code> provides
<code>getName()</code>, <code>getSuperclass()</code>,
<code>getMethods()</code>, and so on.
<code>CtClass</code> also provides methods for modifying a class
definition. It allows to add a new field, constructor, and method.
Instrumenting a method body is also possible.
<p>
Methods are represented by <code>CtMethod</code> objects.
<code>CtMethod</code> provides several methods for modifying
the definition of the method. Note that if a method is inherited
from a super class, then
the same <code>CtMethod</code> object
that represents the inherited method represents the method declared
in that super class.
A <code>CtMethod</code> object corresponds to every method declaration.
<p>
For example, if class <code>Point</code> declares method <code>move()</code>
and a subclass <code>ColorPoint</code> of <code>Point</code> does
not override <code>move()</code>, the two <code>move()</code> methods
declared in <code>Point</code> and inherited in <code>ColorPoint</code>
are represented by the identical <code>CtMethod</code> object.
If the method definition represented by this
<code>CtMethod</code> object is modified, the modification is
reflected on both the methods.
If you want to modify only the <code>move()</code> method in
<code>ColorPoint</code>, you first have to add to <code>ColorPoint</code>
a copy of the <code>CtMethod</code> object representing <code>move()</code>
in <code>Point</code>. A copy of the the <code>CtMethod</code> object
can be obtained by <code>CtNewMethod.copy()</code>.
<p><hr width="40%">
<ul>
Javassist does not allow to remove a method or field, but it allows
to change the name. So if a method is not necessary any more, it should be
renamed and changed to be a private method by calling
<code>setName()</code>
and <code>setModifiers()</code> declared in <code>CtMethod</code>.
<p>Javassist does not allow to add an extra parameter to an existing
method, either. Instead of doing that, a new method receiving the
extra parameter as well as the other parameters should be added to the
same class. For example, if you want to add an extra <code>int</code>
parameter <code>newZ</code> to a method:
<ul><pre>void move(int newX, int newY) { x = newX; y = newY; }</pre></ul>
<p>in a <code>Point</code> class, then you should add the following
method to the <code>Point</code> class:
<ul><pre>void move(int newX, int newY, int newZ) {
// do what you want with newZ.
move(newX, newY);
}</pre></ul>
</ul>
<p><hr width="40%">
<p>Javassist also provides low-level API for directly editing a raw
class file. For example, <code>getClassFile()</code> in
<code>CtClass</code> returns a <code>ClassFile</code> object
representing a raw class file. <code>getMethodInfo()</code> in
<code>CtMethod</code> returns a <code>MethodInfo</code> object
representing a <code>method_info</code> structure included in a class
file. The low-level API uses the vocabulary from the Java Virtual
machine specification. The users must have the knowledge about class
files and bytecode. For more details, the users should see the
<a href="tutorial3.html#intro"><code>javassist.bytecode</code> package</a>.
<p>The class files modified by Javassist requires the
<code>javassist.runtime</code> package for runtime support
only if some special identifiers starting with <code>$</code>
are used. Those special identifiers are described below.
The class files modified without those special identifiers
do not need the <code>javassist.runtime</code> package or any
other Javassist packages at runtime.
For more details, see the API documentation
of the <code>javassist.runtime</code> package.
<p><br>
<a name="before">
<h3>4.1 Inserting source text at the beginning/end of a method body</h3>
<p><code>CtMethod</code> and <code>CtConstructor</code> provide
methods <code>insertBefore()</code>, <code>insertAfter()</code>, and
<code>addCatch()</code>. They are used for inserting a code fragment
into the body of an existing method. The users can specify those code
fragments with <em>source text</em> written in Java.
Javassist includes a simple Java compiler for processing source
text. It receives source text
written in Java and compiles it into Java bytecode, which will be
<em>inlined</em> into a method body.
<p>
Inserting a code fragment at the position specified by a line number
is also possible
(if the line number table is contained in the class file).
<code>insertAt()</code> in <code>CtMethod</code> and
<code>CtConstructor</code> takes source text and a line number in the source
file of the original class definition.
It compiles the source text and inserts the compiled code at the line number.
<p>The methods <code>insertBefore()</code>, <code>insertAfter()</code>,
<code>addCatch()</code>, and <code>insertAt()</code>
receive a <code>String</code> object representing
a statement or a block. A statement is a single control structure like
<code>if</code> and <code>while</code> or an expression ending with
a semi colon (<code>;</code>). A block is a set of
statements surrounded with braces <code>{}</code>.
Hence each of the following lines is an example of valid statement or block:
<ul><pre>System.out.println("Hello");
{ System.out.println("Hello"); }
if (i < 0) { i = -i; }
</pre></ul>
<p>The statement and the block can refer to fields and methods.
They can also refer to the parameters
to the method that they are inserted into
if that method was compiled with the -g option
(to include a local variable attribute in the class file).
Otherwise, they must access the method parameters through the special
variables <code>$0</code>, <code>$1</code>, <code>$2</code>, ... described
below.
<em>Accessing local variables declared in the method is not allowed</em>
although declaring a new local variable in the block is allowed.
However, <code>insertAt()</code> allows the statement and the block
to access local variables
if these variables are available at the specified line number
and the target method was compiled with the -g option.
<!--
<p><center><table border=8 cellspacing=0 bordercolor="#cfcfcf">
<tr><td bgcolor="#cfcfcf">
<b>Tip:</b>
<br>    Local variables are not accessible.  
</td></tr>
</table></center>
-->
<p>The <code>String</code> object passed to the methods
<code>insertBefore()</code>, <code>insertAfter()</code>,
<code>addCatch()</code>, and <code>insertAt()</code> are compiled by
the compiler included in Javassist.
Since the compiler supports language extensions,
several identifiers starting with <code>$</code>
have special meaning:
<ul><table border=0>
<tr>
<td><code>$0</code>, <code>$1</code>, <code>$2</code>, ...    </td>
<td><code>this</code> and actual parameters</td>
</tr>
<tr>
<td><code>$args</code></td>
<td>An array of parameters.
The type of <code>$args</code> is <code>Object[]</code>.
</td>
</tr>
<tr>
<td><code>$$</code></td>
<td rowspan=2>All actual parameters.<br>
For example, <code>m($$)</code> is equivalent to
<code>m($1,$2,</code>...<code>)</code></td>
</tr>
<tr><td> </td></tr>
<tr>
<td><code>$cflow(</code>...<code>)</code></td>
<td><code>cflow</code> variable</td>
</tr>
<tr>
<td><code>$r</code></td>
<td>The result type. It is used in a cast expression.</td>
</tr>
<tr>
<td><code>$w</code></td>
<td>The wrapper type. It is used in a cast expression.</td>
</tr>
<tr>
<td><code>$_</code></td>
<td>The resulting value</td>
</tr>
<tr>
<td><code>$sig</code></td>
<td>An array of <code>java.lang.Class</code> objects representing
the formal parameter types.
</td>
</tr>
<tr>
<td><code>$type</code></td>
<td>A <code>java.lang.Class</code> object representing
the formal result type.</td>
</tr>
<tr>
<td><code>$class</code></td>
<td>A <code>java.lang.Class</code> object representing
the class currently edited.</td>
</tr>
</table>
</ul>
<h4>$0, $1, $2, ...</h4>
<p>The parameters passed to the target method
are accessible with
<code>$1</code>, <code>$2</code>, ... instead of
the original parameter names.
<code>$1</code> represents the
first parameter, <code>$2</code> represents the second parameter, and
so on. The types of those variables are identical to the parameter
types.
<code>$0</code> is
equivalent to <code>this</code>. If the method is static,
<code>$0</code> is not available.
<p>These variables are used as following. Suppose that a class
<code>Point</code>:
<pre><ul>class Point {
int x, y;
void move(int dx, int dy) { x += dx; y += dy; }
}
</ul></pre>
<p>To print the values of <code>dx</code> and <code>dy</code>
whenever the method <code>move()</code> is called, execute this
program:
<ul><pre>ClassPool pool = ClassPool.getDefault();
CtClass cc = pool.get("Point");
CtMethod m = cc.getDeclaredMethod("move");
m.insertBefore("{ System.out.println($1); System.out.println($2); }");
cc.writeFile();
</pre></ul>
<p>Note that the source text passed to <code>insertBefore()</code> is
surrounded with braces <code>{}</code>.
<code>insertBefore()</code> accepts only a single statement or a block
surrounded with braces.
<p>The definition of the class <code>Point</code> after the
modification is like this:
<pre><ul>class Point {
int x, y;
void move(int dx, int dy) {
{ System.out.println(dx); System.out.println(dy); }
x += dx; y += dy;
}
}
</ul></pre>
<p><code>$1</code> and <code>$2</code> are replaced with
<code>dx</code> and <code>dy</code>, respectively.
<p><code>$1</code>, <code>$2</code>, <code>$3</code> ... are
updatable. If a new value is assigend to one of those variables,
then the value of the parameter represented by that variable is
also updated.
<h4>$args</h4>
<p>The variable <code>$args</code> represents an array of all the
parameters. The type of that variable is an array of class
<code>Object</code>. If a parameter type is a primitive type such as
<code>int</code>, then the parameter value is converted into a wrapper
object such as <code>java.lang.Integer</code> to store in
<code>$args</code>. Thus, <code>$args[0]</code> is equivalent to
<code>$1</code> unless the type of the first parameter is a primitive
type. Note that <code>$args[0]</code> is not equivalent to
<code>$0</code>; <code>$0</code> represents <code>this</code>.
<p>If an array of <code>Object</code> is assigned to
<code>$args</code>, then each element of that array is
assigned to each parameter. If a parameter type is a primitive
type, the type of the corresponding element must be a wrapper type.
The value is converted from the wrapper type to the primitive type
before it is assigned to the parameter.
<h4>$$</h4>
<p>The variable <code>$$</code> is abbreviation of a list of
all the parameters separated by commas.
For example, if the number of the parameters
to method <code>move()</code> is three, then
<ul><pre>move($$)</pre></ul>
<p>is equivalent to this:
<ul><pre>move($1, $2, $3)</pre></ul>
<p>If <code>move()</code> does not take any parameters,
then <code>move($$)</code> is
equivalent to <code>move()</code>.
<p><code>$$</code> can be used with another method.
If you write an expression:
<ul><pre>exMove($$, context)</pre></ul>
<p>then this expression is equivalent to:
<ul><pre>exMove($1, $2, $3, context)</pre></ul>
<p>Note that <code>$$</code> enables generic notation of method call
with respect to the number of parameters.
It is typically used with <code>$proceed</code> shown later.
<h4>$cflow</h4>
<p><code>$cflow</code> means "control flow".
This read-only variable returns the depth of the recursive calls
to a specific method.
<p>Suppose that the method shown below is represented by a
<code>CtMethod</code> object <code>cm</code>:
<ul><pre>int fact(int n) {
if (n <= 1)
return n;
else
return n * fact(n - 1);
}</pre></ul>
<p>To use <code>$cflow</code>, first declare that <code>$cflow</code>
is used for monitoring calls to the method <code>fact()</code>:
<ul><pre>CtMethod cm = ...;
cm.useCflow("fact");</pre></ul>
<p>The parameter to <code>useCflow()</code> is the identifier of the
declared <code>$cflow</code> variable. Any valid Java name can be
used as the identifier. Since the identifier can also include
<code>.</code> (dot), for example, <code>"my.Test.fact"</code>
is a valid identifier.
<p>Then, <code>$cflow(fact)</code> represents the depth of the
recursive calls to the method specified by <code>cm</code>. The value
of <code>$cflow(fact)</code> is 0 (zero) when the method is
first called whereas it is 1 when the method is recursively called
within the method. For example,
<ul><pre>
cm.insertBefore("if ($cflow(fact) == 0)"
+ " System.out.println(\"fact \" + $1);");
</pre></ul>
<p>translates the method <code>fact()</code> so that it shows the
parameter. Since the value of <code>$cflow(fact)</code> is checked,
the method <code>fact()</code> does not show the parameter if it is
recursively called within <code>fact()</code>.
<p>The value of <code>$cflow</code> is the number of stack frames
associated with the specified method <code>cm</code>
under the current topmost
stack frame for the current thread. <code>$cflow</code> is also
accessible within a method different from the specified method
<code>cm</code>.
<h4>$r</h4>
<p><code>$r</code> represents the result type (return type) of the method.
It must be used as the cast type in a cast expression.
For example, this is a typical use:
<ul><pre>Object result = ... ;
$_ = ($r)result;</pre></ul>
<p>If the result type is a primitive type, then <code>($r)</code>
follows special semantics. First, if the operand type of the cast
expression is a primitive type, <code>($r)</code> works as a normal
cast operator to the result type.
On the other hand, if the operand type is a wrapper type,
<code>($r)</code> converts from the wrapper type to the result type.
For example, if the result type is <code>int</code>, then
<code>($r)</code> converts from <code>java.lang.Integer</code> to
<code>int</code>.
<p>If the result type is <code>void</code>, then
<code>($r)</code> does not convert a type; it does nothing.
However, if the operand is a call to a <code>void</code> method,
then <code>($r)</code> results in <code>null</code>. For example,
if the result type is <code>void</code> and
<code>foo()</code> is a <code>void</code> method, then
<ul><pre>$_ = ($r)foo();</pre></ul>
<p>is a valid statement.
<p>The cast operator <code>($r)</code> is also useful in a
<code>return</code> statement. Even if the result type is
<code>void</code>, the following <code>return</code> statement is valid:
<ul><pre>return ($r)result;</pre></ul>
<p>Here, <code>result</code> is some local variable.
Since <code>($r)</code> is specified, the resulting value is
discarded.
This <code>return</code> statement is regarded as the equivalent
of the <code>return</code> statement without a resulting value:
<ul><pre>return;</pre></ul>
<h4>$w</h4>
<p><code>$w</code> represents a wrapper type.
It must be used as the cast type in a cast expression.
<code>($w)</code> converts from a primitive type to the corresponding
wrapper type.
The following code is an example:
<ul><pre>Integer i = ($w)5;</pre></ul>
<p>The selected wrapper type depends on the type of the expression
following <code>($w)</code>. If the type of the expression is
<code>double</code>, then the wrapper type is <code>java.lang.Double</code>.
<p>If the type of the expression following <code>($w)</code> is not
a primitive type, then <code>($w)</code> does nothing.
<h4>$_</h4>
<p><code>insertAfter()</code> in <code>CtMethod</code> and
<code>CtConstructor</code> inserts the
compiled code at the end of the method. In the statement given to
<code>insertAfter()</code>, not only the variables shown above such as
<code>$0</code>, <code>$1</code>, ... but also <code>$_</code> is
available.
<p>The variable <code>$_</code> represents the resulting value of the
method. The type of that variable is the type of the result type (the
return type) of the method. If the result type is <code>void</code>,
then the type of <code>$_</code> is <code>Object</code> and the value
of <code>$_</code> is <code>null</code>.
<p>Although the compiled code inserted by <code>insertAfter()</code>
is executed just before the control normally returns from the method,
it can be also executed when an exception is thrown from the method.
To execute it when an exception is thrown, the second parameter
<code>asFinally</code> to <code>insertAfter()</code> must be
<code>true</code>.
<p>If an exception is thrown, the compiled code inserted by
<code>insertAfter()</code> is executed as a <code>finally</code>
clause. The value of <code>$_</code> is <code>0</code> or
<code>null</code> in the compiled code. After the execution of the
compiled code terminates, the exception originally thrown is re-thrown
to the caller. Note that the value of <code>$_</code> is never thrown
to the caller; it is rather discarded.
<h4>$sig</h4>
<p>The value of <code>$sig</code> is an array of
<code>java.lang.Class</code> objects that represent the formal
parameter types in declaration order.
<h4>$type</h4>
<p>The value of <code>$type</code> is an <code>java.lang.Class</code>
object representing the formal type of the result value. This
variable refers to <code>Void.class</code> if this is a constructor.
<h4>$class</h4>
<p>The value of <code>$class</code> is an <code>java.lang.Class</code>
object representing the class in which the edited method is declared.
This represents the type of <code>$0</code>.
<h4>addCatch()</h4>
<p><code>addCatch()</code> inserts a code fragment into a method body
so that the code fragment is executed when the method body throws
an exception and the control returns to the caller. In the source
text representing the inserted code fragment, the exception value
is referred to with the special variable <code>$e</code>.
<p>For example, this program:
<ul><pre>
CtMethod m = ...;
CtClass etype = ClassPool.getDefault().get("java.io.IOException");
m.addCatch("{ System.out.println($e); throw $e; }", etype);
</pre></ul>
<p>translates the method body represented by <code>m</code> into
something like this:
<ul><pre>
try {
<font face="serif"><em>the original method body</em></font>
}
catch (java.io.IOException e) {
System.out.println(e);
throw e;
}
</pre></ul>
<p>Note that the inserted code fragment must end with a
<code>throw</code> or <code>return</code> statement.
<p><br>
<a name="alter">
<h3>4.2 Altering a method body</h3>
<p><code>CtMethod</code> and <code>CtConstructor</code> provide
<code>setBody()</code> for substituting a whole
method body. They compile the given source text into Java bytecode
and substitutes it for the original method body. If the given source
text is <code>null</code>, the substituted body includes only a
<code>return</code> statement, which returns zero or null unless the
result type is <code>void</code>.
<p>In the source text given to <code>setBody()</code>, the identifiers
starting with <code>$</code> have special meaning
<ul><table border=0>
<tr>
<td><code>$0</code>, <code>$1</code>, <code>$2</code>, ...    </td>
<td><code>this</code> and actual parameters</td>
</tr>
<tr>
<td><code>$args</code></td>
<td>An array of parameters.
The type of <code>$args</code> is <code>Object[]</code>.
</td>
</tr>
<tr>
<td><code>$$</code></td>
<td>All actual parameters.<br>
</tr>
<tr>
<td><code>$cflow(</code>...<code>)</code></td>
<td><code>cflow</code> variable</td>
</tr>
<tr>
<td><code>$r</code></td>
<td>The result type. It is used in a cast expression.</td>
</tr>
<tr>
<td><code>$w</code></td>
<td>The wrapper type. It is used in a cast expression.</td>
</tr>
<tr>
<td><code>$sig</code></td>
<td>An array of <code>java.lang.Class</code> objects representing
the formal parameter types.
</td>
</tr>
<tr>
<td><code>$type</code></td>
<td>A <code>java.lang.Class</code> object representing
the formal result type.</td>
</tr>
<tr>
<td><code>$class</code></td>
<td rowspan=2>A <code>java.lang.Class</code> object representing
the class that declares the method<br>
currently edited (the type of $0).</td>
</tr>
<tr><td> </td></tr>
</table>
</ul>
Note that <code>$_</code> is not available.
<h4>Substituting source text for an existing expression</h4>
<p>Javassist allows modifying only an expression included in a method body.
<code>javassist.expr.ExprEditor</code> is a class
for replacing an expression in a method body.
The users can define a subclass of <code>ExprEditor</code>
to specify how an expression is modified.
<p>To run an <code>ExprEditor</code> object, the users must
call <code>instrument()</code> in <code>CtMethod</code> or
<code>CtClass</code>.
For example,
<ul><pre>
CtMethod cm = ... ;
cm.instrument(
new ExprEditor() {
public void edit(MethodCall m)
throws CannotCompileException
{
if (m.getClassName().equals("Point")
&& m.getMethodName().equals("move"))
m.replace("{ $1 = 0; $_ = $proceed($$); }");
}
});
</pre></ul>
<p>searches the method body represented by <code>cm</code> and
replaces all calls to <code>move()</code> in class <code>Point</code>
with a block:
<ul><pre>{ $1 = 0; $_ = $proceed($$); }
</pre></ul>
<p>so that the first parameter to <code>move()</code> is always 0.
Note that the substituted code is not an expression but
a statement or a block. It cannot be or contain a try-catch statement.
<p>The method <code>instrument()</code> searches a method body.
If it finds an expression such as a method call, field access, and object
creation, then it calls <code>edit()</code> on the given
<code>ExprEditor</code> object. The parameter to <code>edit()</code>
is an object representing the found expression. The <code>edit()</code>
method can inspect and replace the expression through that object.
<p>Calling <code>replace()</code> on the parameter to <code>edit()</code>
substitutes the given statement or block for the expression. If the given
block is an empty block, that is, if <code>replace("{}")</code>
is executed, then the expression is removed from the method body.
If you want to insert a statement (or a block) before/after the
expression, a block like the following should be passed to
<code>replace()</code>:
<ul><pre>
{ <em>before-statements;</em>
$_ = $proceed($$);
<em>after-statements;</em> }
</pre></ul>
<p>whichever the expression is either a method call, field access,
object creation, or others. The second statement could be:
<ul><pre>$_ = $proceed();</pre></ul>
<p>if the expression is read access, or
<ul><pre>$proceed($$);</pre></ul>
<p>if the expression is write access.
<p>Local variables available in the target expression is
also available in the source text passed to <code>replace()</code>
if the method searched by <code>instrument()</code> was compiled
with the -g option (the class file includes a local variable
attribute).
<h4>javassist.expr.MethodCall</h4>
<p>A <code>MethodCall</code> object represents a method call.
The method <code>replace()</code> in
<code>MethodCall</code> substitutes a statement or
a block for the method call.
It receives source text representing the substitued statement or
block, in which the identifiers starting with <code>$</code>
have special meaning as in the source text passed to
<code>insertBefore()</code>.
<ul><table border=0>
<tr>
<td><code>$0</code></td>
<td rowspan=3>
The target object of the method call.<br>
This is not equivalent to <code>this</code>, which represents
the caller-side <code>this</code> object.<br>
<code>$0</code> is <code>null</code> if the method is static.
</td>
</tr>
<tr><td> </td></tr>
<tr><td> </td></tr>
<tr>
<td><code>$1</code>, <code>$2</code>, ...    </td>
<td>
The parameters of the method call.
</td>
</tr>
<tr><td>
<code>$_</code></td>
<td>The resulting value of the method call.</td>
</tr>
<tr><td><code>$r</code></td>
<td>The result type of the method call.</td>
</tr>
<tr><td><code>$class</code>    </td>
<td>A <code>java.lang.Class</code> object representing
the class declaring the method.
</td>
</tr>
<tr><td><code>$sig</code>    </td>
<td>An array of <code>java.lang.Class</code> objects representing
the formal parameter types.</td>
</tr>
<tr><td><code>$type</code>    </td>
<td>A <code>java.lang.Class</code> object representing
the formal result type.</td>
</tr>
<tr><td><code>$proceed</code>    </td>
<td>The name of the method originally called
in the expression.</td>
</tr>
</table>
</ul>
<p>Here the method call means the one represented by the
<code>MethodCall</code> object.
<p>The other identifiers such as <code>$w</code>,
<code>$args</code> and <code>$$</code>
are also available.
<p>Unless the result type of the method call is <code>void</code>,
a value must be assigned to
<code>$_</code> in the source text and the type of <code>$_</code>
is the result type.
If the result type is <code>void</code>, the type of <code>$_</code>
is <code>Object</code> and the value assigned to <code>$_</code>
is ignored.
<p><code>$proceed</code> is not a <code>String</code> value but special
syntax. It must be followed by an argument list surrounded by parentheses
<code>( )</code>.
<h4>javassist.expr.ConstructorCall</h4>
<p>A <code>ConstructorCall</code> object represents a constructor call
such as <code>this()</code> and <code>super</code> included in a constructor
body.
The method <code>replace()</code> in
<code>ConstructorCall</code> substitutes a statement or
a block for the constructor call.
It receives source text representing the substituted statement or
block, in which the identifiers starting with <code>$</code>
have special meaning as in the source text passed to
<code>insertBefore()</code>.
<ul><table border=0>
<tr>
<td><code>$0</code></td>
<td>
The target object of the constructor call.
This is equivalent to <code>this</code>.
</td>
</tr>
<tr>
<td><code>$1</code>, <code>$2</code>, ...    </td>
<td>
The parameters of the constructor call.
</td>
</tr>
<tr><td><code>$class</code>    </td>
<td>A <code>java.lang.Class</code> object representing
the class declaring the constructor.
</td>
</tr>
<tr><td><code>$sig</code>    </td>
<td>An array of <code>java.lang.Class</code> objects representing
the formal parameter types.</td>
</tr>
<tr><td><code>$proceed</code>    </td>
<td>The name of the constructor originally called
in the expression.</td>
</tr>
</table>
</ul>
<p>Here the constructor call means the one represented by the
<code>ConstructorCall</code> object.
<p>The other identifiers such as <code>$w</code>,
<code>$args</code> and <code>$$</code>
are also available.
<p>Since any constructor must call either a constructor of the super
class or another constructor of the same class,
the substituted statement must include a constructor call,
normally a call to <code>$proceed()</code>.
<p><code>$proceed</code> is not a <code>String</code> value but special
syntax. It must be followed by an argument list surrounded by parentheses
<code>( )</code>.
<h4>javassist.expr.FieldAccess</h4>
<p>A <code>FieldAccess</code> object represents field access.
The method <code>edit()</code> in <code>ExprEditor</code>
receives this object if field access is found.
The method <code>replace()</code> in
<code>FieldAccess</code> receives
source text representing the substitued statement or
block for the field access.
<p>
In the source text, the identifiers starting with <code>$</code>
have special meaning:
<ul><table border=0>
<tr>
<td><code>$0</code></td>
<td rowspan=3>
The object containing the field accessed by the expression.
This is not equivalent to <code>this</code>.<br>
<code>this</code> represents the object that the method including the
expression is invoked on.<br>
<code>$0</code> is <code>null</code> if the field is static.
</td>
</tr>
<tr><td> </td></tr>
<tr><td> </td></tr>
<tr>
<td><code>$1</code></td>
<td rowspan=2>
The value that would be stored in the field
if the expression is write access.
<br>Otherwise, <code>$1</code> is not available.
</td>
</tr>
<tr><td> </td></tr>
<tr>
<td><code>$_</code></td>
<td rowspan=2>
The resulting value of the field access
if the expression is read access.
<br>Otherwise, the value stored in <code>$_</code> is discarded.
</td>
</tr>
<tr><td> </td></tr>
<tr>
<td><code>$r</code></td>
<td rowspan=2>
The type of the field if the expression is read access.
<br>Otherwise, <code>$r</code> is <code>void</code>.
</td>
</tr>
<tr><td> </td></tr>
<tr><td><code>$class</code>    </td>
<td>A <code>java.lang.Class</code> object representing
the class declaring the field.
</td></tr>
<tr><td><code>$type</code></td>
<td>A <code>java.lang.Class</code> object representing
the field type.</td>
</tr>
<tr><td><code>$proceed</code>    </td>
<td>The name of a virtual method executing the original
field access.
.</td>
</tr>
</table>
</ul>
<p>The other identifiers such as <code>$w</code>,
<code>$args</code> and <code>$$</code>
are also available.
<p>If the expression is read access, a value must be assigned to
<code>$_</code> in the source text. The type of <code>$_</code>
is the type of the field.
<h4>javassist.expr.NewExpr</h4>
<p>A <code>NewExpr</code> object represents object creation
with the <code>new</code> operator (not including array creation).
The method <code>edit()</code> in <code>ExprEditor</code>
receives this object if object creation is found.
The method <code>replace()</code> in
<code>NewExpr</code> receives
source text representing the substitued statement or
block for the object creation.
<p>
In the source text, the identifiers starting with <code>$</code>
have special meaning:
<ul><table border=0>
<tr>
<td><code>$0</code></td>
<td>
<code>null</code>.
</td>
</tr>
<tr>
<td><code>$1</code>, <code>$2</code>, ...    </td>
<td>
The parameters to the constructor.
</td>
</tr>
<tr>
<td><code>$_</code></td>
<td rowspan=2>
The resulting value of the object creation.
<br>A newly created object must be stored in this variable.
</td>
</tr>
<tr><td> </td></tr>
<tr>
<td><code>$r</code></td>
<td>
The type of the created object.
</td>
</tr>
<tr><td><code>$sig</code>    </td>
<td>An array of <code>java.lang.Class</code> objects representing
the formal parameter types.</td>
</tr>
<tr><td><code>$type</code>    </td>
<td>A <code>java.lang.Class</code> object representing
the class of the created object.
</td></tr>
<tr><td><code>$proceed</code>    </td>
<td>The name of a virtual method executing the original
object creation.
.</td>
</tr>
</table>
</ul>
<p>The other identifiers such as <code>$w</code>,
<code>$args</code> and <code>$$</code>
are also available.
<h4>javassist.expr.NewArray</h4>
<p>A <code>NewArray</code> object represents array creation
with the <code>new</code> operator.
The method <code>edit()</code> in <code>ExprEditor</code>
receives this object if array creation is found.
The method <code>replace()</code> in
<code>NewArray</code> receives
source text representing the substitued statement or
block for the array creation.
<p>
In the source text, the identifiers starting with <code>$</code>
have special meaning:
<ul><table border=0>
<tr>
<td><code>$0</code></td>
<td>
<code>null</code>.
</td>
</tr>
<tr>
<td><code>$1</code>, <code>$2</code>, ...    </td>
<td>
The size of each dimension.
</td>
</tr>
<tr>
<td><code>$_</code></td>
<td rowspan=2>
The resulting value of the array creation.
<br>A newly created array must be stored in this variable.
</td>
</tr>
<tr><td> </td></tr>
<tr>
<td><code>$r</code></td>
<td>
The type of the created array.
</td>
</tr>
<tr><td><code>$type</code>    </td>
<td>A <code>java.lang.Class</code> object representing
the class of the created array.
</td></tr>
<tr><td><code>$proceed</code>    </td>
<td>The name of a virtual method executing the original
array creation.
.</td>
</tr>
</table>
</ul>
<p>The other identifiers such as <code>$w</code>,
<code>$args</code> and <code>$$</code>
are also available.
<p>For example, if the array creation is the following expression,
<ul><pre>
String[][] s = new String[3][4];
</pre></ul>
then the value of $1 and $2 are 3 and 4, respectively. $3 is not available.
<p>If the array creation is the following expression,
<ul><pre>
String[][] s = new String[3][];
</pre></ul>
then the value of $1 is 3 but $2 is not available.
<h4>javassist.expr.Instanceof</h4>
<p>A <code>Instanceof</code> object represents an <code>instanceof</code>
expression.
The method <code>edit()</code> in <code>ExprEditor</code>
receives this object if an instanceof expression is found.
The method <code>replace()</code> in
<code>Instanceof</code> receives
source text representing the substitued statement or
block for the expression.
<p>
In the source text, the identifiers starting with <code>$</code>
have special meaning:
<ul><table border=0>
<tr>
<td><code>$0</code></td>
<td>
<code>null</code>.
</td>
</tr>
<tr>
<td><code>$1</code></td>
<td>
The value on the left hand side of the original
<code>instanceof</code> operator.
</td>
</tr>
<tr>
<td><code>$_</code></td>
<td>
The resulting value of the expression.
The type of <code>$_</code> is <code>boolean</code>.
</td>
</tr>
<tr>
<td><code>$r</code></td>
<td>
The type on the right hand side of the <code>instanceof</code> operator.
</td>
</tr>
<tr><td><code>$type</code></td>
<td>A <code>java.lang.Class</code> object representing
the type on the right hand side of the <code>instanceof</code> operator.
</td>
</tr>
<tr><td><code>$proceed</code>    </td>
<td rowspan=4>The name of a virtual method executing the original
<code>instanceof</code> expression.
<br>It takes one parameter (the type is <code>java.lang.Object</code>)
and returns true
<br>if the parameter value is an instance of the type on the right
hand side of
<br>the original <code>instanceof</code> operator.
Otherwise, it returns false.
</td>
</tr>
<tr><td> </td></tr>
<tr><td> </td></tr>
<tr><td> </td></tr>
</table>
</ul>
<p>The other identifiers such as <code>$w</code>,
<code>$args</code> and <code>$$</code>
are also available.
<h4>javassist.expr.Cast</h4>
<p>A <code>Cast</code> object represents an expression for
explicit type casting.
The method <code>edit()</code> in <code>ExprEditor</code>
receives this object if explicit type casting is found.
The method <code>replace()</code> in
<code>Cast</code> receives
source text representing the substitued statement or
block for the expression.
<p>
In the source text, the identifiers starting with <code>$</code>
have special meaning:
<ul><table border=0>
<tr>
<td><code>$0</code></td>
<td>
<code>null</code>.
</td>
</tr>
<tr>
<td><code>$1</code></td>
<td>
The value the type of which is explicitly cast.
</td>
</tr>
<tr>
<td><code>$_</code></td>
<td rowspan=2>
The resulting value of the expression.
The type of <code>$_</code> is the same as the type
<br>after the explicit casting, that is, the type surrounded
by <code>( )</code>.
</td>
</tr>
<tr><td> </td></tr>
<tr>
<td><code>$r</code></td>
<td>the type after the explicit casting, or the type surrounded
by <code>( )</code>.
</td>
</tr>
<tr><td><code>$type</code></td>
<td>A <code>java.lang.Class</code> object representing
the same type as <code>$r</code>.
</td>
</tr>
<tr><td><code>$proceed</code>    </td>
<td rowspan=3>The name of a virtual method executing the original
type casting.
<br>It takes one parameter of the type <code>java.lang.Object</code>
and returns it after
<br>the explicit type casting specified by the original expression.
</td>
</tr>
<tr><td> </td></tr>
<tr><td> </td></tr>
</table>
</ul>
<p>The other identifiers such as <code>$w</code>,
<code>$args</code> and <code>$$</code>
are also available.
<h4>javassist.expr.Handler</h4>
<p>A <code>Handler</code> object represents a <code>catch</code>
clause of <code>try-catch</code> statement.
The method <code>edit()</code> in <code>ExprEditor</code>
receives this object if a <code>catch</code> is found.
The method <code>insertBefore()</code> in
<code>Handler</code> compiles the received
source text and inserts it at the beginning of the <code>catch</code> clause.
<p>
In the source text, the identifiers starting with <code>$</code>
have meaning:
<ul><table border=0>
<tr>
<td><code>$1</code></td>
<td>
The exception object caught by the <code>catch</code> clause.
</td>
</tr>
<tr>
<td><code>$r</code></td>
<td>the type of the exception caught by the <code>catch</code> clause.
It is used in a cast expression.
</td>
</tr>
<tr>
<td><code>$w</code></td>
<td>The wrapper type. It is used in a cast expression.
</td>
</tr>
<tr><td><code>$type</code>    </td>
<td rowspan=2>
A <code>java.lang.Class</code> object representing
<br>the type of the exception caught by the <code>catch</code> clause.
</td>
</tr>
<tr><td> </td></tr>
</table>
</ul>
<p>If a new exception object is assigned to <code>$1</code>,
it is passed to the original <code>catch</code> clause as the caught
exception.
<p><br>
<a name="add">
<h3>4.3 Adding a new method or field</h3>
<h4>Adding a method</h4>
<p>Javassist allows the users to create a new method and constructor
from scratch. <code>CtNewMethod</code>
and <code>CtNewConstructor</code> provide several factory methods,
which are static methods for creating <code>CtMethod</code> or
<code>CtConstructor</code> objects.
Especially, <code>make()</code> creates
a <code>CtMethod</code> or <code>CtConstructor</code> object
from the given source text.
<p>For example, this program:
<ul><pre>
CtClass point = ClassPool.getDefault().get("Point");
CtMethod m = CtNewMethod.make(
"public int xmove(int dx) { x += dx; }",
point);
point.addMethod(m);
</pre></ul>
<p>adds a public method <code>xmove()</code> to class <code>Point</code>.
In this example, <code>x</code> is a <code>int</code> field in
the class <code>Point</code>.
<p>The source text passed to <code>make()</code> can include the
identifiers starting with <code>$</code> except <code>$_</code>
as in <code>setBody()</code>.
It can also include
<code>$proceed</code> if the target object and the target method name
are also given to <code>make()</code>. For example,
<ul><pre>
CtClass point = ClassPool.getDefault().get("Point");
CtMethod m = CtNewMethod.make(
"public int ymove(int dy) { $proceed(0, dy); }",
point, "this", "move");
</pre></ul>
<p>this program creates a method <code>ymove()</code> defined below:
<ul><pre>
public int ymove(int dy) { this.move(0, dy); }
</pre></ul>
<p>Note that <code>$proceed</code> has been replaced with
<code>this.move</code>.
<p>Javassist provides another way to add a new method.
You can first create an abstract method and later give it a method body:
<ul><pre>
CtClass cc = ... ;
CtMethod m = new CtMethod(CtClass.intType, "move",
new CtClass[] { CtClass.intType }, cc);
cc.addMethod(m);
m.setBody("{ x += $1; }");
cc.setModifiers(cc.getModifiers() & ~Modifier.ABSTRACT);
</pre></ul>
<p>Since Javassist makes a class abstract if an abstract method is
added to the class, you have to explicitly change the class back to a
non-abstract one after calling <code>setBody()</code>.
<h4>Mutual recursive methods</h4>
<p>Javassist cannot compile a method if it calls another method that
has not been added to a class. (Javassist can compile a method that
calls itself recursively.) To add mutual recursive methods to a class,
you need a trick shown below. Suppose that you want to add methods
<code>m()</code> and <code>n()</code> to a class represented
by <code>cc</code>:
<ul><pre>
CtClass cc = ... ;
CtMethod m = CtNewMethod.make("public abstract int m(int i);", cc);
CtMethod n = CtNewMethod.make("public abstract int n(int i);", cc);
cc.addMethod(m);
cc.addMethod(n);
m.setBody("{ return ($1 <= 0) ? 1 : (n($1 - 1) * $1); }");
n.setBody("{ return m($1); }");
cc.setModifiers(cc.getModifiers() & ~Modifier.ABSTRACT);
</pre></ul>
<p>You must first make two abstract methods and add them to the class.
Then you can give the method bodies to these methods even if the method
bodies include method calls to each other. Finally you must change the
class to a not-abstract class since <code>addMethod()</code> automatically
changes a class into an abstract one if an abstract method is added.
<h4>Adding a field</h4>
<p>Javassist also allows the users to create a new field.
<ul><pre>
CtClass point = ClassPool.getDefault().get("Point");
CtField f = new CtField(CtClass.intType, "z", point);
point.addField(f);
</pre></ul>
<p>This program adds a field named <code>z</code> to class
<code>Point</code>.
<p>If the initial value of the added field must be specified,
the program shown above must be modified into:
<ul><pre>
CtClass point = ClassPool.getDefault().get("Point");
CtField f = new CtField(CtClass.intType, "z", point);
point.addField(f, "0"); <em>// initial value is 0.</em>
</pre></ul>
<p>Now, the method <code>addField()</code> receives the second parameter,
which is the source text representing an expression computing the initial
value. This source text can be any Java expression if the result type
of the expression matches the type of the field. Note that an expression
does not end with a semi colon (<code>;</code>).
<p>Furthermore, the above code can be rewritten into the following
simple code:
<ul><pre>
CtClass point = ClassPool.getDefault().get("Point");
CtField f = CtField.make("public int z = 0;", point);
point.addField(f);
</pre></ul>
<h4>Removing a member</h4>
<p>To remove a field or a method, call <code>removeField()</code>
or <code>removeMethod()</code> in <code>CtClass</code>. A
<code>CtConstructor</code> can be removed by <code>removeConstructor()</code>
in <code>CtClass</code>.
<p><br>
<a name="annotation">
<h3>4.4 Annotations</h3>
<p><code>CtClass</code>, <code>CtMethod</code>, <code>CtField</code>
and <code>CtConstructor</code> provides a convenient method
<code>getAnnotations()</code> for reading annotations.
It returns an annotation-type object.
<p>For example, suppose the following annotation:
<ul><pre>
public @interface Author {
String name();
int year();
}
</pre></ul>
<p>This annotation is used as the following:
<ul><pre>
@Author(name="Chiba", year=2005)
public class Point {
int x, y;
}
</pre></ul>
<p>Then, the value of the annotation can be obtained by
<code>getAnnotations()</code>.
It returns an array containing
annotation-type objects.
<ul><pre>
CtClass cc = ClassPool.getDefault().get("Point");
Object[] all = cc.getAnnotations();
Author a = (Author)all[0];
String name = a.name();
int year = a.year();
System.out.println("name: " + name + ", year: " + year);
</pre></ul>
<p>This code snippet should print:
<ul><pre>
name: Chiba, year: 2005
</pre></ul>
<p>
Since the annoation of <code>Point</code> is only <code>@Author</code>,
the length of the array <code>all</code> is one
and <code>all[0]</code> is an <code>Author</code> object.
The member values of the annotation can be obtained
by calling <code>name()</code> and <code>year()</code>
on the <code>Author</code> object.
<p>To use <code>getAnnotations()</code>, annotation types
such as <code>Author</code> must be included in the current
class path. <em>They must be also accessible from a
<code>ClassPool</code> object.</em> If the class file of an annotation
type is not found, Javassist cannot obtain the default values
of the members of that annotation type.
<p><br>
<a name="runtime">
<h3>4.5 Runtime support classes</h3>
<p>In most cases, a class modified by Javassist does not require
Javassist to run. However, some kinds of bytecode generated by the
Javassist compiler need runtime support classes, which are in the
<code>javassist.runtime</code> package (for details, please read
the API reference of that package). Note that the
<code>javassist.runtime</code> package is the only package that
classes modified by Javassist may need for running. The other
Javassist classes are never used at runtime of the modified classes.
<p><br>
<a name="import">
<h3>4.6 Import</h3>
<p>All the class names in source code must be fully qualified
(they must include package names).
However, the <code>java.lang</code> package is an
exception; for example, the Javassist compiler can
resolve <code>Object</code> as
well as <code>java.lang.Object</code>.
<p>To tell the compiler to search other packages when resolving a
class name, call <code>importPackage()</code> in <code>ClassPool</code>.
For example,
<ul><pre>
ClassPool pool = ClassPool.getDefault();
pool.importPackage("java.awt");
CtClass cc = pool.makeClass("Test");
CtField f = CtField.make("public Point p;", cc);
cc.addField(f);
</pre></ul>
<p>The seconde line instructs the compiler
to import the <code>java.awt</code> package.
Thus, the third line will not throw an exception.
The compiler can recognize <code>Point</code>
as <code>java.awt.Point</code>.
<p>Note that <code>importPackage()</code> <em>does not</em> affect
the <code>get()</code> method in <code>ClassPool</code>.
Only the compiler considers the imported packages.
The parameter to <code>get()</code>
must be always a fully qualified name.
<p><br>
<a name="limit">
<h3>4.7 Limitations</h3>
<p>In the current implementation, the Java compiler included in Javassist
has several limitations with respect to the language that the compiler can
accept. Those limitations are:
<p><li>The new syntax introduced by J2SE 5.0 (including enums and generics)
has not been supported. Annotations are supported only by the low level
API of Javassist.
See the <code>javassist.bytecode.annotation</code> package.
<p><li>Array initializers, a comma-separated list of expressions
enclosed by braces <code>{</code> and <code>}</code>, are not
available unless the array dimension is one.
<p><li>Inner classes or anonymous classes are not supported.
<p><li>Labeled <code>continue</code> and <code>break</code> statements
are not supported.
<p><li>The compiler does not correctly implement the Java method dispatch
algorithm. The compiler may confuse if methods defined in a class
have the same name but take different parameter lists.
<p>For example,
<ul><pre>
class A {}
class B extends A {}
class C extends B {}
class X {
void foo(A a) { .. }
void foo(B b) { .. }
}
</pre></ul>
<p>If the compiled expression is <code>x.foo(new C())</code>, where
<code>x</code> is an instance of X, the compiler may produce a call
to <code>foo(A)</code> although the compiler can correctly compile
<code>foo((B)new C())</code>.
<p><li>The users are recommended to use <code>#</code> as the separator
between a class name and a static method or field name.
For example, in regular Java,
<ul><pre>javassist.CtClass.intType.getName()</pre></ul>
<p>calls a method <code>getName()</code> on
the object indicated by the static field <code>intType</code>
in <code>javassist.CtClass</code>. In Javassist, the users can
write the expression shown above but they are recommended to
write:
<ul><pre>javassist.CtClass#intType.getName()</pre></ul>
<p>so that the compiler can quickly parse the expression.
</ul>
<p><br>
<a href="tutorial.html">Previous page</a>
<a href="tutorial3.html">Next page</a>
<hr>
Java(TM) is a trademark of Sun Microsystems, Inc.<br>
Copyright (C) 2000-2010 by Shigeru Chiba, All rights reserved.
</body>
</html>