From 224c89182a9ce082d7f1b2f33a0d36594f1ea462 Mon Sep 17 00:00:00 2001 From: Louis St-Amour Date: Sun, 19 Apr 2020 08:11:48 -0400 Subject: [PATCH] src: Apply clang-format and extend use to Java code (#973) --- .clang-format | 10 +- .../main/java/com/sourcetrail/AccessKind.java | 40 +- .../main/java/com/sourcetrail/AstVisitor.java | 1134 +++++++++-------- .../com/sourcetrail/AstVisitorClient.java | 76 +- .../sourcetrail/ContextAwareAstVisitor.java | 175 ++- .../java/com/sourcetrail/ContextList.java | 11 +- .../java/com/sourcetrail/DefinitionKind.java | 25 +- .../java/com/sourcetrail/FileContent.java | 13 +- .../java/com/sourcetrail/JavaIndexer.java | 318 +++-- .../JavaIndexerAstVisitorClient.java | 176 ++- .../main/java/com/sourcetrail/Position.java | 8 +- .../com/sourcetrail/QualifierVisitor.java | 188 +-- .../src/main/java/com/sourcetrail/Range.java | 16 +- .../java/com/sourcetrail/ReferenceKind.java | 25 +- .../main/java/com/sourcetrail/SymbolKind.java | 25 +- .../main/java/com/sourcetrail/Utility.java | 21 +- .../VerboseContextAwareAstVisitor.java | 14 +- .../com/sourcetrail/gradle/InfoRetriever.java | 94 +- .../java/com/sourcetrail/name/DeclName.java | 58 +- .../java/com/sourcetrail/name/FileName.java | 3 +- .../sourcetrail/name/FunctionDeclName.java | 41 +- .../com/sourcetrail/name/NameElement.java | 30 +- .../com/sourcetrail/name/NameHierarchy.java | 29 +- .../java/com/sourcetrail/name/SymbolName.java | 3 +- .../java/com/sourcetrail/name/TypeName.java | 41 +- .../sourcetrail/name/VariableDeclName.java | 13 +- .../name/resolver/BindingNameResolver.java | 199 +-- .../name/resolver/DeclNameResolver.java | 195 +-- .../name/resolver/NameResolver.java | 18 +- src/app/main.cpp | 67 +- src/indexer/main.cpp | 24 +- src/lib/app/Application.cpp | 8 +- src/lib/app/paths/AppPath.cpp | 4 +- src/lib/component/ComponentManager.cpp | 4 +- .../component/controller/CodeController.cpp | 28 +- src/lib/component/controller/CodeController.h | 2 +- .../component/controller/GraphController.h | 2 +- src/lib/component/view/CompositeView.cpp | 3 +- src/lib/component/view/CompositeView.h | 3 +- src/lib/component/view/GraphViewStyle.cpp | 11 +- .../component/view/helper/CodeScrollParams.h | 12 +- src/lib/data/NodeTypeSet.cpp | 17 +- src/lib/data/graph/Token.h | 2 +- .../storage/sqlite/SqliteIndexStorage.cpp | 3 +- src/lib/project/Project.cpp | 3 +- src/lib/project/Project.h | 3 +- src/lib/project/RefreshInfoGenerator.cpp | 4 +- src/lib/settings/ApplicationSettings.cpp | 4 +- .../utility/commandline/CommandLineParser.cpp | 9 +- .../commands/CommandlineCommandIndex.cpp | 11 +- src/lib/utility/interprocess/SharedMemory.cpp | 13 +- .../messaging/type/MessageLoadProject.h | 5 +- .../messaging/type/MessageRefreshUIState.h | 2 +- .../type/focus/MessageFocusChanged.h | 3 +- .../type/focus/MessageFocusedSearchView.h | 3 +- .../parser/cxx/CanonicalFilePathCache.cpp | 5 +- .../data/parser/cxx/GeneratePCHAction.cpp | 4 +- .../utility/codeblocks/CodeblocksCompiler.h | 2 +- src/lib_gui/platform_includes/includesLinux.h | 6 +- .../qt/element/code/CodeFocusHandler.cpp | 8 +- src/lib_gui/qt/element/code/QtCodeArea.cpp | 2 +- src/lib_gui/qt/element/code/QtCodeField.h | 3 +- src/lib_gui/qt/element/code/QtCodeFile.cpp | 2 +- .../qt/element/code/QtCodeFileList.cpp | 18 +- .../qt/element/code/QtCodeFileSingle.cpp | 10 +- .../qt/element/code/QtCodeNavigateable.cpp | 38 +- .../qt/element/code/QtCodeNavigator.cpp | 49 +- src/lib_gui/qt/element/dialog/QtListBox.cpp | 3 +- src/lib_gui/qt/graphics/GraphFocusHandler.h | 3 +- src/lib_gui/qt/graphics/QtGraphicsView.cpp | 3 +- .../QtGraphNodeComponentClickable.cpp | 3 +- .../content/QtProjectWizardContent.cpp | 4 +- .../QtProjectWizardContentCustomCommand.cpp | 3 +- .../QtProjectWizardContentProjectData.cpp | 10 +- .../QtProjectWizardContentRequiredLabel.h | 3 +- .../QtProjectWizardContentSourceGroupData.cpp | 5 +- .../content/QtProjectWizardContentVS.cpp | 20 +- .../path/QtProjectWizardContentPathCxxPch.cpp | 3 +- ...ojectWizardContentPathsFrameworkSearch.cpp | 3 +- ...tProjectWizardContentPathsHeaderSearch.cpp | 13 +- ...rojectWizardContentPathsIndexedHeaders.cpp | 18 +- .../QtProjectWizardContentPathsSource.cpp | 10 +- src/lib_gui/qt/utility/QtHighlighter.cpp | 34 +- src/lib_gui/qt/view/QtCodeView.cpp | 4 +- src/lib_gui/qt/view/QtCompositeView.cpp | 3 +- src/lib_gui/qt/view/QtCompositeView.h | 3 +- src/lib_gui/qt/view/QtGraphView.cpp | 7 +- src/lib_gui/qt/view/QtViewFactory.cpp | 5 +- src/lib_gui/qt/window/QtKeyboardShortcuts.h | 8 +- src/lib_gui/qt/window/QtMainWindow.cpp | 3 +- .../parser/java/JavaEnvironmentFactory.cpp | 4 +- .../project/SourceGroupPythonEmpty.cpp | 3 +- src/test/GraphTestSuite.cpp | 168 +-- src/test/UtilityStringTestSuite.cpp | 29 +- 94 files changed, 1998 insertions(+), 1773 deletions(-) diff --git a/.clang-format b/.clang-format index 3803bf9c..c8ceb4cc 100644 --- a/.clang-format +++ b/.clang-format @@ -1,5 +1,3 @@ -Language: Cpp - AccessModifierOffset: -4 AlignAfterOpenBracket: AlwaysBreak AlignConsecutiveAssignments: false @@ -37,7 +35,7 @@ ContinuationIndentWidth: 4 Cpp11BracedListStyle: true DerivePointerAlignment: false FixNamespaceComments: true -IncludeBlocks: Preserve +IncludeBlocks: Preserve IndentCaseLabels: false IndentPPDirectives: AfterHash IndentWidth: 4 @@ -76,3 +74,9 @@ SpacesInSquareBrackets: false Standard: c++17 TabWidth: 4 UseTab: Always +--- +Language: Cpp +--- +Language: Java +#BasedOnStyle: Google +#BreakAfterJavaFieldAnnotations: true diff --git a/java_indexer/src/main/java/com/sourcetrail/AccessKind.java b/java_indexer/src/main/java/com/sourcetrail/AccessKind.java index 35745f2a..a74b8407 100644 --- a/java_indexer/src/main/java/com/sourcetrail/AccessKind.java +++ b/java_indexer/src/main/java/com/sourcetrail/AccessKind.java @@ -2,8 +2,7 @@ package com.sourcetrail; import org.eclipse.jdt.core.dom.Modifier; -public enum AccessKind -{ // these values need to be the same as AccesKind in C++ code +public enum AccessKind { // these values need to be the same as AccesKind in C++ code NONE(0), PUBLIC(1), PROTECTED(2), @@ -11,26 +10,37 @@ public enum AccessKind DEFAULT(4), TEMPLATE_PARAMETER(5), TYPE_PARAMETER(6); - + private final int m_value; - - private AccessKind(int value) + + private AccessKind(int value) { - this.m_value = value; + this.m_value = value; } - - public int getValue() + + public int getValue() { - return m_value; + return m_value; } - + public static AccessKind fromModifiers(int modifiers) { - if ((modifiers & Modifier.PUBLIC) != 0) { return AccessKind.PUBLIC; } - if ((modifiers & Modifier.PROTECTED) != 0) { return AccessKind.PROTECTED; } - if ((modifiers & Modifier.PRIVATE) != 0) { return AccessKind.PRIVATE; } - if ((modifiers & Modifier.DEFAULT) != 0) { return AccessKind.DEFAULT; } + if ((modifiers & Modifier.PUBLIC) != 0) + { + return AccessKind.PUBLIC; + } + if ((modifiers & Modifier.PROTECTED) != 0) + { + return AccessKind.PROTECTED; + } + if ((modifiers & Modifier.PRIVATE) != 0) + { + return AccessKind.PRIVATE; + } + if ((modifiers & Modifier.DEFAULT) != 0) + { + return AccessKind.DEFAULT; + } return AccessKind.DEFAULT; } } - diff --git a/java_indexer/src/main/java/com/sourcetrail/AstVisitor.java b/java_indexer/src/main/java/com/sourcetrail/AstVisitor.java index 3e467143..0898a778 100644 --- a/java_indexer/src/main/java/com/sourcetrail/AstVisitor.java +++ b/java_indexer/src/main/java/com/sourcetrail/AstVisitor.java @@ -1,11 +1,19 @@ package com.sourcetrail; +import com.sourcetrail.name.DeclName; +import com.sourcetrail.name.FileName; +import com.sourcetrail.name.NameHierarchy; +import com.sourcetrail.name.SymbolName; +import com.sourcetrail.name.TypeName; +import com.sourcetrail.name.resolver.BindingNameResolver; +import com.sourcetrail.name.resolver.DeclNameResolver; import java.io.File; import java.lang.String; +import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import java.util.Optional; import java.util.Stack; - import org.eclipse.jdt.core.dom.ASTNode; import org.eclipse.jdt.core.dom.ASTVisitor; import org.eclipse.jdt.core.dom.Annotation; @@ -60,17 +68,6 @@ import org.eclipse.jdt.core.dom.TypeMethodReference; import org.eclipse.jdt.core.dom.TypeParameter; import org.eclipse.jdt.core.dom.VariableDeclarationFragment; -import com.sourcetrail.name.DeclName; -import com.sourcetrail.name.FileName; -import com.sourcetrail.name.SymbolName; -import com.sourcetrail.name.TypeName; -import com.sourcetrail.name.NameHierarchy; -import com.sourcetrail.name.resolver.BindingNameResolver; -import com.sourcetrail.name.resolver.DeclNameResolver; - -import java.util.ArrayList; -import java.util.Arrays; - public abstract class AstVisitor extends ASTVisitor { protected AstVisitorClient m_client = null; @@ -78,9 +75,10 @@ public abstract class AstVisitor extends ASTVisitor private FileContent m_fileContent = null; private CompilationUnit m_compilationUnit; private Stack> m_contextStack = new Stack<>(); - - public AstVisitor(AstVisitorClient client, File filePath, String fileContent, CompilationUnit compilationUnit) - { + + public AstVisitor( + AstVisitorClient client, File filePath, String fileContent, CompilationUnit compilationUnit) + { m_client = client; m_filePath = filePath; m_fileContent = new FileContent(fileContent); @@ -88,322 +86,327 @@ public abstract class AstVisitor extends ASTVisitor m_contextStack.push(Arrays.asList(new FileName(filePath))); } - + protected abstract ReferenceKind getTypeReferenceKind(); - - + + // --- record declarations --- - - @Override - public boolean visit(PackageDeclaration node) + + @Override public boolean visit(PackageDeclaration node) { Name name = node.getName(); - + Range range = getRange(name); if (name instanceof QualifiedName) { - range = getRange(((QualifiedName) name).getName()); + range = getRange(((QualifiedName)name).getName()); } - - m_client.recordSymbolWithLocation( - DeclNameResolver.getQualifiedName(name).toNameHierarchy(), - SymbolKind.PACKAGE, - range, - AccessKind.NONE, - DefinitionKind.EXPLICIT); - // Here we just record the symbol types of qualifiers. The nodes and their location are visited and recorded because the "name" is a QualifiedName + m_client.recordSymbolWithLocation( + DeclNameResolver.getQualifiedName(name).toNameHierarchy(), + SymbolKind.PACKAGE, + range, + AccessKind.NONE, + DefinitionKind.EXPLICIT); + + // Here we just record the symbol types of qualifiers. The nodes and their location are + // visited and recorded because the "name" is a QualifiedName while (name instanceof QualifiedName) { - name = ((QualifiedName) name).getQualifier(); + name = ((QualifiedName)name).getQualifier(); m_client.recordSymbol( - DeclNameResolver.getQualifiedName(name).toNameHierarchy(), - SymbolKind.PACKAGE, - AccessKind.NONE, - DefinitionKind.EXPLICIT); - } - - return true; - } - - - @Override - public boolean visit(AnnotationTypeDeclaration node) - { - DeclName symbolName = DeclNameResolver.getQualifiedDeclName(node, m_filePath, m_compilationUnit); - Range scopeRange = getRange(node); - - m_client.recordSymbolWithLocationAndScope( - symbolName.toNameHierarchy(), - SymbolKind.ANNOTATION, - getRange(node.getName()), - scopeRange, - AccessKind.fromModifiers(node.getModifiers()), - DefinitionKind.EXPLICIT); - - scopeRange.begin = m_fileContent.findStartPosition("{", scopeRange.begin); - recordScope(scopeRange); - - m_contextStack.push(Arrays.asList(symbolName)); - - return true; - } - - @Override - public void endVisit(AnnotationTypeDeclaration node) - { - m_contextStack.pop(); - } - - - @Override - public boolean visit(AnnotationTypeMemberDeclaration node) - { - DeclName symbolName = BindingNameResolver.getQualifiedName(node.resolveBinding(), m_filePath, m_compilationUnit).orElse(DeclName.unsolved()); - - m_client.recordSymbolWithLocation( - symbolName.toNameHierarchy(), - SymbolKind.FIELD, - getRange(node.getName()), - AccessKind.fromModifiers(node.getModifiers()), - DefinitionKind.EXPLICIT); - - m_contextStack.push(Arrays.asList(symbolName)); - - return true; - } - - @Override - public void endVisit(AnnotationTypeMemberDeclaration node) - { - m_contextStack.pop(); - } - - - @Override - public boolean visit(TypeDeclaration node) - { - DeclName symbolName = DeclNameResolver.getQualifiedDeclName(node, m_filePath, m_compilationUnit); - Range scopeRange = getRange(node); - - m_client.recordSymbolWithLocationAndScope( - symbolName.toNameHierarchy(), - node.isInterface() ? SymbolKind.INTERFACE : SymbolKind.CLASS, - getRange(node.getName()), - scopeRange, - AccessKind.fromModifiers(node.getModifiers()), - DefinitionKind.EXPLICIT); - - scopeRange.begin = m_fileContent.findStartPosition("{", scopeRange.begin); - recordScope(scopeRange); - - m_contextStack.push(Arrays.asList(symbolName)); - - return true; - } - - @Override - public void endVisit(TypeDeclaration node) - { - m_contextStack.pop(); - } - - - @Override - public boolean visit(TypeParameter node) - { - DeclName symbolName = BindingNameResolver.getQualifiedName(node.resolveBinding(), m_filePath, m_compilationUnit).map(tn -> tn.toDeclName()).orElse(DeclName.unsolved()); - - m_client.recordSymbolWithLocation( - symbolName.toNameHierarchy(), - SymbolKind.TYPE_PARAMETER, - getRange(node.getName()), - AccessKind.TYPE_PARAMETER, - DefinitionKind.EXPLICIT); - - m_contextStack.push(Arrays.asList(symbolName)); - - return true; - } - - @Override - public void endVisit(TypeParameter node) - { - m_contextStack.pop(); - } - - - - @Override - public boolean visit(EnumDeclaration node) - { - DeclName symbolName = DeclNameResolver.getQualifiedDeclName(node, m_filePath, m_compilationUnit); - Range scopeRange = getRange(node); - - m_client.recordSymbolWithLocationAndScope( - symbolName.toNameHierarchy(), - SymbolKind.ENUM, - getRange(node.getName()), - scopeRange, - AccessKind.fromModifiers(node.getModifiers()), - DefinitionKind.EXPLICIT); - - scopeRange.begin = m_fileContent.findStartPosition("{", scopeRange.begin); - recordScope(scopeRange); - - m_contextStack.push(Arrays.asList(symbolName)); - - return true; - } - - @Override - public void endVisit(EnumDeclaration node) - { - m_contextStack.pop(); - } - - - public boolean visit(EnumConstantDeclaration node) - { - DeclName symbolName = DeclNameResolver.getQualifiedDeclName(node, m_filePath, m_compilationUnit); - - m_client.recordSymbolWithLocation( - symbolName.toNameHierarchy(), - SymbolKind.ENUM_CONSTANT, - getRange(node.getName()), + DeclNameResolver.getQualifiedName(name).toNameHierarchy(), + SymbolKind.PACKAGE, AccessKind.NONE, DefinitionKind.EXPLICIT); + } - m_contextStack.push(Arrays.asList(symbolName)); - return true; } - - @Override - public void endVisit(EnumConstantDeclaration node) + + + @Override public boolean visit(AnnotationTypeDeclaration node) + { + DeclName symbolName = DeclNameResolver.getQualifiedDeclName( + node, m_filePath, m_compilationUnit); + Range scopeRange = getRange(node); + + m_client.recordSymbolWithLocationAndScope( + symbolName.toNameHierarchy(), + SymbolKind.ANNOTATION, + getRange(node.getName()), + scopeRange, + AccessKind.fromModifiers(node.getModifiers()), + DefinitionKind.EXPLICIT); + + scopeRange.begin = m_fileContent.findStartPosition("{", scopeRange.begin); + recordScope(scopeRange); + + m_contextStack.push(Arrays.asList(symbolName)); + + return true; + } + + @Override public void endVisit(AnnotationTypeDeclaration node) { m_contextStack.pop(); } - - - @Override - public boolean visit(MethodDeclaration node) + + + @Override public boolean visit(AnnotationTypeMemberDeclaration node) + { + DeclName symbolName = BindingNameResolver + .getQualifiedName( + node.resolveBinding(), m_filePath, m_compilationUnit) + .orElse(DeclName.unsolved()); + + m_client.recordSymbolWithLocation( + symbolName.toNameHierarchy(), + SymbolKind.FIELD, + getRange(node.getName()), + AccessKind.fromModifiers(node.getModifiers()), + DefinitionKind.EXPLICIT); + + m_contextStack.push(Arrays.asList(symbolName)); + + return true; + } + + @Override public void endVisit(AnnotationTypeMemberDeclaration node) + { + m_contextStack.pop(); + } + + + @Override public boolean visit(TypeDeclaration node) + { + DeclName symbolName = DeclNameResolver.getQualifiedDeclName( + node, m_filePath, m_compilationUnit); + Range scopeRange = getRange(node); + + m_client.recordSymbolWithLocationAndScope( + symbolName.toNameHierarchy(), + node.isInterface() ? SymbolKind.INTERFACE : SymbolKind.CLASS, + getRange(node.getName()), + scopeRange, + AccessKind.fromModifiers(node.getModifiers()), + DefinitionKind.EXPLICIT); + + scopeRange.begin = m_fileContent.findStartPosition("{", scopeRange.begin); + recordScope(scopeRange); + + m_contextStack.push(Arrays.asList(symbolName)); + + return true; + } + + @Override public void endVisit(TypeDeclaration node) + { + m_contextStack.pop(); + } + + + @Override public boolean visit(TypeParameter node) + { + DeclName symbolName = BindingNameResolver + .getQualifiedName( + node.resolveBinding(), m_filePath, m_compilationUnit) + .map(tn -> tn.toDeclName()) + .orElse(DeclName.unsolved()); + + m_client.recordSymbolWithLocation( + symbolName.toNameHierarchy(), + SymbolKind.TYPE_PARAMETER, + getRange(node.getName()), + AccessKind.TYPE_PARAMETER, + DefinitionKind.EXPLICIT); + + m_contextStack.push(Arrays.asList(symbolName)); + + return true; + } + + @Override public void endVisit(TypeParameter node) + { + m_contextStack.pop(); + } + + + @Override public boolean visit(EnumDeclaration node) + { + DeclName symbolName = DeclNameResolver.getQualifiedDeclName( + node, m_filePath, m_compilationUnit); + Range scopeRange = getRange(node); + + m_client.recordSymbolWithLocationAndScope( + symbolName.toNameHierarchy(), + SymbolKind.ENUM, + getRange(node.getName()), + scopeRange, + AccessKind.fromModifiers(node.getModifiers()), + DefinitionKind.EXPLICIT); + + scopeRange.begin = m_fileContent.findStartPosition("{", scopeRange.begin); + recordScope(scopeRange); + + m_contextStack.push(Arrays.asList(symbolName)); + + return true; + } + + @Override public void endVisit(EnumDeclaration node) + { + m_contextStack.pop(); + } + + + public boolean visit(EnumConstantDeclaration node) + { + DeclName symbolName = DeclNameResolver.getQualifiedDeclName( + node, m_filePath, m_compilationUnit); + + m_client.recordSymbolWithLocation( + symbolName.toNameHierarchy(), + SymbolKind.ENUM_CONSTANT, + getRange(node.getName()), + AccessKind.NONE, + DefinitionKind.EXPLICIT); + + m_contextStack.push(Arrays.asList(symbolName)); + + return true; + } + + @Override public void endVisit(EnumConstantDeclaration node) + { + m_contextStack.pop(); + } + + + @Override public boolean visit(MethodDeclaration node) { if (m_client.getInterrupted()) { m_contextStack.push(new ArrayList<>()); return false; } - - DeclName symbolName = DeclNameResolver.getQualifiedDeclName(node, m_filePath, m_compilationUnit); - + + DeclName symbolName = DeclNameResolver.getQualifiedDeclName( + node, m_filePath, m_compilationUnit); + Range signatureRange = getRange(node); if (!node.thrownExceptionTypes().isEmpty()) { - Object lastExceptionType = node.thrownExceptionTypes().get(node.thrownExceptionTypes().size() - 1); + Object lastExceptionType = node.thrownExceptionTypes().get( + node.thrownExceptionTypes().size() - 1); if (lastExceptionType instanceof ASTNode) { - signatureRange.end = getRange((ASTNode) lastExceptionType).end; + signatureRange.end = getRange((ASTNode)lastExceptionType).end; } } else { signatureRange.end = getRange(node.getName()).end; - + if (!node.parameters().isEmpty()) { Object lastParametersType = node.parameters().get(node.parameters().size() - 1); if (lastParametersType instanceof ASTNode) { - signatureRange.end = getRange((ASTNode) lastParametersType).end; + signatureRange.end = getRange((ASTNode)lastParametersType).end; } } - + signatureRange.end = m_fileContent.findStartPosition(")", signatureRange.end); } - - + + m_client.recordSymbolWithLocationAndScopeAndSignature( - symbolName.toNameHierarchy(), - SymbolKind.METHOD, - getRange(node.getName()), - getRange(node), - signatureRange, - AccessKind.fromModifiers(node.getModifiers()), - DefinitionKind.EXPLICIT); - - + symbolName.toNameHierarchy(), + SymbolKind.METHOD, + getRange(node.getName()), + getRange(node), + signatureRange, + AccessKind.fromModifiers(node.getModifiers()), + DefinitionKind.EXPLICIT); + + Optional overriddenMethod = getOverriddenMethod(node.resolveBinding()); if (overriddenMethod.isPresent()) { - // We use the declaration to replace type arguments with the respective type parameters inside the signature. + // We use the declaration to replace type arguments with the respective type parameters + // inside the signature. IMethodBinding overriddenMethodDeclaration = overriddenMethod.get().getMethodDeclaration(); - DeclName overriddenMethodName = BindingNameResolver.getQualifiedName(overriddenMethodDeclaration, m_filePath, m_compilationUnit).orElse(DeclName.unsolved()); + DeclName overriddenMethodName = + BindingNameResolver + .getQualifiedName(overriddenMethodDeclaration, m_filePath, m_compilationUnit) + .orElse(DeclName.unsolved()); if (!overriddenMethodName.getIsUnsolved()) { - m_client.recordSymbol(overriddenMethodName.toNameHierarchy(), SymbolKind.METHOD, AccessKind.NONE, DefinitionKind.NONE); + m_client.recordSymbol( + overriddenMethodName.toNameHierarchy(), + SymbolKind.METHOD, + AccessKind.NONE, + DefinitionKind.NONE); } - + m_client.recordReference( - ReferenceKind.OVERRIDE, - overriddenMethodName.toNameHierarchy(), - symbolName.toNameHierarchy(), - getRange(node.getName())); + ReferenceKind.OVERRIDE, + overriddenMethodName.toNameHierarchy(), + symbolName.toNameHierarchy(), + getRange(node.getName())); } - + m_contextStack.push(Arrays.asList(symbolName)); - + return true; } - - @Override - public void endVisit(MethodDeclaration node) + + @Override public void endVisit(MethodDeclaration node) { m_contextStack.pop(); } - - @Override - public boolean visit(FieldDeclaration node) + + @Override public boolean visit(FieldDeclaration node) { ArrayList childContext = new ArrayList<>(); - + for (Object declarator: node.fragments()) { if (declarator instanceof VariableDeclarationFragment) { - VariableDeclarationFragment fragment = (VariableDeclarationFragment) declarator; - - DeclName symbolName = DeclNameResolver.getQualifiedDeclName(fragment, m_filePath, m_compilationUnit); - + VariableDeclarationFragment fragment = (VariableDeclarationFragment)declarator; + + DeclName symbolName = DeclNameResolver.getQualifiedDeclName( + fragment, m_filePath, m_compilationUnit); + m_client.recordSymbolWithLocation( - symbolName.toNameHierarchy(), - SymbolKind.FIELD, - getRange(fragment.getName()), - AccessKind.fromModifiers(node.getModifiers()), - DefinitionKind.EXPLICIT); - + symbolName.toNameHierarchy(), + SymbolKind.FIELD, + getRange(fragment.getName()), + AccessKind.fromModifiers(node.getModifiers()), + DefinitionKind.EXPLICIT); + childContext.add(symbolName); } } - + m_contextStack.push(childContext); - + return true; } - - @Override - public void endVisit(FieldDeclaration node) + + @Override public void endVisit(FieldDeclaration node) { m_contextStack.pop(); } - - + + // --- record references --- - @Override - public boolean visit(final ImportDeclaration node) + @Override public boolean visit(final ImportDeclaration node) { DeclName symbolName = DeclName.unsolved(); IBinding binding = node.resolveBinding(); @@ -411,60 +414,71 @@ public abstract class AstVisitor extends ASTVisitor { if (binding instanceof IPackageBinding) { - symbolName = BindingNameResolver.getQualifiedName((IPackageBinding) binding, m_filePath, m_compilationUnit).orElse(DeclName.unsolved()); + symbolName = BindingNameResolver + .getQualifiedName( + (IPackageBinding)binding, m_filePath, m_compilationUnit) + .orElse(DeclName.unsolved()); } else if (binding instanceof ITypeBinding) { - symbolName = BindingNameResolver.getQualifiedName((ITypeBinding) binding, m_filePath, m_compilationUnit).map(tn -> tn.toDeclName()).orElse(DeclName.unsolved()); + symbolName = BindingNameResolver + .getQualifiedName( + (ITypeBinding)binding, m_filePath, m_compilationUnit) + .map(tn -> tn.toDeclName()) + .orElse(DeclName.unsolved()); } else if (binding instanceof IMethodBinding) { - symbolName = BindingNameResolver.getQualifiedName((IMethodBinding) binding, m_filePath, m_compilationUnit).orElse(DeclName.unsolved()); + symbolName = BindingNameResolver + .getQualifiedName( + (IMethodBinding)binding, m_filePath, m_compilationUnit) + .orElse(DeclName.unsolved()); } else if (binding instanceof IVariableBinding) { - symbolName = BindingNameResolver.getQualifiedName((IVariableBinding) binding, m_filePath, m_compilationUnit); + symbolName = BindingNameResolver.getQualifiedName( + (IVariableBinding)binding, m_filePath, m_compilationUnit); } } - + for (SymbolName context: m_contextStack.peek()) { Range range = getRange(node.getName()); if (node.getName() instanceof QualifiedName) { - range = getRange(((QualifiedName) node.getName()).getName()); + range = getRange(((QualifiedName)node.getName()).getName()); } - + m_client.recordReference( - ReferenceKind.IMPORT, - symbolName.toNameHierarchy(), context.toNameHierarchy(), - range); - } - + ReferenceKind.IMPORT, symbolName.toNameHierarchy(), context.toNameHierarchy(), range); + } + // record package symbol kind of current node if appliccable if (binding instanceof IPackageBinding) { - Optional packageName = BindingNameResolver.getQualifiedName((IPackageBinding)binding, m_filePath, m_compilationUnit); + Optional packageName = BindingNameResolver.getQualifiedName( + (IPackageBinding)binding, m_filePath, m_compilationUnit); if (packageName.isPresent()) { - m_client.recordSymbol(packageName.get().toNameHierarchy(), - SymbolKind.PACKAGE, AccessKind.NONE, DefinitionKind.NONE); + m_client.recordSymbol( + packageName.get().toNameHierarchy(), + SymbolKind.PACKAGE, + AccessKind.NONE, + DefinitionKind.NONE); } } - + new QualifierVisitor(m_client, m_filePath, m_compilationUnit, true).recordQualifierOfNode(node); - + return true; } - @Override - public boolean visit(SingleMemberAnnotation node) + @Override public boolean visit(SingleMemberAnnotation node) { return recordAnnotation(node); } - @Override - public boolean visit(NormalAnnotation node) + @Override public boolean visit(NormalAnnotation node) { for (Object value: node.values()) { @@ -474,25 +488,31 @@ public abstract class AstVisitor extends ASTVisitor IBinding binding = name.resolveBinding(); if (binding instanceof IMethodBinding) { - DeclName symbolName = BindingNameResolver.getQualifiedName((IMethodBinding) binding, m_filePath, m_compilationUnit).orElse(DeclName.unsolved()); + DeclName symbolName = + BindingNameResolver + .getQualifiedName((IMethodBinding)binding, m_filePath, m_compilationUnit) + .orElse(DeclName.unsolved()); for (SymbolName context: m_contextStack.peek()) { - m_client.recordReference(ReferenceKind.USAGE, symbolName.toNameHierarchy(), context.toNameHierarchy(), getRange(name)); + m_client.recordReference( + ReferenceKind.USAGE, + symbolName.toNameHierarchy(), + context.toNameHierarchy(), + getRange(name)); } } } } - + return recordAnnotation(node); } - @Override - public boolean visit(MarkerAnnotation node) + @Override public boolean visit(MarkerAnnotation node) { return recordAnnotation(node); } - + private boolean recordAnnotation(Annotation node) { for (SymbolName context: m_contextStack.peek()) @@ -503,26 +523,28 @@ public abstract class AstVisitor extends ASTVisitor { typeBinding = annotationBinding.getAnnotationType(); } - + Range range = getRange(node.getTypeName()); if (node.getTypeName() instanceof QualifiedName) { - range = getRange(((QualifiedName) node.getTypeName()).getName()); + range = getRange(((QualifiedName)node.getTypeName()).getName()); } - + m_client.recordReference( - ReferenceKind.ANNOTATION_USAGE, - BindingNameResolver.getQualifiedName(typeBinding, m_filePath, m_compilationUnit).orElse(TypeName.unsolved()).toDeclName().toNameHierarchy(), - context.toNameHierarchy(), - range); + ReferenceKind.ANNOTATION_USAGE, + BindingNameResolver.getQualifiedName(typeBinding, m_filePath, m_compilationUnit) + .orElse(TypeName.unsolved()) + .toDeclName() + .toNameHierarchy(), + context.toNameHierarchy(), + range); } - + return true; } - - - @Override - public boolean visit(SimpleType node) + + + @Override public boolean visit(SimpleType node) { for (SymbolName context: m_contextStack.peek()) { @@ -531,27 +553,29 @@ public abstract class AstVisitor extends ASTVisitor { binding = binding.getTypeDeclaration(); } - + Range range = getRange(node.getName()); if (node.getName() instanceof QualifiedName) { - range = getRange(((QualifiedName) node.getName()).getName()); + range = getRange(((QualifiedName)node.getName()).getName()); } - + m_client.recordReference( - getTypeReferenceKind(), - BindingNameResolver.getQualifiedName(binding, m_filePath, m_compilationUnit).orElse(TypeName.unsolved()).toDeclName().toNameHierarchy(), - context.toNameHierarchy(), - range); + getTypeReferenceKind(), + BindingNameResolver.getQualifiedName(binding, m_filePath, m_compilationUnit) + .orElse(TypeName.unsolved()) + .toDeclName() + .toNameHierarchy(), + context.toNameHierarchy(), + range); } new QualifierVisitor(m_client, m_filePath, m_compilationUnit, false).recordQualifierOfNode(node); - + return true; } - - @Override - public boolean visit(QualifiedType node) + + @Override public boolean visit(QualifiedType node) { for (SymbolName context: m_contextStack.peek()) { @@ -560,21 +584,23 @@ public abstract class AstVisitor extends ASTVisitor { binding = binding.getTypeDeclaration(); } - + m_client.recordReference( - getTypeReferenceKind(), - BindingNameResolver.getQualifiedName(binding, m_filePath, m_compilationUnit).orElse(TypeName.unsolved()).toDeclName().toNameHierarchy(), - context.toNameHierarchy(), - getRange(node.getName())); + getTypeReferenceKind(), + BindingNameResolver.getQualifiedName(binding, m_filePath, m_compilationUnit) + .orElse(TypeName.unsolved()) + .toDeclName() + .toNameHierarchy(), + context.toNameHierarchy(), + getRange(node.getName())); } - + new QualifierVisitor(m_client, m_filePath, m_compilationUnit, false).recordQualifierOfNode(node); - + return true; } - - @Override - public boolean visit(NameQualifiedType node) + + @Override public boolean visit(NameQualifiedType node) { for (SymbolName context: m_contextStack.peek()) { @@ -583,258 +609,246 @@ public abstract class AstVisitor extends ASTVisitor { binding = binding.getTypeDeclaration(); } - + m_client.recordReference( - getTypeReferenceKind(), - BindingNameResolver.getQualifiedName(binding, m_filePath, m_compilationUnit).orElse(TypeName.unsolved()).toDeclName().toNameHierarchy(), - context.toNameHierarchy(), - getRange(node.getName())); + getTypeReferenceKind(), + BindingNameResolver.getQualifiedName(binding, m_filePath, m_compilationUnit) + .orElse(TypeName.unsolved()) + .toDeclName() + .toNameHierarchy(), + context.toNameHierarchy(), + getRange(node.getName())); } new QualifierVisitor(m_client, m_filePath, m_compilationUnit, false).recordQualifierOfNode(node); - + return true; } - @Override - public boolean visit(final PrimitiveType node) + @Override public boolean visit(final PrimitiveType node) { - NameHierarchy referencedName = TypeName.fromDotSeparatedString(node.getPrimitiveTypeCode().toString()).toDeclName().toNameHierarchy(); - + NameHierarchy referencedName = + TypeName.fromDotSeparatedString(node.getPrimitiveTypeCode().toString()) + .toDeclName() + .toNameHierarchy(); + m_client.recordSymbol( - referencedName, SymbolKind.BUILTIN_TYPE, - AccessKind.NONE, - DefinitionKind.EXPLICIT); - + referencedName, SymbolKind.BUILTIN_TYPE, AccessKind.NONE, DefinitionKind.EXPLICIT); + for (SymbolName context: m_contextStack.peek()) - { + { m_client.recordReference( - getTypeReferenceKind(), - referencedName, - context.toNameHierarchy(), - getRange(node)); + getTypeReferenceKind(), referencedName, context.toNameHierarchy(), getRange(node)); } return true; } - - @Override - public boolean visit(SimpleName node) + + @Override public boolean visit(SimpleName node) { IBinding binding = node.resolveBinding(); if (binding instanceof IVariableBinding) { - IVariableBinding variableBinding = ((IVariableBinding) binding).getVariableDeclaration(); + IVariableBinding variableBinding = ((IVariableBinding)binding).getVariableDeclaration(); DeclName declName = BindingNameResolver.getQualifiedName( - variableBinding, m_filePath, m_compilationUnit); - - if (declName.getIsUnsolved() && variableBinding.getDeclaringClass() == null && variableBinding.getName().equals("length")) + variableBinding, m_filePath, m_compilationUnit); + + if (declName.getIsUnsolved() && variableBinding.getDeclaringClass() == null && + variableBinding.getName().equals("length")) { // Do nothing. We ignore the case of unsolved symbols on array type } else if (declName.getIsLocal() || declName.getIsGlobal()) { - m_client.recordLocalSymbol( - declName.toNameHierarchy(), getRange(node)); + m_client.recordLocalSymbol(declName.toNameHierarchy(), getRange(node)); } else { - m_client.recordSymbol(declName.toNameHierarchy(), SymbolKind.FIELD, AccessKind.NONE, DefinitionKind.NONE); - + m_client.recordSymbol( + declName.toNameHierarchy(), SymbolKind.FIELD, AccessKind.NONE, DefinitionKind.NONE); + for (SymbolName context: m_contextStack.peek()) { m_client.recordReference( - ReferenceKind.USAGE, - declName.toNameHierarchy(), - context.toNameHierarchy(), - getRange(node)); + ReferenceKind.USAGE, + declName.toNameHierarchy(), + context.toNameHierarchy(), + getRange(node)); } } } return true; } - @Override - public boolean visit(ParameterizedType node) + @Override public boolean visit(ParameterizedType node) { ITypeBinding binding = node.resolveBinding(); if (binding != null) { binding = binding.getTypeDeclaration(); } - - for (Object o : node.typeArguments()) + + for (Object o: node.typeArguments()) { if (o instanceof Type) { Type type = (Type)o; ITypeBinding typeBinding = type.resolveBinding(); m_client.recordReference( - ReferenceKind.TYPE_ARGUMENT, - BindingNameResolver.getQualifiedName(typeBinding, m_filePath, m_compilationUnit).orElse(TypeName.unsolved()).toDeclName().toNameHierarchy(), - BindingNameResolver.getQualifiedName(binding, m_filePath, m_compilationUnit).orElse(TypeName.unsolved()).toDeclName().toNameHierarchy(), - getRange(type)); + ReferenceKind.TYPE_ARGUMENT, + BindingNameResolver.getQualifiedName(typeBinding, m_filePath, m_compilationUnit) + .orElse(TypeName.unsolved()) + .toDeclName() + .toNameHierarchy(), + BindingNameResolver.getQualifiedName(binding, m_filePath, m_compilationUnit) + .orElse(TypeName.unsolved()) + .toDeclName() + .toNameHierarchy(), + getRange(type)); } } - + return true; } - - @Override - public boolean visit(QualifiedName node) + + @Override public boolean visit(QualifiedName node) { new QualifierVisitor(m_client, m_filePath, m_compilationUnit, false).recordQualifierOfNode(node); - - return true; - } - - @Override - public boolean visit(FieldAccess node) - { - new QualifierVisitor(m_client, m_filePath, m_compilationUnit, false).recordQualifierOfNode(node, m_fileContent); - - return true; - } - - @Override - public boolean visit(SuperFieldAccess node) - { - new QualifierVisitor(m_client, m_filePath, m_compilationUnit, false).recordQualifierOfNode(node, m_fileContent); - - return true; - } - - @Override - public boolean visit(ThisExpression node) - { - new QualifierVisitor(m_client, m_filePath, m_compilationUnit, false).recordQualifierOfNode(node, m_fileContent); - - return true; - } - - @Override - public boolean visit(MethodInvocation node) - { - IMethodBinding methodBinding = node.resolveMethodBinding(); - - recordReferenceToMethodDeclaration( - methodBinding, - getRange(node.getName()), - ReferenceKind.CALL, - m_contextStack.peek()); - - recordReferenceToTypeArguments(methodBinding, node.typeArguments()); - - new QualifierVisitor(m_client, m_filePath, m_compilationUnit, false).recordQualifierOfNode(node, m_fileContent); - - return true; - } - - @Override - public boolean visit(SuperMethodInvocation node) - { - IMethodBinding methodBinding = node.resolveMethodBinding(); - - recordReferenceToMethodDeclaration( - methodBinding, - getRange(node.getName()), - ReferenceKind.CALL, - m_contextStack.peek()); - - recordReferenceToTypeArguments(methodBinding, node.typeArguments()); - new QualifierVisitor(m_client, m_filePath, m_compilationUnit, false).recordQualifierOfNode(node, m_fileContent); - return true; } - @Override - public boolean visit(ConstructorInvocation node) + @Override public boolean visit(FieldAccess node) + { + new QualifierVisitor(m_client, m_filePath, m_compilationUnit, false) + .recordQualifierOfNode(node, m_fileContent); + + return true; + } + + @Override public boolean visit(SuperFieldAccess node) + { + new QualifierVisitor(m_client, m_filePath, m_compilationUnit, false) + .recordQualifierOfNode(node, m_fileContent); + + return true; + } + + @Override public boolean visit(ThisExpression node) + { + new QualifierVisitor(m_client, m_filePath, m_compilationUnit, false) + .recordQualifierOfNode(node, m_fileContent); + + return true; + } + + @Override public boolean visit(MethodInvocation node) + { + IMethodBinding methodBinding = node.resolveMethodBinding(); + + recordReferenceToMethodDeclaration( + methodBinding, getRange(node.getName()), ReferenceKind.CALL, m_contextStack.peek()); + + recordReferenceToTypeArguments(methodBinding, node.typeArguments()); + + new QualifierVisitor(m_client, m_filePath, m_compilationUnit, false) + .recordQualifierOfNode(node, m_fileContent); + + return true; + } + + @Override public boolean visit(SuperMethodInvocation node) + { + IMethodBinding methodBinding = node.resolveMethodBinding(); + + recordReferenceToMethodDeclaration( + methodBinding, getRange(node.getName()), ReferenceKind.CALL, m_contextStack.peek()); + + recordReferenceToTypeArguments(methodBinding, node.typeArguments()); + + new QualifierVisitor(m_client, m_filePath, m_compilationUnit, false) + .recordQualifierOfNode(node, m_fileContent); + + return true; + } + + @Override public boolean visit(ConstructorInvocation node) { IMethodBinding methodBinding = node.resolveConstructorBinding(); - + recordReferenceToMethodDeclaration( - methodBinding, - m_fileContent.findRange("this", getRange(node).begin), - ReferenceKind.CALL, - m_contextStack.peek()); - + methodBinding, + m_fileContent.findRange("this", getRange(node).begin), + ReferenceKind.CALL, + m_contextStack.peek()); + recordReferenceToTypeArguments(methodBinding, node.typeArguments()); - + return true; } - @Override - public boolean visit(SuperConstructorInvocation node) + @Override public boolean visit(SuperConstructorInvocation node) { IMethodBinding methodBinding = node.resolveConstructorBinding(); - + recordReferenceToMethodDeclaration( - methodBinding, - m_fileContent.findRange("super", getRange(node).begin), - ReferenceKind.CALL, - m_contextStack.peek()); - + methodBinding, + m_fileContent.findRange("super", getRange(node).begin), + ReferenceKind.CALL, + m_contextStack.peek()); + recordReferenceToTypeArguments(methodBinding, node.typeArguments()); - + return true; } - - @Override - public boolean visit(CreationReference node) + + @Override public boolean visit(CreationReference node) { IMethodBinding methodBinding = node.resolveMethodBinding(); - + recordReferenceToMethodDeclaration( - methodBinding, - m_fileContent.findRange("new", getRange(node).begin), - ReferenceKind.USAGE, - m_contextStack.peek()); - + methodBinding, + m_fileContent.findRange("new", getRange(node).begin), + ReferenceKind.USAGE, + m_contextStack.peek()); + recordReferenceToTypeArguments(methodBinding, node.typeArguments()); new QualifierVisitor(m_client, m_filePath, m_compilationUnit, false).recordQualifierOfNode(node); - + return true; } - - @Override - public boolean visit(ExpressionMethodReference node) + + @Override public boolean visit(ExpressionMethodReference node) { IMethodBinding methodBinding = node.resolveMethodBinding(); - + recordReferenceToMethodDeclaration( - methodBinding, - getRange(node.getName()), - ReferenceKind.USAGE, - m_contextStack.peek()); - + methodBinding, getRange(node.getName()), ReferenceKind.USAGE, m_contextStack.peek()); + recordReferenceToTypeArguments(methodBinding, node.typeArguments()); - new QualifierVisitor(m_client, m_filePath, m_compilationUnit, false).recordQualifierOfNode(node, m_fileContent); - + new QualifierVisitor(m_client, m_filePath, m_compilationUnit, false) + .recordQualifierOfNode(node, m_fileContent); + return true; } - - @Override - public boolean visit(SuperMethodReference node) + + @Override public boolean visit(SuperMethodReference node) { IMethodBinding methodBinding = node.resolveMethodBinding(); - + recordReferenceToMethodDeclaration( - methodBinding, - getRange(node.getName()), - ReferenceKind.USAGE, - m_contextStack.peek()); - + methodBinding, getRange(node.getName()), ReferenceKind.USAGE, m_contextStack.peek()); + recordReferenceToTypeArguments(methodBinding, node.typeArguments()); - new QualifierVisitor(m_client, m_filePath, m_compilationUnit, false).recordQualifierOfNode(node, m_fileContent); - + new QualifierVisitor(m_client, m_filePath, m_compilationUnit, false) + .recordQualifierOfNode(node, m_fileContent); + return true; } - - @Override - public boolean visit(TypeMethodReference node) + + @Override public boolean visit(TypeMethodReference node) { IMethodBinding methodBinding = node.resolveMethodBinding(); if (methodBinding == null && node.getType() != null && node.getType().isArrayType()) @@ -844,40 +858,38 @@ public abstract class AstVisitor extends ASTVisitor else { recordReferenceToMethodDeclaration( - methodBinding, - getRange(node.getName()), - ReferenceKind.USAGE, - m_contextStack.peek()); - + methodBinding, getRange(node.getName()), ReferenceKind.USAGE, m_contextStack.peek()); + recordReferenceToTypeArguments(methodBinding, node.typeArguments()); - new QualifierVisitor(m_client, m_filePath, m_compilationUnit, false).recordQualifierOfNode(node); + new QualifierVisitor(m_client, m_filePath, m_compilationUnit, false) + .recordQualifierOfNode(node); } return true; } - - @Override - public boolean visit(ClassInstanceCreation node) + + @Override public boolean visit(ClassInstanceCreation node) { if (node.getAnonymousClassDeclaration() != null) { - // record anonymous class here instead of overriding visit(AnonymousClassDeclaration node) because - // the ClassInstanceCreation still contains the Type node. - + // record anonymous class here instead of overriding visit(AnonymousClassDeclaration + // node) because the ClassInstanceCreation still contains the Type node. + AnonymousClassDeclaration anonymousClassDeclaration = node.getAnonymousClassDeclaration(); - DeclName symbolName = DeclNameResolver.getQualifiedDeclName(anonymousClassDeclaration, m_filePath, m_compilationUnit); - + DeclName symbolName = DeclNameResolver.getQualifiedDeclName( + anonymousClassDeclaration, m_filePath, m_compilationUnit); + Range anonymousClassScope = getRange(anonymousClassDeclaration); - + m_client.recordSymbolWithLocationAndScope( - symbolName.toNameHierarchy(), - SymbolKind.CLASS, - new Range(anonymousClassScope.begin, anonymousClassScope.begin), - anonymousClassScope, - AccessKind.NONE, - DefinitionKind.EXPLICIT); - + symbolName.toNameHierarchy(), + SymbolKind.CLASS, + new Range(anonymousClassScope.begin, anonymousClassScope.begin), + anonymousClassScope, + AccessKind.NONE, + DefinitionKind.EXPLICIT); + recordScope(anonymousClassScope); m_contextStack.push(Arrays.asList(symbolName)); @@ -889,109 +901,113 @@ public abstract class AstVisitor extends ASTVisitor { constructorBinding = constructorBinding.getMethodDeclaration(); } - - DeclName referencedDeclName = BindingNameResolver.getQualifiedName(constructorBinding, m_filePath, m_compilationUnit).orElse(DeclName.unsolved()); + + DeclName referencedDeclName = BindingNameResolver + .getQualifiedName( + constructorBinding, m_filePath, m_compilationUnit) + .orElse(DeclName.unsolved()); if (!referencedDeclName.getIsUnsolved()) { - m_client.recordSymbol(referencedDeclName.toNameHierarchy(), SymbolKind.METHOD, AccessKind.NONE, DefinitionKind.NONE); + m_client.recordSymbol( + referencedDeclName.toNameHierarchy(), + SymbolKind.METHOD, + AccessKind.NONE, + DefinitionKind.NONE); } - + for (SymbolName context: m_contextStack.peek()) { m_client.recordReference( - ReferenceKind.CALL, - referencedDeclName.toNameHierarchy(), - context.toNameHierarchy(), - getRange(node.getType())); + ReferenceKind.CALL, + referencedDeclName.toNameHierarchy(), + context.toNameHierarchy(), + getRange(node.getType())); } - + recordReferenceToTypeArguments(constructorBinding, node.typeArguments()); } return true; } - @Override - public void endVisit(ClassInstanceCreation node) + @Override public void endVisit(ClassInstanceCreation node) { if (node.getAnonymousClassDeclaration() != null) { m_contextStack.pop(); } } - - @Override - public boolean visit(Block node) + + @Override public boolean visit(Block node) { recordScope(getRange(node)); return true; } - - @Override - public boolean visit(ArrayInitializer node) + + @Override public boolean visit(ArrayInitializer node) { recordScope(getRange(node)); return true; } - - @Override - public boolean visit(SwitchStatement node) + + @Override public boolean visit(SwitchStatement node) { Range scopeRange = getRange(node); scopeRange.begin = m_fileContent.findStartPosition("{", scopeRange.begin); recordScope(scopeRange); - + return true; } - - @Override - public boolean visit(LineComment node) + + @Override public boolean visit(LineComment node) { m_client.recordComment(getRange(node)); return true; } - - @Override - public boolean visit(BlockComment node) + + @Override public boolean visit(BlockComment node) { m_client.recordComment(getRange(node)); return true; } - - @Override - public boolean visit(Javadoc node) + + @Override public boolean visit(Javadoc node) { m_client.recordComment(getRange(node)); return true; } - - + + // --- utility methods --- - - private void recordReferenceToMethodDeclaration(IMethodBinding methodBinding, Range range, ReferenceKind referenceKind, List contexts) + + private void recordReferenceToMethodDeclaration( + IMethodBinding methodBinding, Range range, ReferenceKind referenceKind, List contexts) { if (methodBinding != null) { // replacing type arguments of invocation with type variables of declaration methodBinding = methodBinding.getMethodDeclaration(); } - - DeclName referencedDeclName = BindingNameResolver.getQualifiedName(methodBinding, m_filePath, m_compilationUnit).orElse(DeclName.unsolved()); + + DeclName referencedDeclName = + BindingNameResolver.getQualifiedName(methodBinding, m_filePath, m_compilationUnit) + .orElse(DeclName.unsolved()); if (!referencedDeclName.getIsUnsolved()) { - m_client.recordSymbol(referencedDeclName.toNameHierarchy(), SymbolKind.METHOD, AccessKind.NONE, DefinitionKind.NONE); + m_client.recordSymbol( + referencedDeclName.toNameHierarchy(), + SymbolKind.METHOD, + AccessKind.NONE, + DefinitionKind.NONE); } - + for (SymbolName context: m_contextStack.peek()) { m_client.recordReference( - referenceKind, - referencedDeclName.toNameHierarchy(), - context.toNameHierarchy(), - range); + referenceKind, referencedDeclName.toNameHierarchy(), context.toNameHierarchy(), range); } } - + private void recordReferenceToTypeArguments(IMethodBinding methodBinding, List typeArguments) { if (!typeArguments.isEmpty()) @@ -1001,35 +1017,42 @@ public abstract class AstVisitor extends ASTVisitor // replacing type arguments of invocation with type variables of declaration methodBinding = methodBinding.getMethodDeclaration(); } - - for (Object o : typeArguments) + + for (Object o: typeArguments) { if (o instanceof Type) { Type type = (Type)o; ITypeBinding typeBinding = type.resolveBinding(); m_client.recordReference( - ReferenceKind.TYPE_ARGUMENT, - BindingNameResolver.getQualifiedName(typeBinding, m_filePath, m_compilationUnit).orElse(TypeName.unsolved()).toDeclName().toNameHierarchy(), - BindingNameResolver.getQualifiedName(methodBinding, m_filePath, m_compilationUnit).orElse(DeclName.unsolved()).toNameHierarchy(), - getRange(type)); + ReferenceKind.TYPE_ARGUMENT, + BindingNameResolver + .getQualifiedName(typeBinding, m_filePath, m_compilationUnit) + .orElse(TypeName.unsolved()) + .toDeclName() + .toNameHierarchy(), + BindingNameResolver + .getQualifiedName(methodBinding, m_filePath, m_compilationUnit) + .orElse(DeclName.unsolved()) + .toNameHierarchy(), + getRange(type)); } } } } - + private void recordScope(Range range) { NameHierarchy nameHierarchy = DeclName.scope(m_filePath, range.begin).toNameHierarchy(); m_client.recordLocalSymbol(nameHierarchy, new Range(range.begin, range.begin)); m_client.recordLocalSymbol(nameHierarchy, new Range(range.end, range.end)); } - + protected Range getRange(ASTNode node) { return Utility.getRange(node, m_compilationUnit); } - + private IPackageBinding getDeclaringPackage(IBinding binding) { if (binding != null) @@ -1037,20 +1060,21 @@ public abstract class AstVisitor extends ASTVisitor IBinding parentBinding = BindingNameResolver.getParentBinding(binding); if (parentBinding instanceof IPackageBinding) { - return (IPackageBinding) parentBinding; + return (IPackageBinding)parentBinding; } return getDeclaringPackage(parentBinding); } return null; } - + private Optional getOverriddenMethod(IMethodBinding method) { if (method != null) { for (ITypeBinding declaringClassAncestor: getAllAncestorTypes(method.getDeclaringClass())) { - for (IMethodBinding potentiallyOverridden: declaringClassAncestor.getDeclaredMethods()) + for (IMethodBinding potentiallyOverridden: + declaringClassAncestor.getDeclaredMethods()) { if (method.overrides(potentiallyOverridden)) { @@ -1059,29 +1083,29 @@ public abstract class AstVisitor extends ASTVisitor } } } - + return Optional.empty(); } - + private List getAllAncestorTypes(ITypeBinding type) { List allAncestorTypes = new ArrayList<>(); - + List directAncestorTypes = getDirectAncestorTypes(type); allAncestorTypes.addAll(directAncestorTypes); - + for (ITypeBinding directAncestorType: directAncestorTypes) { allAncestorTypes.addAll(getAllAncestorTypes(directAncestorType)); } - + return allAncestorTypes; } - + private List getDirectAncestorTypes(ITypeBinding type) { List ancestorTypes = new ArrayList<>(); - + if (type != null) { ITypeBinding superclass = type.getSuperclass(); @@ -1089,10 +1113,10 @@ public abstract class AstVisitor extends ASTVisitor { ancestorTypes.add(superclass); } - + ancestorTypes.addAll(Arrays.asList(type.getInterfaces())); } - + return ancestorTypes; } } \ No newline at end of file diff --git a/java_indexer/src/main/java/com/sourcetrail/AstVisitorClient.java b/java_indexer/src/main/java/com/sourcetrail/AstVisitorClient.java index 6a6a1ad2..f0608a2a 100644 --- a/java_indexer/src/main/java/com/sourcetrail/AstVisitorClient.java +++ b/java_indexer/src/main/java/com/sourcetrail/AstVisitorClient.java @@ -2,55 +2,57 @@ package com.sourcetrail; import com.sourcetrail.name.NameHierarchy; -public abstract class AstVisitorClient +public abstract class AstVisitorClient { public abstract boolean getInterrupted(); - + public abstract void logInfo(String info); - + public abstract void logWarning(String warning); - + public abstract void logError(String error); public abstract void recordSymbol( - NameHierarchy symbolName, SymbolKind symbolKind, - AccessKind access, DefinitionKind definitionKind); - + NameHierarchy symbolName, + SymbolKind symbolKind, + AccessKind access, + DefinitionKind definitionKind); + public abstract void recordSymbolWithLocation( - NameHierarchy symbolName, SymbolKind symbolKind, - Range range, - AccessKind access, DefinitionKind definitionKind); + NameHierarchy symbolName, + SymbolKind symbolKind, + Range range, + AccessKind access, + DefinitionKind definitionKind); public abstract void recordSymbolWithLocationAndScope( - NameHierarchy symbolName, SymbolKind symbolKind, - Range range, - Range scopeRange, - AccessKind access, DefinitionKind definitionKind); - + NameHierarchy symbolName, + SymbolKind symbolKind, + Range range, + Range scopeRange, + AccessKind access, + DefinitionKind definitionKind); + public abstract void recordSymbolWithLocationAndScopeAndSignature( - NameHierarchy symbolName, SymbolKind symbolKind, - Range range, - Range scopeRange, - Range signatureRange, - AccessKind access, DefinitionKind definitionKind); + NameHierarchy symbolName, + SymbolKind symbolKind, + Range range, + Range scopeRange, + Range signatureRange, + AccessKind access, + DefinitionKind definitionKind); public abstract void recordReference( - ReferenceKind referenceKind, NameHierarchy referencedName, NameHierarchy contextName, - Range range); + ReferenceKind referenceKind, + NameHierarchy referencedName, + NameHierarchy contextName, + Range range); - public abstract void recordQualifierLocation( - NameHierarchy qualifierName, - Range range); - - public abstract void recordLocalSymbol( - NameHierarchy symbolName, - Range range); - - public abstract void recordComment( - Range range); - - public abstract void recordError( - String message, boolean fatal, boolean indexed, - Range range); + public abstract void recordQualifierLocation(NameHierarchy qualifierName, Range range); + + public abstract void recordLocalSymbol(NameHierarchy symbolName, Range range); + + public abstract void recordComment(Range range); + + public abstract void recordError(String message, boolean fatal, boolean indexed, Range range); } - diff --git a/java_indexer/src/main/java/com/sourcetrail/ContextAwareAstVisitor.java b/java_indexer/src/main/java/com/sourcetrail/ContextAwareAstVisitor.java index 94b182a4..81572823 100644 --- a/java_indexer/src/main/java/com/sourcetrail/ContextAwareAstVisitor.java +++ b/java_indexer/src/main/java/com/sourcetrail/ContextAwareAstVisitor.java @@ -3,7 +3,6 @@ package com.sourcetrail; import java.io.File; import java.util.List; import java.util.Stack; - import org.eclipse.jdt.core.dom.ASTNode; import org.eclipse.jdt.core.dom.ClassInstanceCreation; import org.eclipse.jdt.core.dom.CompilationUnit; @@ -29,17 +28,17 @@ import org.eclipse.jdt.core.dom.VariableDeclarationFragment; public class ContextAwareAstVisitor extends AstVisitor { private Stack m_typeRefKind = new Stack<>(); - - public ContextAwareAstVisitor(AstVisitorClient client, File filePath, String fileContent, CompilationUnit compilationUnit) + + public ContextAwareAstVisitor( + AstVisitorClient client, File filePath, String fileContent, CompilationUnit compilationUnit) { super(client, filePath, fileContent, compilationUnit); } - - @Override - public boolean visit(TypeDeclaration node) + + @Override public boolean visit(TypeDeclaration node) { boolean visitChildren = super.visit(node); - + if (visitChildren) { m_typeRefKind.push(ReferenceKind.TYPE_USAGE); @@ -56,12 +55,11 @@ public class ContextAwareAstVisitor extends AstVisitor acceptChildren(node.bodyDeclarations()); m_typeRefKind.pop(); } - + return false; } - - @Override - public boolean visit(EnumDeclaration node) + + @Override public boolean visit(EnumDeclaration node) { boolean visitChildren = super.visit(node); @@ -80,18 +78,17 @@ public class ContextAwareAstVisitor extends AstVisitor acceptChildren(node.bodyDeclarations()); m_typeRefKind.pop(); } - + return false; } - - @Override - public boolean visit(EnumConstantDeclaration node) + + @Override public boolean visit(EnumConstantDeclaration node) { boolean visitChildren = super.visit(node); if (visitChildren) { - // we don't visit and record the name of enum constant declarations because + // we don't visit and record the name of enum constant declarations because // this would create an unwanted self-reference. m_typeRefKind.push(ReferenceKind.TYPE_USAGE); acceptChild(node.getJavadoc()); @@ -100,18 +97,17 @@ public class ContextAwareAstVisitor extends AstVisitor acceptChild(node.getAnonymousClassDeclaration()); m_typeRefKind.pop(); } - + return false; } - - @Override - public boolean visit(VariableDeclarationFragment node) + + @Override public boolean visit(VariableDeclarationFragment node) { boolean visitChildren = super.visit(node); if (visitChildren) { - // we don't visit and record the name of field declarations because + // we don't visit and record the name of field declarations because // this would create an unwanted self-reference. m_typeRefKind.push(ReferenceKind.TYPE_USAGE); if (!(node.getParent() instanceof FieldDeclaration)) @@ -122,20 +118,19 @@ public class ContextAwareAstVisitor extends AstVisitor acceptChild(node.getInitializer()); m_typeRefKind.pop(); } - + return false; } - - @Override - public boolean visit(final ImportDeclaration node) + + @Override public boolean visit(final ImportDeclaration node) { - // We don't want to visit the name of the ImportDeclaration because this could cause a self reference. + // We don't want to visit the name of the ImportDeclaration because this could cause a self + // reference. super.visit(node); return false; } - - @Override - public boolean visit(ParameterizedType node) + + @Override public boolean visit(ParameterizedType node) { boolean visitChildren = super.visit(node); if (visitChildren) @@ -147,12 +142,11 @@ public class ContextAwareAstVisitor extends AstVisitor m_typeRefKind.pop(); } } - + return false; } - - @Override - public boolean visit(QualifiedType node) + + @Override public boolean visit(QualifiedType node) { // We don't want to visit the qualifier right now. boolean visitChildren = super.visit(node); @@ -164,12 +158,11 @@ public class ContextAwareAstVisitor extends AstVisitor acceptChild(node.getName()); m_typeRefKind.pop(); } - + return false; } - - @Override - public boolean visit(NameQualifiedType node) + + @Override public boolean visit(NameQualifiedType node) { // We don't want to visit the qualifier right now. boolean visitChildren = super.visit(node); @@ -181,15 +174,14 @@ public class ContextAwareAstVisitor extends AstVisitor acceptChild(node.getName()); m_typeRefKind.pop(); } - + return false; } - - @Override - public boolean visit(MethodInvocation node) + + @Override public boolean visit(MethodInvocation node) { boolean visitChildren = super.visit(node); - + if (visitChildren) { m_typeRefKind.push(ReferenceKind.TYPE_USAGE); @@ -199,16 +191,15 @@ public class ContextAwareAstVisitor extends AstVisitor acceptChildren(node.arguments()); m_typeRefKind.pop(); } - + return false; } - - @Override - public boolean visit(SuperMethodInvocation node) + + @Override public boolean visit(SuperMethodInvocation node) { // We don't want to visit the qualifier right now. boolean visitChildren = super.visit(node); - + if (visitChildren) { m_typeRefKind.push(ReferenceKind.TYPE_USAGE); @@ -217,15 +208,14 @@ public class ContextAwareAstVisitor extends AstVisitor acceptChildren(node.arguments()); m_typeRefKind.pop(); } - + return false; } - @Override - public boolean visit(ConstructorInvocation node) + @Override public boolean visit(ConstructorInvocation node) { boolean visitChildren = super.visit(node); - + if (visitChildren) { m_typeRefKind.push(ReferenceKind.TYPE_USAGE); @@ -233,15 +223,14 @@ public class ContextAwareAstVisitor extends AstVisitor acceptChildren(node.arguments()); m_typeRefKind.pop(); } - + return false; } - @Override - public boolean visit(SuperConstructorInvocation node) + @Override public boolean visit(SuperConstructorInvocation node) { boolean visitChildren = super.visit(node); - + if (visitChildren) { m_typeRefKind.push(ReferenceKind.TYPE_USAGE); @@ -250,32 +239,30 @@ public class ContextAwareAstVisitor extends AstVisitor acceptChildren(node.arguments()); m_typeRefKind.pop(); } - + return false; } - - @Override - public boolean visit(CreationReference node) + + @Override public boolean visit(CreationReference node) { // We don't want to visit the qualifying type right now. boolean visitChildren = super.visit(node); - + if (visitChildren) { m_typeRefKind.push(ReferenceKind.TYPE_USAGE); acceptChildren(node.typeArguments()); m_typeRefKind.pop(); } - + return false; } - @Override - public boolean visit(ExpressionMethodReference node) + @Override public boolean visit(ExpressionMethodReference node) { // We don't want to visit qualifiers right now. boolean visitChildren = super.visit(node); - + if (visitChildren) { m_typeRefKind.push(ReferenceKind.TYPE_USAGE); @@ -284,16 +271,15 @@ public class ContextAwareAstVisitor extends AstVisitor acceptChild(node.getName()); m_typeRefKind.pop(); } - + return false; } - - @Override - public boolean visit(SuperMethodReference node) + + @Override public boolean visit(SuperMethodReference node) { // We don't want to visit qualifiers right now. boolean visitChildren = super.visit(node); - + if (visitChildren) { m_typeRefKind.push(ReferenceKind.TYPE_USAGE); @@ -301,38 +287,36 @@ public class ContextAwareAstVisitor extends AstVisitor acceptChild(node.getName()); m_typeRefKind.pop(); } - + return false; } - - @Override - public boolean visit(TypeMethodReference node) + + @Override public boolean visit(TypeMethodReference node) { // We don't want to visit the qualifying type right now. boolean visitChildren = super.visit(node); - - if (visitChildren) + + if (visitChildren) { m_typeRefKind.push(ReferenceKind.TYPE_USAGE); acceptChildren(node.typeArguments()); acceptChild(node.getName()); m_typeRefKind.pop(); } - + return false; } - - @Override - public boolean visit(ClassInstanceCreation node) + + @Override public boolean visit(ClassInstanceCreation node) { boolean visitChildren = super.visit(node); - + if (visitChildren) { m_typeRefKind.push(ReferenceKind.TYPE_USAGE); acceptChild(node.getExpression()); acceptChildren(node.typeArguments()); - + if (node.getAnonymousClassDeclaration() != null) { m_typeRefKind.push(ReferenceKind.INHERITANCE); @@ -343,25 +327,23 @@ public class ContextAwareAstVisitor extends AstVisitor { acceptChild(node.getType()); } - + acceptChildren(node.arguments()); acceptChild(node.getAnonymousClassDeclaration()); m_typeRefKind.pop(); } - - return false; - } - - @Override - public boolean visit(Javadoc node) - { - // We don't want to visit symbol references inside Javadoc right now. - super.visit( node); + return false; } - @Override - protected ReferenceKind getTypeReferenceKind() + @Override public boolean visit(Javadoc node) + { + // We don't want to visit symbol references inside Javadoc right now. + super.visit(node); + return false; + } + + @Override protected ReferenceKind getTypeReferenceKind() { if (!m_typeRefKind.isEmpty()) { @@ -369,7 +351,7 @@ public class ContextAwareAstVisitor extends AstVisitor } return ReferenceKind.TYPE_USAGE; } - + private void acceptChild(ASTNode node) { if (node != null) @@ -377,7 +359,7 @@ public class ContextAwareAstVisitor extends AstVisitor node.accept(this); } } - + private void acceptChildren(List nodes) { if (nodes != null) @@ -386,10 +368,9 @@ public class ContextAwareAstVisitor extends AstVisitor { if (node instanceof ASTNode) { - acceptChild((ASTNode) node); + acceptChild((ASTNode)node); } } } } } - diff --git a/java_indexer/src/main/java/com/sourcetrail/ContextList.java b/java_indexer/src/main/java/com/sourcetrail/ContextList.java index bc5ef072..31f07646 100644 --- a/java_indexer/src/main/java/com/sourcetrail/ContextList.java +++ b/java_indexer/src/main/java/com/sourcetrail/ContextList.java @@ -2,30 +2,29 @@ package com.sourcetrail; import java.util.HashSet; import java.util.Set; - import org.eclipse.jdt.core.dom.IBinding; public class ContextList { private Set m_bindingKeys = new HashSet<>(); - + public ContextList copy() { ContextList contextList = new ContextList(); contextList.m_bindingKeys = new HashSet<>(m_bindingKeys); - + return contextList; } - - public void add(IBinding v) + + public void add(IBinding v) { if (v != null) { m_bindingKeys.add(v.getKey()); } } - + public boolean contains(IBinding v) { return v != null && m_bindingKeys.contains(v.getKey()); diff --git a/java_indexer/src/main/java/com/sourcetrail/DefinitionKind.java b/java_indexer/src/main/java/com/sourcetrail/DefinitionKind.java index bf164a6a..2f31418a 100644 --- a/java_indexer/src/main/java/com/sourcetrail/DefinitionKind.java +++ b/java_indexer/src/main/java/com/sourcetrail/DefinitionKind.java @@ -1,20 +1,19 @@ package com.sourcetrail; -public enum DefinitionKind -{ // these values need to be the same as DefinitionKind in C++ code +public enum DefinitionKind { // these values need to be the same as DefinitionKind in C++ code NONE(0), IMPLICIT(1), EXPLICIT(2); - - private final int m_value; - - private DefinitionKind(int value) - { - this.m_value = value; - } - public int getValue() - { - return m_value; - } + private final int m_value; + + private DefinitionKind(int value) + { + this.m_value = value; + } + + public int getValue() + { + return m_value; + } } diff --git a/java_indexer/src/main/java/com/sourcetrail/FileContent.java b/java_indexer/src/main/java/com/sourcetrail/FileContent.java index 83669ca0..9a8720b4 100644 --- a/java_indexer/src/main/java/com/sourcetrail/FileContent.java +++ b/java_indexer/src/main/java/com/sourcetrail/FileContent.java @@ -3,20 +3,20 @@ package com.sourcetrail; import java.util.Arrays; import java.util.List; -public class FileContent +public class FileContent { private List m_lines; - + public FileContent(String text) { m_lines = Arrays.asList(text.split("\\r?\\n")); } - + public Position findStartPosition(String s) { return findStartPosition(s, new Position(1, 1)); } - + public Position findStartPosition(String s, Position from) { int lineIndex = from.line - 1; @@ -43,9 +43,8 @@ public class FileContent public Range findRange(String s, Position from) { Position startPosition = findStartPosition(s, from); - + return new Range( - startPosition, - new Position(startPosition.line, startPosition.column + s.length() - 1)); + startPosition, new Position(startPosition.line, startPosition.column + s.length() - 1)); } } diff --git a/java_indexer/src/main/java/com/sourcetrail/JavaIndexer.java b/java_indexer/src/main/java/com/sourcetrail/JavaIndexer.java index c91539d7..95618a8b 100644 --- a/java_indexer/src/main/java/com/sourcetrail/JavaIndexer.java +++ b/java_indexer/src/main/java/com/sourcetrail/JavaIndexer.java @@ -14,7 +14,6 @@ import java.util.Hashtable; import java.util.List; import java.util.jar.JarFile; import java.util.zip.ZipEntry; - import org.eclipse.jdt.core.JavaCore; import org.eclipse.jdt.core.compiler.IProblem; import org.eclipse.jdt.core.dom.AST; @@ -26,55 +25,77 @@ import org.eclipse.jdt.core.dom.CompilationUnit; import org.eclipse.jdt.core.dom.LineComment; import org.eclipse.jdt.core.dom.PackageDeclaration; -public class JavaIndexer -{ - public static void processFile(int address, String filePath, String fileContent, String languageStandard, String classPath, int verbose) +public class JavaIndexer +{ + public static void processFile( + int address, + String filePath, + String fileContent, + String languageStandard, + String classPath, + int verbose) { - processFile(new JavaIndexerAstVisitorClient(address), filePath, fileContent, languageStandard, classPath, verbose); + processFile( + new JavaIndexerAstVisitorClient(address), + filePath, + fileContent, + languageStandard, + classPath, + verbose); } - - public static void processFile(AstVisitorClient astVisitorClient, String filePath, String fileContent, String languageStandard, String classPath, int verbose) + + public static void processFile( + AstVisitorClient astVisitorClient, + String filePath, + String fileContent, + String languageStandard, + String classPath, + int verbose) { try { astVisitorClient.logInfo("indexing source file: " + filePath); - + Path path = Paths.get(filePath); - + ASTParser parser = ASTParser.newParser(AST.JLS12); - - parser.setResolveBindings(true); // solve "bindings" like the declaration of the type used in a var decl - parser.setKind(ASTParser.K_COMPILATION_UNIT); // specify to parse the entire compilation unit - parser.setBindingsRecovery(true); // also return bindings that are not resolved completely + + parser.setResolveBindings( + true); // solve "bindings" like the declaration of the type used in a var decl + parser.setKind( + ASTParser.K_COMPILATION_UNIT); // specify to parse the entire compilation unit + parser.setBindingsRecovery( + true); // also return bindings that are not resolved completely parser.setStatementsRecovery(true); { String convertedLanguageStandard = convertLanguageStandard(languageStandard); astVisitorClient.logInfo("using language standard " + convertedLanguageStandard); - + Hashtable options = JavaCore.getOptions(); - options.put(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, JavaCore.ENABLED); - options.put(JavaCore.COMPILER_PB_REPORT_PREVIEW_FEATURES, JavaCore.IGNORE); - options.put(JavaCore.COMPILER_SOURCE, convertedLanguageStandard); - options.put(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, convertedLanguageStandard); - options.put(JavaCore.COMPILER_COMPLIANCE, convertedLanguageStandard); + options.put(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, JavaCore.ENABLED); + options.put(JavaCore.COMPILER_PB_REPORT_PREVIEW_FEATURES, JavaCore.IGNORE); + options.put(JavaCore.COMPILER_SOURCE, convertedLanguageStandard); + options.put(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, convertedLanguageStandard); + options.put(JavaCore.COMPILER_COMPLIANCE, convertedLanguageStandard); parser.setCompilerOptions(options); } - + parser.setUnitName(path.getFileName().toString()); - + List classpath = new ArrayList<>(); List sources = new ArrayList<>(); - + for (String classPathEntry: classPath.split("\\;")) - { + { if (classPathEntry.endsWith(".jar")) { classpath.add(classPathEntry); } - else if(classPathEntry.endsWith(".aar")) + else if (classPathEntry.endsWith(".aar")) { - File extractedJarFile = extractClassesJarFileFromAarFile(Paths.get(classPathEntry), astVisitorClient); + File extractedJarFile = extractClassesJarFileFromAarFile( + Paths.get(classPathEntry), astVisitorClient); if (extractedJarFile != null) { classpath.add(extractedJarFile.getAbsolutePath()); @@ -83,47 +104,50 @@ public class JavaIndexer else if (!classPathEntry.isEmpty()) { sources.add(classPathEntry); - } + } } - - parser.setEnvironment(classpath.toArray(new String[0]), sources.toArray(new String[0]), null, true); + + parser.setEnvironment( + classpath.toArray(new String[0]), sources.toArray(new String[0]), null, true); parser.setSource(fileContent.toCharArray()); - - CompilationUnit cu = (CompilationUnit) parser.createAST(null); - + + CompilationUnit cu = (CompilationUnit)parser.createAST(null); + ASTVisitor visitor; if (verbose != 0) { - visitor = new VerboseContextAwareAstVisitor(astVisitorClient, path.toFile(), fileContent, cu); + visitor = new VerboseContextAwareAstVisitor( + astVisitorClient, path.toFile(), fileContent, cu); } else { - visitor = new ContextAwareAstVisitor(astVisitorClient, path.toFile(), fileContent, cu); + visitor = new ContextAwareAstVisitor( + astVisitorClient, path.toFile(), fileContent, cu); } - + astVisitorClient.logInfo("starting AST traversal"); - + cu.accept(visitor); - + for (IProblem problem: cu.getProblems()) { if (problem.isError()) { Range range = new Range( - cu.getLineNumber(problem.getSourceStart()), - cu.getColumnNumber(problem.getSourceStart() + 1), - cu.getLineNumber(problem.getSourceEnd()), - cu.getColumnNumber(problem.getSourceEnd()) + 1); - + cu.getLineNumber(problem.getSourceStart()), + cu.getColumnNumber(problem.getSourceStart() + 1), + cu.getLineNumber(problem.getSourceEnd()), + cu.getColumnNumber(problem.getSourceEnd()) + 1); + astVisitorClient.recordError(problem.getMessage(), false, true, range); } } - + for (Object commentObject: cu.getCommentList()) { if ((commentObject instanceof LineComment) || (commentObject instanceof BlockComment)) { - ((Comment) commentObject).accept(visitor); + ((Comment)commentObject).accept(visitor); } } } @@ -135,15 +159,16 @@ public class JavaIndexer astVisitorClient.logError(sw.toString()); } } - + public static String getPackageName(String fileContent) { String packageName = ""; - + ASTParser parser = ASTParser.newParser(AST.JLS12); - parser.setKind(ASTParser.K_COMPILATION_UNIT); // specify to parse the entire compilation unit + parser.setKind( + ASTParser.K_COMPILATION_UNIT); // specify to parse the entire compilation unit parser.setSource(fileContent.toCharArray()); - CompilationUnit cu = (CompilationUnit) parser.createAST(null); + CompilationUnit cu = (CompilationUnit)parser.createAST(null); PackageDeclaration packageDeclaration = cu.getPackage(); if (packageDeclaration != null) { @@ -151,138 +176,181 @@ public class JavaIndexer } return packageName; } - + public static void clearCaches() { Runtime.getRuntime().gc(); } - + private static String convertLanguageStandard(String s) { switch (s) - { - case "1": - return JavaCore.VERSION_1_1; - case "2": - return JavaCore.VERSION_1_2; - case "3": - return JavaCore.VERSION_1_3; - case "4": - return JavaCore.VERSION_1_4; - case "5": - return JavaCore.VERSION_1_5; - case "6": - return JavaCore.VERSION_1_6; - case "7": - return JavaCore.VERSION_1_7; - case "8": - return JavaCore.VERSION_1_8; - case "9": - return JavaCore.VERSION_9; - case "10": - return JavaCore.VERSION_10; - case "11": - return JavaCore.VERSION_11; - case "12": - default: - return JavaCore.VERSION_12; - } + { + case "1": + return JavaCore.VERSION_1_1; + case "2": + return JavaCore.VERSION_1_2; + case "3": + return JavaCore.VERSION_1_3; + case "4": + return JavaCore.VERSION_1_4; + case "5": + return JavaCore.VERSION_1_5; + case "6": + return JavaCore.VERSION_1_6; + case "7": + return JavaCore.VERSION_1_7; + case "8": + return JavaCore.VERSION_1_8; + case "9": + return JavaCore.VERSION_9; + case "10": + return JavaCore.VERSION_10; + case "11": + return JavaCore.VERSION_11; + case "12": + default: + return JavaCore.VERSION_12; + } } - - private static File extractClassesJarFileFromAarFile(Path aarFilePath, AstVisitorClient astVisitorClient) throws IOException + + private static File extractClassesJarFileFromAarFile( + Path aarFilePath, AstVisitorClient astVisitorClient) throws IOException { JarFile jarFile = new JarFile(aarFilePath.toString()); ZipEntry classesJarEntry = jarFile.getEntry("classes.jar"); if (classesJarEntry != null) { InputStream inputStream = jarFile.getInputStream(classesJarEntry); - File tempFile = File.createTempFile("jar_file_from_" + Utility.getFilenameWithoutExtension(aarFilePath) + "_", ".jar"); + File tempFile = File.createTempFile( + "jar_file_from_" + Utility.getFilenameWithoutExtension(aarFilePath) + "_", ".jar"); tempFile.deleteOnExit(); - + byte[] buffer = new byte[8 * 1024]; - - try + + try { OutputStream output = new FileOutputStream(tempFile); - try + try { int bytesRead; - while ((bytesRead = inputStream.read(buffer)) != -1) + while ((bytesRead = inputStream.read(buffer)) != -1) { output.write(buffer, 0, bytesRead); } - } - finally + } + finally { output.close(); } - } - finally + } + finally { inputStream.close(); - } - + } + astVisitorClient.logInfo( - "Extracted classes.jar file from \"" + aarFilePath.toString() + "\" to \"" + tempFile.getAbsolutePath() + "\". " + - "This file will be automatically deleted when the session ends."); - + "Extracted classes.jar file from \"" + aarFilePath.toString() + "\" to \"" + + tempFile.getAbsolutePath() + "\". " + + "This file will be automatically deleted when the session ends."); + return tempFile; } else { - astVisitorClient.logError("Classpath entry \"" + aarFilePath + "\" is malformed. No internal \"classes.jar\" entry could be found."); + astVisitorClient.logError( + "Classpath entry \"" + aarFilePath + + "\" is malformed. No internal \"classes.jar\" entry could be found."); } jarFile.close(); - + return null; } // the following methods are defined in the native c++ code static public native boolean getInterrupted(int address); - + static public native void logInfo(int address, String info); - + static public native void logWarning(int address, String warning); - + static public native void logError(int address, String error); - + static public native void recordSymbol( - int address, String symbolName, int symbolType, - int access, int definitionKind); + int address, String symbolName, int symbolType, int access, int definitionKind); static public native void recordSymbolWithLocation( - int address, String symbolName, int symbolType, - int beginLine, int beginColumn, int endLine, int endColumn, - int access, int definitionKind); - + int address, + String symbolName, + int symbolType, + int beginLine, + int beginColumn, + int endLine, + int endColumn, + int access, + int definitionKind); + static public native void recordSymbolWithLocationAndScope( - int address, String symbolName, int symbolType, - int beginLine, int beginColumn, int endLine, int endColumn, - int scopeBeginLine, int scopeBeginColumn, int scopeEndLine, int scopeEndColumn, - int access, int definitionKind - ); - + int address, + String symbolName, + int symbolType, + int beginLine, + int beginColumn, + int endLine, + int endColumn, + int scopeBeginLine, + int scopeBeginColumn, + int scopeEndLine, + int scopeEndColumn, + int access, + int definitionKind); + static public native void recordSymbolWithLocationAndScopeAndSignature( - int address, String symbolName, int symbolType, - int beginLine, int beginColumn, int endLine, int endColumn, - int scopeBeginLine, int scopeBeginColumn, int scopeEndLine, int scopeEndColumn, - int signatureBeginLine, int signatureBeginColumn, int signatureEndLine, int signatureEndColumn, - int access, int definitionKind - ); + int address, + String symbolName, + int symbolType, + int beginLine, + int beginColumn, + int endLine, + int endColumn, + int scopeBeginLine, + int scopeBeginColumn, + int scopeEndLine, + int scopeEndColumn, + int signatureBeginLine, + int signatureBeginColumn, + int signatureEndLine, + int signatureEndColumn, + int access, + int definitionKind); static public native void recordReference( - int address, int referenceKind, String referencedName, String contextName, int beginLine, int beginColumn, int endLine, int endColumn); + int address, + int referenceKind, + String referencedName, + String contextName, + int beginLine, + int beginColumn, + int endLine, + int endColumn); static public native void recordQualifierLocation( - int address, String qualifierName, int beginLine, int beginColumn, int endLine, int endColumn); - + int address, String qualifierName, int beginLine, int beginColumn, int endLine, int endColumn); + static public native void recordLocalSymbol( - int address, String symbolName, int beginLine, int beginColumn, int endLine, int endColumn); - + int address, String symbolName, int beginLine, int beginColumn, int endLine, int endColumn); + static public native void recordComment( - int address, int beginLine, int beginColumn, int endLine, int endColumn); - + int address, int beginLine, int beginColumn, int endLine, int endColumn); + static public native void recordError( - int address, String message, int fatal, int indexed, int beginLine, int beginColumn, int endLine, int endColumn); + int address, + String message, + int fatal, + int indexed, + int beginLine, + int beginColumn, + int endLine, + int endColumn); } \ No newline at end of file diff --git a/java_indexer/src/main/java/com/sourcetrail/JavaIndexerAstVisitorClient.java b/java_indexer/src/main/java/com/sourcetrail/JavaIndexerAstVisitorClient.java index 1656391a..aae5d722 100644 --- a/java_indexer/src/main/java/com/sourcetrail/JavaIndexerAstVisitorClient.java +++ b/java_indexer/src/main/java/com/sourcetrail/JavaIndexerAstVisitorClient.java @@ -3,7 +3,7 @@ package com.sourcetrail; import com.sourcetrail.name.NameElement; import com.sourcetrail.name.NameHierarchy; -public class JavaIndexerAstVisitorClient extends AstVisitorClient +public class JavaIndexerAstVisitorClient extends AstVisitorClient { private int m_address; private String m_javaLangPackageName; @@ -12,135 +12,187 @@ public class JavaIndexerAstVisitorClient extends AstVisitorClient public JavaIndexerAstVisitorClient(int address) { m_address = address; - + NameHierarchy javaLangPackageNameHierarchy = new NameHierarchy(); javaLangPackageNameHierarchy.push(new NameElement("java")); javaLangPackageNameHierarchy.push(new NameElement("lang")); m_javaLangPackageName = javaLangPackageNameHierarchy.serialize(); m_javaLangPackageRecorded = false; } - - @Override - public boolean getInterrupted() + + @Override public boolean getInterrupted() { return JavaIndexer.getInterrupted(m_address); } - - @Override - public void logInfo(String info) + + @Override public void logInfo(String info) { JavaIndexer.logInfo(m_address, info); } - @Override - public void logWarning(String warning) + @Override public void logWarning(String warning) { JavaIndexer.logWarning(m_address, warning); } - - @Override - public void logError(String error) + + @Override public void logError(String error) { JavaIndexer.logError(m_address, error); } - + @Override public void recordSymbol( - NameHierarchy symbolName, SymbolKind symbolKind, - AccessKind access, DefinitionKind definitionKind) + NameHierarchy symbolName, SymbolKind symbolKind, AccessKind access, DefinitionKind definitionKind) { JavaIndexer.recordSymbol( - m_address, symbolName.serialize(), symbolKind.getValue(), - access.getValue(), definitionKind.getValue()); + m_address, + symbolName.serialize(), + symbolKind.getValue(), + access.getValue(), + definitionKind.getValue()); } @Override public void recordSymbolWithLocation( - NameHierarchy symbolName, SymbolKind symbolKind, Range range, - AccessKind access, DefinitionKind definitionKind) + NameHierarchy symbolName, + SymbolKind symbolKind, + Range range, + AccessKind access, + DefinitionKind definitionKind) { JavaIndexer.recordSymbolWithLocation( - m_address, symbolName.serialize(), symbolKind.getValue(), - range.begin.line, range.begin.column, range.end.line, range.end.column, - access.getValue(), definitionKind.getValue()); + m_address, + symbolName.serialize(), + symbolKind.getValue(), + range.begin.line, + range.begin.column, + range.end.line, + range.end.column, + access.getValue(), + definitionKind.getValue()); } @Override public void recordSymbolWithLocationAndScope( - NameHierarchy symbolName, SymbolKind symbolKind, Range range, - Range scopeRange, AccessKind access, DefinitionKind definitionKind) + NameHierarchy symbolName, + SymbolKind symbolKind, + Range range, + Range scopeRange, + AccessKind access, + DefinitionKind definitionKind) { JavaIndexer.recordSymbolWithLocationAndScope( - m_address, symbolName.serialize(), symbolKind.getValue(), - range.begin.line, range.begin.column, range.end.line, range.end.column, - scopeRange.begin.line, scopeRange.begin.column, scopeRange.end.line, scopeRange.end.column, - access.getValue(), definitionKind.getValue()); + m_address, + symbolName.serialize(), + symbolKind.getValue(), + range.begin.line, + range.begin.column, + range.end.line, + range.end.column, + scopeRange.begin.line, + scopeRange.begin.column, + scopeRange.end.line, + scopeRange.end.column, + access.getValue(), + definitionKind.getValue()); } @Override public void recordSymbolWithLocationAndScopeAndSignature( - NameHierarchy symbolName, SymbolKind symbolKind, Range range, - Range scopeRange, Range signatureRange, AccessKind access, DefinitionKind definitionKind) + NameHierarchy symbolName, + SymbolKind symbolKind, + Range range, + Range scopeRange, + Range signatureRange, + AccessKind access, + DefinitionKind definitionKind) { JavaIndexer.recordSymbolWithLocationAndScopeAndSignature( - m_address, symbolName.serialize(), symbolKind.getValue(), - range.begin.line, range.begin.column, range.end.line, range.end.column, - scopeRange.begin.line, scopeRange.begin.column, scopeRange.end.line, scopeRange.end.column, - signatureRange.begin.line, signatureRange.begin.column, signatureRange.end.line, signatureRange.end.column, - access.getValue(), definitionKind.getValue()); + m_address, + symbolName.serialize(), + symbolKind.getValue(), + range.begin.line, + range.begin.column, + range.end.line, + range.end.column, + scopeRange.begin.line, + scopeRange.begin.column, + scopeRange.end.line, + scopeRange.end.column, + signatureRange.begin.line, + signatureRange.begin.column, + signatureRange.end.line, + signatureRange.end.column, + access.getValue(), + definitionKind.getValue()); } @Override public void recordReference( - ReferenceKind referenceKind, NameHierarchy referencedName, - NameHierarchy contextName, Range range) + ReferenceKind referenceKind, NameHierarchy referencedName, NameHierarchy contextName, Range range) { String serializedReferencedName = referencedName.serialize(); if (!m_javaLangPackageRecorded && serializedReferencedName.startsWith(m_javaLangPackageName)) { JavaIndexer.recordSymbol( - m_address, m_javaLangPackageName, SymbolKind.PACKAGE.getValue(), - AccessKind.NONE.getValue(), DefinitionKind.NONE.getValue()); - + m_address, + m_javaLangPackageName, + SymbolKind.PACKAGE.getValue(), + AccessKind.NONE.getValue(), + DefinitionKind.NONE.getValue()); + m_javaLangPackageRecorded = true; } - + JavaIndexer.recordReference( - m_address, referenceKind.getValue(), serializedReferencedName, contextName.serialize(), - range.begin.line, range.begin.column, range.end.line, range.end.column); + m_address, + referenceKind.getValue(), + serializedReferencedName, + contextName.serialize(), + range.begin.line, + range.begin.column, + range.end.line, + range.end.column); } - @Override - public void recordQualifierLocation( - NameHierarchy qualifierName, - Range range) + @Override public void recordQualifierLocation(NameHierarchy qualifierName, Range range) { JavaIndexer.recordQualifierLocation( - m_address, qualifierName.serialize(), - range.begin.line, range.begin.column, range.end.line, range.end.column); + m_address, + qualifierName.serialize(), + range.begin.line, + range.begin.column, + range.end.line, + range.end.column); } - @Override - public void recordLocalSymbol(NameHierarchy symbolName, Range range) + @Override public void recordLocalSymbol(NameHierarchy symbolName, Range range) { JavaIndexer.recordLocalSymbol( - m_address, symbolName.serialize(), - range.begin.line, range.begin.column, range.end.line, range.end.column); + m_address, + symbolName.serialize(), + range.begin.line, + range.begin.column, + range.end.line, + range.end.column); } - @Override - public void recordComment(Range range) + @Override public void recordComment(Range range) { JavaIndexer.recordComment( - m_address, - range.begin.line, range.begin.column, range.end.line, range.end.column); + m_address, range.begin.line, range.begin.column, range.end.line, range.end.column); } - @Override - public void recordError(String message, boolean fatal, boolean indexed, Range range) + @Override public void recordError(String message, boolean fatal, boolean indexed, Range range) { JavaIndexer.recordError( - m_address, message, (fatal ? 1 : 0), (indexed ? 1 : 0), - range.begin.line, range.begin.column, range.end.line, range.end.column); + m_address, + message, + (fatal ? 1 : 0), + (indexed ? 1 : 0), + range.begin.line, + range.begin.column, + range.end.line, + range.end.column); } } diff --git a/java_indexer/src/main/java/com/sourcetrail/Position.java b/java_indexer/src/main/java/com/sourcetrail/Position.java index 20e21635..88e4365c 100644 --- a/java_indexer/src/main/java/com/sourcetrail/Position.java +++ b/java_indexer/src/main/java/com/sourcetrail/Position.java @@ -1,14 +1,12 @@ package com.sourcetrail; -public class Position +public class Position { public int line = 0; public int column = 0; - public Position() - { - } - + public Position() {} + public Position(int line, int column) { this.line = line; diff --git a/java_indexer/src/main/java/com/sourcetrail/QualifierVisitor.java b/java_indexer/src/main/java/com/sourcetrail/QualifierVisitor.java index 631626f0..cecac117 100644 --- a/java_indexer/src/main/java/com/sourcetrail/QualifierVisitor.java +++ b/java_indexer/src/main/java/com/sourcetrail/QualifierVisitor.java @@ -1,7 +1,10 @@ package com.sourcetrail; +import com.sourcetrail.name.DeclName; +import com.sourcetrail.name.NameHierarchy; +import com.sourcetrail.name.TypeName; +import com.sourcetrail.name.resolver.BindingNameResolver; import java.io.File; - import org.eclipse.jdt.core.dom.ASTNode; import org.eclipse.jdt.core.dom.CompilationUnit; import org.eclipse.jdt.core.dom.CreationReference; @@ -27,45 +30,41 @@ import org.eclipse.jdt.core.dom.ThisExpression; import org.eclipse.jdt.core.dom.Type; import org.eclipse.jdt.core.dom.TypeMethodReference; -import com.sourcetrail.name.DeclName; -import com.sourcetrail.name.NameHierarchy; -import com.sourcetrail.name.TypeName; -import com.sourcetrail.name.resolver.BindingNameResolver; - -public class QualifierVisitor +public class QualifierVisitor { protected AstVisitorClient m_client = null; private File m_filePath; private CompilationUnit m_compilationUnit; private boolean m_recordSymbolKinds = false; - - public QualifierVisitor(AstVisitorClient client, File filePath, CompilationUnit compilationUnit, boolean recordSymbolKinds) - { + + public QualifierVisitor( + AstVisitorClient client, File filePath, CompilationUnit compilationUnit, boolean recordSymbolKinds) + { m_client = client; m_filePath = filePath; m_compilationUnit = compilationUnit; m_recordSymbolKinds = recordSymbolKinds; } - public void recordQualifierOfNode(ImportDeclaration node) + public void recordQualifierOfNode(ImportDeclaration node) { if (node != null && node.getName() instanceof QualifiedName) { - recordNodeAsQualifier(((QualifiedName) node.getName()).getQualifier()); + recordNodeAsQualifier(((QualifiedName)node.getName()).getQualifier()); } } - + public void recordQualifierOfNode(SimpleType node) { if (node != null) { if (node.getName() instanceof QualifiedName) { - recordNodeAsQualifier(((QualifiedName) node.getName()).getQualifier()); + recordNodeAsQualifier(((QualifiedName)node.getName()).getQualifier()); } } } - + public void recordQualifierOfNode(QualifiedType node) { if (node != null) @@ -73,7 +72,7 @@ public class QualifierVisitor recordNodeAsQualifier(node.getQualifier()); } } - + public void recordQualifierOfNode(NameQualifiedType node) { if (node != null) @@ -121,11 +120,11 @@ public class QualifierVisitor recordNodeAsQualifier(node.getExpression(), fileContent); } } - + public void recordQualifierOfNode(SuperMethodInvocation node, FileContent fileContent) { if (node != null) - { + { IMethodBinding methodBinding = node.resolveMethodBinding(); if (methodBinding != null) { @@ -133,23 +132,23 @@ public class QualifierVisitor if (typeBinding != null) { m_client.recordQualifierLocation( - BindingNameResolver - .getQualifiedName(typeBinding, m_filePath, m_compilationUnit) - .orElse(TypeName.unsolved()) - .toDeclName() - .toNameHierarchy(), - fileContent.findRange("super", getRange(node).begin)); + BindingNameResolver + .getQualifiedName(typeBinding, m_filePath, m_compilationUnit) + .orElse(TypeName.unsolved()) + .toDeclName() + .toNameHierarchy(), + fileContent.findRange("super", getRange(node).begin)); } } - + recordNodeAsQualifier(node.getQualifier()); } } - public void recordQualifierOfNode(CreationReference node) + public void recordQualifierOfNode(CreationReference node) { if (node != null) - { + { recordNodeAsQualifier(node.getType()); } } @@ -165,7 +164,7 @@ public class QualifierVisitor public void recordQualifierOfNode(SuperMethodReference node, FileContent fileContent) { if (node != null) - { + { IMethodBinding methodBinding = node.resolveMethodBinding(); if (methodBinding != null) { @@ -173,15 +172,15 @@ public class QualifierVisitor if (typeBinding != null) { m_client.recordQualifierLocation( - BindingNameResolver - .getQualifiedName(typeBinding, m_filePath, m_compilationUnit) - .orElse(TypeName.unsolved()) - .toDeclName() - .toNameHierarchy(), - fileContent.findRange("super", getRange(node).begin)); + BindingNameResolver + .getQualifiedName(typeBinding, m_filePath, m_compilationUnit) + .orElse(TypeName.unsolved()) + .toDeclName() + .toNameHierarchy(), + fileContent.findRange("super", getRange(node).begin)); } } - + recordNodeAsQualifier(node.getQualifier()); } } @@ -193,79 +192,80 @@ public class QualifierVisitor recordNodeAsQualifier(node.getType()); } } - - - private void recordNodeAsQualifier(Expression node, FileContent fileContent) { + + + private void recordNodeAsQualifier(Expression node, FileContent fileContent) + { if (node != null) { if (node instanceof Name) { - recordNodeAsQualifier((Name) node); + recordNodeAsQualifier((Name)node); } else if (node instanceof SuperFieldAccess) { - SuperFieldAccess expression = (SuperFieldAccess) node; + SuperFieldAccess expression = (SuperFieldAccess)node; IVariableBinding fieldBinding = expression.resolveFieldBinding(); - + if (fieldBinding != null) { m_client.recordQualifierLocation( - BindingNameResolver - .getQualifiedName(fieldBinding.getDeclaringClass(), m_filePath, m_compilationUnit) - .orElse(TypeName.unsolved()) - .toDeclName() - .toNameHierarchy(), - fileContent.findRange( - "super", - expression.getQualifier() != null - ? getRange(expression.getQualifier()).end - : getRange(expression).begin)); + BindingNameResolver + .getQualifiedName( + fieldBinding.getDeclaringClass(), m_filePath, m_compilationUnit) + .orElse(TypeName.unsolved()) + .toDeclName() + .toNameHierarchy(), + fileContent.findRange( + "super", + expression.getQualifier() != null ? getRange(expression.getQualifier()).end + : getRange(expression).begin)); } - + recordNodeAsQualifier(expression.getQualifier()); } else if (node instanceof ThisExpression) { - ThisExpression expression = (ThisExpression) node; - + ThisExpression expression = (ThisExpression)node; + m_client.recordQualifierLocation( - BindingNameResolver - .getQualifiedName(expression.resolveTypeBinding(), m_filePath, m_compilationUnit) - .orElse(TypeName.unsolved()) - .toDeclName() - .toNameHierarchy(), - fileContent.findRange( - "this", - expression.getQualifier() != null - ? getRange(expression.getQualifier()).end - : getRange(expression).begin)); - + BindingNameResolver + .getQualifiedName( + expression.resolveTypeBinding(), m_filePath, m_compilationUnit) + .orElse(TypeName.unsolved()) + .toDeclName() + .toNameHierarchy(), + fileContent.findRange( + "this", + expression.getQualifier() != null ? getRange(expression.getQualifier()).end + : getRange(expression).begin)); + recordNodeAsQualifier(expression.getQualifier()); } } } - + private void recordNodeAsQualifier(Type node) { if (node != null) - { + { if (node instanceof SimpleType) { - recordNodeAsQualifier(((SimpleType) node).getName()); + recordNodeAsQualifier(((SimpleType)node).getName()); } else if (node instanceof QualifiedType) { - recordNodeAsQualifier(((QualifiedType) node).getName()); - recordNodeAsQualifier(((QualifiedType) node).getQualifier()); + recordNodeAsQualifier(((QualifiedType)node).getName()); + recordNodeAsQualifier(((QualifiedType)node).getQualifier()); } else if (node instanceof NameQualifiedType) { - recordNodeAsQualifier(((NameQualifiedType) node).getName()); - recordNodeAsQualifier(((NameQualifiedType) node).getQualifier()); + recordNodeAsQualifier(((NameQualifiedType)node).getName()); + recordNodeAsQualifier(((NameQualifiedType)node).getQualifier()); } } } - + private void recordNodeAsQualifier(Name node) { if (node != null) @@ -276,47 +276,47 @@ public class QualifierVisitor Range range = getRange(node); if (node instanceof QualifiedName) { - range = getRange(((QualifiedName) node).getName()); + range = getRange(((QualifiedName)node).getName()); } - + m_client.recordQualifierLocation( - BindingNameResolver - .getQualifiedName((ITypeBinding) binding, m_filePath, m_compilationUnit) - .orElse(TypeName.unsolved()) - .toDeclName() - .toNameHierarchy(), - range); + BindingNameResolver + .getQualifiedName((ITypeBinding)binding, m_filePath, m_compilationUnit) + .orElse(TypeName.unsolved()) + .toDeclName() + .toNameHierarchy(), + range); } else if (binding instanceof IPackageBinding) { Range range = getRange(node); if (node instanceof QualifiedName) { - range = getRange(((QualifiedName) node).getName()); + range = getRange(((QualifiedName)node).getName()); } - - NameHierarchy symbolName = BindingNameResolver - .getQualifiedName((IPackageBinding) binding, m_filePath, m_compilationUnit) + + NameHierarchy symbolName = + BindingNameResolver + .getQualifiedName((IPackageBinding)binding, m_filePath, m_compilationUnit) .orElse(DeclName.unsolved()) .toNameHierarchy(); - + if (m_recordSymbolKinds) { - m_client.recordSymbol(symbolName, SymbolKind.PACKAGE, AccessKind.NONE, DefinitionKind.NONE); + m_client.recordSymbol( + symbolName, SymbolKind.PACKAGE, AccessKind.NONE, DefinitionKind.NONE); } - - m_client.recordQualifierLocation( - symbolName, - range); + + m_client.recordQualifierLocation(symbolName, range); } - + if (node instanceof QualifiedName) { - recordNodeAsQualifier(((QualifiedName) node).getQualifier()); + recordNodeAsQualifier(((QualifiedName)node).getQualifier()); } } } - + private Range getRange(ASTNode node) { return Utility.getRange(node, m_compilationUnit); diff --git a/java_indexer/src/main/java/com/sourcetrail/Range.java b/java_indexer/src/main/java/com/sourcetrail/Range.java index 1cb54973..0c8c1357 100644 --- a/java_indexer/src/main/java/com/sourcetrail/Range.java +++ b/java_indexer/src/main/java/com/sourcetrail/Range.java @@ -1,23 +1,21 @@ package com.sourcetrail; -public class Range +public class Range { public Position begin = new Position(); public Position end = new Position(); - - public Range() - { - } - - public Range(int beginLine, int beginColumn, int endLine, int endColumn) + + public Range() {} + + public Range(int beginLine, int beginColumn, int endLine, int endColumn) { this.begin.line = beginLine; this.begin.column = beginColumn; this.end.line = endLine; this.end.column = endColumn; } - - public Range(Position begin, Position end) + + public Range(Position begin, Position end) { this.begin.line = begin.line; this.begin.column = begin.column; diff --git a/java_indexer/src/main/java/com/sourcetrail/ReferenceKind.java b/java_indexer/src/main/java/com/sourcetrail/ReferenceKind.java index aa8d52a9..0916058d 100644 --- a/java_indexer/src/main/java/com/sourcetrail/ReferenceKind.java +++ b/java_indexer/src/main/java/com/sourcetrail/ReferenceKind.java @@ -1,7 +1,6 @@ package com.sourcetrail; -public enum ReferenceKind -{ // these values need to be the same as ReferenceKind in C++ code +public enum ReferenceKind { // these values need to be the same as ReferenceKind in C++ code UNDEFINED(0), TYPE_USAGE(1), USAGE(2), @@ -14,16 +13,16 @@ public enum ReferenceKind IMPORT(9), MACRO_USAGE(10), ANNOTATION_USAGE(11); - - private final int m_value; - - private ReferenceKind(int value) - { - this.m_value = value; - } - public int getValue() - { - return m_value; - } + private final int m_value; + + private ReferenceKind(int value) + { + this.m_value = value; + } + + public int getValue() + { + return m_value; + } } diff --git a/java_indexer/src/main/java/com/sourcetrail/SymbolKind.java b/java_indexer/src/main/java/com/sourcetrail/SymbolKind.java index c08e2a46..5d597a64 100644 --- a/java_indexer/src/main/java/com/sourcetrail/SymbolKind.java +++ b/java_indexer/src/main/java/com/sourcetrail/SymbolKind.java @@ -1,7 +1,6 @@ package com.sourcetrail; -public enum SymbolKind -{ // these values need to be the same as SymbolKind in C++ code +public enum SymbolKind { // these values need to be the same as SymbolKind in C++ code ANNOTATION(1), BUILTIN_TYPE(2), CLASS(3), @@ -21,16 +20,16 @@ public enum SymbolKind TYPE_PARAMETER(17), UNION(18), TYPE_MAX(19); - - private final int m_value; - - private SymbolKind(int value) - { - this.m_value = value; - } - public int getValue() - { - return m_value; - } + private final int m_value; + + private SymbolKind(int value) + { + this.m_value = value; + } + + public int getValue() + { + return m_value; + } } diff --git a/java_indexer/src/main/java/com/sourcetrail/Utility.java b/java_indexer/src/main/java/com/sourcetrail/Utility.java index e37ed717..f48ba8af 100644 --- a/java_indexer/src/main/java/com/sourcetrail/Utility.java +++ b/java_indexer/src/main/java/com/sourcetrail/Utility.java @@ -1,32 +1,31 @@ package com.sourcetrail; import java.nio.file.Path; - import org.eclipse.jdt.core.dom.ASTNode; import org.eclipse.jdt.core.dom.BodyDeclaration; import org.eclipse.jdt.core.dom.CompilationUnit; import org.eclipse.jdt.core.dom.Javadoc; -public class Utility +public class Utility { public static Range getRange(ASTNode node, CompilationUnit compilationUnit) { int startPosition = node.getStartPosition() + 1; int endPosition = node.getStartPosition() + node.getLength() - 1; - - if (node instanceof BodyDeclaration && ((BodyDeclaration) node).getJavadoc() != null) + + if (node instanceof BodyDeclaration && ((BodyDeclaration)node).getJavadoc() != null) { - Javadoc javadoc = ((BodyDeclaration) node).getJavadoc(); + Javadoc javadoc = ((BodyDeclaration)node).getJavadoc(); startPosition = javadoc.getStartPosition() + javadoc.getLength() + 2; } - + return new Range( - compilationUnit.getLineNumber(startPosition), - compilationUnit.getColumnNumber(startPosition), - compilationUnit.getLineNumber(endPosition), - compilationUnit.getColumnNumber(endPosition) + 1); + compilationUnit.getLineNumber(startPosition), + compilationUnit.getColumnNumber(startPosition), + compilationUnit.getLineNumber(endPosition), + compilationUnit.getColumnNumber(endPosition) + 1); } - + public static String getFilenameWithoutExtension(Path filePath) { return filePath.getFileName().toString().replaceFirst("[.][^.]+$", ""); diff --git a/java_indexer/src/main/java/com/sourcetrail/VerboseContextAwareAstVisitor.java b/java_indexer/src/main/java/com/sourcetrail/VerboseContextAwareAstVisitor.java index 8e2d25f0..568db1a2 100644 --- a/java_indexer/src/main/java/com/sourcetrail/VerboseContextAwareAstVisitor.java +++ b/java_indexer/src/main/java/com/sourcetrail/VerboseContextAwareAstVisitor.java @@ -1,15 +1,15 @@ package com.sourcetrail; import java.io.File; - import org.eclipse.jdt.core.dom.ASTNode; import org.eclipse.jdt.core.dom.CompilationUnit; -public class VerboseContextAwareAstVisitor extends ContextAwareAstVisitor +public class VerboseContextAwareAstVisitor extends ContextAwareAstVisitor { private String indentation = ""; - - public VerboseContextAwareAstVisitor(AstVisitorClient client, File filePath, String fileContent, CompilationUnit compilationUnit) + + public VerboseContextAwareAstVisitor( + AstVisitorClient client, File filePath, String fileContent, CompilationUnit compilationUnit) { super(client, filePath, fileContent, compilationUnit); } @@ -17,10 +17,12 @@ public class VerboseContextAwareAstVisitor extends ContextAwareAstVisitor public void preVisit(ASTNode node) { Range range = getRange(node); - m_client.logInfo(indentation + node.getClass().toString() + "[" + range.begin.line + ":" + range.begin.column + "|" + range.end.line + ":" + range.end.column + "]"); + m_client.logInfo( + indentation + node.getClass().toString() + "[" + range.begin.line + ":" + + range.begin.column + "|" + range.end.line + ":" + range.end.column + "]"); indentation += "| "; } - + public void postVisit(ASTNode node) { indentation = indentation.substring(0, indentation.length() - 2); diff --git a/java_indexer/src/main/java/com/sourcetrail/gradle/InfoRetriever.java b/java_indexer/src/main/java/com/sourcetrail/gradle/InfoRetriever.java index edbef077..ace16134 100644 --- a/java_indexer/src/main/java/com/sourcetrail/gradle/InfoRetriever.java +++ b/java_indexer/src/main/java/com/sourcetrail/gradle/InfoRetriever.java @@ -9,20 +9,19 @@ import java.io.StringReader; import java.util.ArrayList; import java.util.Arrays; import java.util.List; - import org.gradle.api.GradleException; import org.gradle.tooling.BuildLauncher; import org.gradle.tooling.GradleConnector; import org.gradle.tooling.ProjectConnection; -public class InfoRetriever +public class InfoRetriever { public static String getMainSrcDirs(String projectRootPath, String initScriptPath) { try { String ret = ""; - + List srcDirs = getSrcDirs("printMainSrcDirs", projectRootPath, initScriptPath); for (int i = 0; i < srcDirs.size(); i++) { @@ -32,7 +31,7 @@ public class InfoRetriever } ret += srcDirs.get(i); } - + return ret; } catch (GradleException e) @@ -40,7 +39,7 @@ public class InfoRetriever return "[ERROR] " + e.getMessage(); } } - + public static String getTestSrcDirs(String projectRootPath, String initScriptPath) { try @@ -56,7 +55,7 @@ public class InfoRetriever } ret += srcDirs.get(i); } - + return ret; } catch (GradleException e) @@ -64,50 +63,58 @@ public class InfoRetriever return "[ERROR] " + e.getMessage(); } } - + public static void copyCompileLibs(String projectRootPath, String initScriptPath, String targetPath) { - executeTask("copyCompileLibs", projectRootPath, initScriptPath, Arrays.asList("-Psourcetrail_lib_path=" + targetPath)); + executeTask( + "copyCompileLibs", + projectRootPath, + initScriptPath, + Arrays.asList("-Psourcetrail_lib_path=" + targetPath)); } - + public static void copyTestCompileLibs(String projectRootPath, String initScriptPath, String targetPath) { - executeTask("copyTestCompileLibs", projectRootPath, initScriptPath, Arrays.asList("-Psourcetrail_lib_path=" + targetPath)); + executeTask( + "copyTestCompileLibs", + projectRootPath, + initScriptPath, + Arrays.asList("-Psourcetrail_lib_path=" + targetPath)); } - + private static List getSrcDirs(String taskName, String projectRootPath, String initScriptPath) - { + { String output = executeTask(taskName, projectRootPath, initScriptPath, null); - + List paths = new ArrayList<>(); - - try (BufferedReader reader = new BufferedReader(new StringReader(output))) + + try (BufferedReader reader = new BufferedReader(new StringReader(output))) { - String line; - while ((line = reader.readLine()) != null) - { - paths.add(line); - } - } - catch (IOException e) + String line; + while ((line = reader.readLine()) != null) + { + paths.add(line); + } + } + catch (IOException e) { // TODO: LOGERROR } - + return paths; } - - private static String executeTask(String taskName, String projectRootPath, String initScriptPath, List additionalArguments) throws GradleException - { - ProjectConnection connection = GradleConnector - .newConnector() - .forProjectDirectory(new File(projectRootPath)) - .connect(); - + + private static String executeTask( + String taskName, String projectRootPath, String initScriptPath, List additionalArguments) + throws GradleException + { + ProjectConnection connection = + GradleConnector.newConnector().forProjectDirectory(new File(projectRootPath)).connect(); + ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); ByteArrayOutputStream errorStream = new ByteArrayOutputStream(); - - try + + try { List arguments = new ArrayList<>(); arguments.add("--init-script"); @@ -118,28 +125,29 @@ public class InfoRetriever { arguments.addAll(additionalArguments); } - - BuildLauncher Launcher = connection.newBuild().forTasks(taskName) - .withArguments(arguments) - .setStandardOutput(new PrintStream(outputStream)) - .setStandardError(new PrintStream(errorStream)); - + + BuildLauncher Launcher = connection.newBuild() + .forTasks(taskName) + .withArguments(arguments) + .setStandardOutput(new PrintStream(outputStream)) + .setStandardError(new PrintStream(errorStream)); + Launcher.run(); - } + } catch (Exception e) { // TODO: LOGERROR } - finally + finally { connection.close(); } - + if (!errorStream.toString().isEmpty()) { throw new GradleException(errorStream.toString()); } - + return outputStream.toString(); } } diff --git a/java_indexer/src/main/java/com/sourcetrail/name/DeclName.java b/java_indexer/src/main/java/com/sourcetrail/name/DeclName.java index 4a68f657..854456df 100644 --- a/java_indexer/src/main/java/com/sourcetrail/name/DeclName.java +++ b/java_indexer/src/main/java/com/sourcetrail/name/DeclName.java @@ -1,10 +1,9 @@ package com.sourcetrail.name; +import com.sourcetrail.Position; import java.io.File; import java.util.List; -import com.sourcetrail.Position; - public class DeclName implements SymbolName { private DeclName m_parent = null; @@ -21,34 +20,36 @@ public class DeclName implements SymbolName declName.m_isUnsolved = true; return declName; } - + public static DeclName anonymousClass(File filePath, int line, int col) { - DeclName declName = new DeclName("anonymous class (" + filePath.getName() + "<" + line + ":" + col + ">)"); + DeclName declName = new DeclName( + "anonymous class (" + filePath.getName() + "<" + line + ":" + col + ">)"); declName.m_isAnonymous = true; return declName; } - + public static DeclName localSymbol(DeclName methodContextName, int id) { DeclName declName = new DeclName(methodContextName + "<" + id + ">"); declName.m_isLocal = true; return declName; } - + public static DeclName globalSymbol(File fileContext, int id) { DeclName declName = new DeclName(fileContext.getName() + "<" + id + ">"); declName.m_isGlobal = true; return declName; } - + public static DeclName scope(File fileContext, Position begin) { - DeclName declName = new DeclName(fileContext.getName() + "<" + begin.line + ":" + begin.column + ">"); + DeclName declName = new DeclName( + fileContext.getName() + "<" + begin.line + ":" + begin.column + ">"); return declName; } - + public static DeclName fromDotSeparatedString(String s) { DeclName declName = null; @@ -63,60 +64,60 @@ public class DeclName implements SymbolName { declName = new DeclName(s, null); } - + return declName; } - + public DeclName(String name) { m_name = name; } - + public DeclName(String name, List typeParameterNames) { m_name = name; m_typeParameterNames = typeParameterNames; } - + public void setParent(DeclName parent) { m_parent = parent; } - + public DeclName getParent() { return m_parent; } - + public String getName() { return m_name; } - + public boolean getIsUnsolved() { return m_isUnsolved; } - + public boolean getIsAnonymous() { return m_isAnonymous; } - + public boolean getIsLocal() { return m_isLocal; } - + public boolean getIsGlobal() { return m_isGlobal; } - + public NameHierarchy toNameHierarchy() { NameHierarchy nameHierarchy; - + if (m_parent != null) { nameHierarchy = m_parent.toNameHierarchy(); @@ -125,12 +126,12 @@ public class DeclName implements SymbolName { nameHierarchy = new NameHierarchy(); } - + nameHierarchy.push(new NameElement(m_name + getTypeParameterString())); - + return nameHierarchy; } - + public String toString() { String string = ""; @@ -139,13 +140,13 @@ public class DeclName implements SymbolName string = m_parent.toString(); string += "."; } - + string += m_name; string += getTypeParameterString(); - + return string; } - + public String getTypeParameterString() { String string = ""; @@ -165,7 +166,8 @@ public class DeclName implements SymbolName return string; } - public List getTypeParameterNames() { + public List getTypeParameterNames() + { return m_typeParameterNames; } } diff --git a/java_indexer/src/main/java/com/sourcetrail/name/FileName.java b/java_indexer/src/main/java/com/sourcetrail/name/FileName.java index dbbf94d2..b6beec69 100644 --- a/java_indexer/src/main/java/com/sourcetrail/name/FileName.java +++ b/java_indexer/src/main/java/com/sourcetrail/name/FileName.java @@ -11,8 +11,7 @@ public class FileName implements SymbolName m_filePath = filePath; } - @Override - public NameHierarchy toNameHierarchy() + @Override public NameHierarchy toNameHierarchy() { NameHierarchy nameHierarchy; if (m_filePath != null) diff --git a/java_indexer/src/main/java/com/sourcetrail/name/FunctionDeclName.java b/java_indexer/src/main/java/com/sourcetrail/name/FunctionDeclName.java index bad7d2ae..e165ef36 100644 --- a/java_indexer/src/main/java/com/sourcetrail/name/FunctionDeclName.java +++ b/java_indexer/src/main/java/com/sourcetrail/name/FunctionDeclName.java @@ -9,27 +9,34 @@ public class FunctionDeclName extends DeclName private TypeName m_returnTypeName = null; private List m_parameterTypeNames = new ArrayList<>(); private boolean m_isStatic = false; - - public FunctionDeclName(String name, TypeName returnTypeName, List parameterTypeNames, boolean isStatic) + + public FunctionDeclName( + String name, TypeName returnTypeName, List parameterTypeNames, boolean isStatic) { super(name); - + m_returnTypeName = returnTypeName; - if (parameterTypeNames != null) m_parameterTypeNames = parameterTypeNames; + if (parameterTypeNames != null) + m_parameterTypeNames = parameterTypeNames; m_isStatic = isStatic; } - - public FunctionDeclName(String name, List typeParameterNames, TypeName returnTypeName, List parameterTypeNames, boolean isStatic) + + public FunctionDeclName( + String name, + List typeParameterNames, + TypeName returnTypeName, + List parameterTypeNames, + boolean isStatic) { super(name, typeParameterNames); - + m_returnTypeName = returnTypeName; - if (parameterTypeNames != null) m_parameterTypeNames = parameterTypeNames; + if (parameterTypeNames != null) + m_parameterTypeNames = parameterTypeNames; m_isStatic = isStatic; } - - @Override - public NameHierarchy toNameHierarchy() + + @Override public NameHierarchy toNameHierarchy() { String prefix = ""; if (m_isStatic) @@ -40,23 +47,23 @@ public class FunctionDeclName extends DeclName { prefix += m_returnTypeName.toString(); } - + String postfix = getParameterString(); - + NameHierarchy nameHierarchy = super.toNameHierarchy(); - + Optional nameElement = nameHierarchy.peek(); if (nameElement.isPresent()) { String name = nameElement.get().getName(); - + nameHierarchy.pop(); nameHierarchy.push(new NameElement(name, prefix, postfix)); } - + return nameHierarchy; } - + private String getParameterString() { String string = "("; diff --git a/java_indexer/src/main/java/com/sourcetrail/name/NameElement.java b/java_indexer/src/main/java/com/sourcetrail/name/NameElement.java index 19d6d7e6..54c1d928 100644 --- a/java_indexer/src/main/java/com/sourcetrail/name/NameElement.java +++ b/java_indexer/src/main/java/com/sourcetrail/name/NameElement.java @@ -1,33 +1,37 @@ package com.sourcetrail.name; -public class NameElement +public class NameElement { private String m_name = ""; private String m_prefix = ""; private String m_postfix = ""; - - + + public NameElement(String name) { - if (name != null) m_name = name; + if (name != null) + m_name = name; } - + public NameElement(String name, String prefix, String postfix) { - if (name != null) m_name = name; - if (prefix != null) m_prefix = prefix; - if (postfix != null) m_postfix = postfix; + if (name != null) + m_name = name; + if (prefix != null) + m_prefix = prefix; + if (postfix != null) + m_postfix = postfix; } - + String getName() { return m_name; } - + String getNameWithSignature() { String nameWithSignature = m_name; - + if (m_prefix.length() > 0 || m_postfix.length() > 0) { nameWithSignature = m_prefix; @@ -41,10 +45,10 @@ public class NameElement } nameWithSignature += m_postfix; } - + return nameWithSignature; } - + String serialize() { return m_name + "\ts" + m_prefix + "\tp" + m_postfix; diff --git a/java_indexer/src/main/java/com/sourcetrail/name/NameHierarchy.java b/java_indexer/src/main/java/com/sourcetrail/name/NameHierarchy.java index 9ed20b04..54693f45 100644 --- a/java_indexer/src/main/java/com/sourcetrail/name/NameHierarchy.java +++ b/java_indexer/src/main/java/com/sourcetrail/name/NameHierarchy.java @@ -4,40 +4,38 @@ import java.util.ArrayList; import java.util.List; import java.util.Optional; -public class NameHierarchy +public class NameHierarchy { private List m_elements = new ArrayList<>(); private char m_separatpr = '.'; - - public NameHierarchy() - { - } - + + public NameHierarchy() {} + public NameHierarchy(String name) { m_elements.add(new NameElement(name)); } - + public NameHierarchy(NameElement name) { m_elements.add(name); } - + public NameHierarchy(List names) { m_elements.addAll(names); } - + public void setSeparator(char separator) { m_separatpr = separator; } - + public void push(NameElement element) { m_elements.add(element); } - + public void pop() { if (!m_elements.isEmpty()) @@ -45,7 +43,7 @@ public class NameHierarchy m_elements.remove(m_elements.size() - 1); } } - + public Optional peek() { if (!m_elements.isEmpty()) @@ -54,22 +52,21 @@ public class NameHierarchy } return Optional.empty(); } - + public String serialize() { String serialized = m_separatpr + "\tm"; - + for (int i = 0; i < m_elements.size(); i++) { if (i != 0) { serialized += "\tn"; } - + serialized += m_elements.get(i).serialize(); } return serialized; } - } diff --git a/java_indexer/src/main/java/com/sourcetrail/name/SymbolName.java b/java_indexer/src/main/java/com/sourcetrail/name/SymbolName.java index 22399f4d..6e61b34e 100644 --- a/java_indexer/src/main/java/com/sourcetrail/name/SymbolName.java +++ b/java_indexer/src/main/java/com/sourcetrail/name/SymbolName.java @@ -1,6 +1,5 @@ package com.sourcetrail.name; -public interface SymbolName -{ +public interface SymbolName { public NameHierarchy toNameHierarchy(); } diff --git a/java_indexer/src/main/java/com/sourcetrail/name/TypeName.java b/java_indexer/src/main/java/com/sourcetrail/name/TypeName.java index 74c9cf52..ccab3e92 100644 --- a/java_indexer/src/main/java/com/sourcetrail/name/TypeName.java +++ b/java_indexer/src/main/java/com/sourcetrail/name/TypeName.java @@ -16,64 +16,67 @@ public class TypeName implements SymbolName typeName.m_isUnsolved = true; return typeName; } - - public static TypeName fromDotSeparatedString(String s) + + public static TypeName fromDotSeparatedString(String s) { TypeName typeName = null; int separatorIndex = s.lastIndexOf('.'); if (separatorIndex != -1) { - typeName = new TypeName(s.substring(separatorIndex + 1), DeclName.fromDotSeparatedString(s.substring(0, separatorIndex))); + typeName = new TypeName( + s.substring(separatorIndex + 1), + DeclName.fromDotSeparatedString(s.substring(0, separatorIndex))); } else { typeName = new TypeName(s, null); } - + return typeName; } - + public TypeName(String name, DeclName parent) { m_parent = parent; m_name = name; } - - public TypeName(String name, List typeParameterNames, List typeArguments, DeclName parent) + + public TypeName( + String name, List typeParameterNames, List typeArguments, DeclName parent) { m_parent = parent; m_name = name; m_typeParameterNames = typeParameterNames; m_typeArguments = typeArguments; } - + public DeclName getParent() { return m_parent; } - + public String getName() { return m_name; } - + public boolean getIsUnsolved() { return m_isUnsolved; } - + public DeclName toDeclName() { DeclName declName = new DeclName(m_name, m_typeParameterNames); declName.setParent(m_parent); return declName; } - + public NameHierarchy toNameHierarchy() { NameHierarchy nameHierarchy; - + if (m_parent != null) { nameHierarchy = m_parent.toNameHierarchy(); @@ -82,12 +85,12 @@ public class TypeName implements SymbolName { nameHierarchy = new NameHierarchy(); } - + nameHierarchy.push(new NameElement(m_name + getTypeArgumentString())); - + return nameHierarchy; } - + public String toString() { String string = ""; @@ -96,13 +99,13 @@ public class TypeName implements SymbolName string = m_parent.toString(); string += "."; } - + string += m_name; string += getTypeArgumentString(); - + return string; } - + private String getTypeArgumentString() { String string = ""; diff --git a/java_indexer/src/main/java/com/sourcetrail/name/VariableDeclName.java b/java_indexer/src/main/java/com/sourcetrail/name/VariableDeclName.java index 655bfeb3..e894c787 100644 --- a/java_indexer/src/main/java/com/sourcetrail/name/VariableDeclName.java +++ b/java_indexer/src/main/java/com/sourcetrail/name/VariableDeclName.java @@ -6,17 +6,16 @@ public class VariableDeclName extends DeclName { private TypeName m_typeName = null; private boolean m_isStatic = false; - + public VariableDeclName(String name, TypeName typeName, boolean isStatic) { super(name); - + m_typeName = typeName; m_isStatic = isStatic; } - - @Override - public NameHierarchy toNameHierarchy() + + @Override public NameHierarchy toNameHierarchy() { String prefix = ""; if (m_isStatic) @@ -27,13 +26,13 @@ public class VariableDeclName extends DeclName { prefix += m_typeName.toString(); } - + NameHierarchy nameHierarchy = super.toNameHierarchy(); Optional nameElement = nameHierarchy.peek(); if (nameElement.isPresent()) { String name = nameElement.get().getName(); - + nameHierarchy.pop(); nameHierarchy.push(new NameElement(name, prefix, "")); } diff --git a/java_indexer/src/main/java/com/sourcetrail/name/resolver/BindingNameResolver.java b/java_indexer/src/main/java/com/sourcetrail/name/resolver/BindingNameResolver.java index 312fe662..5fe2195d 100644 --- a/java_indexer/src/main/java/com/sourcetrail/name/resolver/BindingNameResolver.java +++ b/java_indexer/src/main/java/com/sourcetrail/name/resolver/BindingNameResolver.java @@ -1,10 +1,14 @@ package com.sourcetrail.name.resolver; +import com.sourcetrail.ContextList; +import com.sourcetrail.name.DeclName; +import com.sourcetrail.name.FunctionDeclName; +import com.sourcetrail.name.TypeName; +import com.sourcetrail.name.VariableDeclName; import java.io.File; import java.util.ArrayList; import java.util.List; import java.util.Optional; - import org.eclipse.jdt.core.dom.ASTNode; import org.eclipse.jdt.core.dom.AnonymousClassDeclaration; import org.eclipse.jdt.core.dom.CompilationUnit; @@ -15,38 +19,32 @@ import org.eclipse.jdt.core.dom.ITypeBinding; import org.eclipse.jdt.core.dom.IVariableBinding; import org.eclipse.jdt.core.dom.Modifier; -import com.sourcetrail.ContextList; -import com.sourcetrail.name.DeclName; -import com.sourcetrail.name.FunctionDeclName; -import com.sourcetrail.name.TypeName; -import com.sourcetrail.name.VariableDeclName; - public class BindingNameResolver extends NameResolver { public static IBinding getParentBinding(IBinding binding) { if (binding instanceof ITypeBinding) { - return getParentBinding((ITypeBinding) binding); + return getParentBinding((ITypeBinding)binding); } if (binding instanceof IMethodBinding) { - return ((IMethodBinding) binding).getDeclaringClass(); + return ((IMethodBinding)binding).getDeclaringClass(); } if (binding instanceof IVariableBinding) { - return ((IVariableBinding) binding).getDeclaringClass(); + return ((IVariableBinding)binding).getDeclaringClass(); } return null; } - + public static IBinding getParentBinding(ITypeBinding binding) { if (binding.isLocal() || binding.isAnonymous()) { if (binding.getDeclaringMember() instanceof IVariableBinding) { - IVariableBinding variableBinding = (IVariableBinding) binding.getDeclaringMember(); + IVariableBinding variableBinding = (IVariableBinding)binding.getDeclaringMember(); if (variableBinding.getDeclaringClass() != null) { return variableBinding.getDeclaringClass(); @@ -60,7 +58,7 @@ public class BindingNameResolver extends NameResolver { return binding.getDeclaringMethod(); } - } + } else if (binding.isMember()) { return binding.getDeclaringClass(); @@ -80,33 +78,40 @@ public class BindingNameResolver extends NameResolver { return binding.getPackage(); } - - return null; // we don't have a parent (like void doesn't have a parent) + + return null; // we don't have a parent (like void doesn't have a parent) } - - public BindingNameResolver(File currentFile, CompilationUnit compilationUnit, ContextList ignoredContexts) + + public BindingNameResolver( + File currentFile, CompilationUnit compilationUnit, ContextList ignoredContexts) { super(currentFile, compilationUnit, ignoredContexts); } - - public static Optional getQualifiedName(ITypeBinding binding, File currentFile, CompilationUnit compilationUnit) + + public static Optional getQualifiedName( + ITypeBinding binding, File currentFile, CompilationUnit compilationUnit) { return getQualifiedName(binding, currentFile, compilationUnit, null); } - - public static Optional getQualifiedName(ITypeBinding binding, File currentFile, CompilationUnit compilationUnit, ContextList ignoredContexts) + + public static Optional getQualifiedName( + ITypeBinding binding, + File currentFile, + CompilationUnit compilationUnit, + ContextList ignoredContexts) { - BindingNameResolver resolver = new BindingNameResolver(currentFile, compilationUnit, ignoredContexts); + BindingNameResolver resolver = new BindingNameResolver( + currentFile, compilationUnit, ignoredContexts); return resolver.getQualifiedName(binding); } - + public Optional getQualifiedName(ITypeBinding binding) { if (binding == null) { return Optional.empty(); } - + if (binding.isArray()) { return getQualifiedName(binding.getElementType()); @@ -116,15 +121,20 @@ public class BindingNameResolver extends NameResolver ASTNode node = m_compilationUnit.findDeclaringNode(binding); if (node instanceof AnonymousClassDeclaration) { - DeclName decl = DeclNameResolver.getQualifiedDeclName((AnonymousClassDeclaration) node, m_currentFile, m_compilationUnit, m_ignoredContexts); - return Optional.of(new TypeName(decl.getName(), decl.getTypeParameterNames(), null, decl.getParent())); + DeclName decl = DeclNameResolver.getQualifiedDeclName( + (AnonymousClassDeclaration)node, + m_currentFile, + m_compilationUnit, + m_ignoredContexts); + return Optional.of(new TypeName( + decl.getName(), decl.getTypeParameterNames(), null, decl.getParent())); } else { return Optional.empty(); } } - + if (binding.isParameterizedType()) { List typeArguments = new ArrayList<>(); @@ -136,19 +146,23 @@ public class BindingNameResolver extends NameResolver typeArguments.add(typeArgument.get()); } } - + Optional typeName = getQualifiedName(binding.getTypeDeclaration()); if (typeName.isPresent()) { DeclName declName = typeName.get().toDeclName(); - return Optional.of(new TypeName(declName.getName(), declName.getTypeParameterNames(), typeArguments, declName.getParent())); + return Optional.of(new TypeName( + declName.getName(), + declName.getTypeParameterNames(), + typeArguments, + declName.getParent())); } else { return Optional.empty(); } } - + String name = binding.getName(); List typeParameterNames = null; if (binding.isGenericType()) @@ -158,38 +172,44 @@ public class BindingNameResolver extends NameResolver { typeParameterNames.add(typeParameter.getName()); } - } - + } + DeclName parentDeclName = getQualifiedContextName(binding); if (parentDeclName != null && parentDeclName.getIsUnsolved()) { return Optional.empty(); } - + // type arguments will be set in caller (which is this same method) return Optional.of(new TypeName(name, typeParameterNames, null, parentDeclName)); } - - public static Optional getQualifiedName(IMethodBinding binding, File currentFile, CompilationUnit compilationUnit) + + public static Optional getQualifiedName( + IMethodBinding binding, File currentFile, CompilationUnit compilationUnit) { return getQualifiedName(binding, currentFile, compilationUnit, null); } - - public static Optional getQualifiedName(IMethodBinding binding, File currentFile, CompilationUnit compilationUnit, ContextList ignoredContexts) + + public static Optional getQualifiedName( + IMethodBinding binding, + File currentFile, + CompilationUnit compilationUnit, + ContextList ignoredContexts) { - BindingNameResolver resolver = new BindingNameResolver(currentFile, compilationUnit, ignoredContexts); + BindingNameResolver resolver = new BindingNameResolver( + currentFile, compilationUnit, ignoredContexts); return resolver.getQualifiedName(binding); } - + public Optional getQualifiedName(IMethodBinding binding) { if (binding == null) { return Optional.empty(); } - + String name = binding.getName(); - + List typeParameterNames = null; if (binding.isGenericMethod()) { @@ -199,32 +219,40 @@ public class BindingNameResolver extends NameResolver typeParameterNames.add(typeParameter.getName()); } } - + DeclName declName = null; { boolean isStatic = Modifier.isStatic(binding.getModifiers()); ContextList ignoredContexts = m_ignoredContexts.copy(); ignoredContexts.add(binding); - - TypeName returnTypeName = binding.isConstructor() ? null : getQualifiedName(binding.getReturnType(), m_currentFile, m_compilationUnit, ignoredContexts).orElse(TypeName.unsolved()); - + + TypeName returnTypeName = binding.isConstructor() + ? null + : getQualifiedName( + binding.getReturnType(), m_currentFile, m_compilationUnit, ignoredContexts) + .orElse(TypeName.unsolved()); + if (binding.isAnnotationMember()) { declName = new VariableDeclName(name, returnTypeName, isStatic); } else { - List parameterTypeNames = new ArrayList<>(); + List parameterTypeNames = new ArrayList<>(); for (ITypeBinding parameterType: binding.getParameterTypes()) { - parameterTypeNames.add(getQualifiedName(parameterType, m_currentFile, m_compilationUnit, ignoredContexts).orElse(TypeName.unsolved())); + parameterTypeNames.add( + getQualifiedName( + parameterType, m_currentFile, m_compilationUnit, ignoredContexts) + .orElse(TypeName.unsolved())); } - - declName = new FunctionDeclName(name, typeParameterNames, returnTypeName, parameterTypeNames, isStatic); + + declName = new FunctionDeclName( + name, typeParameterNames, returnTypeName, parameterTypeNames, isStatic); } } - + DeclName parentDeclName = getQualifiedContextName(binding); if (parentDeclName != null) { @@ -238,47 +266,59 @@ public class BindingNameResolver extends NameResolver } } - return Optional.of(declName); + return Optional.of(declName); } - - public static Optional getQualifiedName(IPackageBinding binding, File currentFile, CompilationUnit compilationUnit) + + public static Optional getQualifiedName( + IPackageBinding binding, File currentFile, CompilationUnit compilationUnit) { return getQualifiedName(binding, currentFile, compilationUnit, null); } - - public static Optional getQualifiedName(IPackageBinding binding, File currentFile, CompilationUnit compilationUnit, ContextList ignoredContexts) + + public static Optional getQualifiedName( + IPackageBinding binding, + File currentFile, + CompilationUnit compilationUnit, + ContextList ignoredContexts) { - BindingNameResolver resolver = new BindingNameResolver(currentFile, compilationUnit, ignoredContexts); + BindingNameResolver resolver = new BindingNameResolver( + currentFile, compilationUnit, ignoredContexts); return resolver.getQualifiedName(binding); } - + public Optional getQualifiedName(IPackageBinding binding) { if (!binding.isUnnamed()) { return Optional.of(DeclName.fromDotSeparatedString(binding.getName())); } - return Optional.empty(); + return Optional.empty(); } - - public static DeclName getQualifiedName(IVariableBinding binding, File currentFile, CompilationUnit compilationUnit) + + public static DeclName getQualifiedName( + IVariableBinding binding, File currentFile, CompilationUnit compilationUnit) { return getQualifiedName(binding, currentFile, compilationUnit, null); } - - public static DeclName getQualifiedName(IVariableBinding binding, File currentFile, CompilationUnit compilationUnit, ContextList ignoredContexts) + + public static DeclName getQualifiedName( + IVariableBinding binding, + File currentFile, + CompilationUnit compilationUnit, + ContextList ignoredContexts) { - BindingNameResolver resolver = new BindingNameResolver(currentFile, compilationUnit, ignoredContexts); + BindingNameResolver resolver = new BindingNameResolver( + currentFile, compilationUnit, ignoredContexts); return resolver.getQualifiedName(binding); } - + public DeclName getQualifiedName(IVariableBinding binding) { if (binding == null) { return DeclName.unsolved(); } - + if (binding.isField() || binding.isEnumConstant()) { DeclName declName; @@ -289,9 +329,10 @@ public class BindingNameResolver extends NameResolver else { TypeName typeName = getQualifiedName(binding.getType()).orElse(TypeName.unsolved()); - declName = new VariableDeclName(binding.getName(), typeName, Modifier.isStatic(binding.getModifiers())); + declName = new VariableDeclName( + binding.getName(), typeName, Modifier.isStatic(binding.getModifiers())); } - + DeclName parentDeclName = getQualifiedContextName(binding); if (parentDeclName != null) { @@ -304,14 +345,16 @@ public class BindingNameResolver extends NameResolver declName = DeclName.unsolved(); } } - + return declName; } else { if (binding.getDeclaringMethod() != null) { - return DeclName.localSymbol(getQualifiedName(binding.getDeclaringMethod()).orElse(DeclName.unsolved()), binding.getVariableId()); + return DeclName.localSymbol( + getQualifiedName(binding.getDeclaringMethod()).orElse(DeclName.unsolved()), + binding.getVariableId()); } else { @@ -319,33 +362,35 @@ public class BindingNameResolver extends NameResolver } } } - + private DeclName getQualifiedContextName(IBinding binding) { IBinding parentBinding = getParentBinding(binding); - + if (parentBinding == null || m_ignoredContexts.contains(parentBinding)) { return null; } - + if (parentBinding instanceof ITypeBinding) { - return getQualifiedName((ITypeBinding) parentBinding).map(tn ->tn.toDeclName()).orElse(DeclName.unsolved()); + return getQualifiedName((ITypeBinding)parentBinding) + .map(tn -> tn.toDeclName()) + .orElse(DeclName.unsolved()); } else if (parentBinding instanceof IMethodBinding) { - return getQualifiedName((IMethodBinding) parentBinding).orElse(DeclName.unsolved()); + return getQualifiedName((IMethodBinding)parentBinding).orElse(DeclName.unsolved()); } else if (parentBinding instanceof IVariableBinding) { - return getQualifiedName((IVariableBinding) parentBinding); + return getQualifiedName((IVariableBinding)parentBinding); } else if (parentBinding instanceof IPackageBinding) { - return getQualifiedName((IPackageBinding) parentBinding).orElse(null); + return getQualifiedName((IPackageBinding)parentBinding).orElse(null); } - + return null; } } diff --git a/java_indexer/src/main/java/com/sourcetrail/name/resolver/DeclNameResolver.java b/java_indexer/src/main/java/com/sourcetrail/name/resolver/DeclNameResolver.java index 360754ba..cbfefef8 100644 --- a/java_indexer/src/main/java/com/sourcetrail/name/resolver/DeclNameResolver.java +++ b/java_indexer/src/main/java/com/sourcetrail/name/resolver/DeclNameResolver.java @@ -1,10 +1,16 @@ package com.sourcetrail.name.resolver; +import com.sourcetrail.ContextList; +import com.sourcetrail.Position; +import com.sourcetrail.Utility; +import com.sourcetrail.name.DeclName; +import com.sourcetrail.name.FunctionDeclName; +import com.sourcetrail.name.TypeName; +import com.sourcetrail.name.VariableDeclName; import java.io.File; import java.util.ArrayList; import java.util.List; import java.util.Optional; - import org.eclipse.jdt.core.dom.ASTNode; import org.eclipse.jdt.core.dom.AnnotationTypeDeclaration; import org.eclipse.jdt.core.dom.AnnotationTypeMemberDeclaration; @@ -27,32 +33,30 @@ import org.eclipse.jdt.core.dom.TypeDeclaration; import org.eclipse.jdt.core.dom.TypeParameter; import org.eclipse.jdt.core.dom.VariableDeclarationFragment; -import com.sourcetrail.ContextList; -import com.sourcetrail.Position; -import com.sourcetrail.Utility; -import com.sourcetrail.name.DeclName; -import com.sourcetrail.name.FunctionDeclName; -import com.sourcetrail.name.TypeName; -import com.sourcetrail.name.VariableDeclName; - public class DeclNameResolver extends NameResolver -{ - public DeclNameResolver(File currentFile, CompilationUnit compilationUnit, ContextList ignoredContexts) +{ + public DeclNameResolver(File currentFile, CompilationUnit compilationUnit, ContextList ignoredContexts) { super(currentFile, compilationUnit, ignoredContexts); } - public static DeclName getQualifiedDeclName(VariableDeclarationFragment decl, File currentFile, CompilationUnit compilationUnit) + public static DeclName getQualifiedDeclName( + VariableDeclarationFragment decl, File currentFile, CompilationUnit compilationUnit) { return getQualifiedDeclName(decl, currentFile, compilationUnit, null); } - - public static DeclName getQualifiedDeclName(VariableDeclarationFragment decl, File currentFile, CompilationUnit compilationUnit, ContextList ignoredContexts) + + public static DeclName getQualifiedDeclName( + VariableDeclarationFragment decl, + File currentFile, + CompilationUnit compilationUnit, + ContextList ignoredContexts) { - DeclNameResolver resolver = new DeclNameResolver(currentFile, compilationUnit, ignoredContexts); + DeclNameResolver resolver = new DeclNameResolver( + currentFile, compilationUnit, ignoredContexts); return resolver.getQualifiedDeclName(decl); } - + public DeclName getQualifiedDeclName(VariableDeclarationFragment decl) { DeclName declName = DeclName.unsolved(); @@ -78,11 +82,11 @@ public class DeclNameResolver extends NameResolver } return declName; } - + public DeclName getDeclName(VariableDeclarationFragment decl) { TypeName typeName = TypeName.unsolved(); - + boolean isStatic = false; Optional fieldDeclaration = getAncestorOfType(decl, FieldDeclaration.class); if (fieldDeclaration.isPresent()) @@ -95,31 +99,39 @@ public class DeclNameResolver extends NameResolver { isStatic = Modifier.isStatic(fieldDeclaration.get().getModifiers()); } - typeName = BindingNameResolver.getQualifiedName( - fieldDeclaration.get().getType().resolveBinding(), - m_currentFile, - m_compilationUnit, - m_ignoredContexts.copy()).orElse(TypeName.unsolved()); + typeName = BindingNameResolver + .getQualifiedName( + fieldDeclaration.get().getType().resolveBinding(), + m_currentFile, + m_compilationUnit, + m_ignoredContexts.copy()) + .orElse(TypeName.unsolved()); } - + return new VariableDeclName(decl.getName().getIdentifier(), typeName, isStatic); } - - public static DeclName getQualifiedDeclName(BodyDeclaration decl, File currentFile, CompilationUnit compilationUnit) + + public static DeclName getQualifiedDeclName( + BodyDeclaration decl, File currentFile, CompilationUnit compilationUnit) { return getQualifiedDeclName(decl, currentFile, compilationUnit, null); } - - public static DeclName getQualifiedDeclName(BodyDeclaration decl, File currentFile, CompilationUnit compilationUnit, ContextList ignoredContexts) + + public static DeclName getQualifiedDeclName( + BodyDeclaration decl, + File currentFile, + CompilationUnit compilationUnit, + ContextList ignoredContexts) { - DeclNameResolver resolver = new DeclNameResolver(currentFile, compilationUnit, ignoredContexts); + DeclNameResolver resolver = new DeclNameResolver( + currentFile, compilationUnit, ignoredContexts); return resolver.getQualifiedDeclName(decl); } - + public DeclName getQualifiedDeclName(BodyDeclaration decl) { DeclName declName = DeclName.unsolved(); - + if (decl != null) { declName = getDeclName(decl); @@ -139,46 +151,49 @@ public class DeclNameResolver extends NameResolver } } } - + return declName; - } - + } + public DeclName getDeclName(BodyDeclaration decl) { DeclName declName = DeclName.unsolved(); - + if (decl != null) { if (decl instanceof AnnotationTypeDeclaration) { - declName = new DeclName(((AnnotationTypeDeclaration) decl).getName().getIdentifier()); + declName = new DeclName(((AnnotationTypeDeclaration)decl).getName().getIdentifier()); } else if (decl instanceof EnumDeclaration) { - declName = new DeclName(((EnumDeclaration) decl).getName().getIdentifier()); + declName = new DeclName(((EnumDeclaration)decl).getName().getIdentifier()); } else if (decl instanceof TypeDeclaration) { - TypeDeclaration typeDeclaration = (TypeDeclaration) decl; + TypeDeclaration typeDeclaration = (TypeDeclaration)decl; List typeParameterNames = new ArrayList<>(); for (Object typeParameter: typeDeclaration.typeParameters()) { if (typeParameter instanceof TypeParameter) { - typeParameterNames.add(((TypeParameter) typeParameter).getName().getIdentifier()); + typeParameterNames.add( + ((TypeParameter)typeParameter).getName().getIdentifier()); } } - - declName = new DeclName(typeDeclaration.getName().getIdentifier(), typeParameterNames); + + declName = new DeclName( + typeDeclaration.getName().getIdentifier(), typeParameterNames); } else if (decl instanceof AnnotationTypeMemberDeclaration) { - declName = new DeclName(((AnnotationTypeMemberDeclaration) decl).getName().getIdentifier()); + declName = new DeclName( + ((AnnotationTypeMemberDeclaration)decl).getName().getIdentifier()); } else if (decl instanceof EnumConstantDeclaration) { - declName = new DeclName(((EnumConstantDeclaration) decl).getName().getIdentifier()); + declName = new DeclName(((EnumConstantDeclaration)decl).getName().getIdentifier()); } else if (decl instanceof FieldDeclaration) { @@ -190,56 +205,76 @@ public class DeclNameResolver extends NameResolver } else if (decl instanceof MethodDeclaration) { - MethodDeclaration methodDeclaration = (MethodDeclaration) decl; - + MethodDeclaration methodDeclaration = (MethodDeclaration)decl; + List typeParameterNames = new ArrayList<>(); for (Object typeParameter: methodDeclaration.typeParameters()) { if (typeParameter instanceof TypeParameter) { - typeParameterNames.add(((TypeParameter) typeParameter).getName().getIdentifier()); + typeParameterNames.add( + ((TypeParameter)typeParameter).getName().getIdentifier()); } } - + ContextList ignoredContexts = m_ignoredContexts.copy(); - ignoredContexts.add(((MethodDeclaration) decl).resolveBinding()); - - TypeName returnTypeName = methodDeclaration.isConstructor() ? null : BindingNameResolver.getQualifiedName( - methodDeclaration.getReturnType2().resolveBinding(), m_currentFile, m_compilationUnit, ignoredContexts).orElse(TypeName.unsolved()); - - List parameterTypeNames = new ArrayList<>(); + ignoredContexts.add(((MethodDeclaration)decl).resolveBinding()); + + TypeName returnTypeName = methodDeclaration.isConstructor() + ? null + : BindingNameResolver + .getQualifiedName( + methodDeclaration.getReturnType2().resolveBinding(), + m_currentFile, + m_compilationUnit, + ignoredContexts) + .orElse(TypeName.unsolved()); + + List parameterTypeNames = new ArrayList<>(); for (Object parameter: methodDeclaration.parameters()) { if (parameter instanceof SingleVariableDeclaration) { - parameterTypeNames.add(BindingNameResolver.getQualifiedName( - ((SingleVariableDeclaration) parameter).getType().resolveBinding(), m_currentFile, m_compilationUnit, ignoredContexts).orElse(TypeName.unsolved())); + parameterTypeNames.add( + BindingNameResolver + .getQualifiedName( + ((SingleVariableDeclaration)parameter).getType().resolveBinding(), + m_currentFile, + m_compilationUnit, + ignoredContexts) + .orElse(TypeName.unsolved())); } } - + declName = new FunctionDeclName( - methodDeclaration.getName().getIdentifier(), - typeParameterNames, - returnTypeName, - parameterTypeNames, - Modifier.isStatic(methodDeclaration.getModifiers())); + methodDeclaration.getName().getIdentifier(), + typeParameterNames, + returnTypeName, + parameterTypeNames, + Modifier.isStatic(methodDeclaration.getModifiers())); } } - + return declName; } - - public static DeclName getQualifiedDeclName(AnonymousClassDeclaration decl, File currentFile, CompilationUnit compilationUnit) + + public static DeclName getQualifiedDeclName( + AnonymousClassDeclaration decl, File currentFile, CompilationUnit compilationUnit) { return getQualifiedDeclName(decl, currentFile, compilationUnit, null); } - - public static DeclName getQualifiedDeclName(AnonymousClassDeclaration decl, File currentFile, CompilationUnit compilationUnit, ContextList ignoredContexts) + + public static DeclName getQualifiedDeclName( + AnonymousClassDeclaration decl, + File currentFile, + CompilationUnit compilationUnit, + ContextList ignoredContexts) { - DeclNameResolver resolver = new DeclNameResolver(currentFile, compilationUnit, ignoredContexts); + DeclNameResolver resolver = new DeclNameResolver( + currentFile, compilationUnit, ignoredContexts); return resolver.getQualifiedDeclName(decl); } - + public DeclName getQualifiedDeclName(AnonymousClassDeclaration decl) { DeclName declName = DeclName.unsolved(); @@ -265,28 +300,28 @@ public class DeclNameResolver extends NameResolver } return declName; } - + public DeclName getDeclName(AnonymousClassDeclaration decl) { Position pos = Utility.getRange(decl, m_compilationUnit).begin; return DeclName.anonymousClass(m_currentFile, pos.line, pos.column); } - - + + public static DeclName getQualifiedName(Name name) { if (name.isSimpleName()) { - return new DeclName(((SimpleName) name).getIdentifier()); + return new DeclName(((SimpleName)name).getIdentifier()); } else { - DeclName declName = new DeclName(((QualifiedName) name).getName().getIdentifier()); - declName.setParent(getQualifiedName(((QualifiedName) name).getQualifier())); + DeclName declName = new DeclName(((QualifiedName)name).getName().getIdentifier()); + declName.setParent(getQualifiedName(((QualifiedName)name).getQualifier())); return declName; } } - + private DeclName getQualifiedContextName(ASTNode decl) { ASTNode parentNode = decl.getParent(); @@ -294,25 +329,25 @@ public class DeclNameResolver extends NameResolver { return null; } - + if (parentNode instanceof BodyDeclaration && !(parentNode instanceof FieldDeclaration)) { - return getQualifiedDeclName((BodyDeclaration) parentNode); + return getQualifiedDeclName((BodyDeclaration)parentNode); } else if (parentNode instanceof AnonymousClassDeclaration) { - return getQualifiedDeclName((AnonymousClassDeclaration) parentNode); + return getQualifiedDeclName((AnonymousClassDeclaration)parentNode); } else if (parentNode instanceof CompilationUnit) { - PackageDeclaration packageDecl = ((CompilationUnit) parentNode).getPackage(); + PackageDeclaration packageDecl = ((CompilationUnit)parentNode).getPackage(); if (packageDecl != null) { return getQualifiedName(packageDecl.getName()); } return null; } - + return getQualifiedContextName(parentNode); } } diff --git a/java_indexer/src/main/java/com/sourcetrail/name/resolver/NameResolver.java b/java_indexer/src/main/java/com/sourcetrail/name/resolver/NameResolver.java index c15a00b9..1b6ef468 100644 --- a/java_indexer/src/main/java/com/sourcetrail/name/resolver/NameResolver.java +++ b/java_indexer/src/main/java/com/sourcetrail/name/resolver/NameResolver.java @@ -1,23 +1,21 @@ package com.sourcetrail.name.resolver; +import com.sourcetrail.ContextList; import java.io.File; import java.util.Optional; - import org.eclipse.jdt.core.dom.ASTNode; import org.eclipse.jdt.core.dom.CompilationUnit; -import com.sourcetrail.ContextList; - -public abstract class NameResolver +public abstract class NameResolver { protected File m_currentFile = null; protected ContextList m_ignoredContexts = null; protected CompilationUnit m_compilationUnit = null; - - static protected Optional getAncestorOfType(ASTNode node, Class classType) + + static protected Optional getAncestorOfType(ASTNode node, Class classType) { ASTNode parent = node.getParent(); - while (parent != null) + while (parent != null) { if (classType.isAssignableFrom(parent.getClass())) { @@ -27,12 +25,12 @@ public abstract class NameResolver } return Optional.empty(); } - + public NameResolver(File currentFile, CompilationUnit compilationUnit, ContextList ignoredContexts) { m_currentFile = currentFile; m_compilationUnit = compilationUnit; - + if (ignoredContexts != null) { m_ignoredContexts = ignoredContexts; @@ -41,5 +39,5 @@ public abstract class NameResolver { m_ignoredContexts = new ContextList(); } - } + } } diff --git a/src/app/main.cpp b/src/app/main.cpp index 00c28b34..9705bcdc 100644 --- a/src/app/main.cpp +++ b/src/app/main.cpp @@ -12,39 +12,39 @@ #include "ConsoleLogger.h" #include "FileLogger.h" #include "LanguagePackageManager.h" -#include "logging.h" #include "LogManager.h" #include "MessageIndexingInterrupted.h" #include "MessageLoadProject.h" #include "MessageStatus.h" -#include "productVersion.h" -#include "QtNetworkFactory.h" #include "QtApplication.h" #include "QtCoreApplication.h" +#include "QtNetworkFactory.h" #include "QtViewFactory.h" #include "ResourcePaths.h" #include "ScopedFunctor.h" #include "SourceGroupFactory.h" #include "SourceGroupFactoryModuleCustom.h" #include "UserPaths.h" +#include "Version.h" +#include "logging.h" +#include "productVersion.h" #include "utility.h" #include "utilityApp.h" #include "utilityQt.h" -#include "Version.h" #if BUILD_CXX_LANGUAGE_PACKAGE -#include "LanguagePackageCxx.h" -#include "SourceGroupFactoryModuleCxx.h" -#endif // BUILD_CXX_LANGUAGE_PACKAGE +# include "LanguagePackageCxx.h" +# include "SourceGroupFactoryModuleCxx.h" +#endif // BUILD_CXX_LANGUAGE_PACKAGE #if BUILD_JAVA_LANGUAGE_PACKAGE -#include "LanguagePackageJava.h" -#include "SourceGroupFactoryModuleJava.h" -#endif // BUILD_JAVA_LANGUAGE_PACKAGE +# include "LanguagePackageJava.h" +# include "SourceGroupFactoryModuleJava.h" +#endif // BUILD_JAVA_LANGUAGE_PACKAGE #if BUILD_PYTHON_LANGUAGE_PACKAGE -#include "SourceGroupFactoryModulePython.h" -#endif // BUILD_PYTHON_LANGUAGE_PACKAGE +# include "SourceGroupFactoryModulePython.h" +#endif // BUILD_PYTHON_LANGUAGE_PACKAGE void signalHandler(int signum) { @@ -72,26 +72,26 @@ void addLanguagePackages() #if BUILD_CXX_LANGUAGE_PACKAGE SourceGroupFactory::getInstance()->addModule(std::make_shared()); -#endif // BUILD_CXX_LANGUAGE_PACKAGE +#endif // BUILD_CXX_LANGUAGE_PACKAGE #if BUILD_JAVA_LANGUAGE_PACKAGE SourceGroupFactory::getInstance()->addModule(std::make_shared()); -#endif // BUILD_JAVA_LANGUAGE_PACKAGE +#endif // BUILD_JAVA_LANGUAGE_PACKAGE #if BUILD_PYTHON_LANGUAGE_PACKAGE SourceGroupFactory::getInstance()->addModule(std::make_shared()); -#endif // BUILD_PYTHON_LANGUAGE_PACKAGE +#endif // BUILD_PYTHON_LANGUAGE_PACKAGE #if BUILD_CXX_LANGUAGE_PACKAGE LanguagePackageManager::getInstance()->addPackage(std::make_shared()); -#endif // BUILD_CXX_LANGUAGE_PACKAGE +#endif // BUILD_CXX_LANGUAGE_PACKAGE #if BUILD_JAVA_LANGUAGE_PACKAGE LanguagePackageManager::getInstance()->addPackage(std::make_shared()); -#endif // BUILD_JAVA_LANGUAGE_PACKAGE +#endif // BUILD_JAVA_LANGUAGE_PACKAGE } -int main(int argc, char *argv[]) +int main(int argc, char* argv[]) { QCoreApplication::addLibraryPath(QStringLiteral(".")); @@ -111,19 +111,14 @@ int main(int argc, char *argv[]) QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling, true); } - Version version( - VERSION_YEAR, - VERSION_MINOR, - VERSION_COMMIT, - GIT_COMMIT_HASH - ); + Version version(VERSION_YEAR, VERSION_MINOR, VERSION_COMMIT, GIT_COMMIT_HASH); QApplication::setApplicationVersion(version.toDisplayString().c_str()); MessageStatus( std::wstring(L"Starting Sourcetrail ") + - (utility::getApplicationArchitectureType() == APPLICATION_ARCHITECTURE_X86_32 ? L"32" : L"64") + L" bit, " + - L"version " + version.toDisplayWString() - ).dispatch(); + (utility::getApplicationArchitectureType() == APPLICATION_ARCHITECTURE_X86_32 ? L"32" : L"64") + + L" bit, " + L"version " + version.toDisplayWString()) + .dispatch(); commandline::CommandLineParser commandLineParser(version.toDisplayString()); commandLineParser.preparse(argc, argv); @@ -144,9 +139,7 @@ int main(int argc, char *argv[]) setupLogging(); Application::createInstance(version, nullptr, nullptr); - ScopedFunctor f([](){ - Application::destroyInstance(); - }); + ScopedFunctor f([]() { Application::destroyInstance(); }); ApplicationSettingsPrefiller::prefillPaths(ApplicationSettings::getInstance().get()); addLanguagePackages(); @@ -172,8 +165,8 @@ int main(int argc, char *argv[]) commandLineParser.getProjectFilePath(), false, commandLineParser.getRefreshMode(), - commandLineParser.getShallowIndexingRequested() - ).dispatch(); + commandLineParser.getShallowIndexingRequested()) + .dispatch(); } return qtApp.exec(); @@ -204,9 +197,7 @@ int main(int argc, char *argv[]) QtNetworkFactory networkFactory; Application::createInstance(version, &viewFactory, &networkFactory); - ScopedFunctor f([](){ - Application::destroyInstance(); - }); + ScopedFunctor f([]() { Application::destroyInstance(); }); ApplicationSettingsPrefiller::prefillPaths(ApplicationSettings::getInstance().get()); addLanguagePackages(); @@ -220,11 +211,7 @@ int main(int argc, char *argv[]) } else { - MessageLoadProject( - commandLineParser.getProjectFilePath(), - false, - REFRESH_NONE - ).dispatch(); + MessageLoadProject(commandLineParser.getProjectFilePath(), false, REFRESH_NONE).dispatch(); } return qtApp.exec(); diff --git a/src/indexer/main.cpp b/src/indexer/main.cpp index 68296479..64f3d2d1 100644 --- a/src/indexer/main.cpp +++ b/src/indexer/main.cpp @@ -2,22 +2,22 @@ #include "language_packages.h" -#include "LanguagePackageManager.h" -#include "InterprocessIndexer.h" -#include "ApplicationSettings.h" #include "AppPath.h" +#include "ApplicationSettings.h" #include "ConsoleLogger.h" #include "FileLogger.h" -#include "logging.h" +#include "InterprocessIndexer.h" +#include "LanguagePackageManager.h" #include "LogManager.h" +#include "logging.h" #if BUILD_CXX_LANGUAGE_PACKAGE -#include "LanguagePackageCxx.h" -#endif // BUILD_CXX_LANGUAGE_PACKAGE +# include "LanguagePackageCxx.h" +#endif // BUILD_CXX_LANGUAGE_PACKAGE #if BUILD_JAVA_LANGUAGE_PACKAGE -#include "LanguagePackageJava.h" -#endif // BUILD_JAVA_LANGUAGE_PACKAGE +# include "LanguagePackageJava.h" +#endif // BUILD_JAVA_LANGUAGE_PACKAGE void setupLogging(const FilePath& logFilePath) { @@ -38,10 +38,10 @@ void suppressCrashMessage() { #ifdef _WIN32 SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOGPFAULTERRORBOX); -#endif // _WIN32 +#endif // _WIN32 } -int main(int argc, char *argv[]) +int main(int argc, char* argv[]) { int processId = -1; std::string instanceUuid; @@ -94,11 +94,11 @@ int main(int argc, char *argv[]) #if BUILD_CXX_LANGUAGE_PACKAGE LanguagePackageManager::getInstance()->addPackage(std::make_shared()); -#endif // BUILD_CXX_LANGUAGE_PACKAGE +#endif // BUILD_CXX_LANGUAGE_PACKAGE #if BUILD_JAVA_LANGUAGE_PACKAGE LanguagePackageManager::getInstance()->addPackage(std::make_shared()); -#endif // BUILD_JAVA_LANGUAGE_PACKAGE +#endif // BUILD_JAVA_LANGUAGE_PACKAGE InterprocessIndexer indexer(instanceUuid, processId); indexer.work(); diff --git a/src/lib/app/Application.cpp b/src/lib/app/Application.cpp index 93355ffd..d8cd35c9 100644 --- a/src/lib/app/Application.cpp +++ b/src/lib/app/Application.cpp @@ -4,6 +4,7 @@ #include "ApplicationSettings.h" #include "ColorScheme.h" #include "DialogView.h" +#include "FileLogger.h" #include "FileSystem.h" #include "GraphViewStyle.h" #include "IDECommunicationController.h" @@ -30,7 +31,6 @@ #include "tracing.h" #include "utilityString.h" #include "utilityUuid.h" -#include "FileLogger.h" std::shared_ptr Application::s_instance; std::string Application::s_uuid; @@ -333,8 +333,7 @@ void Application::handleMessage(MessageRefresh* message) { TRACE("app refresh"); - refreshProject( - message->all ? REFRESH_ALL_FILES : REFRESH_UPDATED_FILES, false); + refreshProject(message->all ? REFRESH_ALL_FILES : REFRESH_UPDATED_FILES, false); } void Application::handleMessage(MessageRefreshUI* message) @@ -424,7 +423,8 @@ void Application::refreshProject(RefreshMode refreshMode, bool shallowIndexingRe { if (m_project && checkSharedMemory()) { - m_project->refresh(getDialogView(DialogView::UseCase::INDEXING), refreshMode, shallowIndexingRequested); + m_project->refresh( + getDialogView(DialogView::UseCase::INDEXING), refreshMode, shallowIndexingRequested); if (!m_hasGUI && !m_project->isIndexing()) { diff --git a/src/lib/app/paths/AppPath.cpp b/src/lib/app/paths/AppPath.cpp index 62ddc3dc..c37ee503 100644 --- a/src/lib/app/paths/AppPath.cpp +++ b/src/lib/app/paths/AppPath.cpp @@ -21,9 +21,9 @@ bool AppPath::setSharedDataPath(const FilePath& path) FilePath AppPath::getCxxIndexerPath() { #if _WIN32 -const std::wstring cxxIndexerName(L"sourcetrail_indexer.exe"); + const std::wstring cxxIndexerName(L"sourcetrail_indexer.exe"); #else -const std::wstring cxxIndexerName(L"sourcetrail_indexer"); + const std::wstring cxxIndexerName(L"sourcetrail_indexer"); #endif if (!m_cxxIndexerPath.empty()) diff --git a/src/lib/component/ComponentManager.cpp b/src/lib/component/ComponentManager.cpp index 35cded7b..5a1d7601 100644 --- a/src/lib/component/ComponentManager.cpp +++ b/src/lib/component/ComponentManager.cpp @@ -18,9 +18,9 @@ namespace { template -void reverseErase(Container & container) +void reverseErase(Container& container) { - while(!container.empty()) + while (!container.empty()) container.pop_back(); } } // namespace diff --git a/src/lib/component/controller/CodeController.cpp b/src/lib/component/controller/CodeController.cpp index 918b09dc..b43f2ba1 100644 --- a/src/lib/component/controller/CodeController.cpp +++ b/src/lib/component/controller/CodeController.cpp @@ -577,10 +577,15 @@ void CodeController::handleMessage(MessageToNextCodeReference* message) } else if (referenceFileIndex == 0) { - if (m_references[referenceIndex].lineNumber == m_localReferences[localReferenceIndex].lineNumber) + if (m_references[referenceIndex].lineNumber == + m_localReferences[localReferenceIndex].lineNumber) { - if ((next && m_references[referenceIndex].columnNumber < m_localReferences[localReferenceIndex].columnNumber) || - (!next && m_references[referenceIndex].columnNumber > m_localReferences[localReferenceIndex].columnNumber)) + if ((next && + m_references[referenceIndex].columnNumber < + m_localReferences[localReferenceIndex].columnNumber) || + (!next && + m_references[referenceIndex].columnNumber > + m_localReferences[localReferenceIndex].columnNumber)) { localReferenceIndex = -1; } @@ -591,8 +596,12 @@ void CodeController::handleMessage(MessageToNextCodeReference* message) } else { - if ((next && m_references[referenceIndex].lineNumber < m_localReferences[localReferenceIndex].lineNumber) || - (!next && m_references[referenceIndex].lineNumber > m_localReferences[localReferenceIndex].lineNumber)) + if ((next && + m_references[referenceIndex].lineNumber < + m_localReferences[localReferenceIndex].lineNumber) || + (!next && + m_references[referenceIndex].lineNumber > + m_localReferences[localReferenceIndex].lineNumber)) { localReferenceIndex = -1; } @@ -1200,7 +1209,8 @@ std::pair CodeController::findClosestReferenceIndex( if (!next) { if (references[i].lineNumber < currentLineNumber || - (references[i].lineNumber == currentLineNumber && references[i].columnNumber < currentColumnNumber)) + (references[i].lineNumber == currentLineNumber && + references[i].columnNumber < currentColumnNumber)) { referenceIndex = static_cast(i); } @@ -1209,8 +1219,10 @@ std::pair CodeController::findClosestReferenceIndex( return {referenceIndex, beforeCurrentFile ? -1 : 0}; } } - else if (references[i].lineNumber > currentLineNumber || - (references[i].lineNumber == currentLineNumber && references[i].columnNumber > currentColumnNumber)) + else if ( + references[i].lineNumber > currentLineNumber || + (references[i].lineNumber == currentLineNumber && + references[i].columnNumber > currentColumnNumber)) { return {static_cast(i), 0}; } diff --git a/src/lib/component/controller/CodeController.h b/src/lib/component/controller/CodeController.h index 3b857458..c2b46442 100644 --- a/src/lib/component/controller/CodeController.h +++ b/src/lib/component/controller/CodeController.h @@ -19,8 +19,8 @@ #include "MessageCodeShowDefinition.h" #include "MessageDeactivateEdge.h" #include "MessageErrorCountClear.h" -#include "MessageFocusChanged.h" #include "MessageFlushUpdates.h" +#include "MessageFocusChanged.h" #include "MessageFocusIn.h" #include "MessageFocusOut.h" #include "MessageListener.h" diff --git a/src/lib/component/controller/GraphController.h b/src/lib/component/controller/GraphController.h index 40cb4252..322a4dd8 100644 --- a/src/lib/component/controller/GraphController.h +++ b/src/lib/component/controller/GraphController.h @@ -12,8 +12,8 @@ #include "MessageActivateTrail.h" #include "MessageActivateTrailEdge.h" #include "MessageDeactivateEdge.h" -#include "MessageFocusChanged.h" #include "MessageFlushUpdates.h" +#include "MessageFocusChanged.h" #include "MessageFocusIn.h" #include "MessageFocusOut.h" #include "MessageGraphNodeBundleSplit.h" diff --git a/src/lib/component/view/CompositeView.cpp b/src/lib/component/view/CompositeView.cpp index c60eeab9..af18e504 100644 --- a/src/lib/component/view/CompositeView.cpp +++ b/src/lib/component/view/CompositeView.cpp @@ -2,7 +2,8 @@ #include -CompositeView::CompositeView(ViewLayout* viewLayout, CompositeDirection direction, const std::string& name, Id tabId) +CompositeView::CompositeView( + ViewLayout* viewLayout, CompositeDirection direction, const std::string& name, Id tabId) : View(viewLayout), m_direction(direction), m_name(name), m_tabId(tabId) { } diff --git a/src/lib/component/view/CompositeView.h b/src/lib/component/view/CompositeView.h index 44908fd8..380bf08a 100644 --- a/src/lib/component/view/CompositeView.h +++ b/src/lib/component/view/CompositeView.h @@ -20,7 +20,8 @@ public: DIRECTION_VERTICAL }; - CompositeView(ViewLayout* viewLayout, CompositeDirection direction, const std::string& name, Id tabId); + CompositeView( + ViewLayout* viewLayout, CompositeDirection direction, const std::string& name, Id tabId); virtual ~CompositeView(); Id getSchedulerId() const override; diff --git a/src/lib/component/view/GraphViewStyle.cpp b/src/lib/component/view/GraphViewStyle.cpp index d80c6755..fa13cb2b 100644 --- a/src/lib/component/view/GraphViewStyle.cpp +++ b/src/lib/component/view/GraphViewStyle.cpp @@ -371,7 +371,13 @@ GraphViewStyle::NodeMargins GraphViewStyle::getMarginsOfGroupNode(GroupType type } GraphViewStyle::NodeStyle GraphViewStyle::getStyleForNodeType( - NodeType type, bool defined, bool isActive, bool isFocused, bool isCoFocused, bool hasChildren, bool hasQualifier) + NodeType type, + bool defined, + bool isActive, + bool isFocused, + bool isCoFocused, + bool hasChildren, + bool hasQualifier) { return getStyleForNodeType( type.getNodeStyle(), @@ -685,7 +691,8 @@ GraphViewStyle::EdgeStyle GraphViewStyle::getStyleForEdgeType( if (isTrailEdge && isActive) { style.width = 3; - style.color = ColorScheme::getInstance()->getColor("graph/edge/call_trail_focus", style.color); + style.color = ColorScheme::getInstance()->getColor( + "graph/edge/call_trail_focus", style.color); } break; diff --git a/src/lib/component/view/helper/CodeScrollParams.h b/src/lib/component/view/helper/CodeScrollParams.h index f9ea8493..33c47816 100644 --- a/src/lib/component/view/helper/CodeScrollParams.h +++ b/src/lib/component/view/helper/CodeScrollParams.h @@ -22,9 +22,11 @@ struct CodeScrollParams TOP }; - static CodeScrollParams toReference(const FilePath& filePath, Id locationId, Id scopeLocationId, Target target) + static CodeScrollParams toReference( + const FilePath& filePath, Id locationId, Id scopeLocationId, Target target) { - return CodeScrollParams(Type::TO_REFERENCE, target, filePath, locationId, scopeLocationId, 0, 0, false); + return CodeScrollParams( + Type::TO_REFERENCE, target, filePath, locationId, scopeLocationId, 0, 0, false); } static CodeScrollParams toFile(const FilePath& filePath, Target target) @@ -39,7 +41,8 @@ struct CodeScrollParams static CodeScrollParams toValue(size_t value, bool inListMode) { - return CodeScrollParams(Type::TO_VALUE, Target::VISIBLE, FilePath(), 0, 0, 0, value, inListMode); + return CodeScrollParams( + Type::TO_VALUE, Target::VISIBLE, FilePath(), 0, 0, 0, value, inListMode); } CodeScrollParams( @@ -50,8 +53,7 @@ struct CodeScrollParams Id scopeLocationId, size_t line, size_t value, - bool inListMode - ) + bool inListMode) : type(type) , target(target) , filePath(filePath) diff --git a/src/lib/data/NodeTypeSet.cpp b/src/lib/data/NodeTypeSet.cpp index 6a5bb8c8..52d49a4d 100644 --- a/src/lib/data/NodeTypeSet.cpp +++ b/src/lib/data/NodeTypeSet.cpp @@ -166,13 +166,10 @@ NodeTypeSet::MaskType NodeTypeSet::nodeTypeToMask(const NodeType& nodeType) } const std::vector NodeTypeSet::s_allNodeTypes = { - NodeType(NODE_SYMBOL), NodeType(NODE_TYPE), - NodeType(NODE_BUILTIN_TYPE), NodeType(NODE_MODULE), - NodeType(NODE_NAMESPACE), NodeType(NODE_PACKAGE), - NodeType(NODE_STRUCT), NodeType(NODE_CLASS), - NodeType(NODE_INTERFACE), NodeType(NODE_GLOBAL_VARIABLE), - NodeType(NODE_FIELD), NodeType(NODE_FUNCTION), - NodeType(NODE_METHOD), NodeType(NODE_ENUM), - NodeType(NODE_ENUM_CONSTANT), NodeType(NODE_TYPEDEF), - NodeType(NODE_TYPE_PARAMETER), NodeType(NODE_FILE), - NodeType(NODE_MACRO), NodeType(NODE_UNION)}; + NodeType(NODE_SYMBOL), NodeType(NODE_TYPE), NodeType(NODE_BUILTIN_TYPE), + NodeType(NODE_MODULE), NodeType(NODE_NAMESPACE), NodeType(NODE_PACKAGE), + NodeType(NODE_STRUCT), NodeType(NODE_CLASS), NodeType(NODE_INTERFACE), + NodeType(NODE_GLOBAL_VARIABLE), NodeType(NODE_FIELD), NodeType(NODE_FUNCTION), + NodeType(NODE_METHOD), NodeType(NODE_ENUM), NodeType(NODE_ENUM_CONSTANT), + NodeType(NODE_TYPEDEF), NodeType(NODE_TYPE_PARAMETER), NodeType(NODE_FILE), + NodeType(NODE_MACRO), NodeType(NODE_UNION)}; diff --git a/src/lib/data/graph/Token.h b/src/lib/data/graph/Token.h index 590fa59c..5c13b1dc 100644 --- a/src/lib/data/graph/Token.h +++ b/src/lib/data/graph/Token.h @@ -1,9 +1,9 @@ #ifndef TOKEN_H #define TOKEN_H +#include #include #include -#include #include "TokenComponent.h" #include "types.h" diff --git a/src/lib/data/storage/sqlite/SqliteIndexStorage.cpp b/src/lib/data/storage/sqlite/SqliteIndexStorage.cpp index c1c3005b..fc112c94 100644 --- a/src/lib/data/storage/sqlite/SqliteIndexStorage.cpp +++ b/src/lib/data/storage/sqlite/SqliteIndexStorage.cpp @@ -361,7 +361,8 @@ std::vector SqliteIndexStorage::addSourceLocations(const std::vector(data.endCol), data.type); - std::map& index = m_tempSourceLocationIndices[static_cast(data.fileNodeId)]; + std::map& index = + m_tempSourceLocationIndices[static_cast(data.fileNodeId)]; std::map::const_iterator it = index.find(tempLoc); if (it != index.end()) { diff --git a/src/lib/project/Project.cpp b/src/lib/project/Project.cpp index 80b1e3bd..2d47f979 100644 --- a/src/lib/project/Project.cpp +++ b/src/lib/project/Project.cpp @@ -272,7 +272,8 @@ void Project::load(std::shared_ptr dialogView) } } -void Project::refresh(std::shared_ptr dialogView, RefreshMode refreshMode, bool shallowIndexingRequested) +void Project::refresh( + std::shared_ptr dialogView, RefreshMode refreshMode, bool shallowIndexingRequested) { if (m_refreshStage != RefreshStageType::NONE) { diff --git a/src/lib/project/Project.h b/src/lib/project/Project.h index e24cea3f..e590bca5 100644 --- a/src/lib/project/Project.h +++ b/src/lib/project/Project.h @@ -37,7 +37,8 @@ public: void load(std::shared_ptr dialogView); - void refresh(std::shared_ptr dialogView, RefreshMode refreshMode, bool shallowIndexingRequested); + void refresh( + std::shared_ptr dialogView, RefreshMode refreshMode, bool shallowIndexingRequested); RefreshInfo getRefreshInfo(RefreshMode mode) const; diff --git a/src/lib/project/RefreshInfoGenerator.cpp b/src/lib/project/RefreshInfoGenerator.cpp index 741dddf1..e1dad72d 100644 --- a/src/lib/project/RefreshInfoGenerator.cpp +++ b/src/lib/project/RefreshInfoGenerator.cpp @@ -82,8 +82,8 @@ RefreshInfo RefreshInfoGenerator::getRefreshInfoForUpdatedFiles( // 2.3) Handle files that are referenced by the files that will be cleared. These will be // re-indexed on the fly. However, we do not - // need to clear files that are also referenced by unchanged source files, because otherwise - //we will lose these connections. + // need to clear files that are also referenced by unchanged source files, because + //otherwise we will lose these connections. // 2.3.1) Get all source file paths that will not be cleared. // - Initially this list contains all source file paths the project would index right now. // - Then we remove all source files that will be cleared diff --git a/src/lib/settings/ApplicationSettings.cpp b/src/lib/settings/ApplicationSettings.cpp index 35eae9dc..124d136e 100644 --- a/src/lib/settings/ApplicationSettings.cpp +++ b/src/lib/settings/ApplicationSettings.cpp @@ -340,10 +340,10 @@ void ApplicationSettings::setVerboseIndexerLoggingEnabled(bool value) FilePath ApplicationSettings::getLogDirectoryPath() const { return FilePath(getValue( - "application/log_directory_path", UserPaths::getLogPath().getAbsolute().wstr())); + "application/log_directory_path", UserPaths::getLogPath().getAbsolute().wstr())); } -void ApplicationSettings::setLogDirectoryPath(const FilePath &path) +void ApplicationSettings::setLogDirectoryPath(const FilePath& path) { setValue("application/log_directory_path", path.wstr()); } diff --git a/src/lib/utility/commandline/CommandLineParser.cpp b/src/lib/utility/commandline/CommandLineParser.cpp index bc0981d3..9a050469 100644 --- a/src/lib/utility/commandline/CommandLineParser.cpp +++ b/src/lib/utility/commandline/CommandLineParser.cpp @@ -19,10 +19,9 @@ namespace commandline CommandLineParser::CommandLineParser(const std::string& version): m_version(version) { po::options_description options("Options"); - options.add_options() - ("help,h", "Print this help message") - ("version,v", "Version of Sourcetrail") - ("project-file", po::value(), "Open Sourcetrail with this project (.srctrlprj)"); + options.add_options()("help,h", "Print this help message")( + "version,v", "Version of Sourcetrail")( + "project-file", po::value(), "Open Sourcetrail with this project (.srctrlprj)"); m_options.add(options); m_positional.add("project-file", 1); @@ -30,7 +29,7 @@ CommandLineParser::CommandLineParser(const std::string& version): m_version(vers m_commands.push_back(std::make_unique(this)); m_commands.push_back(std::make_unique(this)); - for (auto& command : m_commands) + for (auto& command: m_commands) { command->setup(); } diff --git a/src/lib/utility/commandline/commands/CommandlineCommandIndex.cpp b/src/lib/utility/commandline/commands/CommandlineCommandIndex.cpp index 1943ce0b..a98986ee 100644 --- a/src/lib/utility/commandline/commands/CommandlineCommandIndex.cpp +++ b/src/lib/utility/commandline/commands/CommandlineCommandIndex.cpp @@ -19,12 +19,11 @@ CommandlineCommandIndex::~CommandlineCommandIndex() {} void CommandlineCommandIndex::setup() { po::options_description options("Config Options"); - options.add_options() - ("help,h", "Print this help message") - ("incomplete,i", "Also reindex incomplete files (files with errors)") - ("full,f", "Index full project (omit to only index new/changed files)") - ("shallow,s", "Build a shallow index is supported by the project") - ("project-file", po::value(), "Project file to index (.srctrlprj)"); + options.add_options()("help,h", "Print this help message")( + "incomplete,i", "Also reindex incomplete files (files with errors)")( + "full,f", "Index full project (omit to only index new/changed files)")( + "shallow,s", "Build a shallow index is supported by the project")( + "project-file", po::value(), "Project file to index (.srctrlprj)"); m_options.add(options); m_positional.add("project-file", 1); diff --git a/src/lib/utility/interprocess/SharedMemory.cpp b/src/lib/utility/interprocess/SharedMemory.cpp index 44599bd4..8f19a30b 100644 --- a/src/lib/utility/interprocess/SharedMemory.cpp +++ b/src/lib/utility/interprocess/SharedMemory.cpp @@ -14,16 +14,17 @@ SharedMemory::ScopedAccess::ScopedAccess(SharedMemory* memory) { try { - m_memory = boost::interprocess::managed_shared_memory(boost::interprocess::open_only, memory->getMemoryName().c_str()); + m_memory = boost::interprocess::managed_shared_memory( + boost::interprocess::open_only, memory->getMemoryName().c_str()); } catch (boost::interprocess::interprocess_exception& e) { LOG_ERROR_STREAM( - << "boost exception thrown at ScopedAccess constructor - " << memory->getMemoryName() << ": " - << e.what()); + << "boost exception thrown at ScopedAccess constructor - " << memory->getMemoryName() + << ": " << e.what()); // Behaves the same as the initializer construction, with the error printed out - //throw e; + // throw e; boost::interprocess::permissions permissions; permissions.set_unrestricted(); @@ -32,10 +33,8 @@ SharedMemory::ScopedAccess::ScopedAccess(SharedMemory* memory) memory->getMemoryName().c_str(), memory->getInitialMemorySize(), 0, - permissions - ); + permissions); } - } SharedMemory::ScopedAccess::~ScopedAccess() {} diff --git a/src/lib/utility/messaging/type/MessageLoadProject.h b/src/lib/utility/messaging/type/MessageLoadProject.h index 174fdd28..1ee7b5bf 100644 --- a/src/lib/utility/messaging/type/MessageLoadProject.h +++ b/src/lib/utility/messaging/type/MessageLoadProject.h @@ -10,7 +10,10 @@ class MessageLoadProject: public Message { public: MessageLoadProject( - const FilePath& filePath, bool settingsChanged = false, RefreshMode refreshMode = REFRESH_NONE, bool shallowIndexingRequested = false) + const FilePath& filePath, + bool settingsChanged = false, + RefreshMode refreshMode = REFRESH_NONE, + bool shallowIndexingRequested = false) : projectSettingsFilePath(filePath) , settingsChanged(settingsChanged) , refreshMode(refreshMode) diff --git a/src/lib/utility/messaging/type/MessageRefreshUIState.h b/src/lib/utility/messaging/type/MessageRefreshUIState.h index d8ca57f1..aea92820 100644 --- a/src/lib/utility/messaging/type/MessageRefreshUIState.h +++ b/src/lib/utility/messaging/type/MessageRefreshUIState.h @@ -11,7 +11,7 @@ public: return "MessageRefreshUIState"; } - MessageRefreshUIState(bool isAfterIndexing) : isAfterIndexing(isAfterIndexing) {} + MessageRefreshUIState(bool isAfterIndexing): isAfterIndexing(isAfterIndexing) {} bool isAfterIndexing = false; }; diff --git a/src/lib/utility/messaging/type/focus/MessageFocusChanged.h b/src/lib/utility/messaging/type/focus/MessageFocusChanged.h index 4ff8f477..3d920606 100644 --- a/src/lib/utility/messaging/type/focus/MessageFocusChanged.h +++ b/src/lib/utility/messaging/type/focus/MessageFocusChanged.h @@ -14,8 +14,7 @@ public: }; MessageFocusChanged(ViewType type, Id tokenOrLocationId) - : type(type) - , tokenOrLocationId(tokenOrLocationId) + : type(type), tokenOrLocationId(tokenOrLocationId) { setIsLogged(false); setSchedulerId(TabId::currentTab()); diff --git a/src/lib/utility/messaging/type/focus/MessageFocusedSearchView.h b/src/lib/utility/messaging/type/focus/MessageFocusedSearchView.h index ac2149ae..84899ba7 100644 --- a/src/lib/utility/messaging/type/focus/MessageFocusedSearchView.h +++ b/src/lib/utility/messaging/type/focus/MessageFocusedSearchView.h @@ -7,8 +7,7 @@ class MessageFocusedSearchView: public Message { public: - MessageFocusedSearchView(bool focusIn) - : focusIn(focusIn) + MessageFocusedSearchView(bool focusIn): focusIn(focusIn) { setIsLogged(false); setSchedulerId(TabId::currentTab()); diff --git a/src/lib_cxx/data/parser/cxx/CanonicalFilePathCache.cpp b/src/lib_cxx/data/parser/cxx/CanonicalFilePathCache.cpp index 86c418cc..6148dda8 100644 --- a/src/lib_cxx/data/parser/cxx/CanonicalFilePathCache.cpp +++ b/src/lib_cxx/data/parser/cxx/CanonicalFilePathCache.cpp @@ -130,9 +130,8 @@ FilePath CanonicalFilePathCache::getDeclarationFilePath(const clang::Decl* decla { return getCanonicalFilePath(fileId, sourceManager); } - return getCanonicalFilePath( - utility::decodeFromUtf8( - sourceManager.getPresumedLoc(declaration->getBeginLoc()).getFilename())); + return getCanonicalFilePath(utility::decodeFromUtf8( + sourceManager.getPresumedLoc(declaration->getBeginLoc()).getFilename())); } std::wstring CanonicalFilePathCache::getDeclarationFileName(const clang::Decl* declaration) diff --git a/src/lib_cxx/data/parser/cxx/GeneratePCHAction.cpp b/src/lib_cxx/data/parser/cxx/GeneratePCHAction.cpp index 972f3f69..dd4e963c 100644 --- a/src/lib_cxx/data/parser/cxx/GeneratePCHAction.cpp +++ b/src/lib_cxx/data/parser/cxx/GeneratePCHAction.cpp @@ -2,8 +2,8 @@ #include #include -#include #include +#include #include "PreprocessorCallbacks.h" @@ -44,7 +44,7 @@ std::unique_ptr GeneratePCHAction::CreateASTConsumer( Sysroot, Buffer, FrontendOpts.ModuleFileExtensions, - true, // always allow errors in the PCH + true, // always allow errors in the PCH FrontendOpts.IncludeTimestamps, +CI.getLangOpts().CacheGeneratedPCH)); Consumers.push_back(CI.getPCHContainerWriter().CreatePCHContainerGenerator( diff --git a/src/lib_cxx/utility/codeblocks/CodeblocksCompiler.h b/src/lib_cxx/utility/codeblocks/CodeblocksCompiler.h index e945b47c..9e72e5f3 100644 --- a/src/lib_cxx/utility/codeblocks/CodeblocksCompiler.h +++ b/src/lib_cxx/utility/codeblocks/CodeblocksCompiler.h @@ -2,8 +2,8 @@ #define CODEBLOCKS_COMPILER_H #include -#include #include +#include class TiXmlElement; diff --git a/src/lib_gui/platform_includes/includesLinux.h b/src/lib_gui/platform_includes/includesLinux.h index 2835085b..8ddd496a 100644 --- a/src/lib_gui/platform_includes/includesLinux.h +++ b/src/lib_gui/platform_includes/includesLinux.h @@ -44,7 +44,8 @@ void setupPlatform(int argc, char* argv[]) void setupApp(int argc, char* argv[]) { - FilePath appPath = FilePath(QCoreApplication::applicationDirPath().toStdWString() + L"/").getAbsolute(); + FilePath appPath = + FilePath(QCoreApplication::applicationDirPath().toStdWString() + L"/").getAbsolute(); AppPath::setSharedDataPath(appPath); AppPath::setCxxIndexerPath(appPath); @@ -67,7 +68,8 @@ void setupApp(int argc, char* argv[]) utility::copyNewFilesFromDirectory( QString::fromStdWString(ResourcePaths::getFallbackPath().wstr()), userDataPath); utility::copyNewFilesFromDirectory( - QString::fromStdWString(AppPath::getSharedDataPath().concatenate(L"user/").wstr()), userDataPath); + QString::fromStdWString(AppPath::getSharedDataPath().concatenate(L"user/").wstr()), + userDataPath); } #endif // INCLUDES_DEFAULT_H diff --git a/src/lib_gui/qt/element/code/CodeFocusHandler.cpp b/src/lib_gui/qt/element/code/CodeFocusHandler.cpp index cbd14997..b1c10b96 100644 --- a/src/lib_gui/qt/element/code/CodeFocusHandler.cpp +++ b/src/lib_gui/qt/element/code/CodeFocusHandler.cpp @@ -81,7 +81,13 @@ bool CodeFocusHandler::hasCurrentFocus() const } void CodeFocusHandler::setFocusedLocationId( - QtCodeArea* area, size_t lineNumber, size_t columnNumber, Id locationId, const std::vector& tokenIds, bool updateTargetColumn, bool fromMouse) + QtCodeArea* area, + size_t lineNumber, + size_t columnNumber, + Id locationId, + const std::vector& tokenIds, + bool updateTargetColumn, + bool fromMouse) { if (updateTargetColumn) { diff --git a/src/lib_gui/qt/element/code/QtCodeArea.cpp b/src/lib_gui/qt/element/code/QtCodeArea.cpp index 41fc5fb8..b2216a79 100644 --- a/src/lib_gui/qt/element/code/QtCodeArea.cpp +++ b/src/lib_gui/qt/element/code/QtCodeArea.cpp @@ -1066,7 +1066,7 @@ void QtCodeArea::activateAnnotationsOrErrors( } } - if (!m_showLineNumbers) // for links in project description + if (!m_showLineNumbers) // for links in project description { std::set tokenIds; for (const Annotation* annotation: annotations) diff --git a/src/lib_gui/qt/element/code/QtCodeField.h b/src/lib_gui/qt/element/code/QtCodeField.h index 5f250603..440abb6c 100644 --- a/src/lib_gui/qt/element/code/QtCodeField.h +++ b/src/lib_gui/qt/element/code/QtCodeField.h @@ -94,7 +94,8 @@ protected: Id focusedLocationId); void createAnnotations(std::shared_ptr locationFile); - void activateAnnotations(const std::vector& annotations, bool fromMouse, int mouseOffsetX); + void activateAnnotations( + const std::vector& annotations, bool fromMouse, int mouseOffsetX); int toTextEditPosition(int lineNumber, int columnNumber) const; std::pair toLineColumn(int textEditPosition) const; diff --git a/src/lib_gui/qt/element/code/QtCodeFile.cpp b/src/lib_gui/qt/element/code/QtCodeFile.cpp index 6e418a4b..7a9c8c84 100644 --- a/src/lib_gui/qt/element/code/QtCodeFile.cpp +++ b/src/lib_gui/qt/element/code/QtCodeFile.cpp @@ -33,7 +33,7 @@ QtCodeFile::QtCodeFile(const FilePath& filePath, QtCodeNavigator* navigator, boo connect(m_titleBar, &QtCodeFileTitleBar::minimize, this, &QtCodeFile::clickedMinimizeButton); connect(m_titleBar, &QtCodeFileTitleBar::snippet, this, &QtCodeFile::clickedSnippetButton); connect(m_titleBar, &QtCodeFileTitleBar::maximize, this, &QtCodeFile::clickedMaximizeButton); - connect(m_titleBar, &QtHoverButton::hoveredIn, [this](){ + connect(m_titleBar, &QtHoverButton::hoveredIn, [this]() { m_navigator->setFocusedFile(this); m_navigator->setFocus(); }); diff --git a/src/lib_gui/qt/element/code/QtCodeFileList.cpp b/src/lib_gui/qt/element/code/QtCodeFileList.cpp index 0f788ca1..dd3347c0 100644 --- a/src/lib_gui/qt/element/code/QtCodeFileList.cpp +++ b/src/lib_gui/qt/element/code/QtCodeFileList.cpp @@ -177,7 +177,8 @@ void QtCodeFileList::addFile(const CodeFileParams& params) { Id focusedLocationId = 0; const CodeFocusHandler::Focus& currentFocus = m_navigator->getCurrentFocus(); - if (currentFocus.area && file->getFilePath() == currentFocus.area->getSourceLocationFile()->getFilePath()) + if (currentFocus.area && + file->getFilePath() == currentFocus.area->getSourceLocationFile()->getFilePath()) { focusedLocationId = currentFocus.locationId; } @@ -299,8 +300,14 @@ void QtCodeFileList::scrollTo( if (focusTarget) { - m_navigator->setFocusedLocationId(snippet->getArea(), lineNumber, - snippet->getArea()->getColumnNumberForLocationId(locationId), locationId, {}, false, false); + m_navigator->setFocusedLocationId( + snippet->getArea(), + lineNumber, + snippet->getArea()->getColumnNumberForLocationId(locationId), + locationId, + {}, + false, + false); } } @@ -429,7 +436,8 @@ void QtCodeFileList::updateSnippetTitleAndScrollBarSlot() if (m_firstSnippetTitleBar && m_firstSnippetFile) { - m_firstSnippetTitleBar->setIsFocused(m_navigator->getCurrentFocus().file == m_firstSnippetFile); + m_firstSnippetTitleBar->setIsFocused( + m_navigator->getCurrentFocus().file == m_firstSnippetFile); } } @@ -525,7 +533,7 @@ void QtCodeFileList::updateFirstSnippetTitleBar(QtCodeFile* file, int fileTitleB &QtCodeFileTitleBar::maximize, file, &QtCodeFile::clickedMaximizeButton); - connect(m_firstSnippetTitleBar, &QtHoverButton::hoveredIn, [this, file](){ + connect(m_firstSnippetTitleBar, &QtHoverButton::hoveredIn, [this, file]() { m_navigator->setFocusedFile(file); m_navigator->setFocus(); }); diff --git a/src/lib_gui/qt/element/code/QtCodeFileSingle.cpp b/src/lib_gui/qt/element/code/QtCodeFileSingle.cpp index 9388c284..64173f7b 100644 --- a/src/lib_gui/qt/element/code/QtCodeFileSingle.cpp +++ b/src/lib_gui/qt/element/code/QtCodeFileSingle.cpp @@ -217,8 +217,14 @@ void QtCodeFileSingle::scrollTo( if (focusTarget && locationId) { - m_navigator->setFocusedLocationId(m_area, lineNumber, m_area->getColumnNumberForLocationId(locationId), - locationId, {}, false, false); + m_navigator->setFocusedLocationId( + m_area, + lineNumber, + m_area->getColumnNumberForLocationId(locationId), + locationId, + {}, + false, + false); } } diff --git a/src/lib_gui/qt/element/code/QtCodeNavigateable.cpp b/src/lib_gui/qt/element/code/QtCodeNavigateable.cpp index b52d898b..12ba23c3 100644 --- a/src/lib_gui/qt/element/code/QtCodeNavigateable.cpp +++ b/src/lib_gui/qt/element/code/QtCodeNavigateable.cpp @@ -128,27 +128,27 @@ void QtCodeNavigateable::ensurePercentVisibleAnimated( switch (target) { case CodeScrollParams::Target::VISIBLE: + { + int visibleTop = visibleY + 50; + int visibleBottom = visibleY + visibleHeight - 50; + + int scrollTop = scrollY; + int scrollBottom = scrollY + rectHeight; + + if (scrollTop < visibleTop) { - int visibleTop = visibleY + 50; - int visibleBottom = visibleY + visibleHeight - 50; - - int scrollTop = scrollY; - int scrollBottom = scrollY + rectHeight; - - if (scrollTop < visibleTop) - { - scrollY = scrollTop - 50; - } - else if (scrollBottom > visibleBottom) - { - scrollY = visibleTop + scrollBottom - visibleBottom; - } - else - { - return; - } + scrollY = scrollTop - 50; } - break; + else if (scrollBottom > visibleBottom) + { + scrollY = visibleTop + scrollBottom - visibleBottom; + } + else + { + return; + } + } + break; case CodeScrollParams::Target::CENTER: if (rectHeight < visibleHeight / 2) diff --git a/src/lib_gui/qt/element/code/QtCodeNavigator.cpp b/src/lib_gui/qt/element/code/QtCodeNavigator.cpp index 02a6c2a7..6723728b 100644 --- a/src/lib_gui/qt/element/code/QtCodeNavigator.cpp +++ b/src/lib_gui/qt/element/code/QtCodeNavigator.cpp @@ -562,10 +562,7 @@ void QtCodeNavigator::activateScreenMatch(size_t matchIndex) scrollTo( CodeScrollParams::toReference( - p.first->getFilePath(), - m_activeScreenMatchId, - 0, - CodeScrollParams::Target::CENTER), + p.first->getFilePath(), m_activeScreenMatchId, 0, CodeScrollParams::Target::CENTER), true, true); } @@ -619,15 +616,24 @@ void QtCodeNavigator::scrollTo(const CodeScrollParams& params, bool animated, bo case CodeScrollParams::Type::TO_REFERENCE: func = [=]() { m_current->scrollTo( - params.filePath, 0, params.locationId, params.scopeLocationId, animated, params.target, focusTarget); + params.filePath, + 0, + params.locationId, + params.scopeLocationId, + animated, + params.target, + focusTarget); }; break; case CodeScrollParams::Type::TO_FILE: - func = [=]() { m_current->scrollTo(params.filePath, 0, 0, 0, animated, params.target, focusTarget); }; + func = [=]() { + m_current->scrollTo(params.filePath, 0, 0, 0, animated, params.target, focusTarget); + }; break; case CodeScrollParams::Type::TO_LINE: func = [=]() { - m_current->scrollTo(params.filePath, params.line, 0, 0, animated, params.target, focusTarget); + m_current->scrollTo( + params.filePath, params.line, 0, 0, animated, params.target, focusTarget); }; break; case CodeScrollParams::Type::TO_VALUE: @@ -664,15 +670,26 @@ void QtCodeNavigator::scrollToFocus() if (focus.file) { - scrollTo(CodeScrollParams::toFile(focus.file->getFilePath(), CodeScrollParams::Target::VISIBLE), true, false); + scrollTo( + CodeScrollParams::toFile(focus.file->getFilePath(), CodeScrollParams::Target::VISIBLE), + true, + false); } else if (focus.scopeLine) { - scrollTo(CodeScrollParams::toLine(focus.area->getFilePath(), focus.lineNumber, CodeScrollParams::Target::VISIBLE), true, false); + scrollTo( + CodeScrollParams::toLine( + focus.area->getFilePath(), focus.lineNumber, CodeScrollParams::Target::VISIBLE), + true, + false); } else if (focus.locationId) { - scrollTo(CodeScrollParams::toReference(focus.area->getFilePath(), focus.locationId, 0, CodeScrollParams::Target::VISIBLE), true, false); + scrollTo( + CodeScrollParams::toReference( + focus.area->getFilePath(), focus.locationId, 0, CodeScrollParams::Target::VISIBLE), + true, + false); } } @@ -709,9 +726,12 @@ void QtCodeNavigator::keyPressEvent(QKeyEvent* event) if (shift) { MessageToNextCodeReference( - currentFilePath, currentFocus.lineNumber, currentFocus.columnNumber, - direction == CodeFocusHandler::Direction::DOWN || direction == CodeFocusHandler::Direction::RIGHT - ).dispatch(); + currentFilePath, + currentFocus.lineNumber, + currentFocus.columnNumber, + direction == CodeFocusHandler::Direction::DOWN || + direction == CodeFocusHandler::Direction::RIGHT) + .dispatch(); } else { @@ -726,7 +746,8 @@ void QtCodeNavigator::keyPressEvent(QKeyEvent* event) { QAbstractScrollArea* scrollArea = currentFocus.area; int step = currentFocus.area ? currentFocus.area->lineHeight() * 3 : 50; - if (direction == CodeFocusHandler::Direction::DOWN || direction == CodeFocusHandler::Direction::UP) + if (direction == CodeFocusHandler::Direction::DOWN || + direction == CodeFocusHandler::Direction::UP) { if (m_mode == MODE_LIST) { diff --git a/src/lib_gui/qt/element/dialog/QtListBox.cpp b/src/lib_gui/qt/element/dialog/QtListBox.cpp index 4ecb6014..27076a6c 100644 --- a/src/lib_gui/qt/element/dialog/QtListBox.cpp +++ b/src/lib_gui/qt/element/dialog/QtListBox.cpp @@ -22,8 +22,7 @@ void QtListWidget::wheelEvent(QWheelEvent* event) QScrollBar* bar = verticalScrollBar(); bool down = event->angleDelta().y() < 0; - if (bar->minimum() == bar->maximum() || - (down && bar->value() == bar->maximum()) || + if (bar->minimum() == bar->maximum() || (down && bar->value() == bar->maximum()) || (!down && bar->value() == bar->minimum())) { event->ignore(); diff --git a/src/lib_gui/qt/graphics/GraphFocusHandler.h b/src/lib_gui/qt/graphics/GraphFocusHandler.h index d4922026..ae6923f3 100644 --- a/src/lib_gui/qt/graphics/GraphFocusHandler.h +++ b/src/lib_gui/qt/graphics/GraphFocusHandler.h @@ -42,7 +42,8 @@ public: void defocus(); void focusInitialNode(); - void focusTokenId(const std::list& nodes, const std::list& edges, Id tokenId); + void focusTokenId( + const std::list& nodes, const std::list& edges, Id tokenId); void refocusNode(const std::list& newNodes, Id oldActiveTokenId, Id newActiveTokenId); void focusNext(Direction direction, bool navigateEdges); diff --git a/src/lib_gui/qt/graphics/QtGraphicsView.cpp b/src/lib_gui/qt/graphics/QtGraphicsView.cpp index df310bd2..ce07b2e8 100644 --- a/src/lib_gui/qt/graphics/QtGraphicsView.cpp +++ b/src/lib_gui/qt/graphics/QtGraphicsView.cpp @@ -57,7 +57,8 @@ QtGraphicsView::QtGraphicsView(GraphFocusHandler* focusHandler, QWidget* parent) m_zoomLabelTimer = std::make_shared(this); connect(m_zoomLabelTimer.get(), &QTimer::timeout, this, &QtGraphicsView::hideZoomLabel); - m_openInTabAction = new QAction(QStringLiteral("Open in New Tab (Ctrl + Shift + Left Click)"), this); + m_openInTabAction = new QAction( + QStringLiteral("Open in New Tab (Ctrl + Shift + Left Click)"), this); #if defined(Q_OS_MAC) m_openInTabAction->setText(QStringLiteral("Open in New Tab (Cmd + Shift + Left Click)")); #endif diff --git a/src/lib_gui/qt/graphics/component/QtGraphNodeComponentClickable.cpp b/src/lib_gui/qt/graphics/component/QtGraphNodeComponentClickable.cpp index 5bf77842..a85761ee 100644 --- a/src/lib_gui/qt/graphics/component/QtGraphNodeComponentClickable.cpp +++ b/src/lib_gui/qt/graphics/component/QtGraphNodeComponentClickable.cpp @@ -48,8 +48,7 @@ void QtGraphNodeComponentClickable::nodeMouseReleaseEvent(QGraphicsSceneMouseEve if (!m_mouseMoved) { - if ( - event->modifiers() & Qt::ControlModifier && event->modifiers() & Qt::ShiftModifier && + if (event->modifiers() & Qt::ControlModifier && event->modifiers() & Qt::ShiftModifier && event->button() == Qt::LeftButton) { m_graphNode->onMiddleClick(); diff --git a/src/lib_gui/qt/project_wizard/content/QtProjectWizardContent.cpp b/src/lib_gui/qt/project_wizard/content/QtProjectWizardContent.cpp index aaa3a499..482d1a2d 100644 --- a/src/lib_gui/qt/project_wizard/content/QtProjectWizardContent.cpp +++ b/src/lib_gui/qt/project_wizard/content/QtProjectWizardContent.cpp @@ -147,7 +147,9 @@ void QtProjectWizardContent::showFilesDialog(const std::vector& filePa if (!m_filesDialog) { m_filesDialog = new QtTextEditDialog( - getFileNamesTitle(), QString::number(filePaths.size()) + " " + getFileNamesDescription(), m_window); + getFileNamesTitle(), + QString::number(filePaths.size()) + " " + getFileNamesDescription(), + m_window); m_filesDialog->setup(); m_filesDialog->setText(utility::join(utility::toWStrings(filePaths), L"\n")); diff --git a/src/lib_gui/qt/project_wizard/content/QtProjectWizardContentCustomCommand.cpp b/src/lib_gui/qt/project_wizard/content/QtProjectWizardContentCustomCommand.cpp index d1611742..696c531f 100644 --- a/src/lib_gui/qt/project_wizard/content/QtProjectWizardContentCustomCommand.cpp +++ b/src/lib_gui/qt/project_wizard/content/QtProjectWizardContentCustomCommand.cpp @@ -80,7 +80,8 @@ bool QtProjectWizardContentCustomCommand::check() if (m_customCommand->text().toStdWString().find(L"%{SOURCE_FILE_PATH}") == std::wstring::npos) { QMessageBox msgBox(m_window); - msgBox.setText(QStringLiteral("The variable %{SOURCE_FILE_PATH} is missing in the custom command.")); + msgBox.setText( + QStringLiteral("The variable %{SOURCE_FILE_PATH} is missing in the custom command.")); msgBox.exec(); return false; } diff --git a/src/lib_gui/qt/project_wizard/content/QtProjectWizardContentProjectData.cpp b/src/lib_gui/qt/project_wizard/content/QtProjectWizardContentProjectData.cpp index 98bc3810..7bebfc50 100644 --- a/src/lib_gui/qt/project_wizard/content/QtProjectWizardContentProjectData.cpp +++ b/src/lib_gui/qt/project_wizard/content/QtProjectWizardContentProjectData.cpp @@ -91,7 +91,8 @@ bool QtProjectWizardContentProjectData::check() if (m_projectFileLocation->getText().isEmpty()) { QMessageBox msgBox(m_window); - msgBox.setText(QStringLiteral("Please define the location for the Sourcetrail project file.")); + msgBox.setText( + QStringLiteral("Please define the location for the Sourcetrail project file.")); msgBox.exec(); return false; } @@ -128,10 +129,11 @@ bool QtProjectWizardContentProjectData::check() else if (!paths[0].exists()) { QMessageBox msgBox(m_window); - msgBox.setText( - QStringLiteral("The specified location does not exist. Do you want to create the directory?")); + msgBox.setText(QStringLiteral( + "The specified location does not exist. Do you want to create the directory?")); msgBox.addButton(QStringLiteral("Abort"), QMessageBox::ButtonRole::NoRole); - QPushButton* createButton = msgBox.addButton(QStringLiteral("Create"), QMessageBox::ButtonRole::YesRole); + QPushButton* createButton = msgBox.addButton( + QStringLiteral("Create"), QMessageBox::ButtonRole::YesRole); msgBox.setDefaultButton(createButton); msgBox.setIcon(QMessageBox::Icon::Question); int ret = msgBox.exec(); diff --git a/src/lib_gui/qt/project_wizard/content/QtProjectWizardContentRequiredLabel.h b/src/lib_gui/qt/project_wizard/content/QtProjectWizardContentRequiredLabel.h index 170f2016..b2dabae0 100644 --- a/src/lib_gui/qt/project_wizard/content/QtProjectWizardContentRequiredLabel.h +++ b/src/lib_gui/qt/project_wizard/content/QtProjectWizardContentRequiredLabel.h @@ -8,7 +8,8 @@ class QtProjectWizardContentRequiredLabel: public QtProjectWizardContent public: QtProjectWizardContentRequiredLabel(QtProjectWizardWindow* window) : QtProjectWizardContent(window) - {} + { + } // QtProjectWizardContent implementation void populate(QGridLayout* layout, int& row) override diff --git a/src/lib_gui/qt/project_wizard/content/QtProjectWizardContentSourceGroupData.cpp b/src/lib_gui/qt/project_wizard/content/QtProjectWizardContentSourceGroupData.cpp index c25ecc87..95d42263 100644 --- a/src/lib_gui/qt/project_wizard/content/QtProjectWizardContentSourceGroupData.cpp +++ b/src/lib_gui/qt/project_wizard/content/QtProjectWizardContentSourceGroupData.cpp @@ -32,7 +32,10 @@ void QtProjectWizardContentSourceGroupData::populate(QGridLayout* layout, int& r connect( m_status, &QCheckBox::toggled, this, &QtProjectWizardContentSourceGroupData::changedStatus); layout->addWidget( - createFormSubLabel(QStringLiteral("Status")), row, QtProjectWizardWindow::FRONT_COL, Qt::AlignRight); + createFormSubLabel(QStringLiteral("Status")), + row, + QtProjectWizardWindow::FRONT_COL, + Qt::AlignRight); layout->addWidget(m_status, row, QtProjectWizardWindow::BACK_COL); addHelpButton( diff --git a/src/lib_gui/qt/project_wizard/content/QtProjectWizardContentVS.cpp b/src/lib_gui/qt/project_wizard/content/QtProjectWizardContentVS.cpp index 8e4c4088..0d1c5e4c 100644 --- a/src/lib_gui/qt/project_wizard/content/QtProjectWizardContentVS.cpp +++ b/src/lib_gui/qt/project_wizard/content/QtProjectWizardContentVS.cpp @@ -15,16 +15,22 @@ void QtProjectWizardContentVS::populate(QGridLayout* layout, int& row) addHelpButton( QStringLiteral("Create Compilation Database"), - QStringLiteral("To create a new Compilation Database from a Visual Studio Solution, a Solution has to be open in Visual " - "Studio.\n Sourcetrail will call Visual Studio to open the 'Create Compilation Database' dialog. Please follow " - "the instructions in Visual Studio to complete the process.\n Note: Sourcetrail's Visual Studio plugin has to " - "be installed. Visual Studio has to be running with an eligible Solution, containing C/C++ projects, loaded."), + QStringLiteral("To create a new Compilation Database from a Visual Studio Solution, a " + "Solution has to be open in Visual " + "Studio.\n Sourcetrail will call Visual Studio to open the 'Create " + "Compilation Database' dialog. Please follow " + "the instructions in Visual Studio to complete the process.\n Note: " + "Sourcetrail's Visual Studio plugin has to " + "be installed. Visual Studio has to be running with an eligible Solution, " + "containing C/C++ projects, loaded."), layout, row); - QLabel* descriptionLabel = createFormSubLabel( - QStringLiteral("Call Visual Studio to create a Compilation Database from the loaded Solution (requires installed " - "Sourcetrail Visual Studio " + QLabel* descriptionLabel = createFormSubLabel(QStringLiteral( + "Call Visual Studio to create a Compilation Database from the loaded Solution (requires " + "installed " + "Sourcetrail " + "Visual Studio " "Extension).")); descriptionLabel->setObjectName(QStringLiteral("description")); descriptionLabel->setOpenExternalLinks(true); diff --git a/src/lib_gui/qt/project_wizard/content/path/QtProjectWizardContentPathCxxPch.cpp b/src/lib_gui/qt/project_wizard/content/path/QtProjectWizardContentPathCxxPch.cpp index ff4c6377..dcf4f328 100644 --- a/src/lib_gui/qt/project_wizard/content/path/QtProjectWizardContentPathCxxPch.cpp +++ b/src/lib_gui/qt/project_wizard/content/path/QtProjectWizardContentPathCxxPch.cpp @@ -57,7 +57,8 @@ bool QtProjectWizardContentPathCxxPch::check() if (!cdb) { QMessageBox msgBox(m_window); - msgBox.setText(QStringLiteral("Unable to open and read the provided compilation database file.")); + msgBox.setText( + QStringLiteral("Unable to open and read the provided compilation database file.")); msgBox.exec(); return false; } diff --git a/src/lib_gui/qt/project_wizard/content/paths/QtProjectWizardContentPathsFrameworkSearch.cpp b/src/lib_gui/qt/project_wizard/content/paths/QtProjectWizardContentPathsFrameworkSearch.cpp index 25e05d5c..c527a0a2 100644 --- a/src/lib_gui/qt/project_wizard/content/paths/QtProjectWizardContentPathsFrameworkSearch.cpp +++ b/src/lib_gui/qt/project_wizard/content/paths/QtProjectWizardContentPathsFrameworkSearch.cpp @@ -7,7 +7,8 @@ QtProjectWizardContentPathsFrameworkSearch::QtProjectWizardContentPathsFramework std::shared_ptr settings, QtProjectWizardWindow* window, bool indicateAsAdditional) - : QtProjectWizardContentPaths(settings, window, QtPathListBox::SELECTION_POLICY_DIRECTORIES_ONLY, true) + : QtProjectWizardContentPaths( + settings, window, QtPathListBox::SELECTION_POLICY_DIRECTORIES_ONLY, true) { setTitleString( indicateAsAdditional ? QStringLiteral("Additional Framework Search Paths") diff --git a/src/lib_gui/qt/project_wizard/content/paths/QtProjectWizardContentPathsHeaderSearch.cpp b/src/lib_gui/qt/project_wizard/content/paths/QtProjectWizardContentPathsHeaderSearch.cpp index fc31858c..459d1600 100644 --- a/src/lib_gui/qt/project_wizard/content/paths/QtProjectWizardContentPathsHeaderSearch.cpp +++ b/src/lib_gui/qt/project_wizard/content/paths/QtProjectWizardContentPathsHeaderSearch.cpp @@ -25,7 +25,8 @@ QtProjectWizardContentPathsHeaderSearch::QtProjectWizardContentPathsHeaderSearch std::shared_ptr settings, QtProjectWizardWindow* window, bool indicateAsAdditional) - : QtProjectWizardContentPaths(settings, window, QtPathListBox::SELECTION_POLICY_DIRECTORIES_ONLY, true) + : QtProjectWizardContentPaths( + settings, window, QtPathListBox::SELECTION_POLICY_DIRECTORIES_ONLY, true) , m_showDetectedIncludesResultFunctor(std::bind( &QtProjectWizardContentPathsHeaderSearch::showDetectedIncludesResult, this, @@ -363,7 +364,8 @@ void QtProjectWizardContentPathsHeaderSearch::showDetectedIncludesResult( ("

The following " + std::to_string(additionalHeaderSearchPaths.size()) + " include paths have been " "detected and will be added to the include paths of this Source Group.") - .c_str(), m_window); + .c_str(), + m_window); m_filesDialog->setup(); m_filesDialog->setReadOnly(true); @@ -392,8 +394,8 @@ void QtProjectWizardContentPathsHeaderSearch::showValidationResult( if (unresolvedIncludes.empty()) { QMessageBox msgBox(m_window); - msgBox.setText( - QStringLiteral("

All include directives throughout the indexed files have been resolved.

")); + msgBox.setText(QStringLiteral( + "

All include directives throughout the indexed files have been resolved.

")); msgBox.exec(); } else @@ -428,7 +430,8 @@ void QtProjectWizardContentPathsHeaderSearch::showValidationResult( "conditional preprocessor " "directives. This means that some of the unresolved includes may actually not be " "required by the indexer.

") - .c_str(), m_window); + .c_str(), + m_window); m_filesDialog->setup(); m_filesDialog->setCloseVisible(false); diff --git a/src/lib_gui/qt/project_wizard/content/paths/QtProjectWizardContentPathsIndexedHeaders.cpp b/src/lib_gui/qt/project_wizard/content/paths/QtProjectWizardContentPathsIndexedHeaders.cpp index 02644c8c..a0e7512a 100644 --- a/src/lib_gui/qt/project_wizard/content/paths/QtProjectWizardContentPathsIndexedHeaders.cpp +++ b/src/lib_gui/qt/project_wizard/content/paths/QtProjectWizardContentPathsIndexedHeaders.cpp @@ -166,11 +166,13 @@ bool QtProjectWizardContentPathsIndexedHeaders::check() if (m_list->getPathsAsDisplayed().empty()) { QMessageBox msgBox(m_window); - msgBox.setText(QStringLiteral("You didn't specify any Header Files & Directories to Index.")); + msgBox.setText( + QStringLiteral("You didn't specify any Header Files & Directories to Index.")); msgBox.setInformativeText(QString::fromStdString( "Sourcetrail will only index the source files listed in the " + m_projectKindName + " file and none of the included header files.")); - QPushButton* yesButton = msgBox.addButton(QStringLiteral("Continue"), QMessageBox::ButtonRole::YesRole); + QPushButton* yesButton = msgBox.addButton( + QStringLiteral("Continue"), QMessageBox::ButtonRole::YesRole); msgBox.addButton(QStringLiteral("Cancel"), QMessageBox::ButtonRole::NoRole); msgBox.setDefaultButton(yesButton); @@ -197,7 +199,8 @@ void QtProjectWizardContentPathsIndexedHeaders::buttonClicked() if (!codeblocksProjectPath.exists()) { QMessageBox msgBox(m_window); - msgBox.setText(QStringLiteral("The provided Code::Blocks project path does not exist.")); + msgBox.setText( + QStringLiteral("The provided Code::Blocks project path does not exist.")); msgBox.setDetailedText(QString::fromStdWString(codeblocksProjectPath.wstr())); msgBox.exec(); return; @@ -207,7 +210,8 @@ void QtProjectWizardContentPathsIndexedHeaders::buttonClicked() "Select from Include Paths", "The list contains all Include Paths found in the Code::Blocks project. Red paths " "do not exist. Select the " - "paths containing the header files you want to index with Sourcetrail.", m_window); + "paths containing the header files you want to index with Sourcetrail.", + m_window); m_filesDialog->setup(); connect( @@ -241,7 +245,8 @@ void QtProjectWizardContentPathsIndexedHeaders::buttonClicked() if (!cdbPath.exists()) { QMessageBox msgBox(m_window); - msgBox.setText(QStringLiteral("The provided Compilation Database path does not exist.")); + msgBox.setText( + QStringLiteral("The provided Compilation Database path does not exist.")); msgBox.setDetailedText(QString::fromStdWString(cdbPath.wstr())); msgBox.exec(); return; @@ -251,7 +256,8 @@ void QtProjectWizardContentPathsIndexedHeaders::buttonClicked() "Select from Include Paths", "The list contains all Include Paths found in the Compilation Database. Red paths " "do not exist. Select the " - "paths containing the header files you want to index with Sourcetrail.", m_window); + "paths containing the header files you want to index with Sourcetrail.", + m_window); m_filesDialog->setup(); connect( diff --git a/src/lib_gui/qt/project_wizard/content/paths/QtProjectWizardContentPathsSource.cpp b/src/lib_gui/qt/project_wizard/content/paths/QtProjectWizardContentPathsSource.cpp index ebaaf8f7..f50841d8 100644 --- a/src/lib_gui/qt/project_wizard/content/paths/QtProjectWizardContentPathsSource.cpp +++ b/src/lib_gui/qt/project_wizard/content/paths/QtProjectWizardContentPathsSource.cpp @@ -72,10 +72,12 @@ bool QtProjectWizardContentPathsSource::check() { QMessageBox msgBox(m_window); msgBox.setText(QStringLiteral("You didn't specify any 'Files & Directories to Index'.")); - msgBox.setInformativeText(QStringLiteral( - "Sourcetrail will not index any files for this Source Group. Please add paths to files or directories " - "that should be indexed.")); - QPushButton* yesButton = msgBox.addButton(QStringLiteral("Continue"), QMessageBox::ButtonRole::YesRole); + msgBox.setInformativeText( + QStringLiteral("Sourcetrail will not index any files for this Source Group. Please add " + "paths to files or directories " + "that should be indexed.")); + QPushButton* yesButton = msgBox.addButton( + QStringLiteral("Continue"), QMessageBox::ButtonRole::YesRole); msgBox.addButton(QStringLiteral("Cancel"), QMessageBox::ButtonRole::NoRole); msgBox.setDefaultButton(yesButton); diff --git a/src/lib_gui/qt/utility/QtHighlighter.cpp b/src/lib_gui/qt/utility/QtHighlighter.cpp index cb35cd9b..991f6e06 100644 --- a/src/lib_gui/qt/utility/QtHighlighter.cpp +++ b/src/lib_gui/qt/utility/QtHighlighter.cpp @@ -44,14 +44,15 @@ std::string QtHighlighter::highlightTypeToString(QtHighlighter::HighlightType ty QtHighlighter::HighlightType QtHighlighter::highlightTypeFromString(const std::string& typeStr) { - const std::array types = {HighlightType::COMMENT, - HighlightType::DIRECTIVE, - HighlightType::FUNCTION, - HighlightType::KEYWORD, - HighlightType::NUMBER, - HighlightType::QUOTATION, - HighlightType::TEXT, - HighlightType::TYPE}; + const std::array types = { + HighlightType::COMMENT, + HighlightType::DIRECTIVE, + HighlightType::FUNCTION, + HighlightType::KEYWORD, + HighlightType::NUMBER, + HighlightType::QUOTATION, + HighlightType::TEXT, + HighlightType::TYPE}; for (HighlightType type: types) { @@ -68,14 +69,15 @@ void QtHighlighter::loadHighlightingRules() { ColorScheme* scheme = ColorScheme::getInstance().get(); - const std::array types = {HighlightType::COMMENT, - HighlightType::DIRECTIVE, - HighlightType::FUNCTION, - HighlightType::KEYWORD, - HighlightType::NUMBER, - HighlightType::QUOTATION, - HighlightType::TEXT, - HighlightType::TYPE}; + const std::array types = { + HighlightType::COMMENT, + HighlightType::DIRECTIVE, + HighlightType::FUNCTION, + HighlightType::KEYWORD, + HighlightType::NUMBER, + HighlightType::QUOTATION, + HighlightType::TEXT, + HighlightType::TYPE}; s_charFormats.clear(); for (HighlightType type: types) diff --git a/src/lib_gui/qt/view/QtCodeView.cpp b/src/lib_gui/qt/view/QtCodeView.cpp index fc19d104..3594adf4 100644 --- a/src/lib_gui/qt/view/QtCodeView.cpp +++ b/src/lib_gui/qt/view/QtCodeView.cpp @@ -15,8 +15,8 @@ QtCodeView::QtCodeView(ViewLayout* viewLayout): CodeView(viewLayout) { m_widget = new QtCodeNavigator(); - m_widget->connect(m_widget, &QtCodeNavigator::focusIn, [this](){ setNavigationFocus(true); }); - m_widget->connect(m_widget, &QtCodeNavigator::focusOut, [this](){ setNavigationFocus(false); }); + m_widget->connect(m_widget, &QtCodeNavigator::focusIn, [this]() { setNavigationFocus(true); }); + m_widget->connect(m_widget, &QtCodeNavigator::focusOut, [this]() { setNavigationFocus(false); }); } void QtCodeView::createWidgetWrapper() diff --git a/src/lib_gui/qt/view/QtCompositeView.cpp b/src/lib_gui/qt/view/QtCompositeView.cpp index fb533c5c..bfbf6c78 100644 --- a/src/lib_gui/qt/view/QtCompositeView.cpp +++ b/src/lib_gui/qt/view/QtCompositeView.cpp @@ -69,6 +69,7 @@ void QtCompositeView::showFocusIndicator(bool focus) { m_onQtThread([=]() { const std::string& colorName = focus ? "window/focus" : "search/background"; - utility::setWidgetBackgroundColor(m_focusIndicator, ColorScheme::getInstance()->getColor(colorName)); + utility::setWidgetBackgroundColor( + m_focusIndicator, ColorScheme::getInstance()->getColor(colorName)); }); } diff --git a/src/lib_gui/qt/view/QtCompositeView.h b/src/lib_gui/qt/view/QtCompositeView.h index 6575c726..563eb520 100644 --- a/src/lib_gui/qt/view/QtCompositeView.h +++ b/src/lib_gui/qt/view/QtCompositeView.h @@ -10,7 +10,8 @@ class QWidget; class QtCompositeView: public CompositeView { public: - QtCompositeView(ViewLayout* viewLayout, CompositeDirection direction, const std::string& name, Id tabId); + QtCompositeView( + ViewLayout* viewLayout, CompositeDirection direction, const std::string& name, Id tabId); ~QtCompositeView() = default; // View implementation diff --git a/src/lib_gui/qt/view/QtGraphView.cpp b/src/lib_gui/qt/view/QtGraphView.cpp index 11f6fed3..fd5659a2 100644 --- a/src/lib_gui/qt/view/QtGraphView.cpp +++ b/src/lib_gui/qt/view/QtGraphView.cpp @@ -67,8 +67,8 @@ QtGraphView::QtGraphView(ViewLayout* viewLayout) connect(view, &QtGraphicsView::emptySpaceClicked, this, &QtGraphView::clickedInEmptySpace); connect(view, &QtGraphicsView::resized, this, &QtGraphView::resized); - connect(view, &QtGraphicsView::focusIn, [this](){ setNavigationFocus(true); }); - connect(view, &QtGraphicsView::focusOut, [this](){ setNavigationFocus(false); }); + connect(view, &QtGraphicsView::focusIn, [this]() { setNavigationFocus(true); }); + connect(view, &QtGraphicsView::focusOut, [this]() { setNavigationFocus(false); }); m_scrollSpeedChangeListenerHorizontal.setScrollBar(view->horizontalScrollBar()); m_scrollSpeedChangeListenerVertical.setScrollBar(view->verticalScrollBar()); @@ -1056,7 +1056,8 @@ QtGraphNode* QtGraphView::createNodeRecursive( } else if (node->isExpandToggleNode()) { - newNode = new QtGraphNodeExpandToggle(node->isExpanded(), static_cast(node->invisibleSubNodeCount)); + newNode = new QtGraphNodeExpandToggle( + node->isExpanded(), static_cast(node->invisibleSubNodeCount)); } else if (node->isBundleNode()) { diff --git a/src/lib_gui/qt/view/QtViewFactory.cpp b/src/lib_gui/qt/view/QtViewFactory.cpp index e5a8d92a..45d9e1a0 100644 --- a/src/lib_gui/qt/view/QtViewFactory.cpp +++ b/src/lib_gui/qt/view/QtViewFactory.cpp @@ -28,7 +28,10 @@ std::shared_ptr QtViewFactory::createMainView(StorageAccess* storageAc } std::shared_ptr QtViewFactory::createCompositeView( - ViewLayout* viewLayout, CompositeView::CompositeDirection direction, const std::string& name, const Id tabId) const + ViewLayout* viewLayout, + CompositeView::CompositeDirection direction, + const std::string& name, + const Id tabId) const { return View::createAndAddToLayout(viewLayout, direction, name, tabId); } diff --git a/src/lib_gui/qt/window/QtKeyboardShortcuts.h b/src/lib_gui/qt/window/QtKeyboardShortcuts.h index dccb7332..bc14179e 100644 --- a/src/lib_gui/qt/window/QtKeyboardShortcuts.h +++ b/src/lib_gui/qt/window/QtKeyboardShortcuts.h @@ -36,9 +36,13 @@ private: const QString shortcut; Shortcut(const QString& name, const QString& shortcut); - static Shortcut defaultOrMac(const QString& name, const QString& defaultShortcut, const QString& macShortcut); + static Shortcut defaultOrMac( + const QString& name, const QString& defaultShortcut, const QString& macShortcut); static Shortcut winMacOrLinux( - const QString& name, const QString& winShortcut, const QString& macShortcut, const QString& linuxShortcut); + const QString& name, + const QString& winShortcut, + const QString& macShortcut, + const QString& linuxShortcut); }; QtShortcutTable* createTableWidget(const std::string& objectName); diff --git a/src/lib_gui/qt/window/QtMainWindow.cpp b/src/lib_gui/qt/window/QtMainWindow.cpp index 002acc32..71ca6d37 100644 --- a/src/lib_gui/qt/window/QtMainWindow.cpp +++ b/src/lib_gui/qt/window/QtMainWindow.cpp @@ -758,7 +758,8 @@ void QtMainWindow::updateRecentProjectsMenu() { m_recentProjectsMenu->clear(); - const std::vector recentProjects = ApplicationSettings::getInstance()->getRecentProjects(); + const std::vector recentProjects = + ApplicationSettings::getInstance()->getRecentProjects(); const size_t recentProjectsCount = ApplicationSettings::getInstance()->getMaxRecentProjectsCount(); for (size_t i = 0; i < recentProjects.size() && i < recentProjectsCount; ++i) diff --git a/src/lib_java/data/parser/java/JavaEnvironmentFactory.cpp b/src/lib_java/data/parser/java/JavaEnvironmentFactory.cpp index 7a96f100..66ba020d 100644 --- a/src/lib_java/data/parser/java/JavaEnvironmentFactory.cpp +++ b/src/lib_java/data/parser/java/JavaEnvironmentFactory.cpp @@ -63,8 +63,8 @@ void JavaEnvironmentFactory::createInstance(std::string classPath, std::string& // options[3].optionString = const_cast("-Dcom.sun.management.jmxremote.port=9010"); // options[4].optionString = // const_cast("-Dcom.sun.management.jmxremote.local.only=false"); options[5].optionString - // = const_cast("-Dcom.sun.management.jmxremote.authenticate=false"); options[6].optionString - // = const_cast("-Dcom.sun.management.jmxremote.ssl=false"); + // = const_cast("-Dcom.sun.management.jmxremote.authenticate=false"); + // options[6].optionString = const_cast("-Dcom.sun.management.jmxremote.ssl=false"); vm_args.version = JNI_VERSION_1_8; vm_args.nOptions = optionCount; diff --git a/src/lib_python/project/SourceGroupPythonEmpty.cpp b/src/lib_python/project/SourceGroupPythonEmpty.cpp index be50accd..dfe7a498 100644 --- a/src/lib_python/project/SourceGroupPythonEmpty.cpp +++ b/src/lib_python/project/SourceGroupPythonEmpty.cpp @@ -56,7 +56,8 @@ std::vector> SourceGroupPythonEmpty::getIndexerC if (!m_settings->getEnvironmentPath().empty()) { - args += L" --environment-path=\"" + m_settings->getEnvironmentPathExpandedAndAbsolute().wstr() + L"\""; + args += L" --environment-path=\"" + + m_settings->getEnvironmentPathExpandedAndAbsolute().wstr() + L"\""; } if (ApplicationSettings::getInstance()->getVerboseIndexerLoggingEnabled()) diff --git a/src/test/GraphTestSuite.cpp b/src/test/GraphTestSuite.cpp index 423f56af..1ee65e9c 100644 --- a/src/test/GraphTestSuite.cpp +++ b/src/test/GraphTestSuite.cpp @@ -142,11 +142,7 @@ TEST_CASE("token copies components when token is copied") TEST_CASE("nodes are nodes") { - Node a( - 1, - NodeType(NODE_SYMBOL), - NameHierarchy(L"A", NAME_DELIMITER_CXX), - DEFINITION_EXPLICIT); + Node a(1, NodeType(NODE_SYMBOL), NameHierarchy(L"A", NAME_DELIMITER_CXX), DEFINITION_EXPLICIT); REQUIRE(a.isNode()); REQUIRE(!a.isEdge()); @@ -154,16 +150,8 @@ TEST_CASE("nodes are nodes") TEST_CASE("edges are edges") { - Node a( - 1, - NodeType(NODE_SYMBOL), - NameHierarchy(L"A", NAME_DELIMITER_CXX), - DEFINITION_EXPLICIT); - Node b( - 2, - NodeType(NODE_SYMBOL), - NameHierarchy(L"B", NAME_DELIMITER_CXX), - DEFINITION_EXPLICIT); + Node a(1, NodeType(NODE_SYMBOL), NameHierarchy(L"A", NAME_DELIMITER_CXX), DEFINITION_EXPLICIT); + Node b(2, NodeType(NODE_SYMBOL), NameHierarchy(L"B", NAME_DELIMITER_CXX), DEFINITION_EXPLICIT); Edge e(3, Edge::EDGE_USAGE, &a, &b); REQUIRE(!e.isNode()); @@ -172,43 +160,27 @@ TEST_CASE("edges are edges") TEST_CASE("set type of node from constructor") { - Node n( - 1, - NodeType(NODE_FUNCTION), - NameHierarchy(L"A", NAME_DELIMITER_CXX), - DEFINITION_EXPLICIT); + Node n(1, NodeType(NODE_FUNCTION), NameHierarchy(L"A", NAME_DELIMITER_CXX), DEFINITION_EXPLICIT); REQUIRE(NodeType(NODE_FUNCTION) == n.getType()); } TEST_CASE("set type of node from non indexed") { - Node n( - 2, - NodeType(NODE_SYMBOL), - NameHierarchy(L"A", NAME_DELIMITER_CXX), - DEFINITION_EXPLICIT); + Node n(2, NodeType(NODE_SYMBOL), NameHierarchy(L"A", NAME_DELIMITER_CXX), DEFINITION_EXPLICIT); n.setType(NodeType(NODE_CLASS)); REQUIRE(NodeType(NODE_CLASS) == n.getType()); } TEST_CASE("can not change type of node after it was set") { - Node n( - 3, - NodeType(NODE_NAMESPACE), - NameHierarchy(L"A", NAME_DELIMITER_CXX), - DEFINITION_EXPLICIT); + Node n(3, NodeType(NODE_NAMESPACE), NameHierarchy(L"A", NAME_DELIMITER_CXX), DEFINITION_EXPLICIT); n.setType(NodeType(NODE_CLASS)); REQUIRE(NodeType(NODE_CLASS) != n.getType()); } TEST_CASE("node can be copied and keeps same id") { - Node n( - 4, - NodeType(NODE_NAMESPACE), - NameHierarchy(L"A", NAME_DELIMITER_CXX), - DEFINITION_EXPLICIT); + Node n(4, NodeType(NODE_NAMESPACE), NameHierarchy(L"A", NAME_DELIMITER_CXX), DEFINITION_EXPLICIT); Node n2(n); REQUIRE(&n != &n2); @@ -219,27 +191,15 @@ TEST_CASE("node can be copied and keeps same id") TEST_CASE("node type bit masking") { - Node n( - 1, - NodeType(NODE_NAMESPACE), - NameHierarchy(L"A", NAME_DELIMITER_CXX), - DEFINITION_EXPLICIT); + Node n(1, NodeType(NODE_NAMESPACE), NameHierarchy(L"A", NAME_DELIMITER_CXX), DEFINITION_EXPLICIT); REQUIRE(n.isType(NODE_FUNCTION | NODE_NAMESPACE | NODE_CLASS)); REQUIRE(!n.isType(NODE_FUNCTION | NODE_METHOD | NODE_CLASS)); } TEST_CASE("get type of edges") { - Node a( - 1, - NodeType(NODE_SYMBOL), - NameHierarchy(L"A", NAME_DELIMITER_CXX), - DEFINITION_EXPLICIT); - Node b( - 2, - NodeType(NODE_SYMBOL), - NameHierarchy(L"B", NAME_DELIMITER_CXX), - DEFINITION_EXPLICIT); + Node a(1, NodeType(NODE_SYMBOL), NameHierarchy(L"A", NAME_DELIMITER_CXX), DEFINITION_EXPLICIT); + Node b(2, NodeType(NODE_SYMBOL), NameHierarchy(L"B", NAME_DELIMITER_CXX), DEFINITION_EXPLICIT); Edge e(3, Edge::EDGE_USAGE, &a, &b); REQUIRE(Edge::EDGE_USAGE == e.getType()); @@ -247,16 +207,8 @@ TEST_CASE("get type of edges") TEST_CASE("edge can be copied and keeps same id") { - Node a( - 1, - NodeType(NODE_SYMBOL), - NameHierarchy(L"A", NAME_DELIMITER_CXX), - DEFINITION_EXPLICIT); - Node b( - 2, - NodeType(NODE_SYMBOL), - NameHierarchy(L"B", NAME_DELIMITER_CXX), - DEFINITION_EXPLICIT); + Node a(1, NodeType(NODE_SYMBOL), NameHierarchy(L"A", NAME_DELIMITER_CXX), DEFINITION_EXPLICIT); + Node b(2, NodeType(NODE_SYMBOL), NameHierarchy(L"B", NAME_DELIMITER_CXX), DEFINITION_EXPLICIT); Edge e(3, Edge::EDGE_USAGE, &a, &b); Edge e2(e, &a, &b); @@ -267,16 +219,8 @@ TEST_CASE("edge can be copied and keeps same id") TEST_CASE("edge type bit masking") { - Node a( - 1, - NodeType(NODE_SYMBOL), - NameHierarchy(L"A", NAME_DELIMITER_CXX), - DEFINITION_EXPLICIT); - Node b( - 2, - NodeType(NODE_SYMBOL), - NameHierarchy(L"B", NAME_DELIMITER_CXX), - DEFINITION_EXPLICIT); + Node a(1, NodeType(NODE_SYMBOL), NameHierarchy(L"A", NAME_DELIMITER_CXX), DEFINITION_EXPLICIT); + Node b(2, NodeType(NODE_SYMBOL), NameHierarchy(L"B", NAME_DELIMITER_CXX), DEFINITION_EXPLICIT); Edge e(3, Edge::EDGE_USAGE, &a, &b); REQUIRE(e.isType(Edge::EDGE_MEMBER | Edge::EDGE_CALL | Edge::EDGE_USAGE)); @@ -285,21 +229,9 @@ TEST_CASE("edge type bit masking") TEST_CASE("node finds child node") { - Node a( - 1, - NodeType(NODE_SYMBOL), - NameHierarchy(L"A", NAME_DELIMITER_CXX), - DEFINITION_EXPLICIT); - Node b( - 2, - NodeType(NODE_SYMBOL), - NameHierarchy(L"B", NAME_DELIMITER_CXX), - DEFINITION_EXPLICIT); - Node c( - 3, - NodeType(NODE_SYMBOL), - NameHierarchy(L"C", NAME_DELIMITER_CXX), - DEFINITION_EXPLICIT); + Node a(1, NodeType(NODE_SYMBOL), NameHierarchy(L"A", NAME_DELIMITER_CXX), DEFINITION_EXPLICIT); + Node b(2, NodeType(NODE_SYMBOL), NameHierarchy(L"B", NAME_DELIMITER_CXX), DEFINITION_EXPLICIT); + Node c(3, NodeType(NODE_SYMBOL), NameHierarchy(L"C", NAME_DELIMITER_CXX), DEFINITION_EXPLICIT); Edge e(4, Edge::EDGE_MEMBER, &a, &b); Edge e2(5, Edge::EDGE_MEMBER, &a, &c); @@ -311,21 +243,9 @@ TEST_CASE("node finds child node") TEST_CASE("node can not find child node") { - Node a( - 1, - NodeType(NODE_SYMBOL), - NameHierarchy(L"A", NAME_DELIMITER_CXX), - DEFINITION_EXPLICIT); - Node b( - 2, - NodeType(NODE_SYMBOL), - NameHierarchy(L"B", NAME_DELIMITER_CXX), - DEFINITION_EXPLICIT); - Node c( - 3, - NodeType(NODE_SYMBOL), - NameHierarchy(L"C", NAME_DELIMITER_CXX), - DEFINITION_EXPLICIT); + Node a(1, NodeType(NODE_SYMBOL), NameHierarchy(L"A", NAME_DELIMITER_CXX), DEFINITION_EXPLICIT); + Node b(2, NodeType(NODE_SYMBOL), NameHierarchy(L"B", NAME_DELIMITER_CXX), DEFINITION_EXPLICIT); + Node c(3, NodeType(NODE_SYMBOL), NameHierarchy(L"C", NAME_DELIMITER_CXX), DEFINITION_EXPLICIT); Edge e(4, Edge::EDGE_MEMBER, &a, &b); Edge e2(5, Edge::EDGE_MEMBER, &a, &c); @@ -336,21 +256,9 @@ TEST_CASE("node can not find child node") TEST_CASE("node visits child nodes") { - Node a( - 1, - NodeType(NODE_SYMBOL), - NameHierarchy(L"A", NAME_DELIMITER_CXX), - DEFINITION_EXPLICIT); - Node b( - 2, - NodeType(NODE_SYMBOL), - NameHierarchy(L"B", NAME_DELIMITER_CXX), - DEFINITION_EXPLICIT); - Node c( - 3, - NodeType(NODE_SYMBOL), - NameHierarchy(L"C", NAME_DELIMITER_CXX), - DEFINITION_EXPLICIT); + Node a(1, NodeType(NODE_SYMBOL), NameHierarchy(L"A", NAME_DELIMITER_CXX), DEFINITION_EXPLICIT); + Node b(2, NodeType(NODE_SYMBOL), NameHierarchy(L"B", NAME_DELIMITER_CXX), DEFINITION_EXPLICIT); + Node c(3, NodeType(NODE_SYMBOL), NameHierarchy(L"C", NAME_DELIMITER_CXX), DEFINITION_EXPLICIT); Edge e(4, Edge::EDGE_MEMBER, &a, &b); Edge e2(5, Edge::EDGE_MEMBER, &a, &c); @@ -366,15 +274,9 @@ TEST_CASE("graph saves nodes") { Graph graph; Node* a = graph.createNode( - 1, - NodeType(NODE_SYMBOL), - NameHierarchy(L"A", NAME_DELIMITER_CXX), - DEFINITION_EXPLICIT); + 1, NodeType(NODE_SYMBOL), NameHierarchy(L"A", NAME_DELIMITER_CXX), DEFINITION_EXPLICIT); Node* b = graph.createNode( - 2, - NodeType(NODE_SYMBOL), - NameHierarchy(L"B", NAME_DELIMITER_CXX), - DEFINITION_EXPLICIT); + 2, NodeType(NODE_SYMBOL), NameHierarchy(L"B", NAME_DELIMITER_CXX), DEFINITION_EXPLICIT); REQUIRE(2 == graph.getNodeCount()); REQUIRE(0 == graph.getEdgeCount()); @@ -393,15 +295,9 @@ TEST_CASE("graph saves edges") Graph graph; Node* a = graph.createNode( - 1, - NodeType(NODE_FUNCTION), - NameHierarchy(L"A", NAME_DELIMITER_CXX), - DEFINITION_EXPLICIT); + 1, NodeType(NODE_FUNCTION), NameHierarchy(L"A", NAME_DELIMITER_CXX), DEFINITION_EXPLICIT); Node* b = graph.createNode( - 2, - NodeType(NODE_FUNCTION), - NameHierarchy(L"B", NAME_DELIMITER_CXX), - DEFINITION_EXPLICIT); + 2, NodeType(NODE_FUNCTION), NameHierarchy(L"B", NAME_DELIMITER_CXX), DEFINITION_EXPLICIT); Edge* e = graph.createEdge(3, Edge::EDGE_CALL, a, b); @@ -417,15 +313,9 @@ TEST_CASE("graph removes nodes") Graph graph; Node* a = graph.createNode( - 1, - NodeType(NODE_SYMBOL), - NameHierarchy(L"A", NAME_DELIMITER_CXX), - DEFINITION_EXPLICIT); + 1, NodeType(NODE_SYMBOL), NameHierarchy(L"A", NAME_DELIMITER_CXX), DEFINITION_EXPLICIT); graph.createNode( - 2, - NodeType(NODE_SYMBOL), - NameHierarchy(L"B", NAME_DELIMITER_CXX), - DEFINITION_EXPLICIT); + 2, NodeType(NODE_SYMBOL), NameHierarchy(L"B", NAME_DELIMITER_CXX), DEFINITION_EXPLICIT); REQUIRE(2 == graph.getNodeCount()); REQUIRE(0 == graph.getEdgeCount()); diff --git a/src/test/UtilityStringTestSuite.cpp b/src/test/UtilityStringTestSuite.cpp index e9574d78..1f51e308 100644 --- a/src/test/UtilityStringTestSuite.cpp +++ b/src/test/UtilityStringTestSuite.cpp @@ -311,8 +311,9 @@ TEST_CASE("caseInsensitiveLess should return false when both wstrings are equal" REQUIRE_FALSE(utility::caseInsensitiveLess(L"ab_cd!", L"ab_cd!")); } -TEST_CASE("caseInsensitiveLess should return false when both wstrings have" - "different cases but after lower casing are equal") +TEST_CASE( + "caseInsensitiveLess should return false when both wstrings have" + "different cases but after lower casing are equal") { REQUIRE_FALSE(utility::caseInsensitiveLess(L"ab_CD!", L"aB_cD!")); } @@ -337,32 +338,44 @@ TEST_CASE("caseInsensitiveLess should return false when second wstring is prefix REQUIRE_FALSE(utility::caseInsensitiveLess(L"ab_cd!e", L"ab_cd!")); } -TEST_CASE("caseInsensitiveLess should return true when after lower casing first wstring, first is prefix of second") +TEST_CASE( + "caseInsensitiveLess should return true when after lower casing first wstring, first is prefix " + "of second") { REQUIRE(utility::caseInsensitiveLess(L"aB_cd!", L"ab_cd!e")); } -TEST_CASE("caseInsensitiveLess should return true when after lower casing second wstring, first is prefix of second") +TEST_CASE( + "caseInsensitiveLess should return true when after lower casing second wstring, first is " + "prefix of second") { REQUIRE(utility::caseInsensitiveLess(L"ab_cd!", L"ab_cD!e")); } -TEST_CASE("caseInsensitiveLess should return true when after lower casing both wstrings, first is prefix of second") +TEST_CASE( + "caseInsensitiveLess should return true when after lower casing both wstrings, first is prefix " + "of second") { REQUIRE(utility::caseInsensitiveLess(L"aB_cd!", L"ab_cD!E")); } -TEST_CASE("caseInsensitiveLess should return false when after lower casing first wstring, second is prefix of first") +TEST_CASE( + "caseInsensitiveLess should return false when after lower casing first wstring, second is " + "prefix of first") { REQUIRE_FALSE(utility::caseInsensitiveLess(L"ab_Cd!e", L"ab_cd!")); } -TEST_CASE("caseInsensitiveLess should return false when after lower casing second wstring, second is prefix of first") +TEST_CASE( + "caseInsensitiveLess should return false when after lower casing second wstring, second is " + "prefix of first") { REQUIRE_FALSE(utility::caseInsensitiveLess(L"ab_cd!e", L"Ab_cd!")); } -TEST_CASE("caseInsensitiveLess should return false when after lower casing both wstrings, second is prefix of first") +TEST_CASE( + "caseInsensitiveLess should return false when after lower casing both wstrings, second is " + "prefix of first") { REQUIRE_FALSE(utility::caseInsensitiveLess(L"ab_cD!E", L"aB_cd!")); }