wangzw / cppstyle Goto Github PK
View Code? Open in Web Editor NEWAn Eclipse plugin that integrates clang-format and cpplint (cpplint.py)
Home Page: https://zhanwei.wang/CppStyle/
License: MIT License
An Eclipse plugin that integrates clang-format and cpplint (cpplint.py)
Home Page: https://zhanwei.wang/CppStyle/
License: MIT License
Hi there,
I've been experiencing a null pointer exception under some circumstances when I use the CDT's "Organize imports" function. It seems this function calls ChangeFormatter.formatChangedCode(..)
, which calls ClangFormatFormatter.format(String source, String path, IRegion[] regions)
.
In the case in which there are no changes that need to be formatted, this method in ClangFormatFormatter returns null on line 226, which causes a null pointer exception in the ChangeFormatter on line 104.
As a temporary fix, I was able to avoid the error by removing lines 225-227 in ClangFormatFormatter. However, I'm not sure whether this results in correct behavior in all scenarios.
Best,
Eric
java.lang.NullPointerException
at java.io.File.(File.java:277)
at org.wangzw.plugin.cppstyle.ui.CppStylePropertyPage.constructPage(CppStylePropertyPage.java:137)
at org.wangzw.plugin.cppstyle.ui.CppStylePropertyPage.createContents(CppStylePropertyPage.java:194)
at org.eclipse.jface.preference.PreferencePage.createControl(PreferencePage.java:241)
at org.eclipse.jface.preference.PreferenceDialog.createPageControl(PreferenceDialog.java:1450)
at org.eclipse.jface.preference.PreferenceDialog$13.run(PreferenceDialog.java:1217)
at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
at org.eclipse.ui.internal.JFaceUtil$1.run(JFaceUtil.java:50)
at org.eclipse.jface.util.SafeRunnable.run(SafeRunnable.java:173)
at org.eclipse.jface.preference.PreferenceDialog.showPage(PreferenceDialog.java:1209)
at org.eclipse.ui.internal.dialogs.FilteredPreferenceDialog.showPage(FilteredPreferenceDialog.java:608)
at org.eclipse.jface.preference.PreferenceDialog$9$1.run(PreferenceDialog.java:675)
at org.eclipse.swt.custom.BusyIndicator.showWhile(BusyIndicator.java:70)
at org.eclipse.jface.preference.PreferenceDialog$9.selectionChanged(PreferenceDialog.java:670)
at org.eclipse.jface.viewers.StructuredViewer$3.run(StructuredViewer.java:877)
at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
at org.eclipse.ui.internal.JFaceUtil$1.run(JFaceUtil.java:50)
at org.eclipse.jface.util.SafeRunnable.run(SafeRunnable.java:173)
at org.eclipse.jface.viewers.StructuredViewer.firePostSelectionChanged(StructuredViewer.java:874)
at org.eclipse.jface.viewers.StructuredViewer.setSelection(StructuredViewer.java:1734)
at org.eclipse.jface.viewers.TreeViewer.setSelection(TreeViewer.java:1093)
at org.eclipse.jface.preference.PreferenceDialog.selectSavedItem(PreferenceDialog.java:1011)
at org.eclipse.ui.internal.dialogs.FilteredPreferenceDialog.selectSavedItem(FilteredPreferenceDialog.java:656)
at org.eclipse.jface.preference.PreferenceDialog$4.run(PreferenceDialog.java:351)
at org.eclipse.swt.custom.BusyIndicator.showWhile(BusyIndicator.java:70)
at org.eclipse.jface.preference.PreferenceDialog.createContents(PreferenceDialog.java:346)
at org.eclipse.jface.window.Window.create(Window.java:430)
at org.eclipse.jface.dialogs.Dialog.create(Dialog.java:1096)
at org.eclipse.ui.internal.dialogs.PropertyDialog.createDialogOn(PropertyDialog.java:83)
at org.eclipse.ui.dialogs.PropertyDialogAction.createDialog(PropertyDialogAction.java:174)
at org.eclipse.ui.dialogs.PropertyDialogAction.run(PropertyDialogAction.java:155)
at org.eclipse.ui.internal.ide.actions.ProjectPropertyDialogAction.run(ProjectPropertyDialogAction.java:78)
at org.eclipse.jface.action.Action.runWithEvent(Action.java:473)
at org.eclipse.jface.action.ActionContributionItem.handleWidgetSelection(ActionContributionItem.java:595)
at org.eclipse.jface.action.ActionContributionItem.access$2(ActionContributionItem.java:511)
at org.eclipse.jface.action.ActionContributionItem$5.handleEvent(ActionContributionItem.java:420)
at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
at org.eclipse.swt.widgets.Display.sendEvent(Display.java:4481)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1329)
at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:3819)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3430)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$4.run(PartRenderingEngine.java:1127)
at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:337)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.run(PartRenderingEngine.java:1018)
at org.eclipse.e4.ui.internal.workbench.E4Workbench.createAndRunUI(E4Workbench.java:156)
at org.eclipse.ui.internal.Workbench$5.run(Workbench.java:694)
at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:337)
at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:606)
at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:150)
at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:139)
at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:134)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:104)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:380)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:235)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:669)
at org.eclipse.equinox.launcher.Main.basicRun(Main.java:608)
at org.eclipse.equinox.launcher.Main.run(Main.java:1515)
at org.eclipse.equinox.launcher.Main.main(Main.java:1488)
Please provide manual setup instructions. It would be great if a jar file is attached to the website with manual setup instructions. This is required because sometimes, due to firewall restrictions, it could be difficult to connect to marketplace to get this plugin.
For example, moonrise theme for eclipse has manual setup instructions on git as ::
In the global preference formatter is set to CppStyle:
The projet is set to use the global formater:
But it does not work. I'm not sure what formatter it's using but it's not the right one. If I enable "Enable project specific setting" it's all good.
I'm also not sure about this but it seems under some condition that cppstyle is looking for the .clang-format file at the root of the workspace and not at the root of the project folder.
When using a .clang-format file with invalid contents like
invalid-key: invalid-value
the error message from .clang-format is inserted into the formatted source code.
It should rather be displayed in a warning dialog and probably also in the error log.
With the latest update CppStyle is now working very well for me. I was wondering if you could sign your plugin builds so that the eclipse security warning goes away. This guide appears to be a helpful how to on signing Eclipse plugins: https://nirmalsasidharan.wordpress.com/2010/09/04/signing_eclipse_plugins/
Hi,
I'd really like to integrate cpplint into our eclipse setup at work. Unfortunately, I have no experience with Eclipse plugins and now I don't know how to search for the origin of the problem I'm encountering.
If you can point me to a general resource about troubleshooting eclipse plugins, that would already be great.
The installation of the plugin seems to have worked, there is an entry for CpplintIssues in Preferences/C/C++/Code Analysis.
If I do "run C/C++ code analysis" I get a "Launching cpplint" in the console. I haven't found any way of getting more information about the invocation of cpplint.
However, I get no issues from cpplint (as opposed to running it as an external program).
I can run cpplint.py as an external program:
Path\to\cpplint.py --extensions=cpp,hpp ${resource_loc}
Therefore cpplint by itself cannot be completely broken.
Here's the basic information about the eclipse installation (on windows):
Eclipse IDE for C/C++ Developers
Version: Luna Release (4.4.0)
Build id: 20140612-0600
I get the following stacktrace whenever I try to use the refactoring feature of CDT in Eclipse Mars. This seems to be related to CppStyle.
Cyril
java.lang.reflect.InvocationTargetException
at org.eclipse.jface.operation.ModalContext.run(ModalContext.java:420)
at org.eclipse.ltk.internal.ui.refactoring.RefactoringWizardDialog2.run(RefactoringWizardDialog2.java:331)
at org.eclipse.ltk.ui.refactoring.RefactoringWizard.internalPerformFinish(RefactoringWizard.java:637)
at org.eclipse.ltk.ui.refactoring.UserInputWizardPage.performFinish(UserInputWizardPage.java:153)
at org.eclipse.ltk.ui.refactoring.RefactoringWizard.performFinish(RefactoringWizard.java:710)
at org.eclipse.cdt.internal.ui.refactoring.implementmethod.ImplementMethodWizard.performFinish(ImplementMethodWizard.java:113)
at org.eclipse.ltk.internal.ui.refactoring.RefactoringWizardDialog2.okPressed(RefactoringWizardDialog2.java:455)
at org.eclipse.jface.dialogs.Dialog.buttonPressed(Dialog.java:466)
at org.eclipse.jface.dialogs.Dialog$2.widgetSelected(Dialog.java:619)
at org.eclipse.swt.widgets.TypedListener.handleEvent(TypedListener.java:248)
at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
at org.eclipse.swt.widgets.Display.sendEvent(Display.java:4481)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1327)
at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:3819)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3430)
at org.eclipse.jface.window.Window.runEventLoop(Window.java:827)
at org.eclipse.jface.window.Window.open(Window.java:803)
at org.eclipse.ltk.ui.refactoring.RefactoringWizardOpenOperation$1.run(RefactoringWizardOpenOperation.java:187)
at org.eclipse.swt.custom.BusyIndicator.showWhile(BusyIndicator.java:70)
at org.eclipse.ltk.ui.refactoring.RefactoringWizardOpenOperation.run(RefactoringWizardOpenOperation.java:202)
at org.eclipse.ltk.ui.refactoring.RefactoringWizardOpenOperation.run(RefactoringWizardOpenOperation.java:122)
at org.eclipse.cdt.internal.ui.refactoring.RefactoringStarter.activate(RefactoringStarter.java:33)
at org.eclipse.cdt.internal.ui.refactoring.RefactoringRunner.run(RefactoringRunner.java:43)
at org.eclipse.cdt.internal.ui.refactoring.implementmethod.ImplementMethodRefactoringRunner.run(ImplementMethodRefactoringRunner.java:40)
at org.eclipse.cdt.ui.refactoring.actions.ImplementMethodAction.run(ImplementMethodAction.java:58)
at org.eclipse.cdt.ui.refactoring.actions.RefactoringAction.run(RefactoringAction.java:84)
at org.eclipse.jface.action.Action.runWithEvent(Action.java:473)
at org.eclipse.jface.action.ActionContributionItem.handleWidgetSelection(ActionContributionItem.java:595)
at org.eclipse.jface.action.ActionContributionItem.access$2(ActionContributionItem.java:511)
at org.eclipse.jface.action.ActionContributionItem$5.handleEvent(ActionContributionItem.java:420)
at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
at org.eclipse.swt.widgets.Display.sendEvent(Display.java:4481)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1327)
at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:3819)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3430)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$4.run(PartRenderingEngine.java:1127)
at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:337)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.run(PartRenderingEngine.java:1018)
at org.eclipse.e4.ui.internal.workbench.E4Workbench.createAndRunUI(E4Workbench.java:156)
at org.eclipse.ui.internal.Workbench$5.run(Workbench.java:654)
at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:337)
at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:598)
at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:150)
at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:139)
at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:134)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:104)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:380)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:235)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:669)
at org.eclipse.equinox.launcher.Main.basicRun(Main.java:608)
at org.eclipse.equinox.launcher.Main.run(Main.java:1515)
at org.eclipse.equinox.launcher.Main.main(Main.java:1488)
Caused by: java.lang.NullPointerException
at org.wangzw.plugin.cppstyle.ClangFormatFormatter.format(ClangFormatFormatter.java:68)
at org.eclipse.cdt.internal.formatter.ChangeFormatter.formatChangedCode(ChangeFormatter.java:100)
at org.eclipse.cdt.internal.core.dom.rewrite.changegenerator.ChangeGenerator.generateChange(ChangeGenerator.java:117)
at org.eclipse.cdt.internal.core.dom.rewrite.changegenerator.ChangeGenerator.generateChange(ChangeGenerator.java:104)
at org.eclipse.cdt.internal.core.dom.rewrite.ASTRewriteAnalyzer.rewriteAST(ASTRewriteAnalyzer.java:26)
at org.eclipse.cdt.core.dom.rewrite.ASTRewrite.rewriteAST(ASTRewrite.java:212)
at org.eclipse.cdt.internal.ui.refactoring.ModificationCollector.createFinalChange(ModificationCollector.java:85)
at org.eclipse.cdt.internal.ui.refactoring.CRefactoring.createChange(CRefactoring.java:177)
at org.eclipse.ltk.core.refactoring.CreateChangeOperation.run(CreateChangeOperation.java:124)
at org.eclipse.ltk.core.refactoring.PerformChangeOperation.run(PerformChangeOperation.java:209)
at org.eclipse.core.internal.resources.Workspace.run(Workspace.java:2241)
at org.eclipse.ltk.internal.ui.refactoring.WorkbenchRunnableAdapter.run(WorkbenchRunnableAdapter.java:87)
at org.eclipse.jface.operation.ModalContext$ModalContextThread.run(ModalContext.java:119)
Root exception:
java.lang.NullPointerException
at org.wangzw.plugin.cppstyle.ClangFormatFormatter.format(ClangFormatFormatter.java:68)
at org.eclipse.cdt.internal.formatter.ChangeFormatter.formatChangedCode(ChangeFormatter.java:100)
at org.eclipse.cdt.internal.core.dom.rewrite.changegenerator.ChangeGenerator.generateChange(ChangeGenerator.java:117)
at org.eclipse.cdt.internal.core.dom.rewrite.changegenerator.ChangeGenerator.generateChange(ChangeGenerator.java:104)
at org.eclipse.cdt.internal.core.dom.rewrite.ASTRewriteAnalyzer.rewriteAST(ASTRewriteAnalyzer.java:26)
at org.eclipse.cdt.core.dom.rewrite.ASTRewrite.rewriteAST(ASTRewrite.java:212)
at org.eclipse.cdt.internal.ui.refactoring.ModificationCollector.createFinalChange(ModificationCollector.java:85)
at org.eclipse.cdt.internal.ui.refactoring.CRefactoring.createChange(CRefactoring.java:177)
at org.eclipse.ltk.core.refactoring.CreateChangeOperation.run(CreateChangeOperation.java:124)
at org.eclipse.ltk.core.refactoring.PerformChangeOperation.run(PerformChangeOperation.java:209)
at org.eclipse.core.internal.resources.Workspace.run(Workspace.java:2241)
at org.eclipse.ltk.internal.ui.refactoring.WorkbenchRunnableAdapter.run(WorkbenchRunnableAdapter.java:87)
at org.eclipse.jface.operation.ModalContext$ModalContextThread.run(ModalContext.java:119)
Weirdly, if we run clang-format on save, it formats correctly using our .clang-format file.
However, if we format by ctrl-shift-f
, it formats using the default formatting (google?).
When I discovered this plugin, it was installable in Neon version of Eclipse. It's not possible anymore (can't find it in the marketplace). Is there any reason for that, our project is stuck on Neon at the moment (custom version of eclipse from our vendor)
When I run this, ocurr this message and it doesn't work.
My system infomation
OS: OS X 10.11.4
Eclipse Version: Mars.2 Release (4.5.2) (Build id: 20160218-0600)
clang-format version: 3.9.0
And this is .clang-format file contents:
---
Language: Cpp
# BasedOnStyle: Google
AccessModifierOffset: -1
AlignAfterOpenBracket: Align
AlignConsecutiveAssignments: false
AlignConsecutiveDeclarations: false
AlignEscapedNewlinesLeft: true
AlignOperands: true
AlignTrailingComments: true
AllowAllParametersOfDeclarationOnNextLine: true
AllowShortBlocksOnASingleLine: false
AllowShortCaseLabelsOnASingleLine: false
AllowShortFunctionsOnASingleLine: All
AllowShortIfStatementsOnASingleLine: true
AllowShortLoopsOnASingleLine: true
AlwaysBreakAfterDefinitionReturnType: None
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: true
AlwaysBreakTemplateDeclarations: true
BinPackArguments: true
BinPackParameters: true
BraceWrapping:
AfterClass: false
AfterControlStatement: false
AfterEnum: false
AfterFunction: false
AfterNamespace: false
AfterObjCDeclaration: false
AfterStruct: false
AfterUnion: false
BeforeCatch: false
BeforeElse: false
IndentBraces: false
BreakBeforeBinaryOperators: None
BreakBeforeBraces: Attach
BreakBeforeTernaryOperators: true
BreakConstructorInitializersBeforeComma: false
BreakAfterJavaFieldAnnotations: false
BreakStringLiterals: true
ColumnLimit: 80
CommentPragmas: '^ IWYU pragma:'
ConstructorInitializerAllOnOneLineOrOnePerLine: true
ConstructorInitializerIndentWidth: 4
ContinuationIndentWidth: 4
Cpp11BracedListStyle: true
DerivePointerAlignment: true
DisableFormat: false
ExperimentalAutoDetectBinPacking: false
ForEachMacros: [ foreach, Q_FOREACH, BOOST_FOREACH ]
IncludeCategories:
- Regex: '^<.*\.h>'
Priority: 1
- Regex: '^<.*'
Priority: 2
- Regex: '.*'
Priority: 3
IncludeIsMainRegex: '([-_](test|unittest))?$'
IndentCaseLabels: true
IndentWidth: 2
IndentWrappedFunctionNames: false
KeepEmptyLinesAtTheStartOfBlocks: false
MacroBlockBegin: ''
MacroBlockEnd: ''
MaxEmptyLinesToKeep: 1
NamespaceIndentation: None
ObjCBlockIndentWidth: 2
ObjCSpaceAfterProperty: false
ObjCSpaceBeforeProtocolList: false
PenaltyBreakBeforeFirstCallParameter: 1
PenaltyBreakComment: 300
PenaltyBreakFirstLessLess: 120
PenaltyBreakString: 1000
PenaltyExcessCharacter: 1000000
PenaltyReturnTypeOnItsOwnLine: 200
PointerAlignment: Left
ReflowComments: true
SortIncludes: true
SpaceAfterCStyleCast: false
SpaceBeforeAssignmentOperators: true
SpaceBeforeParens: ControlStatements
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 2
SpacesInAngles: false
SpacesInContainerLiterals: true
SpacesInCStyleCastParentheses: false
SpacesInParentheses: false
SpacesInSquareBrackets: false
Standard: Auto
TabWidth: 8
UseTab: Never
JavaScriptQuotes: Leave
...
For managing toolchains for older versions of our product, it would be great to be able to store the clang-format executable path in the project settings and not in the workspace settings.
This would also ease up using a version controlled Eclipse project with non-standard clang-format command: everything else comes from the project itself but now we need to manually set up clang-format path for the workspace.
After a broken update of Eclipse I tried to revert to a previous state (Help->Installation Details->Installation History) to regain a working version.
However, that older version also had an older version of CppStyle which is not available anymore on the update site.
Eclipse aborted reverting with the error message
An error occurred while collecting items to be installed
session context was:(profile=epp.package.cpp, phase=org.eclipse.equinox.internal.p2.engine.phases.Collect, operand=, action=).
No repository found containing: org.eclipse.update.feature,org.wangzw.cppstyle.feature,1.2.4.0
Being unable to revert CppStyle prevents the whole revert from taking place (although I could work with the newer version of CppStyle).
Please retain the older versions of CppStyle on the update site to allow for reverting.
Hi all,
I have just installed CppStyle plugin in Code Composer Studio, which is based in Eclipse.
Is there any way to configure in project settings a relative path to the project where it is clang format executable (i.e: .\project1\clang_format.exe?
Or by contrast only absolute paths are supported (i.e.: C:\my_projects\project1\clang_format.exe)?
Thanks in advance
When user selects a snippet in Eclipse editor and uses Ctrl+Shift+F to run clang-format for it, the location of the snippet is specified to clang-format using -offset and -length command line arguments.
Problem is that while clang-format expects them as bytes, CppStyle uses character counts. Considering Unicode characters, this goes easily wrong and the snippet selection becomes unreliable.
One way to tackle this is to use -lines instead of -offset/-length since clang-format also translates the -offset/-length into line numbers internally (no additional accuracy boost from using the byte definitions).
Are there any plans to support Java formatting? According to https://clang.llvm.org/docs/ClangFormat.html, this is supported by clang-format.
Presumably this would mostly be UI work, and clang-format could be called the same way?
It looks like the plugin has been temporarily removed from the Eclipse Marketplace because the install page only uses HTTP and not HTTPS. For more informations see https://gitlab.eclipse.org/eclipsefdn/security/public-tasks/-/issues/1
When using "Run clang-format on file save" the format is not run if the save is triggered by "Save automatically before build". Any type of save should trigger the format if "Run clang-format on file save" is selected.
The "Save" button is disabled state when a file is modified at the first time. After save it using "CTRL+S", modify this file again, it will become enabled state.
Ctrl+Shift+S shortcut (Save All) is often used by developers to save all modified files at once. In that case, CppStyle doesn't automatically format the content.
I'm getting the following stack trace:
java.lang.reflect.InvocationTargetException
at org.eclipse.jface.operation.ModalContext.run(ModalContext.java:398)
at org.eclipse.jface.wizard.WizardDialog.run(WizardDialog.java:980)
at org.eclipse.cdt.internal.ui.wizards.NewElementWizard.performFinish(NewElementWizard.java:98)
at org.eclipse.cdt.internal.ui.wizards.NewClassCreationWizard.performFinish(NewClassCreationWizard.java:71)
at org.eclipse.jface.wizard.WizardDialog.finishPressed(WizardDialog.java:778)
at org.eclipse.jface.wizard.WizardDialog.buttonPressed(WizardDialog.java:417)
at org.eclipse.jface.dialogs.Dialog.lambda$0(Dialog.java:619)
at org.eclipse.swt.events.SelectionListener$1.widgetSelected(SelectionListener.java:81)
at org.eclipse.swt.widgets.TypedListener.handleEvent(TypedListener.java:249)
at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:86)
at org.eclipse.swt.widgets.Display.sendEvent(Display.java:5268)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1348)
at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:4522)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:4107)
at org.eclipse.jface.window.Window.runEventLoop(Window.java:818)
at org.eclipse.jface.window.Window.open(Window.java:794)
at org.eclipse.ui.internal.navigator.wizards.WizardShortcutAction.run(WizardShortcutAction.java:99)
at org.eclipse.jface.action.Action.runWithEvent(Action.java:473)
at org.eclipse.jface.action.ActionContributionItem.handleWidgetSelection(ActionContributionItem.java:565)
at org.eclipse.jface.action.ActionContributionItem.lambda$4(ActionContributionItem.java:397)
at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:86)
at org.eclipse.swt.widgets.Display.sendEvent(Display.java:5268)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1348)
at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:4522)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:4107)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$5.run(PartRenderingEngine.java:1150)
at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:336)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.run(PartRenderingEngine.java:1039)
at org.eclipse.e4.ui.internal.workbench.E4Workbench.createAndRunUI(E4Workbench.java:153)
at org.eclipse.ui.internal.Workbench.lambda$3(Workbench.java:680)
at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:336)
at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:594)
at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:148)
at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:151)
at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:134)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:104)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:388)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:243)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:653)
at org.eclipse.equinox.launcher.Main.basicRun(Main.java:590)
at org.eclipse.equinox.launcher.Main.run(Main.java:1499)
at org.eclipse.equinox.launcher.Main.main(Main.java:1472)
Caused by: java.lang.NullPointerException
at org.wangzw.plugin.cppstyle.ClangFormatFormatter.getSourceFilePath(ClangFormatFormatter.java:77)
at org.wangzw.plugin.cppstyle.ClangFormatFormatter.format(ClangFormatFormatter.java:135)
at org.eclipse.cdt.internal.corext.util.CodeFormatterUtil.format(CodeFormatterUtil.java:125)
at org.eclipse.cdt.internal.corext.util.CodeFormatterUtil.format(CodeFormatterUtil.java:149)
at org.eclipse.cdt.internal.corext.util.CodeFormatterUtil.format(CodeFormatterUtil.java:144)
at org.eclipse.cdt.internal.ui.wizards.classwizard.NewClassCodeGenerator.formatSource(NewClassCodeGenerator.java:337)
at org.eclipse.cdt.internal.ui.wizards.classwizard.NewClassCodeGenerator.createClass(NewClassCodeGenerator.java:221)
at org.eclipse.cdt.ui.wizards.NewClassCreationWizardPage.createClass(NewClassCreationWizardPage.java:2109)
at org.eclipse.cdt.ui.wizards.NewClassCreationWizardPage.createClass(NewClassCreationWizardPage.java:2065)
at org.eclipse.cdt.internal.ui.wizards.NewClassCreationWizard.finishPage(NewClassCreationWizard.java:66)
at org.eclipse.cdt.internal.ui.wizards.NewElementWizard$2.run(NewElementWizard.java:94)
at org.eclipse.cdt.internal.core.model.BatchOperation.executeOperation(BatchOperation.java:36)
at org.eclipse.cdt.internal.core.model.CModelOperation.execute(CModelOperation.java:341)
at org.eclipse.cdt.internal.core.model.CModelOperation.run(CModelOperation.java:607)
at org.eclipse.core.internal.resources.Workspace.run(Workspace.java:2240)
at org.eclipse.core.internal.resources.Workspace.run(Workspace.java:2267)
at org.eclipse.cdt.core.model.CoreModel.run(CoreModel.java:1219)
at org.eclipse.cdt.internal.ui.actions.WorkbenchRunnableAdapter.run(WorkbenchRunnableAdapter.java:87)
at org.eclipse.jface.operation.ModalContext$ModalContextThread.run(ModalContext.java:119)
Root exception:
java.lang.NullPointerException
at org.wangzw.plugin.cppstyle.ClangFormatFormatter.getSourceFilePath(ClangFormatFormatter.java:77)
at org.wangzw.plugin.cppstyle.ClangFormatFormatter.format(ClangFormatFormatter.java:135)
at org.eclipse.cdt.internal.corext.util.CodeFormatterUtil.format(CodeFormatterUtil.java:125)
at org.eclipse.cdt.internal.corext.util.CodeFormatterUtil.format(CodeFormatterUtil.java:149)
at org.eclipse.cdt.internal.corext.util.CodeFormatterUtil.format(CodeFormatterUtil.java:144)
at org.eclipse.cdt.internal.ui.wizards.classwizard.NewClassCodeGenerator.formatSource(NewClassCodeGenerator.java:337)
at org.eclipse.cdt.internal.ui.wizards.classwizard.NewClassCodeGenerator.createClass(NewClassCodeGenerator.java:221)
at org.eclipse.cdt.ui.wizards.NewClassCreationWizardPage.createClass(NewClassCreationWizardPage.java:2109)
at org.eclipse.cdt.ui.wizards.NewClassCreationWizardPage.createClass(NewClassCreationWizardPage.java:2065)
at org.eclipse.cdt.internal.ui.wizards.NewClassCreationWizard.finishPage(NewClassCreationWizard.java:66)
at org.eclipse.cdt.internal.ui.wizards.NewElementWizard$2.run(NewElementWizard.java:94)
at org.eclipse.cdt.internal.core.model.BatchOperation.executeOperation(BatchOperation.java:36)
at org.eclipse.cdt.internal.core.model.CModelOperation.execute(CModelOperation.java:341)
at org.eclipse.cdt.internal.core.model.CModelOperation.run(CModelOperation.java:607)
at org.eclipse.core.internal.resources.Workspace.run(Workspace.java:2240)
at org.eclipse.core.internal.resources.Workspace.run(Workspace.java:2267)
at org.eclipse.cdt.core.model.CoreModel.run(CoreModel.java:1219)
at org.eclipse.cdt.internal.ui.actions.WorkbenchRunnableAdapter.run(WorkbenchRunnableAdapter.java:87)
at org.eclipse.jface.operation.ModalContext$ModalContextThread.run(ModalContext.java:119)
Session data:
eclipse.buildId=4.7.1.M20171009-0410
java.version=1.8.0_112-google-v7
java.vendor=Google Inc.
BootLoader constants: OS=linux, ARCH=x86_64, WS=gtk, NL=en_US
Framework arguments: -product org.eclipse.epp.package.cpp.product
Command-line arguments: -data file:/usr/local/google/home/dmurph/eclipse-workspace-oxygen/ -os linux -ws gtk -arch x86_64 -product org.eclipse.epp.package.cpp.product
Everytime the formatter is used, the console displays
Use clang-format configure file (...
Run clang-format command: /usr/bin/clang-format -assume-filename=...
In itself this is not a problem, but the console gets the focus everytime this happens.
This means that the previously visible tab in the same group as the console (e.g. Problems, Tasks, ...) becomes hidden by the console.
It would be nice if there was an option to disable the focus switch.
It doesn't seem to be possible to run cpplint.py on *.c files with this plugin. On the command line I can run cpplint.py --extensions=c,h foo.c
, but I can't give an argument to cpplint.py in the CppStyle settings dialog.
I even tried to make cpplint.py natively support the c extension, by amending the variable _valid_extensions
in the Python code. Then it works on the command line even without the --extensions=
argument. But strangely, CppStyle still doesn't work with *.c files.
Are there any plans to support this, or is there any possible workaround?
I cannot reach cppstyle.com, neither from my web browser nor from Eclipse. As a result, I cannot update/install the CppStyle plugin.
This issue seems to be present for other people too: https://downforeveryoneorjustme.com/cppstyle.com
First of all thanks for the great extension.
To the issue:
I've seen that with Eclipse Oxygen.1a the clang-formatter does not run after save if saving via "Save all".
By hitting Crtl + S or "Save" the file is formatted and saved as expected.
I think that the normal behavior would be to also format all files that are not saved when saving via "save all"
Right now the cdt(http://download.eclipse.org/tools/cdt/releases/9.3
) repo required at pom.xml is missing.
Using the mvn clean install
would fail.
Since I upgraded to the latest version (1.5.0.0), I get NPE every time I call the organize includes operation.
java.lang.NullPointerException
at org.wangzw.plugin.cppstyle.ClangFormatFormatter.getSourceFilePath(ClangFormatFormatter.java:77)
at org.wangzw.plugin.cppstyle.ClangFormatFormatter.format(ClangFormatFormatter.java:135)
at org.eclipse.cdt.core.formatter.CodeFormatter.format(CodeFormatter.java:116)
at org.eclipse.cdt.internal.formatter.ChangeFormatter.formatChangedCode(ChangeFormatter.java:100)
at org.eclipse.cdt.internal.ui.refactoring.includes.IncludeOrganizer.organizeIncludes(IncludeOrganizer.java:331)
at org.eclipse.cdt.internal.ui.editor.OrganizeIncludesAction$1.run(OrganizeIncludesAction.java:89)
at org.eclipse.core.internal.jobs.Worker.run(Worker.java:56)
eclipse.buildId=4.7.1.M20171009-0410
java.version=1.8.0_144
java.vendor=Oracle Corporation
BootLoader constants: OS=linux, ARCH=x86_64, WS=gtk, NL=en_US
Framework arguments: -product org.eclipse.epp.package.cpp.product
Command-line arguments: -os linux -ws gtk -arch x86_64 -product org.eclipse.epp.package.cpp.product
The -fallback-style
command line parameter is not available in all versions of clang-format and older versions of clang-format will fail to run if the command line option is passed.
I am forced to use an older development environment which only supports clang-format v3.4. This version of clang-format does not support the fallback style option, so cppstyle fails.
Perhaps an option to enable / disable this feature?
Some source menu entries like "Implement Method ... " trigger a formatter call for the newly inserted code.
Using CppStyle under Eclipse Mars "Implement Method" triggers the error:
Plug-in "org.wangzw.cppstyle" was unable to instantiate class "org.wangzw.plugin.cppstyle.CppCodeFormatter".
org.eclipse.swt.SWTException: Invalid thread access
at org.eclipse.swt.SWT.error(SWT.java:4491)
at org.eclipse.swt.SWT.error(SWT.java:4406)
at org.eclipse.swt.SWT.error(SWT.java:4377)
at org.eclipse.swt.widgets.Display.error(Display.java:1186)
at org.eclipse.swt.widgets.Display.checkDevice(Display.java:765)
at org.eclipse.swt.widgets.Display.getSystemColor(Display.java:2138)
at org.wangzw.plugin.cppstyle.CppCodeFormatter.setupConsoleStream(CppCodeFormatter.java:613)
at org.wangzw.plugin.cppstyle.CppCodeFormatter.<init>(CppCodeFormatter.java:56)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:422)
at java.lang.Class.newInstance(Class.java:442)
at org.eclipse.core.internal.registry.osgi.RegistryStrategyOSGI.createExecutableExtension(RegistryStrategyOSGI.java:184)
at org.eclipse.core.internal.registry.ExtensionRegistry.createExecutableExtension(ExtensionRegistry.java:905)
at org.eclipse.core.internal.registry.ConfigurationElement.createExecutableExtension(ConfigurationElement.java:243)
at org.eclipse.core.internal.registry.ConfigurationElementHandle.createExecutableExtension(ConfigurationElementHandle.java:55)
at org.eclipse.cdt.core.ToolFactory.createCodeFormatter(ToolFactory.java:56)
at org.eclipse.cdt.internal.formatter.ChangeFormatter.formatChangedCode(ChangeFormatter.java:98)
at org.eclipse.cdt.internal.core.dom.rewrite.changegenerator.ChangeGenerator.generateChange(ChangeGenerator.java:117)
at org.eclipse.cdt.internal.core.dom.rewrite.changegenerator.ChangeGenerator.generateChange(ChangeGenerator.java:104)
at org.eclipse.cdt.internal.core.dom.rewrite.ASTRewriteAnalyzer.rewriteAST(ASTRewriteAnalyzer.java:26)
at org.eclipse.cdt.core.dom.rewrite.ASTRewrite.rewriteAST(ASTRewrite.java:212)
at org.eclipse.cdt.internal.ui.refactoring.ModificationCollector.createFinalChange(ModificationCollector.java:85)
at org.eclipse.cdt.internal.ui.refactoring.CRefactoring.createChange(CRefactoring.java:177)
at org.eclipse.ltk.core.refactoring.CreateChangeOperation.run(CreateChangeOperation.java:124)
at org.eclipse.ltk.core.refactoring.PerformChangeOperation.run(PerformChangeOperation.java:209)
at org.eclipse.core.internal.resources.Workspace.run(Workspace.java:2241)
at org.eclipse.ltk.internal.ui.refactoring.WorkbenchRunnableAdapter.run(WorkbenchRunnableAdapter.java:87)
at org.eclipse.jface.operation.ModalContext$ModalContextThread.run(ModalContext.java:119)
IIRC you used the currently active editor to determin the path of the file that is currently being formatted. Unfortunately, this is not sufficient for many applications of the formatter, like mass formatting or formatting after automatic source transformations.
I stumbled into the same problem when I implemented my own clang-format plugin. Maybe some of the code there is of use to you.
My project is not inside the workspace folder, it is located at: c:\projects\project1\
and I'm not supposed to change it.
The error message is the following:
Cannot find clang-format configure file under any level parent directories of path (C:\Users\alex\workspace\a.cc).
Run clang-format with Google style by default.
to be consistent with clang-format
This is awesome!
Instructions are pretty clear, but it's not clear at all how do I invoke cpplint?
Cmd-Shift-i calls clang-format, that's clear enough, but what about cpplint?
Thanks in advance!
Hi,
We use your plugin for a project, that mainly uses *.hpp header files. And "modified" it to incorporate hpp header files for that purpose. As I assume, that we are not the only ones, that actually need this, I would suggest to add this within the CpplintChecker.java file.
greetings,
grb19
Your website is being black-listed as spyware by Barracuda Web Security Gateway:
The link you are accessing has been blocked by the Barracuda Web Security Gateway because it
contains spyware. The name of the spyware is: Spyware.Exploit.BRTS.cppstyle.com
Any ideas why?
I have been a very happy user of Cppstyle for some time now. Thanks for the tool!
However, after I updated to Eclipse 2019-06 (4.12.6) Build id 20190614-1200, clang-format is not invoked on the file being saved (ctrl-s) as it used to be the case. I have verified that "Run clang-format on file save" is checked in the selection hierarchy Preferences -> C/C++ -> Cppstyle .
Would someone know how to address this issue?
Thanks for any help!
When I format code with clang-format through cppstyle, some characters get replaced by ? (Moritz Höwer --> Moritz H?wer) (Angle: 90° --> Angle: 90?).
This does not happen when I run clang-format directly (on the command line).
Seems to be a problem with character encoding...my Eclipse Workspace is set to UTF-8.
I just gave this plugin a try with Eclipse Luna and clang-format 3.5, and it works great. Thanks for releasing this. I noticed you have an option to run cpplint on save. Can we we add the option to run clang-format on save? It's nice to just have formatting cleaned up as you go.
Hi, I met a problem about running cpplint. When I save the file, the console outputs like this:
Cannot find clang-format configure file under any level parent directories of path (cpp file omitted).
Run clang-format with Google style by default.
Run clang-format command: /usr/local/Cellar/clang-format/2015-04-02/bin/clang-format -assume-filename=(cpp file omitted) -style=Google
And clang-format runs ok, but cpplint has no response, how can I find the problem?
Thank you very much.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.