Sample

Schnappinger/argoUML/org.argouml.model.euml.XmiReaderEUMLImpl

Human rating uses the original dataset scale.

Human1.9
Lines294

Scores

MethodScoreScaleDataset rank
(0–100)
Posnett00–1; higher is more readable
21.4Δ 19.4
Scalabrino0.7370–1; higher is more readable
45.5Δ 43.6
Dorn0.070–1; higher is more readable
30.0Δ 28.1
Mi0.4840–1; higher is more readable
32.0Δ 30.0
LLOC113Logical lines; fewer is more readable
21.5Δ 19.5
DeepSeek V4 Pro160–20; mean of three runs
47.4Δ 45.4
GPT-6.1 Sol120–20; mean of three runs
5.6Δ 3.6
BTTF0.3130–1; higher is more readable
22.8Δ 20.8
Human1.91–4; original rating
2.0

Views

Source code

// $Id: XmiReaderEUMLImpl.java 19907 2012-12-30 13:06:01Z closettop_nightlybuild $ /******************************************************************************* * Copyright (c) 2007-2012 Tom Morris and other contributors * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: * Tom Morris - initial implementation * Bogdan Pistol - undo support & UUID maps for diagrams * thn *****************************************************************************/ package org.argouml.model.euml; import java.io.BufferedInputStream; import java.io.IOException; import java.io.InputStream; import java.net.MalformedURLException; import java.net.URL; import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Set; import java.util.logging.Level; import java.util.logging.Logger; import org.argouml.model.NotImplementedException; import org.argouml.model.UmlException; import org.argouml.model.XmiReader; import org.eclipse.emf.common.util.URI; import org.eclipse.emf.ecore.EObject; import org.eclipse.emf.ecore.impl.EStructuralFeatureImpl.BasicFeatureMapEntry; import org.eclipse.emf.ecore.impl.EStructuralFeatureImpl.SimpleFeatureMapEntry; import org.eclipse.emf.ecore.resource.Resource; import org.eclipse.emf.ecore.util.FeatureMap.Entry; import org.eclipse.emf.ecore.xml.type.AnyType; import org.eclipse.uml2.uml.Element; import org.xml.sax.InputSource; /** * The implementation of the XmiReader for EUML2. */ class XmiReaderEUMLImpl implements XmiReader { private static final Logger LOG = Logger.getLogger(XmiReaderEUMLImpl.class.getName()); /** * The model implementation. */ private EUMLModelImplementation modelImpl; private static Set<String> searchDirs = new HashSet<String>(); private Resource resource; /** * Constructor. * * @param implementation * The ModelImplementation. */ public XmiReaderEUMLImpl(EUMLModelImplementation implementation) { modelImpl = implementation; } public int getIgnoredElementCount() { return 0; } public String[] getIgnoredElements() { // Not needed currently for UML 2 return new String[0]; } public Map<String, Object> getXMIUUIDToObjectMap() { if (resource == null) { throw new IllegalStateException(); } Map<String, Object> map = new HashMap<String, Object>(); Iterator<EObject> it = resource.getAllContents(); while (it.hasNext()) { EObject o = it.next(); map.put(resource.getURIFragment(o), o); } return map; } public Collection parse(InputSource inputSource, boolean readOnly) throws UmlException { if (inputSource == null) { throw new NullPointerException( "The input source must be non-null."); //$NON-NLS-1$ } InputStream is = null; boolean needsClosing = false; String name = inputSource.getSystemId(); if (name == null) { name = inputSource.getPublicId(); } if (name == null) { name = inputSource.toString(); } LOG.log(Level.FINE, "Parsing {0}", name); //$NON-NLS-1$ if (inputSource.getByteStream() != null) { is = inputSource.getByteStream(); } else if (inputSource.getSystemId() != null) { try { URL url = new URL(inputSource.getSystemId()); if (url != null) { LOG.log(Level.FINE, "Parsing URL {0}", url); //$NON-NLS-1$ is = url.openStream(); if (is != null) { is = new BufferedInputStream(is); needsClosing = true; } } } catch (MalformedURLException e) { // do nothing } catch (IOException e) { // do nothing } } if (is == null) { throw new UnsupportedOperationException(); } // TODO: Review - priority of public ID vs system ID has been reversed // from original implementation String id = inputSource.getPublicId(); if (id == null) { id = inputSource.getSystemId(); if (id != null) { // we only take the filename, not the whole system path int ix = id.lastIndexOf('/'); if (ix != -1) { id = id.substring(ix + 1); } } } Resource r = UMLUtil.getResource(modelImpl, URI.createURI(id), readOnly); try { modelImpl.getModelEventPump().stopPumpingEvents(); r.unload(); r.load(is, null); // TODO: Some import-only UML 2 profiles trigger this - Investigate. // if (!isUML2(r)) { // throw new UmlException("Attempted to load non-UML 2.x file"); // } if (isUML14(r)) { throw new UmlException( "Attempted to load UML 1.4 file"); //$NON-NLS-1$ } } catch (IOException e) { throw new UmlException(e); } finally { modelImpl.getModelEventPump().startPumpingEvents(); if (needsClosing) { try { is.close(); } catch (IOException e) { throw new RuntimeException(e); } } } resource = r; LOG.log(Level.FINE, "Parsed resource " + resource //$NON-NLS-1$ + " with " + resource.getContents().size() //$NON-NLS-1$ + " elements"); //$NON-NLS-1$ return r.getContents(); } /** * Test whether this is a UML2 file. Returns as soon as the first UML2 * element is seen. * * @param r resource containing loaded UML model * @return true if any of the contained objects are instances of UML2 * Element. */ private boolean isUML2(Resource r) { for (EObject eobj : r.getContents()) { if (eobj instanceof Element) { return true; } } return false; } /** * Attempt to detect ArgoUML/NetBeans MDR style UML 1.4 XMI files. These can * be loaded without complaint by EMF, but they won't do us any good. * * @param r resource containing the loaded file * @return true if XMI.header/XMI.metamodel contains xmi.name="UML" and * xmi.version="1.4" */ private boolean isUML14(Resource r) { for (EObject eobj : r.getContents()) { if ("XMI.header".equals(eobj.eClass().getName())) { for (Entry e1 : ((AnyType) eobj).getMixed()) { if (e1 instanceof BasicFeatureMapEntry) { BasicFeatureMapEntry x1 = (BasicFeatureMapEntry) e1; String n1 = x1.getEStructuralFeature().getName(); if ("XMI.metamodel".equals(n1)) { AnyType v = (AnyType) x1.getValue(); for (Entry e2 : v.getAnyAttribute()) { if (e2 instanceof SimpleFeatureMapEntry) { SimpleFeatureMapEntry x = (SimpleFeatureMapEntry) e2; String n = x.getEStructuralFeature().getName(); if ("xmi.name".equals(n)) { if (!("UML".equals((String) x.getValue()))) { LOG.log(Level.WARNING, "Tried to parse XMI file with " + "XMI.header/XMI.metamodel/xmi.name = " + (String) x.getValue()); return false; } } else if ("xmi.version".equals(n)) { String version = (String) x.getValue(); if (version != null && version.startsWith("1.4")) { LOG.log(Level.FINE, "Tried to parse XMI file with " + "XMI.header/XMI.metamodel/xmi.version = " + version); return true; } } } } } } } } } return false; } public boolean setIgnoredElements(String[] elementNames) { if (elementNames == null) { return true; } throw new NotImplementedException( "setIgnoredElements not implemented for UML 2.x"); // TODO: Silently ignore instead? // return false; } public String getTagName() { if (resource == null) { return "uml:Model"; //$NON-NLS-1$ } List l = resource.getContents(); if (!l.isEmpty()) { return "uml:" //$NON-NLS-1$ + modelImpl.getMetaTypes().getName(l.get(0)); } else { return null; } } public void addSearchPath(String path) { searchDirs.add(path); } public List<String> getSearchPath() { return new ArrayList<String>(searchDirs); } public void removeSearchPath(String path) { searchDirs.remove(path); } public String getHeader() { // TODO: Auto-generated method stub throw new NotYetImplementedException(); } }

Loading feature diagnosis…

Source regions

Feature contributions

Feature contributions

FeatureValueContribution
(log-odds)
Halstead volumeHow much symbolic information the code contains. It combines the total number of operators and values with the number of distinct ones.10322.97−340.658
Source linesThe number of non-empty source lines.294+117.6
Byte entropyHow varied the bytes in the source text are. Repeated bytes give a lower value; a more even mixture gives a higher value.4.352−6.528

Intercept 8.87 + feature contributions = -220.716 (log-odds).
Score = sigmoid(-220.716) = 0.

Score0.737

Feature contributions

FeatureValueContribution
(log-odds)
Comment layout frequencyHow frequently the layout switches between lines containing only comments or whitespace and lines containing code.295−9.409
Indentation frequencyHow rapidly indentation changes from line to line.237+7.46
Number layout frequencyHow rapidly the number of numeric values per line changes through the code.237−5.018
Identifier layout (vertical)How rapidly the visual pattern of identifier characters changes from top to bottom.293.927+3.699
Comment layout (horizontal)How rapidly the visual pattern of comment characters changes from left to right.94.953+0.728
Identifier layout (horizontal)How rapidly the visual pattern of identifier characters changes from left to right. It measures spatial frequency, not the meaning of the names.94.936−0.356
Operator visual areaThe share of the code’s visual area occupied by operators such as +, =, and *.0.073+0.233

Intercept 0.07 + feature contributions = -2.592 (log-odds).
Score = sigmoid(-2.592) = 0.07.

Score0.484
Score113
Run 1

The code demonstrates good structure with clear method separation and logical organization within a single class. Nesting is moderate but controlled, except in the isUML14 method which has deeply nested conditionals that reduce readability. Intent is generally clear through descriptive method names and comments, though some methods like getIgnoredElementCount are trivial stubs. Code length is appropriate for the complexity involved, with no unnecessary verbosity. Action granularity is mostly one action per line, making the code easy to follow. Reading flow is natural, with methods arranged in a logical order and good use of comments to explain non-obvious decisions. The isUML14 method stands out as the weakest point due to its complex nesting and multiple level if statements that require careful reading to understand. Overall, this is well-written legacy code that would benefit primarily from refactoring the isUML14 method.

Run 2

The code is well-structured with clear method separation and logical organization. The class has a clear purpose with most methods having good cohesion. Nesting is generally flat, with only the isUML14 method having deeper nesting, though its purpose is clear. Intent is generally clear through descriptive method names and Javadoc comments, despite some commented-out code and TODOs. Code length is reasonable, though the parse method could be slightly more concise with extracted helper methods. Action granularity is good, with one main action per line. Reading flow follows a natural progression from constructor to utility methods to core functions. Minor improvements could include extracting URL handling logic and reducing nesting in isUML14.

Run 3

The code is generally readable with clear method names, Javadoc comments, and logical organization. Methods like getXMIUUIDToObjectMap() and getTagName() are straightforward. However, there are significant readability issues: the parse() method is overly long (50+ lines) with multiple nested conditionals and a long try-catch-finally block, making the flow hard to follow. The isUML14() method has deeply nested loops (4-5 levels) that obscure intent and increase cognitive load. Some sections, like the TODO comments and commented-out code, add noise. Action granularity is mostly reasonable, but several lines combine multiple operations (e.g., conditionals with assignments). Overall, the code is moderate in readability, hindered by excessive nesting and long methods.

Run 1

Code Structure: Responsibilities are organized into named methods, but parse combines input selection, identifier processing, resource loading, validation, and cleanup. Nesting: Most methods are flat, while isUML14 has deeply nested loops and conditionals that significantly hinder comprehension. Clarity of intent: Method names and documentation explain the overall purpose, but abbreviated variables, raw collection types, silent exception catches, and unimplemented methods obscure details. Code length: Small utility methods are concise; parse and isUML14 are lengthy and could benefit from extracted helpers. Commented-out code and repetitive annotations add clutter. Action granularity: Statements generally perform one action per line, making individual operations easy to follow. Reading flow: Consistent formatting and sequential parsing steps help, but nested detection logic, scattered TODOs, and complex cleanup interrupt otherwise natural reading.

Run 2

1. Code Structure: Methods separate public operations and format checks logically, but parse mixes input resolution, resource loading, event management, and cleanup. 2. Nesting: Most methods are flat, but isUML14 contains deeply nested loops and conditionals that make its logic difficult to follow. 3. Clarity of intent: Descriptive method names and documentation establish purpose; abbreviated variables, silent exception handling, and unfinished stubs reduce clarity. 4. Code length: Small methods are concise, while parse and isUML14 would benefit from helper extraction. Commented-out code, redundant checks, and boilerplate add clutter. 5. Action granularity: Statements generally perform one action per line, with consistent formatting; some chained calls and long expressions require extra attention. 6. Reading flow: Input-to-load sequencing is mostly natural, but nested metadata inspection, scattered TODOs, and cleanup-related control flow interrupt readability.

Run 3

Code Structure: Responsibilities are separated into methods, but parse combines input selection, identifier handling, loading, validation, and cleanup. Nesting: Most methods are straightforward, but isUML14 contains deeply nested loops and conditionals that obscure its logic. Clarity of intent: Descriptive method names and documentation explain the overall purpose; abbreviated variables, raw collection types, silent exception handling, and unexplained exceptions reduce clarity. Code length: The class is manageable, but the long parsing and detection methods, redundant checks, commented-out code, and TODOs add clutter. Action granularity: Statements generally perform one action per line, making individual operations easy to follow. Reading flow: Input-to-resource processing follows a logical sequence, but nested validation, cleanup handling, inconsistent wrapping, and legacy comment noise interrupt the flow.