locating term introductions to support code comprehension · r o o t s locating term introductions...

30
R O O T S Locating Term Introductions to support Code Comprehension 13. Workshop Software-Reengineering (WSR) Jan Nonnen, Daniel Speicher Bad Honnef, 03. Mai 2011

Upload: others

Post on 16-Mar-2020

0 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Locating Term Introductions to support Code Comprehension · R O O T S Locating Term Introductions to support Code Comprehension 13. Workshop Software-Reengineering (WSR) Jan Nonnen,

R O O T S

Locating Term Introductions to support Code Comprehension

13. Workshop Software-Reengineering (WSR)

Jan Nonnen, Daniel Speicher

Bad Honnef, 03. Mai 2011

Page 2: Locating Term Introductions to support Code Comprehension · R O O T S Locating Term Introductions to support Code Comprehension 13. Workshop Software-Reengineering (WSR) Jan Nonnen,

R O O T S

Zwei Perspektiven auf den Sourcecode

Page 3: Locating Term Introductions to support Code Comprehension · R O O T S Locating Term Introductions to support Code Comprehension 13. Workshop Software-Reengineering (WSR) Jan Nonnen,

© 2011 Jan Nonnen, Daniel Speicher Locating Term Introductions to support Code Comprehension - WSR 2011 R O O T S

Perspektive Compiler

protected void adjustBoundsToFit() {

S t = gt();

int sbw = bw > 0 ? bw : 1;

if ((t != null)) {

F f = gf();

if (f != null) {

D ms = FU.gte(t, f);

if (gi() != null) {

R ir = gi().gb();

int eh

= M.mx(ir.h - ms.h, 0);

ms.ex(ir.w + 4, eh);

}

ms.ex(10 + (2 * sbw),

4 + (2 * sbw));

sb(new R(gl(), ms));

}

}

}

int sbw = bw > 0 ? bw : 1

F f = gf()

D ms = FU.gte(t, f)

R ir = gi().gb()

int eh = M.mx(ir.h - ms.h, 0)

ms.ex(ir.w + 4, eh)

sb(new R(gl(), ms))

S t = gt()

t != null

f != null

gi() != null

end

ms.ex(10 + (2 * sbw), 4 + (2 * sbw))

Page 4: Locating Term Introductions to support Code Comprehension · R O O T S Locating Term Introductions to support Code Comprehension 13. Workshop Software-Reengineering (WSR) Jan Nonnen,

© 2011 Jan Nonnen, Daniel Speicher Locating Term Introductions to support Code Comprehension - WSR 2011 R O O T S

Perspektive Entwickler

protected void adjustBoundsToFit() {

String text = getText();

int safeBorderWidth = borderWidth > 0 ? borderWidth : 1;

if ((text != null)) {

Font font = getFont();

if (font != null) {

Dimension minSize = FigureUtilities.getTextExtents(text, font);

if (getIcon() != null) {

Rectangle imageRect = getIcon().getBounds();

int expandHeight

= Math.max(imageRect.height - minSize.height, 0);

minSize.expand(imageRect.width + 4, expandHeight);

}

minSize.expand(10 + (2 * safeBorderWidth),

4 + (2 * safeBorderWidth));

setBounds(new Rectangle(getLocation(), minSize));

}

}

}

Page 5: Locating Term Introductions to support Code Comprehension · R O O T S Locating Term Introductions to support Code Comprehension 13. Workshop Software-Reengineering (WSR) Jan Nonnen,

© 2011 Jan Nonnen, Daniel Speicher Locating Term Introductions to support Code Comprehension - WSR 2011 R O O T S

Verstehen anhand von Bezeichnern

protected void adjust bounds to fit() {

String text = get text();

int safe border width = border width > 0 ? border width : 1;

if ((text != null)) {

Font font = get font();

if (font != null) {

Dimension min size = FigureUtilities.get text extents(text, font);

if (get icon() != null) {

Rectangle image rect = get icon().get bounds();

int expand height

= Math.max(image rect.height – min size.height, 0);

min size.expand(image rect.width + 4, expand height);

}

min size.expand(10 + (2 * safe border width),

4 + (2 * safe border width));

set bounds(new Rectangle(get location(), min size));

}

}

}

Page 6: Locating Term Introductions to support Code Comprehension · R O O T S Locating Term Introductions to support Code Comprehension 13. Workshop Software-Reengineering (WSR) Jan Nonnen,

© 2011 Jan Nonnen, Daniel Speicher Locating Term Introductions to support Code Comprehension - WSR 2011 R O O T S

Verstehen anhand von Bezeichnern

protected void adjustBoundsToFit() {

adjust bounds to fit text get safe

border width null font size extents icon image rect expand height

Math max min set bounds location

Page 7: Locating Term Introductions to support Code Comprehension · R O O T S Locating Term Introductions to support Code Comprehension 13. Workshop Software-Reengineering (WSR) Jan Nonnen,

© 2011 Jan Nonnen, Daniel Speicher Locating Term Introductions to support Code Comprehension - WSR 2011 R O O T S

EinleitungNotation und Vorbereitungen

Bezeichner sind

Klassen-, Methoden-, Feld- oder lokale Variablennamen

Zur Analyse von Bezeichnern werden diese nach folgenden Regeln

getrennt und in Kleinbuchstaben umgewandelt:

CamelCase-Notation

IContextProvider wird zu (i, context, provider)

Nutzung von Sonderzeichen(wie „_“) oder Zahlen

my_variable2string wird zu (my, variable, 2, string)

Die so erhaltenen Teile werden in im Folgenden als Terme bezeichnet

Page 8: Locating Term Introductions to support Code Comprehension · R O O T S Locating Term Introductions to support Code Comprehension 13. Workshop Software-Reengineering (WSR) Jan Nonnen,

© 2011 Jan Nonnen, Daniel Speicher Locating Term Introductions to support Code Comprehension - WSR 2011 R O O T S

EinleitungDer inkonsistente Kontext

class NearCompaniesContextTracking implements ServiceTrackerCustomizer {

public static ServiceTracker openTracker(BundleContext bundleContext,

Observer contextObserver)

{

ServiceTrackerCustomizer customizer=new NearCompaniesContextTracking(

bundleContext,

contextObserver);

ServiceTracker serviceTracker = new ServiceTracker(bundleContext,

INearCompaniesContextProvider.class.getName(), customizer);

serviceTracker.open();

return serviceTracker;

}

}

Quelle: CSI Projekt der Abteilung III

Page 9: Locating Term Introductions to support Code Comprehension · R O O T S Locating Term Introductions to support Code Comprehension 13. Workshop Software-Reengineering (WSR) Jan Nonnen,

© 2011 Jan Nonnen, Daniel Speicher Locating Term Introductions to support Code Comprehension - WSR 2011 R O O T S

EinleitungDer inkonsistente Kontext

Page 10: Locating Term Introductions to support Code Comprehension · R O O T S Locating Term Introductions to support Code Comprehension 13. Workshop Software-Reengineering (WSR) Jan Nonnen,

© 2011 Jan Nonnen, Daniel Speicher Locating Term Introductions to support Code Comprehension - WSR 2011 R O O T S

EinleitungFragen und Herausforderungen

Wie kann ich automatisch herausfinden, ob unterschiedliche

Bedeutungen vorliegen?

Ansatz: Werkzeug der Term-Einführung und Analyse der Nutzung

Kann ich jeweils angeben welche Bedeutung gemeint ist?

Ansatz: Identifizierung des Einführungsortes mithilfe der statischen

Abhängigkeiten und des Datenflusses

Gibt ein Modul uneindeutige Bezeichnungen nach außen weiter?

Ansatz: Identifikation und Hinweis an den Entwickler

Page 11: Locating Term Introductions to support Code Comprehension · R O O T S Locating Term Introductions to support Code Comprehension 13. Workshop Software-Reengineering (WSR) Jan Nonnen,

© 2011 Jan Nonnen, Daniel Speicher Locating Term Introductions to support Code Comprehension - WSR 2011 R O O T S

Einleitung Bedeutung von Bezeichnern

„cat“ ist ein Lebenwesen/Haustier

„cat“ ist ein Unix-Programm zur

Konkatenation von Datei-Inhalten

Was bedeutet cat?

Welche Bedeutung steckt dann hinter der Methode killCat() ?

Page 12: Locating Term Introductions to support Code Comprehension · R O O T S Locating Term Introductions to support Code Comprehension 13. Workshop Software-Reengineering (WSR) Jan Nonnen,

R O O T S

Term-Einführung

Page 13: Locating Term Introductions to support Code Comprehension · R O O T S Locating Term Introductions to support Code Comprehension 13. Workshop Software-Reengineering (WSR) Jan Nonnen,

© 2011 Jan Nonnen, Daniel Speicher Locating Term Introductions to support Code Comprehension - WSR 2011 R O O T S

Term-EinführungEinleitung

Ziel: Lokalisierung von Einführungsorten in einem Projekt

Vermutung:

Bedeutung eines Bezeichners lässt sich aus dem Code erschließen …

… wenn man an eine geeignete Stelle schaut

Page 14: Locating Term Introductions to support Code Comprehension · R O O T S Locating Term Introductions to support Code Comprehension 13. Workshop Software-Reengineering (WSR) Jan Nonnen,

© 2011 Jan Nonnen, Daniel Speicher Locating Term Introductions to support Code Comprehension - WSR 2011 R O O T S

Term-EinführungWie finden?

Ziel: Approximation durch eine Heuristik

Ansatz: Explorative empirische Studie

Anfängliche Sammlung von möglichen Heuristiken

Evaluation von Precision und Recall der Heuristiken auf einer

Projektmenge (Exploration Phase)

Fokus auf Precision

Schätzung von Precision und Recall anhand der Stichprobe

Manuelle Klassifikation der Stichproben

Untersuchung der Ergebnisse und Adaption der Heuristiken

Validierung auf einer unabhängigen Projektmenge (Validation Phase)

Page 15: Locating Term Introductions to support Code Comprehension · R O O T S Locating Term Introductions to support Code Comprehension 13. Workshop Software-Reengineering (WSR) Jan Nonnen,

© 2011 Jan Nonnen, Daniel Speicher Locating Term Introductions to support Code Comprehension - WSR 2011 R O O T S

Term-EinführungNaive Heuristik

Definiere die Klasse als

Einführungsort für einen Term,

wenn der Term..

der Klassenname ist

der Name einer public/protected

Methode ist

public class Calvin {

private void likes(){

}

public void eats(Food food){

}

}

Page 16: Locating Term Introductions to support Code Comprehension · R O O T S Locating Term Introductions to support Code Comprehension 13. Workshop Software-Reengineering (WSR) Jan Nonnen,

© 2011 Jan Nonnen, Daniel Speicher Locating Term Introductions to support Code Comprehension - WSR 2011 R O O T S

Term-EinführungEindeutigkeit

Problem bei der Naiven Einführung

Einführung von geerbten Methoden

Lösung: Reduktion der

Einführungen für abhängige

Klassen

Betrachte „Einführungsketten“

gegeben durch statische

Abhängigkeiten

Entferne abhängige Vorkommen

interface Tiger {

public void eats(Food food);

}

public class SofttoyTiger

implements Tiger{

@Override

public void eats(Food food){

// soft toys eat nothing

}

}

Page 17: Locating Term Introductions to support Code Comprehension · R O O T S Locating Term Introductions to support Code Comprehension 13. Workshop Software-Reengineering (WSR) Jan Nonnen,

© 2011 Jan Nonnen, Daniel Speicher Locating Term Introductions to support Code Comprehension - WSR 2011 R O O T S

Term-EinführungIterative Heuristik

Weiteres Problem:

„Kuscheltier-Konzept“ nicht

eingeführt

Lösung:

Benutzung der Termzerlegung

Führe iterativ einzelne fehlende

Terme in einem Klassennamen

ein

interface Tiger {

public void eats(Food food);

}

public class SofttoyTiger

implements Tiger{

@Override

public void eats(Food food){

}

}

Page 18: Locating Term Introductions to support Code Comprehension · R O O T S Locating Term Introductions to support Code Comprehension 13. Workshop Software-Reengineering (WSR) Jan Nonnen,

© 2011 Jan Nonnen, Daniel Speicher Locating Term Introductions to support Code Comprehension - WSR 2011 R O O T S

Term-EinführungSpezialisierungs-Heuristik

Problem:

Bisherige Ansätze funktionierten, da „Tiger“ bekannt war

Ansatz basiert auf Arbeit von Falleri et al.:

Automatic Extraction of a WordNet-Like Identifier Network from Software

In: 2010 IEEE 18th International Conference on Program Comprehension (ICPC)

Aufbau einer eigenen Ontologie zwischen Bezeichnern

Terme der Bezeichner nach linguistischer Dominanz sortiert

I ate an orange and a green apple

ate

I orange apple

green

Page 19: Locating Term Introductions to support Code Comprehension · R O O T S Locating Term Introductions to support Code Comprehension 13. Workshop Software-Reengineering (WSR) Jan Nonnen,

© 2011 Jan Nonnen, Daniel Speicher Locating Term Introductions to support Code Comprehension - WSR 2011 R O O T S

Term-EinführungSpezialisierungs-Heuristik

Vorgehen:

Sortierung der Klassennamen

nach Dominanz

interface AbstractTiger {

public void eats(Food food);

}

public class SofttoyTiger

implements

AbstractTiger{

@Override

public void eats(Food food){

}

}

Page 20: Locating Term Introductions to support Code Comprehension · R O O T S Locating Term Introductions to support Code Comprehension 13. Workshop Software-Reengineering (WSR) Jan Nonnen,

© 2011 Jan Nonnen, Daniel Speicher Locating Term Introductions to support Code Comprehension - WSR 2011 R O O T S

Term-EinführungSpezifische Einführung

Vorgehen:

Sortierung der Klassennamen

nach Dominanz

Entfernen von gemeinsamen

Termen am Anfang der

sortierten Bezeichner

Definiere die übrig gebliebenen

Terme als eingeführt in den

entsprechenden Klassen

Erhalten „Klassenspezifische“

Terme

interface AbstractTiger {

public void eats(Food food);

}

public class SofttoyTiger

implements

AbstractTiger{

@Override

public void eats(Food food){

}

}

Page 21: Locating Term Introductions to support Code Comprehension · R O O T S Locating Term Introductions to support Code Comprehension 13. Workshop Software-Reengineering (WSR) Jan Nonnen,

© 2011 Jan Nonnen, Daniel Speicher Locating Term Introductions to support Code Comprehension - WSR 2011 R O O T S

Evaluations Projekte

Explorations Phase Apache Commons Logging iText JWNL QuickUML

BCEL Jaxen Lexi Smack

GlazedLists jEdit OpenCloud Time & Money Code Library

Google Workspacemechanic Jsch PlanetaMessenger TreeTagger4Java

IBM WALA Core JVM Monitor.core PMD Zest Core

Validations Phase Bouncy Castle Crypto Concept Explorer NGramJ yGuard

BSF DDDSample Rhino zxing

Cobertura Edu.cmu.hcii.paint

30 Open Source Projekte

2.000.000 Lines of Code

8000 Stichproben manuell validiert

Page 22: Locating Term Introductions to support Code Comprehension · R O O T S Locating Term Introductions to support Code Comprehension 13. Workshop Software-Reengineering (WSR) Jan Nonnen,

R O O T S

Was haben wir nach der Exploration gelernt?

Page 23: Locating Term Introductions to support Code Comprehension · R O O T S Locating Term Introductions to support Code Comprehension 13. Workshop Software-Reengineering (WSR) Jan Nonnen,

© 2011 Jan Nonnen, Daniel Speicher Locating Term Introductions to support Code Comprehension - WSR 2011 R O O T S

False PositivesKategorien

without description 17%

compound 9%

anonymous class 11%

preposition 2%

delegation 4%

external 4%

repeats static information

11%

null implementation 6%

from Object 5%

test 17%

enum 4%

bug 2% other

5%

enclosing 1%

abbreviation 2%

Page 24: Locating Term Introductions to support Code Comprehension · R O O T S Locating Term Introductions to support Code Comprehension 13. Workshop Software-Reengineering (WSR) Jan Nonnen,

© 2011 Jan Nonnen, Daniel Speicher Locating Term Introductions to support Code Comprehension - WSR 2011 R O O T S

False PositivesKategorien

without description 17%

compound 9%

anonymous class 11%

preposition 2%

delegation 4%

external 4%

repeats static information

11% null implementation 6%

from Object 5%

test 17%

enum 4%

bug 2% other

5%

enclosing 1%

abbreviation 2%

RichMediaFactory

Page 25: Locating Term Introductions to support Code Comprehension · R O O T S Locating Term Introductions to support Code Comprehension 13. Workshop Software-Reengineering (WSR) Jan Nonnen,

© 2011 Jan Nonnen, Daniel Speicher Locating Term Introductions to support Code Comprehension - WSR 2011 R O O T S

False PositivesKategorien

without description 17%

compound 9%

anonymous class 11%

preposition 2%

delegation 4%

external 4%

repeats static information

11% null implementation 6%

from Object 5%

test 17%

enum 4%

bug 2% other

5%

enclosing 1%

abbreviation 2%

public abstract class

AbstractModel{

..

}

Page 26: Locating Term Introductions to support Code Comprehension · R O O T S Locating Term Introductions to support Code Comprehension 13. Workshop Software-Reengineering (WSR) Jan Nonnen,

© 2011 Jan Nonnen, Daniel Speicher Locating Term Introductions to support Code Comprehension - WSR 2011 R O O T S

False PositivesKategorien

without description 17%

compound 9%

anonymous class 11%

preposition 2%

delegation 4%

external 4%

repeats static information

11% null implementation 6%

from Object 5%

test 17%

enum 4%

bug 2% other

5%

enclosing 1%

abbreviation 2%

@Override

public boolean equals(..

Page 27: Locating Term Introductions to support Code Comprehension · R O O T S Locating Term Introductions to support Code Comprehension 13. Workshop Software-Reengineering (WSR) Jan Nonnen,

© 2011 Jan Nonnen, Daniel Speicher Locating Term Introductions to support Code Comprehension - WSR 2011 R O O T S

False NegativesKategorien

property 17%

public constant 12%

local variable 37%

comment description 14%

methodname 4%

pervasive usage 4%

bugs 10%

enum constant 2%

Page 28: Locating Term Introductions to support Code Comprehension · R O O T S Locating Term Introductions to support Code Comprehension 13. Workshop Software-Reengineering (WSR) Jan Nonnen,

© 2011 Jan Nonnen, Daniel Speicher Locating Term Introductions to support Code Comprehension - WSR 2011 R O O T S

Anpassungen nach Explorations Phase

Terme die statische Informationen wiedergeben sollten ignoriert

werden

Beispiel: Abstract an dem Anfang des Namens einer abstrakten Klasse

Gesonderte Behandlung für Einführungen in einer externen Library

Überschriebene externe Methoden sollten keine Einführung sein

Kombination von den anfänglichen Heuristiken zu einer Heuristik

Anpassung der Behandlung von Enum Klassen

Page 29: Locating Term Introductions to support Code Comprehension · R O O T S Locating Term Introductions to support Code Comprehension 13. Workshop Software-Reengineering (WSR) Jan Nonnen,

© 2011 Jan Nonnen, Daniel Speicher Locating Term Introductions to support Code Comprehension - WSR 2011 R O O T S

FazitZusammenfassung

Konzept der „Term-Einführung“ für die Lokalisierung von

projektspezifischen Term-Bedeutungen

Eine Heuristik als Ergebnis der explorativen empirischen Studie

Precision Median von 76%

Verzicht auf eine externe Ontologie

Unterstützung für den Entwickler und Hilfe zur Vermeidung von

Inkonsistenzen

Beispiel: context im CSI Projekt

Projekt-Wörterbuch als Eclipse Plugin

Enthält: Term, Häufigkeit, Einführungsorte, Nutzungen

Möglichkeit der Abspeicherung von Term-Beschreibungen

Page 30: Locating Term Introductions to support Code Comprehension · R O O T S Locating Term Introductions to support Code Comprehension 13. Workshop Software-Reengineering (WSR) Jan Nonnen,

© 2011 Jan Nonnen, Daniel Speicher Locating Term Introductions to support Code Comprehension - WSR 2011 R O O T S

FazitAnschließende Arbeiten

Expandierung von Abkürzungen zu der entsprechenden Bedeutung

„Psychologische“ Bedienbarkeits-Studien:

Wie verhält sich ein Entwickler beim Suchen im unbekannten Code?

Untersuchung in wieweit die Referenzen auf Term-Einführungen die

Verständlichkeit tatsächlich verbessern

Wie sollten zusammengesetzte Begriffe betrachtet werden?