Skip to content

Commit

Permalink
Perform clean code of bundles/org.eclipse.equinox.p2.updatesite
Browse files Browse the repository at this point in the history
  • Loading branch information
eclipse-equinox-bot committed Mar 9, 2025
1 parent eba65b6 commit dbd556f
Show file tree
Hide file tree
Showing 18 changed files with 551 additions and 287 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -120,14 +120,16 @@ public CategoryParser(URI siteLocation) {
log(e);
}

if (Tracing.DEBUG_GENERATOR_PARSING)
if (Tracing.DEBUG_GENERATOR_PARSING) {
debug("Created"); //$NON-NLS-1$
}
}

public int currentState() {
Integer state = stateStack.peek();
if (state != null)
if (state != null) {
return state.intValue();
}
return STATE_IGNORED_ELEMENT;
}

Expand All @@ -151,10 +153,12 @@ public void characters(char[] ch, int start, int length) {
case STATE_PARAM :
text = text.trim();
String existing = null;
if (objectStack.peek() instanceof String)
if (objectStack.peek() instanceof String) {
existing = (String) objectStack.pop();
if (existing != null)
}
if (existing != null) {
text = existing + text;
}
objectStack.push(text);
break;
default :
Expand Down Expand Up @@ -211,8 +215,9 @@ public void endElement(String uri, String localName, String qName) {
SiteIU completeIU = (SiteIU) objectStack.pop();
String id = completeIU.getID();
String expression = completeIU.getQueryExpression();
if (id == null && expression == null)
if (id == null && expression == null) {
internalError("The IU must specify an id or an expression to match against."); //$NON-NLS-1$
}
break;

case STATE_EXPRESSION :
Expand All @@ -221,8 +226,9 @@ public void endElement(String uri, String localName, String qName) {
text = (String) objectStack.pop();
SiteIU iu = (SiteIU) objectStack.peek();
iu.setQueryExpression(text);
if (Tracing.DEBUG_GENERATOR_PARSING)
if (Tracing.DEBUG_GENERATOR_PARSING) {
debug("Found Expression: " + text); //$NON-NLS-1$
}
}
break;
case STATE_PARAM :
Expand All @@ -231,8 +237,9 @@ public void endElement(String uri, String localName, String qName) {
text = (String) objectStack.pop();
SiteIU iu = (SiteIU) objectStack.peek();
iu.addQueryParams(text);
if (Tracing.DEBUG_GENERATOR_PARSING)
if (Tracing.DEBUG_GENERATOR_PARSING) {
debug("Found Param: " + text); //$NON-NLS-1$
}
}
break;

Expand Down Expand Up @@ -273,15 +280,17 @@ public void endElement(String uri, String localName, String qName) {
text = text.trim();

info = (URLEntry) objectStack.pop();
if (text != null)
if (text != null) {
info.setAnnotation(text);
}

SiteModel siteModel = (SiteModel) objectStack.peek();
// override description.
// do not raise error as previous description may be default one
// when parsing site tag
if (DESCRIPTION_SITE_ALREADY_SEEN)
if (DESCRIPTION_SITE_ALREADY_SEEN) {
debug(NLS.bind(Messages.DefaultSiteParser_ElementAlreadySet, (new String[] {getState(state)})));
}
siteModel.setDescription(info);
DESCRIPTION_SITE_ALREADY_SEEN = true;
break;
Expand All @@ -303,13 +312,14 @@ public void endElement(String uri, String localName, String qName) {
text = text.trim();

info = (URLEntry) objectStack.pop();
if (text != null)
if (text != null) {
info.setAnnotation(text);
}

SiteCategory category = (SiteCategory) objectStack.peek();
if (category.getDescription() != null)
if (category.getDescription() != null) {
internalError(NLS.bind(Messages.DefaultSiteParser_ElementAlreadySet, (new String[] {getState(state), category.getLabel()})));
else {
} else {
checkTranslated(info.getAnnotation());
category.setDescription(info.getAnnotation());
}
Expand All @@ -320,8 +330,9 @@ public void endElement(String uri, String localName, String qName) {
break;
}

if (Tracing.DEBUG_GENERATOR_PARSING)
if (Tracing.DEBUG_GENERATOR_PARSING) {
debug("End Element:" + uri + ":" + localName + ":" + qName);//$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
}
}

/*
Expand All @@ -337,8 +348,9 @@ private void error(IStatus error) {
}

status.add(error);
if (Tracing.DEBUG_GENERATOR_PARSING)
if (Tracing.DEBUG_GENERATOR_PARSING) {
LogHelper.log(error);
}
}

/**
Expand Down Expand Up @@ -447,16 +459,18 @@ private void handleFeatureState(String elementName, Attributes attributes) {
if (elementName.equals(CATEGORY)) {
stateStack.push(Integer.valueOf(STATE_CATEGORY));
processCategory(attributes);
} else
} else {
internalErrorUnknownTag(NLS.bind(Messages.DefaultSiteParser_UnknownElement, (new String[] {elementName, getState(currentState())})));
}
}

private void handleBundleState(String elementName, Attributes attributes) {
if (elementName.equals(CATEGORY)) {
stateStack.push(Integer.valueOf(STATE_CATEGORY));
processCategory(attributes);
} else
} else {
internalErrorUnknownTag(NLS.bind(Messages.DefaultSiteParser_UnknownElement, (new String[] {elementName, getState(currentState())})));
}
}

private void handleInitialState(String elementName, Attributes attributes) throws SAXException {
Expand Down Expand Up @@ -591,15 +605,16 @@ private boolean leadingSpace(String str) {
*/
private void logStatus(SAXParseException ex) {
String name = ex.getSystemId();
if (name == null)
if (name == null) {
name = ""; //$NON-NLS-1$
else
} else {
name = name.substring(1 + name.lastIndexOf("/")); //$NON-NLS-1$
}

String msg;
if (name.equals("")) //$NON-NLS-1$
if (name.equals("")) { //$NON-NLS-1$
msg = NLS.bind(Messages.DefaultSiteParser_ErrorParsing, (new String[] {ex.getMessage()}));
else {
} else {
String[] values = new String[] {name, Integer.toString(ex.getLineNumber()), Integer.toString(ex.getColumnNumber()), ex.getMessage()};
msg = NLS.bind(Messages.DefaultSiteParser_ErrorlineColumnMessage, values);
}
Expand All @@ -619,8 +634,9 @@ private void logStatus(SAXParseException ex) {
public SiteModel parse(InputStream in) throws SAXException, IOException {
stateStack.push(Integer.valueOf(STATE_INITIAL));
parser.parse(new InputSource(in), this);
if (objectStack.isEmpty())
if (objectStack.isEmpty()) {
throw new SAXException(Messages.DefaultSiteParser_NoSiteTag);
}
if (objectStack.peek() instanceof SiteModel) {
SiteModel site = (SiteModel) objectStack.pop();
site.setMessageKeys(messageKeys);
Expand All @@ -639,8 +655,9 @@ public SiteModel parse(InputStream in) throws SAXException, IOException {
*/
private void processArchive(Attributes attributes) {
// don't care about archives in category xml
if (Tracing.DEBUG_GENERATOR_PARSING)
if (Tracing.DEBUG_GENERATOR_PARSING) {
debug("End processing Archive"); //$NON-NLS-1$
}
}

/*
Expand All @@ -660,8 +677,9 @@ private void processCategory(Attributes attributes) {
((SiteCategory) obj).addCategoryName(category);
}

if (Tracing.DEBUG_GENERATOR_PARSING)
if (Tracing.DEBUG_GENERATOR_PARSING) {
debug("End processing Category: name:" + category); //$NON-NLS-1$
}
}

/*
Expand All @@ -679,8 +697,9 @@ private void processCategoryDef(Attributes attributes) {
site.addCategory(category);
objectStack.push(category);

if (Tracing.DEBUG_GENERATOR_PARSING)
if (Tracing.DEBUG_GENERATOR_PARSING) {
debug("End processing CategoryDef: name:" + name + " label:" + label); //$NON-NLS-1$ //$NON-NLS-2$
}
}

/*
Expand Down Expand Up @@ -722,8 +741,9 @@ private void processStatsInfo(Attributes attributes) {
// Ignore if not valid.
}

if (Tracing.DEBUG_GENERATOR_PARSING)
if (Tracing.DEBUG_GENERATOR_PARSING) {
debug("End processing Repository Reference: location:" + location); //$NON-NLS-1$
}
}

/*
Expand All @@ -739,8 +759,9 @@ private void processStatsFeature(Attributes attributes) {
boolean noId = (id == null || id.trim().equals("")); //$NON-NLS-1$

// We need to have id and version, or the url, or both.
if (noId)
if (noId) {
internalError(NLS.bind(Messages.DefaultSiteParser_Missing, (new String[] {"url", getState(currentState())}))); //$NON-NLS-1$
}

feature.setFeatureIdentifier(id);
feature.setFeatureVersion(ver);
Expand All @@ -750,8 +771,9 @@ private void processStatsFeature(Attributes attributes) {
objectStack.push(feature);
feature.setSiteModel(site);

if (Tracing.DEBUG_GENERATOR_PARSING)
if (Tracing.DEBUG_GENERATOR_PARSING) {
debug("End Processing Stats Feature Tag: id:" + id + " version:" + ver); //$NON-NLS-1$ //$NON-NLS-2$ }
}
}

/*
Expand All @@ -767,8 +789,9 @@ private void processStatsBundle(Attributes attributes) {
boolean noId = (id == null || id.trim().equals("")); //$NON-NLS-1$

// We need to have id and version, or the url, or both.
if (noId)
if (noId) {
internalError(NLS.bind(Messages.DefaultSiteParser_Missing, (new String[] {"url", getState(currentState())}))); //$NON-NLS-1$
}

bundle.setBundleIdentifier(id);
bundle.setBundleVersion(ver);
Expand All @@ -778,8 +801,9 @@ private void processStatsBundle(Attributes attributes) {
objectStack.push(bundle);
bundle.setSiteModel(site);

if (Tracing.DEBUG_GENERATOR_PARSING)
if (Tracing.DEBUG_GENERATOR_PARSING) {
debug("End Processing Stats Bundle Tag: id:" + id + " version:" + ver); //$NON-NLS-1$ //$NON-NLS-2$
}
}

/*
Expand All @@ -798,8 +822,9 @@ private void processFeature(Attributes attributes) {
boolean noId = (id == null || id.trim().equals("")); //$NON-NLS-1$

// We need to have id and version, or the url, or both.
if (noId)
if (noId) {
internalError(NLS.bind(Messages.DefaultSiteParser_Missing, (new String[] {"url", getState(currentState())}))); //$NON-NLS-1$
}

feature.setFeatureIdentifier(id);
feature.setFeatureVersion(ver);
Expand All @@ -813,8 +838,9 @@ private void processFeature(Attributes attributes) {

objectStack.push(feature);

if (Tracing.DEBUG_GENERATOR_PARSING)
if (Tracing.DEBUG_GENERATOR_PARSING) {
debug("End Processing Feature Tag: id:" + id + " version:" + ver); //$NON-NLS-1$ //$NON-NLS-2$
}
}

/*
Expand All @@ -833,8 +859,9 @@ private void processBundle(Attributes attributes) {
boolean noId = (id == null || id.trim().equals("")); //$NON-NLS-1$

// We need to have id and version, or the url, or both.
if (noId)
if (noId) {
internalError(NLS.bind(Messages.DefaultSiteParser_Missing, (new String[] {"url", getState(currentState())}))); //$NON-NLS-1$
}

bundle.setBundleIdentifier(id);
bundle.setBundleVersion(ver);
Expand All @@ -848,8 +875,9 @@ private void processBundle(Attributes attributes) {

objectStack.push(bundle);

if (Tracing.DEBUG_GENERATOR_PARSING)
if (Tracing.DEBUG_GENERATOR_PARSING) {
debug("End Processing Bundle Tag: id:" + id + " version:" + ver); //$NON-NLS-1$ //$NON-NLS-2$
}
}

/*
Expand All @@ -871,8 +899,9 @@ private void processIU(Attributes attributes) {
site.addIU(iu);
objectStack.push(iu);

if (Tracing.DEBUG_GENERATOR_PARSING)
if (Tracing.DEBUG_GENERATOR_PARSING) {
debug("End processing iu."); //$NON-NLS-1$
}
}

/*
Expand All @@ -882,25 +911,28 @@ private void processExpression(Attributes attributes) {
SiteIU iu = (SiteIU) objectStack.peek();
iu.setQueryType(attributes.getValue("type")); //$NON-NLS-1$

if (Tracing.DEBUG_GENERATOR_PARSING)
if (Tracing.DEBUG_GENERATOR_PARSING) {
debug("End processing Expression: " + iu.getQueryType()); //$NON-NLS-1$
}
}

/*
* process query info
*/
private void processQuery(Attributes attributes) {
// TODO may have simple attriutes for id and range
if (Tracing.DEBUG_GENERATOR_PARSING)
if (Tracing.DEBUG_GENERATOR_PARSING) {
debug("End processing Query."); //$NON-NLS-1$
}
}

/*
* process param info
*/
private void processParam(Attributes attributes) {
if (Tracing.DEBUG_GENERATOR_PARSING)
if (Tracing.DEBUG_GENERATOR_PARSING) {
debug("End processing Param."); //$NON-NLS-1$
}
}

/*
Expand All @@ -911,8 +943,9 @@ private void processInfo(Attributes attributes) {
String infoURL = attributes.getValue("url"); //$NON-NLS-1$
inf.setURL(infoURL);

if (Tracing.DEBUG_GENERATOR_PARSING)
if (Tracing.DEBUG_GENERATOR_PARSING) {
debug("Processed Info: url:" + infoURL); //$NON-NLS-1$
}

objectStack.push(inf);
}
Expand All @@ -925,8 +958,9 @@ private void processSite(Attributes attributes) {
SiteModel site = new SiteModel();
objectStack.push(site);

if (Tracing.DEBUG_GENERATOR_PARSING)
if (Tracing.DEBUG_GENERATOR_PARSING) {
debug("End process Site tag."); //$NON-NLS-1$
}

}

Expand Down Expand Up @@ -1020,7 +1054,8 @@ private boolean trailingSpace(String str) {
// Add translatable strings from the site.xml
// to the list of message keys.
private void checkTranslated(String value) {
if (value != null && value.length() > 1 && value.startsWith("%")) //$NON-NLS-1$
if (value != null && value.length() > 1 && value.startsWith("%")) { //$NON-NLS-1$
messageKeys.add(value.substring(1));
}
}
}
Loading

0 comments on commit dbd556f

Please sign in to comment.