Skip to content

Commit

Permalink
[FIXUP] further improvements
Browse files Browse the repository at this point in the history
- Use if-statements where suitable
- Add missing default cases to prevent warnings
  • Loading branch information
HannesWell committed May 1, 2023
1 parent 716d206 commit 2a605f8
Show file tree
Hide file tree
Showing 21 changed files with 117 additions and 120 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,7 @@ private IApiBaseline setBaseline(File baselinePath) throws CoreException {
System.out.println("WARNING resolving target platform: " + resolutionStatus.getMessage()); //$NON-NLS-1$
case IStatus.ERROR ->
throw new CoreException(resolutionStatus);
default -> { /*Nothing*/ }
}
// remove ".target"
String baselineName = baselineFileName.substring(0, baselineFileName.lastIndexOf('.'));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ public String toString() {
type = "Type"; //$NON-NLS-1$
name = ((IMemberDescriptor) element).getName();
}
default -> { /**/ }
}
StringBuilder buffer = new StringBuilder();
buffer.append(type == null ? "Unknown" : type).append(" Node: ").append(name == null ? "Unknown Name" : name); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
Expand Down Expand Up @@ -224,6 +225,7 @@ void persistXML(Document document, Element parentElement) {
parentElement.appendChild(field);
break;
}
default -> { /**/ }
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ void flushElementCache(IJavaElement element) {
case IJavaElement.JAVA_PROJECT -> {
ApiModelCache.getCache().removeElementInfo(ApiBaselineManager.WORKSPACE_API_BASELINE_ID, element.getElementName(), null, IApiElement.COMPONENT);
}
default -> { /**/ }
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,7 @@ private String[] collectMissingTags(IApiAnnotations api, List<TagElement> tags,
}
}
}
default -> { /**/ }
}
return missing.toArray(new String[missing.size()]);
}
Expand Down Expand Up @@ -429,6 +430,7 @@ private IElementDescriptor findDescriptorByName(String name, String signature) {
return desc;
}
}
default -> { /**/ }
}
}
return null;
Expand Down Expand Up @@ -719,6 +721,7 @@ private static int getRestrictions(final IJavaProject project, final Element ele
}
}
}
default -> { /**/ }
}
}
return res;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,21 +119,19 @@ private void annotateElementAttributes(IApiAnnotations description, Element elem

@Override
public void endVisitElement(IElementDescriptor element, IApiAnnotations description) {
switch (element.getElementType()) {
case IElementDescriptor.PACKAGE -> {
// A null package indicates there was an override for the
// package in a different context.
// Package rules are stored in the manifest, not the API
// description file.
// No need to add empty packages.
if (fPackage != null && fPackage.hasChildNodes()) {
fComponent.appendChild(fPackage);
}
fPackage = null;
}
case IElementDescriptor.TYPE -> {
fTypeStack.pop();
int elementType = element.getElementType();
if (elementType == IElementDescriptor.PACKAGE) {
// A null package indicates there was an override for the
// package in a different context.
// Package rules are stored in the manifest, not the API
// description file.
// No need to add empty packages.
if (fPackage != null && fPackage.hasChildNodes()) {
fComponent.appendChild(fPackage);
}
fPackage = null;
} else if (elementType == IElementDescriptor.TYPE) {
fTypeStack.pop();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public boolean visitElement(IElementDescriptor element, IApiAnnotations descript
case IElementDescriptor.FIELD -> {
name = ((IFieldDescriptor) element).getName();
}
default -> { /**/ }
}
if (signature != null) {
fCrc.update(signature.getBytes());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,7 @@ public void resolve() throws CoreException {
case IReference.T_METHOD_REFERENCE -> {
resolveVirtualMethod(type, getReferencedMemberName(), getReferencedSignature());
}
default -> { /**/ }
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,13 +207,9 @@ public void visitEnd() {

@Override
public void visitBaseType(char descriptor) {
switch (descriptor) {
case 'J', 'D' -> {
argumentcount += 2;
}
default -> {
this.argumentcount++;
}
argumentcount++;
if (descriptor == 'J' || descriptor == 'D') {
argumentcount++;
}
}

Expand Down Expand Up @@ -269,12 +265,8 @@ public void visitEnd() {
@Override
public void visitVarInsn(int opcode, int var) {
this.stringLiteral = null;
switch (opcode) {
case Opcodes.ASTORE -> {
if (this.lastLineNumber != -1) {
this.localVariableMarker = new LocalLineNumberMarker(this.lastLineNumber, var);
}
}
if (opcode == Opcodes.ASTORE && this.lastLineNumber != -1) {
this.localVariableMarker = new LocalLineNumberMarker(this.lastLineNumber, var);
}
}

Expand Down Expand Up @@ -408,6 +400,7 @@ && getDefaultDefined(type, name, desc, false) != null) {
case Opcodes.INVOKEINTERFACE -> {
kind = IReference.REF_INTERFACEMETHOD;
}
default -> { /**/ }
}
if (kind != -1) {
Reference reference = ReferenceExtractor.this.addMethodReference(declaringType, name, desc, kind, flags);
Expand Down Expand Up @@ -511,6 +504,7 @@ public void visitTypeInsn(int opcode, String desc) {
}
}
}
default -> { /**/ }
}
if (kind != -1) {
Reference reference = ReferenceExtractor.this.addTypeReference(type, kind);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,17 +126,15 @@ private static String createSignatureKey(IReference reference) {
buffer.append(reference.getMember().getApiComponent().getSymbolicName());
buffer.append("#"); //$NON-NLS-1$
buffer.append(reference.getReferencedTypeName());
switch (reference.getReferenceType()) {
case IReference.T_FIELD_REFERENCE -> {
buffer.append("#"); //$NON-NLS-1$
buffer.append(reference.getReferencedMemberName());
}
case IReference.T_METHOD_REFERENCE -> {
buffer.append("#"); //$NON-NLS-1$
buffer.append(reference.getReferencedMemberName());
buffer.append("#"); //$NON-NLS-1$
buffer.append(reference.getReferencedSignature());
}
if (reference.getReferenceType() == IReference.T_FIELD_REFERENCE) {
buffer.append("#"); //$NON-NLS-1$
buffer.append(reference.getReferencedMemberName());

} else if (reference.getReferenceType() == IReference.T_METHOD_REFERENCE) {
buffer.append("#"); //$NON-NLS-1$
buffer.append(reference.getReferencedMemberName());
buffer.append("#"); //$NON-NLS-1$
buffer.append(reference.getReferencedSignature());
}
return buffer.toString();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,7 @@ protected Position getSourceRange(IType type, IDocument document, IReference ref
IApiMethod method = (IApiMethod) reference.getMember();
yield getSourceRangeForMethod(type, reference, method);
}
default -> { /**/ }
}
// reference in a type declaration
ISourceRange range = type.getNameRange();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ private void validateTags(ASTNode node, List<TagElement> tags) {
FieldDeclaration field = (FieldDeclaration) node;
processFieldNode(field, tags);
}
default -> { /**/ }
}
}

Expand Down Expand Up @@ -280,10 +281,7 @@ void processFieldNode(FieldDeclaration field, List<TagElement> tags) {
boolean ispackage = Flags.isPackageDefault(flags);
Set<String> supportedtags = getSupportedTagNames(pkind, IApiJavadocTag.MEMBER_FIELD);
switch (pkind) {
case IApiJavadocTag.TYPE_ANNOTATION -> createTagProblem(item.typename, tag,
IElementDescriptor.FIELD, IApiProblem.UNSUPPORTED_TAG_USE,
IApiMarkerConstants.UNSUPPORTED_TAG_MARKER_ID,
BuilderMessages.TagValidator_annotation_field);
case IApiJavadocTag.TYPE_ANNOTATION -> createTagProblem(item.typename, tag, IElementDescriptor.FIELD, IApiProblem.UNSUPPORTED_TAG_USE, IApiMarkerConstants.UNSUPPORTED_TAG_MARKER_ID, BuilderMessages.TagValidator_annotation_field);
case IApiJavadocTag.TYPE_ENUM -> {
if (!supportedtags.contains(tagname)) {
createTagProblem(item.typename, tag, IElementDescriptor.FIELD, IApiProblem.UNSUPPORTED_TAG_USE, IApiMarkerConstants.UNSUPPORTED_TAG_MARKER_ID, BuilderMessages.TagValidator_enum_field);
Expand Down Expand Up @@ -311,6 +309,7 @@ void processFieldNode(FieldDeclaration field, List<TagElement> tags) {
createTagProblem(item.typename, tag, IElementDescriptor.FIELD, IApiProblem.UNSUPPORTED_TAG_USE, IApiMarkerConstants.UNSUPPORTED_TAG_MARKER_ID, BuilderMessages.TagValidator_a_field_that_is_not_visible);
}
}
default -> { /**/ }
}
}
processed.add(tagname);
Expand Down Expand Up @@ -390,6 +389,7 @@ void processMethodNode(MethodDeclaration method, List<TagElement> tags) {
createTagProblem(item.typename, tag, IElementDescriptor.METHOD, IApiProblem.UNSUPPORTED_TAG_USE, IApiMarkerConstants.UNSUPPORTED_TAG_MARKER_ID, isconstructor ? BuilderMessages.TagValidator_not_visible_constructor : BuilderMessages.TagValidator_a_method_that_is_not_visible);
}
}
default -> { /**/ }
}
}
processed.add(tagname);
Expand Down Expand Up @@ -470,6 +470,7 @@ public boolean visit(MarkerAnnotation node) {
BuilderMessages.TagValidator_an_annotation_method);
case ASTNode.FIELD_DECLARATION -> checkField(node, (FieldDeclaration) parent);
case ASTNode.METHOD_DECLARATION -> checkMethod(node, (MethodDeclaration) parent);
default -> { /**/ }
}
}
return false;
Expand Down Expand Up @@ -606,6 +607,7 @@ void checkField(MarkerAnnotation node, FieldDeclaration parent) {
createAnnotationProblem(item.typename, node, IElementDescriptor.FIELD, IApiProblem.UNSUPPORTED_ANNOTATION_USE, IApiMarkerConstants.UNSUPPORTED_ANNOTATION_MARKER_ID, BuilderMessages.TagValidator_a_field_that_is_not_visible);
}
}
default -> { /**/ }
}
fProcessedAnnotations.add(name);
}
Expand Down Expand Up @@ -677,6 +679,7 @@ void checkMethod(MarkerAnnotation node, MethodDeclaration parent) {
createAnnotationProblem(item.typename, node, IElementDescriptor.METHOD, IApiProblem.UNSUPPORTED_ANNOTATION_USE, IApiMarkerConstants.UNSUPPORTED_ANNOTATION_MARKER_ID, isconstructor ? BuilderMessages.TagValidator_not_visible_constructor : BuilderMessages.TagValidator_a_method_that_is_not_visible);
}
}
default -> { /**/ }
}
}
fProcessedAnnotations.add(name);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,30 +156,25 @@ protected String getTypeName(ASTNode node) {
* @return the fully qualified name of the parent
*/
protected String getTypeName(ASTNode node, StringBuilder buffer) {
return switch (node.getNodeType())
{
case ASTNode.COMPILATION_UNIT -> {
CompilationUnit unit = (CompilationUnit) node;
PackageDeclaration packageDeclaration = unit.getPackage();
if (packageDeclaration != null) {
buffer.insert(0, '.');
buffer.insert(0, packageDeclaration.getName().getFullyQualifiedName());
}
yield String.valueOf(buffer);
if (node.getNodeType() == ASTNode.COMPILATION_UNIT) {
CompilationUnit unit = (CompilationUnit) node;
PackageDeclaration packageDeclaration = unit.getPackage();
if (packageDeclaration != null) {
buffer.insert(0, '.');
buffer.insert(0, packageDeclaration.getName().getFullyQualifiedName());
}
default -> {
if (node instanceof AbstractTypeDeclaration) {
AbstractTypeDeclaration typeDeclaration = (AbstractTypeDeclaration) node;
if (typeDeclaration.isPackageMemberTypeDeclaration()) {
buffer.insert(0, typeDeclaration.getName().getIdentifier());
} else {
buffer.insert(0, typeDeclaration.getName().getFullyQualifiedName());
buffer.insert(0, '$');
}
return buffer.toString();
} else {
if (node instanceof AbstractTypeDeclaration typeDeclaration) {
if (typeDeclaration.isPackageMemberTypeDeclaration()) {
buffer.insert(0, typeDeclaration.getName().getIdentifier());
} else {
buffer.insert(0, typeDeclaration.getName().getFullyQualifiedName());
buffer.insert(0, '$');
}
yield getTypeName(node.getParent(), buffer);
}
};
return getTypeName(node.getParent(), buffer);
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,25 +100,19 @@ private void setApiPatterns(String[] patterns) {

@Override
public boolean visitElement(IElementDescriptor element, IApiAnnotations description) {
return switch (element.getElementType())
{
case IElementDescriptor.COMPONENT -> true;
case IElementDescriptor.PACKAGE -> {
IPackageDescriptor pkg = (IPackageDescriptor) element;
if (fInternalPackages != null) {
if (matchesPattern(pkg.getName(), fInternalPackages)) {
fDescription.setVisibility(element, VisibilityModifiers.PRIVATE);
}
}
if (fApiPackages != null) {
if (matchesPattern(pkg.getName(), fApiPackages)) {
fDescription.setVisibility(element, VisibilityModifiers.API);
}
}
yield false;
int elementType = element.getElementType();
if (elementType == IElementDescriptor.COMPONENT) {
return true;
} else if (elementType == IElementDescriptor.PACKAGE) {
IPackageDescriptor pkg = (IPackageDescriptor) element;
if (fInternalPackages != null && matchesPattern(pkg.getName(), fInternalPackages)) {
fDescription.setVisibility(element, VisibilityModifiers.PRIVATE);
}
default -> false;
};
if (fApiPackages != null && matchesPattern(pkg.getName(), fApiPackages)) {
fDescription.setVisibility(element, VisibilityModifiers.API);
}
}
return false;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,7 @@ public void visitReference(IReferenceDescriptor reference) {
this.currentmember.counts.total_illegal_type_count++;
this.currenttype.counts.total_illegal_type_count++;
}
default -> { /**/ }
}
}
case IElementDescriptor.METHOD -> {
Expand Down Expand Up @@ -290,6 +291,7 @@ public void visitReference(IReferenceDescriptor reference) {
this.currentmember.counts.total_illegal_method_count++;
this.currenttype.counts.total_illegal_method_count++;
}
default -> { /**/ }
}
}
case IElementDescriptor.FIELD -> {
Expand Down Expand Up @@ -324,8 +326,10 @@ public void visitReference(IReferenceDescriptor reference) {
this.currentmember.counts.total_illegal_field_count++;
this.currenttype.counts.total_illegal_field_count++;
}
default -> { /**/ }
}
}
default -> { /**/ }
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,8 @@ private void writeIndexFileForComponent(Report report) throws Exception {
case IApiProblem.API_USE_SCAN_TYPE_PROBLEM -> typeProblems.append(getProblemTable(types));
case IApiProblem.API_USE_SCAN_METHOD_PROBLEM -> methodProblems.append(getProblemTable(types));
case IApiProblem.API_USE_SCAN_FIELD_PROBLEM -> fieldProblems.append(getProblemTable(types));
}

default -> { /**/ }
}
}
buffer.append(getProblemsTableHeader(SearchMessages.MissingRefReportConverter_ProblemDetails, SearchMessages.MissingRefReportConverter_ProblemTypes));
if (typeProblems.length() > 0) {
Expand Down Expand Up @@ -270,6 +270,7 @@ public void add(List<IApiProblem> apipbs) {
case 1 -> ++typeProblems;
case 2 -> ++methodProblems;
case 3 -> ++fieldProblems;
default -> { /**/ }
}
}
}
Expand Down
Loading

0 comments on commit 2a605f8

Please sign in to comment.