├── .gitignore ├── CppTools.iml ├── CppTools_Cardea.ipr ├── CppTools_Cassiopeia.ipr ├── LICENSE.txt ├── META-INF ├── exended_platform.xml └── plugin.xml ├── README.md ├── build.xml ├── log4j.dtd ├── src ├── com │ └── advancedtools │ │ └── cpp │ │ ├── CppBraceMatcher.java │ │ ├── CppBundle.java │ │ ├── CppBundle.properties │ │ ├── CppColorsAndFontsPage.java │ │ ├── CppCommenter.java │ │ ├── CppDeclarationRangeHandler.java │ │ ├── CppDefinitionSearcher.java │ │ ├── CppElementType.java │ │ ├── CppFileTypeFactory.java │ │ ├── CppFindUsagesProvider.java │ │ ├── CppFoldingBuilder.java │ │ ├── CppFormattingModelBuilder.java │ │ ├── CppHighlighter.java │ │ ├── CppLanguage.java │ │ ├── CppLexer.flex │ │ ├── CppNamesValidator.java │ │ ├── CppParameterInfo.java │ │ ├── CppParserDefinition.java │ │ ├── CppProjectConfigurableProvider.java │ │ ├── CppQuoteHandler.java │ │ ├── CppReferencesSearcher.java │ │ ├── CppRenameHandler.java │ │ ├── CppSelectioner.java │ │ ├── CppStructureViewBuilder.java │ │ ├── CppSupportLoader.java │ │ ├── CppSupportSettings.java │ │ ├── CppSurroundDescriptor.java │ │ ├── CppTokenTypes.java │ │ ├── ErrorReporter.form │ │ ├── ErrorReporter.java │ │ ├── LanguageFeatureAware.java │ │ ├── _CppLexer.java │ │ ├── actions │ │ ├── AboutAction.java │ │ ├── AddOrRemoveCppFileFromAnalysisScopeAction.java │ │ ├── BaseEditorAction.java │ │ ├── BuildCppAction.java │ │ ├── BuildProperties.form │ │ ├── CompileCppAction.java │ │ ├── CompileProperties.form │ │ ├── GotoBaseAction.java │ │ ├── GotoConstAction.java │ │ ├── GotoInheritorsAction.java │ │ ├── GotoMacroAction.java │ │ ├── GotoSupersAction.java │ │ ├── IndentSelectionAction.java │ │ ├── SendCommandDialogForm.form │ │ ├── SendSomeTextToServerAction.java │ │ ├── ShowAllProblemsInProjectAction.java │ │ ├── ShowPreprocessedTextAction.java │ │ ├── generate │ │ │ ├── BaseGenerateAction.java │ │ │ ├── GenerateAssignmentOperatorAction.java │ │ │ ├── GenerateCaseBranchesFromEnumAction.java │ │ │ ├── GenerateContructorAction.java │ │ │ ├── GenerateContructorWithParametersAction.java │ │ │ └── GenerateCopyContructorAction.java │ │ └── refactoring │ │ │ ├── ChangesSupport.java │ │ │ └── MoveMethodDefinitionToDeclarationAction.java │ │ ├── build │ │ ├── BaseBuildHandler.java │ │ ├── BasicFormatFilter.java │ │ ├── BuildState.java │ │ ├── BuildTarget.java │ │ ├── BuildUtils.java │ │ ├── ConsoleBuilder.java │ │ ├── MakeBuildHandler.java │ │ ├── NMakeBuildHandler.java │ │ └── VisualStudioBuildHandler.java │ │ ├── c_file_obj.gif │ │ ├── commands │ │ ├── BlockingStringCommand.java │ │ ├── ChangedCommand.java │ │ ├── CompletionCommand.java │ │ ├── EnumerateSymbolsCommand.java │ │ ├── FindSymbolsCommand.java │ │ ├── FindUsagesCommand.java │ │ ├── GenerateSomethingCommand.java │ │ ├── ImplementSomethingCommand.java │ │ ├── NavigationCommand.java │ │ ├── SelectWordCommand.java │ │ ├── ShowPreprocessedCommand.java │ │ └── StringCommand.java │ │ ├── communicator │ │ ├── BlockingCommand.java │ │ ├── BuildingCommandHelper.java │ │ ├── Communicator.java │ │ ├── CommunicatorCommand.java │ │ ├── LoadingCppProjectDialog.form │ │ ├── LoadingCppProjectDialog.java │ │ ├── ServerExecutableState.java │ │ ├── WarnAboutFilesOutOfSourceRootsDialog.form │ │ └── WarnAboutFilesOutOfSourceRootsDialog.java │ │ ├── completion │ │ ├── CppCompletionConfidence.java │ │ └── CppCompletionContributor.java │ │ ├── debugger │ │ ├── CppBaseDebugRunner.java │ │ ├── CppBreakpointManager.java │ │ ├── CppBreakpointType.java │ │ ├── CppDebugProcess.java │ │ ├── CppDebugRunner.java │ │ ├── CppDebuggerConstants.java │ │ ├── CppStackFrame.java │ │ ├── CppSuspendContext.java │ │ ├── CppThreadStackInfo.java │ │ ├── commands │ │ │ ├── AddBreakpointCommand.java │ │ │ ├── ContinueCommand.java │ │ │ ├── CppDebuggerContext.java │ │ │ ├── DebuggerCommand.java │ │ │ ├── QuitCommand.java │ │ │ ├── ReadOutputCommand.java │ │ │ ├── RemoveBreakpointCommand.java │ │ │ ├── StartupCommand.java │ │ │ └── TextDebuggerCommand.java │ │ └── remote │ │ │ ├── CppRemoteDebugConfiguration.java │ │ │ ├── CppRemoteDebugConfigurationType.java │ │ │ ├── CppRemoteDebugParameters.java │ │ │ ├── CppRemoteDebugRunner.java │ │ │ ├── CppRemoteDebugSettingEditor.form │ │ │ └── CppRemoteDebugSettingEditor.java │ │ ├── facade │ │ ├── CppCodeFragment.java │ │ ├── CppCompiler.java │ │ ├── CppDocumentationProvider.java │ │ ├── CppGotoTargetRendererProvider.java │ │ ├── CppIconProvider.java │ │ ├── CppOverrideImplementMethodHandler.java │ │ ├── EnvironmentFacade.java │ │ ├── ExtendedPlatformServices.java │ │ ├── GotoSuperActionHandler.java │ │ ├── LanguageAwareStructureViewFactory.java │ │ └── LanguageAwareSyntaxHighlighterFactory.java │ │ ├── hilighting │ │ ├── AnalyzeProcessor.java │ │ ├── CppErrorHighlightingHandler.java │ │ ├── CppHighlightingPassFactoryBase.java │ │ ├── CppOverridenHighlightingPassFactory.java │ │ ├── CppSimpleEditorHighlightingPassFactory.java │ │ ├── Fix.java │ │ ├── HighlightCommand.java │ │ └── HighlightUtils.java │ │ ├── include_obj.gif │ │ ├── inspections │ │ ├── BaseCppInspection.java │ │ ├── CppInspectionsHighlightingHandler.java │ │ ├── JNIFunction2JavaMethodBinding.java │ │ ├── JNIImplementationsInspection.java │ │ ├── NativeJavaMethodsInspection.java │ │ ├── NativeMethod2JNIFunctionBinding.java │ │ └── UnusedCppSymbolInspection.java │ │ ├── makefile.gif │ │ ├── makefile │ │ ├── MakefileColorsAndFontsPage.java │ │ ├── MakefileCommenter.java │ │ ├── MakefileElementType.java │ │ ├── MakefileFindUsagesProvider.java │ │ ├── MakefileIdentifierReference.java │ │ ├── MakefileLanguage.java │ │ ├── MakefileLexer.flex │ │ ├── MakefileLexer.java │ │ ├── MakefileNamedElement.java │ │ ├── MakefileParserDefinition.java │ │ ├── MakefilePsiElement.java │ │ ├── MakefileSyntaxHighlighter.java │ │ ├── MakefileTokenTypes.java │ │ ├── _MakefileLexer.java │ │ └── makefile-flex.skeleton │ │ ├── navigation │ │ ├── BaseCppSymbolContributor.java │ │ ├── CppFileContributor.java │ │ ├── CppSymbolContributor.java │ │ └── CppTypeContributor.java │ │ ├── psi │ │ ├── CppElement.java │ │ ├── CppElementVisitor.java │ │ ├── CppFile.java │ │ ├── CppKeyword.java │ │ ├── ICppCodeFragment.java │ │ ├── ICppElement.java │ │ ├── MyLookupItem.java │ │ ├── MyPsiPolyVariantReference.java │ │ └── PsiElementResolveResult.java │ │ ├── refactoring │ │ ├── CppInlineHandler.java │ │ ├── CppRefactoringSupportProvider.java │ │ ├── ExtractFunctionDialog.form │ │ ├── ExtractFunctionDialog.java │ │ ├── IntroduceVariableDialog.form │ │ └── IntroduceVariableDialog.java │ │ ├── run │ │ ├── BaseCppConfiguration.java │ │ ├── BaseCppRunSettingsEditor.java │ │ ├── BaseCppRunnerParameters.java │ │ ├── CppRunConfiguration.java │ │ ├── CppRunConfigurationType.java │ │ ├── CppRunSettingsEditor.form │ │ ├── CppRunSettingsEditor.java │ │ ├── CppRunner.java │ │ └── CppRunnerParameters.java │ │ ├── sdk │ │ ├── BuildFileType.java │ │ ├── ChooseCppSdk.form │ │ ├── ChooseCppSdkStep.java │ │ ├── CppModuleBuilder.java │ │ ├── CppModuleConfigurationEditorProvider.java │ │ ├── CppModuleType.java │ │ ├── CppSdkType.java │ │ ├── CreateEntryCodeStep.form │ │ ├── CreateEntryCodeStep.java │ │ └── EntryPointType.java │ │ ├── settings │ │ ├── AbstractFileListEditor.java │ │ ├── CppHighlightingSettings.form │ │ ├── CppHighlightingSettings.java │ │ ├── IncludeFilesListEditor.java │ │ ├── IncludePathesListEditor.java │ │ ├── MacrosListEditor.java │ │ ├── ProjectSettings.form │ │ ├── Settings.form │ │ ├── StringListEditor.form │ │ ├── StringListEditor.java │ │ └── ValidatingFilePathCellRenderer.java │ │ ├── usages │ │ ├── FileUsage.java │ │ ├── FileUsageList.java │ │ └── OurUsage.java │ │ └── utils │ │ ├── About.form │ │ ├── IconableGutterNavigator.java │ │ ├── LM.java │ │ ├── NavigationUtils.java │ │ ├── Register.form │ │ ├── StringTokenizerIterable.java │ │ └── TemplateUtils.java ├── fileTemplates │ ├── C_Main.c.ft │ ├── Cpp_Main.cpp.ft │ └── Makefile.empty.ft └── inspectionDescriptions │ ├── JNIImplementations.html │ ├── NativeJavaMethods.html │ └── UnusedCppSymbol.html ├── testData ├── makefile_parsing │ ├── CheckRefResolve.mk │ ├── CheckRefResolve2.mk │ ├── CheckRefResolve3.mk │ ├── CompleteTargetRef.mk │ ├── CompleteTargetRef_after.mk │ ├── CompleteVar.mk │ ├── CompleteVar_after.mk │ ├── Makefile1.mk │ ├── Makefile1.txt │ ├── Makefile2.mk │ ├── Makefile2.txt │ ├── Makefile3.mk │ └── Makefile3.txt ├── parsing │ ├── ParseWithMacrosDef.cpp │ ├── ParseWithMacrosDef.txt │ ├── ParseWithNs.cpp │ ├── ParseWithNs.txt │ ├── SimpleParse.cpp │ └── SimpleParse.txt └── project_files │ ├── A.dsp │ └── A.vcproj └── testSrc └── tests ├── BaseCppTestCase.java ├── CppParsingTest.java ├── CppProjectFilesScanningTest.java ├── HighlightCommandTest.java ├── MakefileParsingTest.java └── ToolOutputParsingTest.java /.gitignore: -------------------------------------------------------------------------------- 1 | classes/ 2 | target/ 3 | CppTools.zip 4 | *.iws 5 | -------------------------------------------------------------------------------- /CppTools.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /META-INF/exended_platform.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | com.advancedtools.cpp.sdk.CppSdkType 6 | 7 | 8 | com.advancedtools.cpp.sdk.CppModuleType 9 | 10 | 11 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 1. Plugin needs IntelliJ IDEA Plugin SDK defined and named as "IDEA", or you will need to modify the customJdkName 2 | field in the CppTools_Cardea.ipr with the name of your plugin SDK. 3 | 2. Ant file needs IDEA_SANDBOX_HOME_PATH variable defined in settings, that is location defined in Idea plugin sdk. 4 | 3. Ant file assumes that native analyzer binaries and its resources are located in paret directory of the project. 5 | When developing plugin stand-alone these binaries and resources are located in "lib" directory of existing plugin. 6 | 4. Ant will also require a "DOC" directory exists in the parent directory of the project, so you will want to create it. -------------------------------------------------------------------------------- /build.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /src/com/advancedtools/cpp/CppBraceMatcher.java: -------------------------------------------------------------------------------- 1 | // Copyright 2006-2012 AdvancedTools. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. 2 | package com.advancedtools.cpp; 3 | 4 | import com.intellij.lang.PairedBraceMatcher; 5 | import com.intellij.lang.BracePair; 6 | import com.intellij.psi.tree.IElementType; 7 | import com.intellij.psi.PsiFile; 8 | import org.jetbrains.annotations.NotNull; 9 | import org.jetbrains.annotations.Nullable; 10 | 11 | /** 12 | * @author maxim 13 | * Date: 23.09.2006 14 | * Time: 3:16:22w 15 | */ 16 | public class CppBraceMatcher implements PairedBraceMatcher { 17 | private static final BracePair[] PAIRS = new BracePair[] { 18 | new BracePair(CppTokenTypes.LPAR, CppTokenTypes.RPAR, false), 19 | new BracePair(CppTokenTypes.LBRACKET, CppTokenTypes.RBRACKET, false), 20 | new BracePair(CppTokenTypes.LBRACE, CppTokenTypes.RBRACE, true) 21 | }; 22 | 23 | public BracePair[] getPairs() { 24 | return PAIRS; 25 | } 26 | 27 | public boolean isPairedBracesAllowedBeforeType(@NotNull IElementType iElementType, @Nullable IElementType tokenType) { 28 | if (tokenType == CppTokenTypes.WHITE_SPACE || 29 | CppTokenTypes.COMMENTS.contains(tokenType) || 30 | CppTokenTypes.RBRACE == tokenType || 31 | null == tokenType || 32 | CppTokenTypes.COMMA == tokenType || 33 | CppTokenTypes.SEMICOLON == tokenType || 34 | CppTokenTypes.COLON == tokenType || 35 | CppTokenTypes.RPAR == tokenType || 36 | CppTokenTypes.RBRACKET == tokenType 37 | ) { 38 | return true; 39 | } 40 | return false; 41 | } 42 | 43 | // IDEA8 44 | public int getCodeConstructStart(PsiFile psiFile, int i) { 45 | return i; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/com/advancedtools/cpp/CppBundle.java: -------------------------------------------------------------------------------- 1 | // Copyright 2006-2012 AdvancedTools. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. 2 | package com.advancedtools.cpp; 3 | 4 | import org.jetbrains.annotations.NonNls; 5 | import org.jetbrains.annotations.PropertyKey; 6 | 7 | import java.util.ResourceBundle; 8 | import java.lang.ref.Reference; 9 | 10 | import com.intellij.CommonBundle; 11 | import com.intellij.reference.SoftReference; 12 | 13 | /** 14 | * @author maxim 15 | * Date: 21.09.2006 16 | * Time: 5:05:57 17 | */ 18 | public class CppBundle { 19 | private static Reference ourBundle; 20 | 21 | @NonNls private static final String BUNDLE = "com.advancedtools.cpp.CppBundle"; 22 | 23 | private CppBundle() {} 24 | 25 | public static String message(@NonNls @PropertyKey(resourceBundle = BUNDLE)String key, Object... params) { 26 | return CommonBundle.message(getBundle(), key, params); 27 | } 28 | 29 | private static ResourceBundle getBundle() { 30 | ResourceBundle bundle = null; 31 | if (ourBundle != null) bundle = ourBundle.get(); 32 | if (bundle == null) { 33 | bundle = ResourceBundle.getBundle(BUNDLE); 34 | ourBundle = new SoftReference(bundle); 35 | } 36 | return bundle; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/com/advancedtools/cpp/CppCommenter.java: -------------------------------------------------------------------------------- 1 | // Copyright 2006-2012 AdvancedTools. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. 2 | package com.advancedtools.cpp; 3 | 4 | import com.intellij.lang.Commenter; 5 | import org.jetbrains.annotations.Nullable; 6 | 7 | /** 8 | * @author maxim 9 | * Date: 2/3/12 10 | * Time: 1:28 PM 11 | */ 12 | public class CppCommenter implements Commenter { 13 | @Nullable 14 | public String getLineCommentPrefix() { 15 | return "//"; 16 | } 17 | 18 | @Nullable 19 | public String getBlockCommentPrefix() { 20 | return "/*"; 21 | } 22 | 23 | @Nullable 24 | public String getBlockCommentSuffix() { 25 | return "*/"; 26 | } 27 | 28 | public String getCommentedBlockCommentPrefix() { 29 | return null; 30 | } 31 | 32 | public String getCommentedBlockCommentSuffix() { 33 | return null; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/com/advancedtools/cpp/CppDeclarationRangeHandler.java: -------------------------------------------------------------------------------- 1 | // Copyright 2006-2012 AdvancedTools. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. 2 | package com.advancedtools.cpp; 3 | 4 | import com.intellij.codeInsight.hint.DeclarationRangeHandler; 5 | import org.jetbrains.annotations.NotNull; 6 | import com.intellij.openapi.util.TextRange; 7 | import com.intellij.psi.PsiElement; 8 | import com.intellij.psi.PsiFile; 9 | 10 | /** 11 | * User: maxim 12 | * Date: 10.01.2009 13 | * Time: 19:28:37 14 | */ 15 | public class CppDeclarationRangeHandler implements DeclarationRangeHandler { 16 | @NotNull 17 | public TextRange getDeclarationRange(@NotNull PsiElement container) { 18 | PsiElement e = container; 19 | while(e.getNode().getElementType() != CppTokenTypes.BLOCK) { 20 | e = e.getParent(); 21 | if (e instanceof PsiFile) break; 22 | } 23 | return e.getTextRange(); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/com/advancedtools/cpp/CppElementType.java: -------------------------------------------------------------------------------- 1 | // Copyright 2006-2012 AdvancedTools. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. 2 | package com.advancedtools.cpp; 3 | 4 | import com.intellij.psi.tree.IElementType; 5 | 6 | /** 7 | * @author maxim 8 | * Date: 21.09.2006 9 | * Time: 5:29:48 10 | */ 11 | public class CppElementType extends IElementType { 12 | public CppElementType(String s) { 13 | super(s, CppSupportLoader.CPP_FILETYPE.getLanguage()); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/com/advancedtools/cpp/CppFileTypeFactory.java: -------------------------------------------------------------------------------- 1 | // Copyright 2006-2012 AdvancedTools. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. 2 | package com.advancedtools.cpp; 3 | 4 | import com.intellij.openapi.application.ApplicationManager; 5 | import com.intellij.openapi.fileTypes.*; 6 | import org.jetbrains.annotations.NotNull; 7 | 8 | import java.util.ArrayList; 9 | import java.util.List; 10 | 11 | /** 12 | * @author maxim 13 | */ 14 | public class CppFileTypeFactory extends FileTypeFactory { 15 | @Override 16 | public void createFileTypes(@NotNull FileTypeConsumer fileTypeConsumer) { 17 | List matcherList = new ArrayList(); 18 | for(String s:CppSupportLoader.extensions) { 19 | matcherList.add(new ExtensionFileNameMatcher(s)); 20 | } 21 | 22 | for(String s:CppSupportLoader.filesWithEmptyExtensions()) { 23 | matcherList.add(new ExactFileNameMatcher(s)); 24 | } 25 | 26 | fileTypeConsumer.consume(CppSupportLoader.CPP_FILETYPE, matcherList.toArray(new FileNameMatcher[matcherList.size()])); 27 | matcherList.clear(); 28 | matcherList.add(new ExactFileNameMatcher("Makefile")); 29 | if (ApplicationManager.getApplication().isUnitTestMode()) matcherList.add(new ExtensionFileNameMatcher("mk")); 30 | fileTypeConsumer.consume(CppSupportLoader.MAKE_FILETYPE, matcherList.toArray(new FileNameMatcher[matcherList.size()])); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/com/advancedtools/cpp/CppFindUsagesProvider.java: -------------------------------------------------------------------------------- 1 | // Copyright 2006-2012 AdvancedTools. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. 2 | package com.advancedtools.cpp; 3 | 4 | import com.intellij.lang.cacheBuilder.DefaultWordsScanner; 5 | import com.intellij.lang.cacheBuilder.WordsScanner; 6 | import com.intellij.lang.findUsages.FindUsagesProvider; 7 | import com.intellij.lexer.FlexAdapter; 8 | import com.intellij.psi.PsiElement; 9 | import com.intellij.psi.PsiNamedElement; 10 | import com.intellij.psi.tree.IElementType; 11 | import com.intellij.psi.tree.TokenSet; 12 | import org.jetbrains.annotations.NotNull; 13 | import org.jetbrains.annotations.Nullable; 14 | 15 | /** 16 | * @author maxim 17 | */ 18 | public class CppFindUsagesProvider implements FindUsagesProvider { 19 | @Nullable 20 | public WordsScanner getWordsScanner() { 21 | return new DefaultWordsScanner( 22 | new FlexAdapter(new _CppLexer(true, false, true, true, true)), // TODO: c/c++ dialects 23 | TokenSet.create(CppTokenTypes.IDENTIFIER), 24 | CppTokenTypes.COMMENTS, 25 | TokenSet.create(CppTokenTypes.STRING_LITERAL) 26 | ); 27 | } 28 | 29 | public boolean canFindUsagesFor(PsiElement psiElement) { 30 | return true; 31 | } 32 | 33 | @Nullable 34 | public String getHelpId(PsiElement psiElement) { 35 | return null; 36 | } 37 | 38 | @NotNull 39 | public String getType(PsiElement psiElement) { 40 | return "C/C++ Symbol"; 41 | } 42 | 43 | @NotNull 44 | public String getDescriptiveName(PsiElement psiElement) { 45 | if (psiElement instanceof PsiNamedElement) { 46 | final String name = ((PsiNamedElement) psiElement).getName(); 47 | 48 | return name != null ? name:""; 49 | } 50 | 51 | return psiElement.getText(); 52 | } 53 | 54 | @NotNull 55 | public String getNodeText(PsiElement psiElement, boolean b) { 56 | return getDescriptiveName(psiElement); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/com/advancedtools/cpp/CppLanguage.java: -------------------------------------------------------------------------------- 1 | // Copyright 2006-2012 AdvancedTools. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. 2 | package com.advancedtools.cpp; 3 | 4 | import com.intellij.formatting.FormattingModelBuilder; 5 | import com.intellij.ide.structureView.StructureViewBuilder; 6 | import com.intellij.ide.structureView.StructureViewModel; 7 | import com.intellij.ide.structureView.TreeBasedStructureViewBuilder; 8 | import com.intellij.lang.*; 9 | import com.intellij.lang.findUsages.FindUsagesProvider; 10 | import com.intellij.lang.surroundWith.SurroundDescriptor; 11 | import com.intellij.lexer.FlexAdapter; 12 | import com.intellij.lexer.Lexer; 13 | import com.intellij.openapi.editor.Editor; 14 | import com.intellij.openapi.fileTypes.SyntaxHighlighter; 15 | import com.intellij.openapi.project.Project; 16 | import com.intellij.openapi.vfs.VirtualFile; 17 | import com.intellij.psi.PsiFile; 18 | import org.jetbrains.annotations.NotNull; 19 | import org.jetbrains.annotations.Nullable; 20 | 21 | /** 22 | * @author maxim 23 | */ 24 | public class CppLanguage extends Language implements LanguageFeatureAware { 25 | public CppLanguage() { 26 | super("C/C++"); 27 | } 28 | 29 | @NotNull 30 | public SyntaxHighlighter getSyntaxHighlighter(Project project, VirtualFile file) { 31 | return new CppHighlighter(); 32 | } 33 | 34 | @Nullable 35 | public StructureViewBuilder getStructureViewBuilder(final PsiFile psiFile) { 36 | return new TreeBasedStructureViewBuilder() { 37 | @NotNull 38 | @Override 39 | public StructureViewModel createStructureViewModel(@Nullable Editor editor) { 40 | return createStructureViewModel(); // todo, new api Idea 14.1 41 | } 42 | 43 | public StructureViewModel createStructureViewModel() { 44 | return new CppStructureViewBuilder(psiFile); 45 | } 46 | }; 47 | } 48 | 49 | static Lexer createLexerStatic(Project project) { 50 | return new FlexAdapter(new _CppLexer(false, false, true, true, true)); // TODO: different lexers needed! 51 | } 52 | 53 | @Nullable 54 | public FormattingModelBuilder getFormattingModelBuilder() { 55 | if (true) return null; 56 | return new CppFormattingModelBuilder(); 57 | } 58 | 59 | } -------------------------------------------------------------------------------- /src/com/advancedtools/cpp/CppNamesValidator.java: -------------------------------------------------------------------------------- 1 | // Copyright 2006-2012 AdvancedTools. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. 2 | package com.advancedtools.cpp; 3 | 4 | import com.advancedtools.cpp.facade.EnvironmentFacade; 5 | import com.intellij.lang.refactoring.NamesValidator; 6 | import com.intellij.lexer.Lexer; 7 | import com.intellij.openapi.project.Project; 8 | import com.intellij.psi.tree.IElementType; 9 | 10 | /** 11 | * @author maxim 12 | * Date: 2/3/12 13 | * Time: 1:09 PM 14 | */ 15 | public class CppNamesValidator implements NamesValidator { 16 | 17 | public boolean isKeyword(String s, Project project) { 18 | return CppTokenTypes.KEYWORDS.contains(tokenType(s, project)); 19 | 20 | } 21 | 22 | public boolean isIdentifier(String s, Project project) { 23 | return tokenType(s, project) == CppTokenTypes.IDENTIFIER; 24 | } 25 | 26 | private IElementType tokenType(String s, Project project) { 27 | final Lexer lexer = CppLanguage.createLexerStatic(project); 28 | lexer.start(s, 0, s.length(), 0); 29 | 30 | final IElementType tokenType = lexer.getTokenType(); 31 | 32 | lexer.advance(); 33 | return lexer.getTokenType() == null ? tokenType:null; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/com/advancedtools/cpp/CppProjectConfigurableProvider.java: -------------------------------------------------------------------------------- 1 | // Copyright 2006-2012 AdvancedTools. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. 2 | package com.advancedtools.cpp; 3 | 4 | import com.intellij.openapi.options.Configurable; 5 | import com.intellij.openapi.options.ConfigurationException; 6 | import com.intellij.openapi.project.Project; 7 | import com.intellij.openapi.roots.ui.configuration.ProjectStructureConfigurableContributor; 8 | import com.intellij.openapi.roots.ui.configuration.projectRoot.StructureConfigurableContext; 9 | import com.intellij.util.SmartList; 10 | import org.jetbrains.annotations.Nls; 11 | import org.jetbrains.annotations.NonNls; 12 | import org.jetbrains.annotations.NotNull; 13 | import org.jetbrains.annotations.Nullable; 14 | 15 | import javax.swing.*; 16 | import java.util.List; 17 | 18 | /** 19 | * Created by maximmossienko on 30/11/14. 20 | */ 21 | public class CppProjectConfigurableProvider extends ProjectStructureConfigurableContributor { 22 | @NotNull 23 | @Override 24 | public List getExtraProjectConfigurables(@NotNull Project project, @NotNull StructureConfigurableContext context) { 25 | return new SmartList(new ProjectConfigurable(project)); 26 | } 27 | 28 | private static class ProjectConfigurable implements Configurable { 29 | private final Project myProject; 30 | 31 | private ProjectConfigurable(Project project) { 32 | this.myProject = project; 33 | } 34 | 35 | @Nls 36 | public String getDisplayName() { 37 | return "C/C++"; 38 | } 39 | 40 | @Nullable 41 | @NonNls 42 | public String getHelpTopic() { 43 | return null; 44 | } 45 | 46 | 47 | private CppSupportLoader.ProjectSettingsForm form; 48 | 49 | public JComponent createComponent() { 50 | CppSupportLoader instance = CppSupportLoader.getInstance(myProject); 51 | form = instance.new ProjectSettingsForm(); 52 | reset(); 53 | return form.getProjectSettingsPanel(); 54 | } 55 | 56 | public boolean isModified() { 57 | return form != null && form.isModified(); 58 | } 59 | 60 | public void apply() throws ConfigurationException { 61 | if(form != null) form.apply(); 62 | } 63 | 64 | public void reset() { 65 | if (form != null) form.init(); 66 | } 67 | 68 | public void disposeUIResources() { 69 | form = null; 70 | } 71 | 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /src/com/advancedtools/cpp/CppQuoteHandler.java: -------------------------------------------------------------------------------- 1 | // Copyright 2006-2012 AdvancedTools. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. 2 | package com.advancedtools.cpp; 3 | 4 | import com.intellij.codeInsight.editorActions.SimpleTokenSetQuoteHandler; 5 | 6 | /** 7 | * @author maxim 8 | */ 9 | public class CppQuoteHandler extends SimpleTokenSetQuoteHandler { 10 | public CppQuoteHandler() { 11 | super(CppTokenTypes.STRING_LITERAL, CppTokenTypes.SINGLE_QUOTE_STRING_LITERAL); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/com/advancedtools/cpp/CppRenameHandler.java: -------------------------------------------------------------------------------- 1 | // Copyright 2006-2012 AdvancedTools. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. 2 | package com.advancedtools.cpp; 3 | 4 | import com.intellij.openapi.actionSystem.DataContext; 5 | import com.intellij.openapi.editor.Editor; 6 | import com.intellij.openapi.project.Project; 7 | import com.intellij.psi.PsiElement; 8 | import com.intellij.psi.PsiFile; 9 | import com.intellij.refactoring.rename.PsiElementRenameHandler; 10 | import com.intellij.refactoring.rename.RenameHandler; 11 | import org.jetbrains.annotations.NotNull; 12 | 13 | /** 14 | * @author maxim 15 | * Date: 2/7/12 16 | * Time: 12:48 PM 17 | */ 18 | public class CppRenameHandler implements RenameHandler { 19 | final PsiElementRenameHandler renameHandler = new PsiElementRenameHandler(); 20 | 21 | public boolean isAvailableOnDataContext(DataContext dataContext) { 22 | return CppSupportSettings.getInstance().canDoSomething(dataContext); 23 | } 24 | 25 | public boolean isRenaming(DataContext dataContext) { 26 | return CppSupportSettings.getInstance().canDoSomething(dataContext); 27 | } 28 | 29 | public void invoke(@NotNull Project project, Editor editor, PsiFile psiFile, DataContext dataContext) { 30 | renameHandler.invoke(project, editor, psiFile, dataContext); 31 | } 32 | 33 | public void invoke(@NotNull Project project, @NotNull PsiElement[] psiElements, DataContext dataContext) { 34 | renameHandler.invoke(project, psiElements, dataContext); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/com/advancedtools/cpp/CppSelectioner.java: -------------------------------------------------------------------------------- 1 | // Copyright 2006-2012 AdvancedTools. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. 2 | package com.advancedtools.cpp; 3 | 4 | import com.intellij.codeInsight.editorActions.ExtendWordSelectionHandler; 5 | import com.intellij.codeInsight.editorActions.SelectWordUtil; 6 | import com.intellij.lang.ASTNode; 7 | import com.intellij.psi.PsiElement; 8 | import com.intellij.psi.PsiFile; 9 | import com.intellij.openapi.util.TextRange; 10 | import com.intellij.openapi.editor.Editor; 11 | import com.intellij.openapi.wm.WindowManager; 12 | import com.advancedtools.cpp.commands.SelectWordCommand; 13 | 14 | import java.util.List; 15 | import java.util.ArrayList; 16 | 17 | /** 18 | * @author maxim 19 | * Date: Sep 24, 2006 20 | * Time: 6:17:59 AM 21 | */ 22 | public class CppSelectioner implements ExtendWordSelectionHandler { 23 | public boolean canSelect(PsiElement psiElement) { 24 | return psiElement.getLanguage() == CppSupportLoader.CPP_FILETYPE.getLanguage(); 25 | } 26 | 27 | public List select(PsiElement psiElement, CharSequence charSequence, int i, Editor editor) { 28 | final PsiFile psiFile = psiElement.getContainingFile(); 29 | final SelectWordCommand command = new SelectWordCommand(psiFile.getVirtualFile().getPath(),editor); 30 | command.post(psiFile.getProject()); 31 | 32 | List result = new ArrayList(); 33 | ASTNode node = psiElement.getNode(); 34 | if (node != null && node.getElementType() == CppTokenTypes.STRING_LITERAL) { 35 | int textOffset = psiElement.getTextOffset(); 36 | result.add(new TextRange(textOffset + 1, textOffset + psiElement.getTextLength() - 1)); 37 | } 38 | if (!command.hasReadyResult()) { 39 | WindowManager.getInstance().getStatusBar(psiFile.getProject()).setInfo("Command was cancelled"); 40 | return result; 41 | } 42 | 43 | final int start = command.getSelectionStart(); 44 | int selectionEnd = command.getSelectionEnd(); 45 | 46 | if (selectionEnd >= editor.getDocument().getTextLength()) { 47 | selectionEnd = editor.getDocument().getTextLength(); 48 | } 49 | result.add(new TextRange(start, selectionEnd)); 50 | 51 | return result; 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/com/advancedtools/cpp/LanguageFeatureAware.java: -------------------------------------------------------------------------------- 1 | package com.advancedtools.cpp; 2 | 3 | import com.intellij.lang.findUsages.FindUsagesProvider; 4 | import com.intellij.openapi.vfs.VirtualFile; 5 | import com.intellij.openapi.project.Project; 6 | import com.intellij.openapi.fileTypes.SyntaxHighlighter; 7 | import com.intellij.psi.PsiFile; 8 | import com.intellij.ide.structureView.StructureViewBuilder; 9 | import com.intellij.lang.Commenter; 10 | import com.intellij.lang.ParserDefinition; 11 | 12 | /** 13 | * User: maxim 14 | * Date: Jan 11, 2009 15 | * Time: 9:22:35 PM 16 | */ 17 | public interface LanguageFeatureAware { 18 | StructureViewBuilder getStructureViewBuilder(PsiFile psiFile); 19 | 20 | SyntaxHighlighter getSyntaxHighlighter(Project project, VirtualFile virtualFile); 21 | } 22 | -------------------------------------------------------------------------------- /src/com/advancedtools/cpp/actions/AboutAction.java: -------------------------------------------------------------------------------- 1 | // Copyright 2006-2012 AdvancedTools. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. 2 | package com.advancedtools.cpp.actions; 3 | 4 | import com.advancedtools.cpp.utils.LM; 5 | import com.intellij.openapi.actionSystem.AnAction; 6 | import com.intellij.openapi.actionSystem.AnActionEvent; 7 | 8 | /** 9 | * User: maxim 10 | * Date: 20.03.2010 11 | * Time: 20:11:29 12 | */ 13 | public class AboutAction extends AnAction { 14 | @Override 15 | public void actionPerformed(AnActionEvent anActionEvent) { 16 | LM.showAboutDialog(anActionEvent.getDataContext()); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/com/advancedtools/cpp/actions/AddOrRemoveCppFileFromAnalysisScopeAction.java: -------------------------------------------------------------------------------- 1 | // Copyright 2006-2012 AdvancedTools. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. 2 | package com.advancedtools.cpp.actions; 3 | 4 | import com.advancedtools.cpp.CppSupportLoader; 5 | import com.advancedtools.cpp.communicator.Communicator; 6 | import com.intellij.openapi.actionSystem.AnAction; 7 | import com.intellij.openapi.actionSystem.AnActionEvent; 8 | import com.intellij.openapi.actionSystem.DataConstants; 9 | import com.intellij.openapi.actionSystem.Presentation; 10 | import com.intellij.openapi.project.Project; 11 | import com.intellij.openapi.vfs.VirtualFile; 12 | 13 | import java.io.File; 14 | import java.util.Set; 15 | 16 | /** 17 | * @author maxim 18 | */ 19 | public class AddOrRemoveCppFileFromAnalysisScopeAction extends AnAction { 20 | public void actionPerformed(AnActionEvent anActionEvent) { 21 | final VirtualFile file = (VirtualFile) anActionEvent.getDataContext().getData(DataConstants.VIRTUAL_FILE); 22 | final Project project = (Project) anActionEvent.getDataContext().getData(DataConstants.PROJECT); 23 | assert file != null; 24 | assert project != null; 25 | 26 | final Set strings = CppSupportLoader.getInstance(project).getIgnoredFilesSet(); 27 | final String path = file.getPresentableUrl().replace(File.separatorChar, '/'); 28 | if (!strings.contains(path)) strings.add(path); 29 | else strings.remove(path); 30 | Communicator.getInstance(project).restartServer(); 31 | } 32 | 33 | public void update(AnActionEvent anActionEvent) { 34 | final VirtualFile file = (VirtualFile) anActionEvent.getDataContext().getData(DataConstants.VIRTUAL_FILE); 35 | final Project project = (Project) anActionEvent.getDataContext().getData(DataConstants.PROJECT); 36 | final Presentation presentation = anActionEvent.getPresentation(); 37 | 38 | if (project == null || 39 | file == null || 40 | file.getFileType() != CppSupportLoader.CPP_FILETYPE || 41 | Communicator.isHeaderFile(file) 42 | ) { 43 | presentation.setVisible(false); 44 | } else { 45 | String url = file.getPresentableUrl().replace(File.separatorChar,'/'); 46 | final Set ignoredFiles = CppSupportLoader.getInstance(project).getIgnoredFilesSet(); 47 | presentation.setVisible(true); 48 | 49 | final String fileName = file.getName(); 50 | final String term = "Cpp Support Analysis Scope"; 51 | presentation.setText(ignoredFiles.contains(url) ? "Add " + fileName + " to "+ term :"Remove " + fileName + " from " + term); 52 | } 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/com/advancedtools/cpp/actions/BaseEditorAction.java: -------------------------------------------------------------------------------- 1 | // Copyright 2006-2012 AdvancedTools. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. 2 | package com.advancedtools.cpp.actions; 3 | 4 | import com.advancedtools.cpp.psi.CppFile; 5 | import com.advancedtools.cpp.communicator.Communicator; 6 | import com.intellij.openapi.actionSystem.AnAction; 7 | import com.intellij.openapi.actionSystem.AnActionEvent; 8 | import com.intellij.openapi.actionSystem.DataConstants; 9 | import com.intellij.openapi.actionSystem.DataContext; 10 | import com.intellij.openapi.editor.Editor; 11 | import com.intellij.openapi.fileEditor.FileEditorManager; 12 | import com.intellij.openapi.project.Project; 13 | import com.intellij.psi.PsiDocumentManager; 14 | import com.intellij.psi.PsiFile; 15 | 16 | /** 17 | * @author: maxim 18 | * Date: Sep 25, 2006 19 | * Time: 2:00:35 AM 20 | */ 21 | public abstract class BaseEditorAction extends AnAction { 22 | public void update(AnActionEvent anActionEvent) { 23 | final DataContext dataContext = anActionEvent.getDataContext(); 24 | final PsiFile psiFile = findFileFromDataContext(dataContext); 25 | Editor editor = findEditorFromDataContext(dataContext); 26 | 27 | anActionEvent.getPresentation().setVisible( 28 | psiFile instanceof CppFile && 29 | editor != null && 30 | acceptableState(editor, psiFile) && 31 | Communicator.getInstance(psiFile.getProject()).isServerUpAndRunning() 32 | ); 33 | } 34 | 35 | public void actionPerformed(AnActionEvent e) { 36 | final DataContext dataContext = e.getDataContext(); 37 | final Editor editor = findEditorFromDataContext(dataContext); 38 | PsiFile file = findFileFromDataContext(dataContext); 39 | execute(editor, file, (Project) dataContext.getData(DataConstants.PROJECT)); 40 | } 41 | 42 | protected void execute(Editor editor,PsiFile file,Project project) {} 43 | 44 | protected abstract boolean acceptableState(Editor editor, PsiFile file); 45 | 46 | static Editor findEditorFromDataContext(DataContext context) { 47 | Editor editor = (Editor) context.getData(DataConstants.EDITOR); 48 | final Project project = (Project) context.getData(DataConstants.PROJECT); 49 | 50 | if (editor == null && project != null) { 51 | editor = FileEditorManager.getInstance(project).getSelectedTextEditor(); 52 | } 53 | 54 | return editor; 55 | } 56 | 57 | static PsiFile findFileFromDataContext(DataContext context) { 58 | PsiFile file = (PsiFile)context.getData(DataConstants.PSI_FILE); 59 | final Project project = (Project) context.getData(DataConstants.PROJECT); 60 | final Editor editor = findEditorFromDataContext(context); 61 | 62 | if (file == null && editor != null) { 63 | file = PsiDocumentManager.getInstance(project).getPsiFile( 64 | editor.getDocument() 65 | ); 66 | } 67 | return file; 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /src/com/advancedtools/cpp/actions/GotoConstAction.java: -------------------------------------------------------------------------------- 1 | // Copyright 2006-2012 AdvancedTools. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. 2 | package com.advancedtools.cpp.actions; 3 | 4 | import com.advancedtools.cpp.navigation.CppSymbolContributor; 5 | import com.advancedtools.cpp.CppSupportLoader; 6 | 7 | /** 8 | * @author maxim 9 | */ 10 | public class GotoConstAction extends GotoBaseAction { 11 | public CppSymbolContributor getNameContributor() { 12 | return CppSupportLoader.getConstantContributor(); 13 | } 14 | 15 | protected String getEnterTextPrefix() { 16 | return "Enter constant part:"; 17 | } 18 | 19 | protected String getNoEntityText() { 20 | return "No such constant in project"; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/com/advancedtools/cpp/actions/GotoInheritorsAction.java: -------------------------------------------------------------------------------- 1 | // Copyright 2006-2012 AdvancedTools. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. 2 | package com.advancedtools.cpp.actions; 3 | 4 | import com.intellij.openapi.actionSystem.AnActionEvent; 5 | import com.intellij.openapi.editor.Editor; 6 | import com.intellij.psi.PsiFile; 7 | 8 | /** 9 | * @author maxim 10 | * Date: Sep 24, 2006 11 | * Time: 4:08:13 AM 12 | */ 13 | public class GotoInheritorsAction extends BaseEditorAction { 14 | public void actionPerformed(AnActionEvent anActionEvent) { 15 | GotoSupersAction.doAction(anActionEvent, false); 16 | } 17 | 18 | protected boolean acceptableState(Editor editor, PsiFile file) { 19 | return true; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/com/advancedtools/cpp/actions/GotoMacroAction.java: -------------------------------------------------------------------------------- 1 | // Copyright 2006-2012 AdvancedTools. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. 2 | package com.advancedtools.cpp.actions; 3 | 4 | import com.advancedtools.cpp.navigation.CppSymbolContributor; 5 | import com.advancedtools.cpp.CppSupportLoader; 6 | 7 | /** 8 | * @author maxim 9 | */ 10 | public class GotoMacroAction extends GotoBaseAction { 11 | public CppSymbolContributor getNameContributor() { 12 | return CppSupportLoader.getMacrosContributor(); 13 | } 14 | 15 | protected String getEnterTextPrefix() { 16 | return "Enter macro prefix:"; 17 | } 18 | 19 | protected String getNoEntityText() { 20 | return "No such macro in pproject"; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/com/advancedtools/cpp/actions/GotoSupersAction.java: -------------------------------------------------------------------------------- 1 | // Copyright 2006-2012 AdvancedTools. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. 2 | package com.advancedtools.cpp.actions; 3 | 4 | import com.advancedtools.cpp.commands.NavigationCommand; 5 | import com.advancedtools.cpp.communicator.Communicator; 6 | import com.advancedtools.cpp.utils.NavigationUtils; 7 | import com.intellij.openapi.actionSystem.AnActionEvent; 8 | import com.intellij.openapi.actionSystem.DataContext; 9 | import com.intellij.openapi.editor.Editor; 10 | import com.intellij.psi.PsiFile; 11 | import org.jetbrains.annotations.NonNls; 12 | 13 | /** 14 | * @author maxim 15 | * Date: Sep 24, 2006 16 | * Time: 4:08:13 AM 17 | */ 18 | public class GotoSupersAction extends BaseEditorAction { 19 | public void actionPerformed(AnActionEvent anActionEvent) { 20 | doAction(anActionEvent, true); 21 | } 22 | 23 | static void doAction(AnActionEvent anActionEvent, final boolean supers) { 24 | final DataContext dataContext = anActionEvent.getDataContext(); 25 | final PsiFile psiFile = findFileFromDataContext(dataContext); 26 | final Editor editor = findEditorFromDataContext(dataContext); 27 | 28 | Communicator.getInstance(psiFile.getProject()).sendCommand( 29 | new NavigationCommand(psiFile, editor.getCaretModel().getOffset()) { 30 | @NonNls @Override protected String getCommandText() { 31 | return supers ? "find-parents" : "find-inheritors"; 32 | } 33 | 34 | public boolean doInvokeInDispatchThread() { 35 | return true; 36 | } 37 | 38 | public void doExecute() { 39 | super.doExecute(); 40 | NavigationUtils.navigate(project, usagesList); 41 | } 42 | } 43 | ); 44 | } 45 | 46 | protected boolean acceptableState(Editor editor, PsiFile file) { 47 | return true; 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/com/advancedtools/cpp/actions/IndentSelectionAction.java: -------------------------------------------------------------------------------- 1 | // Copyright 2006-2012 AdvancedTools. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. 2 | package com.advancedtools.cpp.actions; 3 | 4 | import com.intellij.openapi.editor.Editor; 5 | import com.intellij.openapi.project.Project; 6 | import com.intellij.psi.PsiFile; 7 | import com.advancedtools.cpp.psi.CppFile; 8 | import com.advancedtools.cpp.commands.StringCommand; 9 | import com.advancedtools.cpp.communicator.BuildingCommandHelper; 10 | import com.advancedtools.cpp.actions.refactoring.ChangesSupport; 11 | 12 | /** 13 | * @author maxim 14 | * Date: 08.06.2009 15 | * Time: 13:53:47 16 | */ 17 | public class IndentSelectionAction extends BaseEditorAction { 18 | @Override 19 | protected void execute(Editor editor, PsiFile file, final Project project) { 20 | new StringCommand( 21 | "indent " + 22 | BuildingCommandHelper.getQuotedVirtualFileNameAsString(file) + 23 | " " + editor.getSelectionModel().getSelectionStart() + 24 | " " + editor.getSelectionModel().getSelectionEnd() 25 | ) { 26 | final ChangesSupport changesSupport = new ChangesSupport(); 27 | 28 | @Override 29 | public boolean doInvokeInDispatchThread() { 30 | return true; 31 | } 32 | 33 | @Override 34 | public void commandOutputString(String str) { 35 | changesSupport.appendChangesFromString(str); 36 | } 37 | 38 | @Override 39 | public void doExecute() { 40 | changesSupport.applyChanges("Cpp.Indent", project); 41 | } 42 | }.post(project); 43 | } 44 | 45 | protected boolean acceptableState(Editor editor, PsiFile file) { 46 | if (file instanceof CppFile && editor.getSelectionModel().hasSelection()) { 47 | return true; 48 | } 49 | return false; 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/com/advancedtools/cpp/actions/SendCommandDialogForm.form: -------------------------------------------------------------------------------- 1 | 2 |
3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 |
60 | -------------------------------------------------------------------------------- /src/com/advancedtools/cpp/actions/ShowPreprocessedTextAction.java: -------------------------------------------------------------------------------- 1 | // Copyright 2006-2012 AdvancedTools. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. 2 | package com.advancedtools.cpp.actions; 3 | 4 | import com.intellij.openapi.actionSystem.AnActionEvent; 5 | import com.intellij.openapi.actionSystem.DataContext; 6 | import com.intellij.openapi.editor.Editor; 7 | import com.intellij.psi.PsiFile; 8 | import com.advancedtools.cpp.communicator.Communicator; 9 | import com.advancedtools.cpp.commands.ShowPreprocessedCommand; 10 | 11 | /** 12 | * @author maxim 13 | * Date: Sep 24, 2006 14 | * Time: 4:08:13 AM 15 | */ 16 | public class ShowPreprocessedTextAction extends BaseEditorAction { 17 | public void actionPerformed(AnActionEvent anActionEvent) { 18 | final DataContext dataContext = anActionEvent.getDataContext(); 19 | final PsiFile psiFile = findFileFromDataContext(dataContext); 20 | final Editor editor = findEditorFromDataContext(dataContext); 21 | 22 | if (!editor.getSelectionModel().hasSelection()) editor.getSelectionModel().selectLineAtCaret(); 23 | 24 | Communicator.getInstance(psiFile.getProject()).sendCommand( 25 | new ShowPreprocessedCommand(psiFile.getVirtualFile().getPath(), editor) 26 | ); 27 | } 28 | 29 | protected boolean acceptableState(Editor editor, PsiFile file) { 30 | return true; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/com/advancedtools/cpp/actions/generate/BaseGenerateAction.java: -------------------------------------------------------------------------------- 1 | // Copyright 2006-2012 AdvancedTools. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. 2 | package com.advancedtools.cpp.actions.generate; 3 | 4 | import com.advancedtools.cpp.actions.BaseEditorAction; 5 | import com.advancedtools.cpp.commands.GenerateSomethingCommand; 6 | import com.advancedtools.cpp.communicator.Communicator; 7 | import com.advancedtools.cpp.psi.CppFile; 8 | import com.intellij.openapi.editor.Editor; 9 | import com.intellij.openapi.project.Project; 10 | import com.intellij.psi.PsiFile; 11 | 12 | /** 13 | * @author maxim 14 | */ 15 | public abstract class BaseGenerateAction extends BaseEditorAction { 16 | public enum GenerateType { 17 | CONSTRUCTOR, CONSTRUCTOR_WITH_PARAMETERS, COPY_CONSTRUCTOR, ASSIGNMENT_OPERATOR 18 | } 19 | 20 | @Override 21 | protected void execute(Editor editor, PsiFile file, Project project) { 22 | Communicator.getInstance(project).sendCommand( 23 | new GenerateSomethingCommand(file.getVirtualFile().getPath(), editor, getGenerationType()) 24 | ); 25 | } 26 | 27 | protected abstract GenerateType getGenerationType(); 28 | 29 | protected boolean acceptableState(Editor editor, PsiFile file) { 30 | if (file instanceof CppFile) { 31 | return true; 32 | } 33 | return false; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/com/advancedtools/cpp/actions/generate/GenerateAssignmentOperatorAction.java: -------------------------------------------------------------------------------- 1 | // Copyright 2006-2012 AdvancedTools. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. 2 | package com.advancedtools.cpp.actions.generate; 3 | 4 | /** 5 | * @author maxim 6 | * Date: Sep 24, 2006 7 | * Time: 4:08:13 AM 8 | */ 9 | public class GenerateAssignmentOperatorAction extends BaseGenerateAction { 10 | protected GenerateType getGenerationType() { 11 | return GenerateType.ASSIGNMENT_OPERATOR; 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/com/advancedtools/cpp/actions/generate/GenerateCaseBranchesFromEnumAction.java: -------------------------------------------------------------------------------- 1 | // Copyright 2006-2012 AdvancedTools. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. 2 | package com.advancedtools.cpp.actions.generate; 3 | 4 | import com.advancedtools.cpp.actions.BaseEditorAction; 5 | import com.advancedtools.cpp.actions.refactoring.ChangesSupport; 6 | import com.advancedtools.cpp.commands.StringCommand; 7 | import com.advancedtools.cpp.communicator.BuildingCommandHelper; 8 | import com.intellij.openapi.editor.Editor; 9 | import com.intellij.openapi.project.Project; 10 | import com.intellij.psi.PsiFile; 11 | 12 | /** 13 | * @author maxim 14 | */ 15 | public class GenerateCaseBranchesFromEnumAction extends BaseEditorAction { 16 | @Override 17 | protected void execute(Editor editor, PsiFile file, final Project project) { 18 | new MyStringCommand(file, editor, project).post(project); 19 | } 20 | 21 | protected boolean acceptableState(Editor editor, PsiFile file) { 22 | return true; 23 | } 24 | 25 | private class MyStringCommand extends StringCommand { 26 | final ChangesSupport changesSupport; 27 | private final Project project; 28 | 29 | public MyStringCommand(PsiFile file, Editor editor, Project project) { 30 | super("generate-enum-switch-at " + 31 | BuildingCommandHelper.quote(file.getVirtualFile().getPath()) + " " + 32 | editor.getCaretModel().getOffset()); 33 | this.project = project; 34 | changesSupport = new ChangesSupport(); 35 | } 36 | 37 | @Override 38 | public void commandOutputString(String str) { 39 | changesSupport.appendChangesFromString(str); 40 | } 41 | 42 | @Override 43 | public boolean doInvokeInDispatchThread() { 44 | return true; 45 | } 46 | 47 | @Override 48 | public void doExecute() { 49 | changesSupport.applyChanges("CppSupport." + getClass().getName(), project); 50 | } 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/com/advancedtools/cpp/actions/generate/GenerateContructorAction.java: -------------------------------------------------------------------------------- 1 | // Copyright 2006-2012 AdvancedTools. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. 2 | package com.advancedtools.cpp.actions.generate; 3 | 4 | /** 5 | * @author maxim 6 | * Date: Sep 24, 2006 7 | * Time: 4:08:13 AM 8 | */ 9 | public class GenerateContructorAction extends BaseGenerateAction { 10 | protected GenerateType getGenerationType() { 11 | return GenerateType.CONSTRUCTOR; 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/com/advancedtools/cpp/actions/generate/GenerateContructorWithParametersAction.java: -------------------------------------------------------------------------------- 1 | // Copyright 2006-2012 AdvancedTools. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. 2 | package com.advancedtools.cpp.actions.generate; 3 | 4 | /** 5 | * Created by IntelliJ IDEA. 6 | * @author maxim 7 | * Date: Sep 24, 2006 8 | * Time: 4:08:13 AM 9 | */ 10 | public class GenerateContructorWithParametersAction extends BaseGenerateAction { 11 | protected GenerateType getGenerationType() { 12 | return GenerateType.CONSTRUCTOR_WITH_PARAMETERS; 13 | } 14 | } -------------------------------------------------------------------------------- /src/com/advancedtools/cpp/actions/generate/GenerateCopyContructorAction.java: -------------------------------------------------------------------------------- 1 | // Copyright 2006-2012 AdvancedTools. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. 2 | package com.advancedtools.cpp.actions.generate; 3 | 4 | /** 5 | * @author maxim 6 | * Date: Sep 24, 2006 7 | * Time: 4:08:13 AM 8 | */ 9 | public class GenerateCopyContructorAction extends BaseGenerateAction { 10 | protected GenerateType getGenerationType() { 11 | return GenerateType.COPY_CONSTRUCTOR; 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/com/advancedtools/cpp/actions/refactoring/MoveMethodDefinitionToDeclarationAction.java: -------------------------------------------------------------------------------- 1 | // Copyright 2006-2012 AdvancedTools. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. 2 | package com.advancedtools.cpp.actions.refactoring; 3 | 4 | import com.advancedtools.cpp.actions.BaseEditorAction; 5 | import com.advancedtools.cpp.commands.StringCommand; 6 | import com.advancedtools.cpp.communicator.BuildingCommandHelper; 7 | import com.intellij.openapi.editor.Editor; 8 | import com.intellij.openapi.project.Project; 9 | import com.intellij.psi.PsiFile; 10 | 11 | /** 12 | * @author maxim 13 | */ 14 | public class MoveMethodDefinitionToDeclarationAction extends BaseEditorAction { 15 | @Override 16 | protected void execute(Editor editor, PsiFile file, final Project project) { 17 | String filePath = file.getVirtualFile().getPath(); 18 | 19 | StringCommand command = new StringCommand("function-to-inline " + BuildingCommandHelper.quote(filePath) + " " + 20 | editor.getCaretModel().getOffset()) { 21 | private final ChangesSupport changesSupport = new ChangesSupport(); 22 | 23 | @Override 24 | public void commandOutputString(String str) { 25 | changesSupport.appendChangesFromString(str); 26 | } 27 | 28 | @Override 29 | public void doExecute() { 30 | // UsageViewManager.getInstance(project).showUsages( 31 | // new UsageTarget[] {}, new Usage[] {}, new UsageViewPresentation(), new Factory() { 32 | // public UsageSearcher create() { 33 | // return new UsageSearcher() { 34 | // public void generate(Processor usageProcessor) { 35 | // } 36 | // }; 37 | // } 38 | // }); 39 | changesSupport.applyChanges("CppSupport."+getClass().getName(), project); 40 | } 41 | 42 | @Override 43 | public boolean doInvokeInDispatchThread() { 44 | return true; 45 | } 46 | }; 47 | command.post(project); 48 | } 49 | 50 | protected boolean acceptableState(Editor editor, PsiFile file) { 51 | return true; 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/com/advancedtools/cpp/build/BuildState.java: -------------------------------------------------------------------------------- 1 | // Copyright 2006-2012 AdvancedTools. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. 2 | package com.advancedtools.cpp.build; 3 | 4 | import com.intellij.openapi.fileEditor.FileDocumentManager; 5 | import com.intellij.openapi.application.ApplicationManager; 6 | import com.intellij.openapi.application.ModalityState; 7 | 8 | import java.io.File; 9 | import java.io.IOException; 10 | import java.util.List; 11 | import java.util.Map; 12 | 13 | /** 14 | * Created by IntelliJ IDEA. 15 | * User: maxim 16 | * Date: Mar 23, 2009 17 | * Time: 12:54:43 PM 18 | */ 19 | public class BuildState { 20 | private final List runCommand; 21 | private final File runCommandDir; 22 | private final Map commandLineProperties; 23 | private Process process; 24 | 25 | public BuildState(List _runCommand, File _runCommandDir, Map _commandLineProperties) { 26 | runCommand = _runCommand; 27 | runCommandDir = _runCommandDir; 28 | commandLineProperties = _commandLineProperties; 29 | } 30 | 31 | public void start() throws IOException { 32 | ProcessBuilder processBuilder = new ProcessBuilder(runCommand); 33 | Map environment = processBuilder.environment(); 34 | if (commandLineProperties != null) { 35 | environment.clear(); 36 | environment.putAll(commandLineProperties); 37 | } 38 | process = processBuilder.directory(runCommandDir).start(); 39 | } 40 | 41 | public static void saveDocuments() { 42 | invokeOnEDTSynchroneously(new Runnable() { 43 | public void run() { 44 | FileDocumentManager.getInstance().saveAllDocuments(); 45 | } 46 | }); 47 | } 48 | 49 | public static void saveAll() { 50 | invokeOnEDTSynchroneously(new Runnable() { 51 | public void run() { 52 | ApplicationManager.getApplication().saveAll(); 53 | } 54 | }); 55 | } 56 | 57 | public static void invokeOnEDTSynchroneously(Runnable saveRunnable) { 58 | if (ApplicationManager.getApplication().isDispatchThread()) { 59 | saveRunnable.run(); 60 | } 61 | else { 62 | ApplicationManager.getApplication().invokeAndWait(saveRunnable, ModalityState.defaultModalityState()); 63 | } 64 | } 65 | 66 | public Process getProcess() { 67 | return process; 68 | } 69 | 70 | public String getRunCommand() { 71 | return BuildUtils.join(runCommand, " "); 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /src/com/advancedtools/cpp/build/BuildTarget.java: -------------------------------------------------------------------------------- 1 | // Copyright 2006-2012 AdvancedTools. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. 2 | package com.advancedtools.cpp.build; 3 | 4 | import org.jetbrains.annotations.Nullable; 5 | import org.jetbrains.annotations.NonNls; 6 | 7 | /** 8 | * @author maxim 9 | */ 10 | public class BuildTarget { 11 | public final @Nullable String buildConfiguration; 12 | public final @Nullable String buildAction; 13 | public final @Nullable String additionalCommandLineParameters; 14 | 15 | @NonNls 16 | public static final String DEFAULT_BUILD_ACTION = "Default"; 17 | 18 | public BuildTarget(@Nullable String _buildConfiguration, @Nullable String _buildAction, 19 | @Nullable String _additionalCommandLineParameters) { 20 | buildAction = _buildAction; 21 | buildConfiguration = _buildConfiguration; 22 | additionalCommandLineParameters = _additionalCommandLineParameters; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/com/advancedtools/cpp/build/MakeBuildHandler.java: -------------------------------------------------------------------------------- 1 | // Copyright 2006-2012 AdvancedTools. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. 2 | package com.advancedtools.cpp.build; 3 | 4 | import com.intellij.execution.filters.Filter; 5 | import com.intellij.openapi.project.Project; 6 | import com.intellij.openapi.util.text.StringUtil; 7 | import com.intellij.openapi.vfs.VirtualFile; 8 | import org.jetbrains.annotations.Nullable; 9 | import org.jetbrains.annotations.NotNull; 10 | import org.jetbrains.annotations.NonNls; 11 | 12 | import java.util.Arrays; 13 | import java.util.Collections; 14 | import java.util.List; 15 | import java.util.regex.Pattern; 16 | import java.util.Map; 17 | 18 | /** 19 | * @author maxim 20 | */ 21 | public class MakeBuildHandler extends BaseBuildHandler { 22 | private @NonNls Map myItems; 23 | 24 | MakeBuildHandler(Project _project, VirtualFile _file) { 25 | super(_project, _file); 26 | 27 | myItems = BuildUtils.buildEnvironmentMap(_project, _file); 28 | } 29 | 30 | public List getCommandLine(@NotNull BuildTarget buildTarget) { 31 | String buildAction = getBuildAction(buildTarget); 32 | return BuildUtils.buildGccToolCall(BuildUtils.MAKE_TOOL_NAME, StringUtil.isEmpty(buildAction) ? Collections.emptyList() : Arrays.asList(buildAction)); 33 | } 34 | 35 | private static @NotNull String getBuildAction(BuildTarget buildTarget) { 36 | if (buildTarget.buildAction != null && !BuildTarget.DEFAULT_BUILD_ACTION.equals(buildTarget.buildAction)) { 37 | return buildTarget.buildAction; 38 | } 39 | return ""; 40 | } 41 | 42 | @NotNull 43 | public String getBuildTitle(BuildTarget target) { 44 | return "Make"; 45 | } 46 | 47 | public @Nullable Filter getOutputFormatFilter() { 48 | return new MakeFormatFilter(file, project); 49 | } 50 | 51 | public void afterProcessStarted() {} 52 | public void afterProcessFinished() {} 53 | 54 | public static class MakeFormatFilter extends BasicFormatFilter { 55 | public MakeFormatFilter(VirtualFile file, Project project) { 56 | super(file, project, getMatchingPattern()); 57 | } 58 | 59 | public static String getMatchingPattern() { 60 | return "^((?:\\w\\:)?[^\\:]+)(?:\\:([0-9]+)\\:(?:([0-9])+\\:)?)?"; 61 | } 62 | } 63 | 64 | private static Pattern targetPattern = Pattern.compile("^(\\w+)\\:"); 65 | 66 | public @Nullable String[] getAvailableBuildActions() { 67 | return BuildUtils.getTargetsFromMakeFile(file, targetPattern); 68 | } 69 | 70 | protected @Nullable Map getEnvironmentVariables() { 71 | return myItems; 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /src/com/advancedtools/cpp/build/NMakeBuildHandler.java: -------------------------------------------------------------------------------- 1 | // Copyright 2006-2012 AdvancedTools. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. 2 | package com.advancedtools.cpp.build; 3 | 4 | import com.intellij.openapi.project.Project; 5 | import com.intellij.openapi.vfs.VirtualFile; 6 | import com.intellij.execution.filters.Filter; 7 | import org.jetbrains.annotations.NotNull; 8 | import org.jetbrains.annotations.Nullable; 9 | 10 | import java.util.Arrays; 11 | import java.util.List; 12 | import java.util.regex.Pattern; 13 | 14 | /** 15 | * @author maxim 16 | */ 17 | public class NMakeBuildHandler extends BaseBuildHandler { 18 | NMakeBuildHandler(Project _project, VirtualFile _file) { 19 | super(_project, _file); 20 | } 21 | 22 | public List getCommandLine(@NotNull BuildTarget buildTarget) { 23 | List shellCommand = Arrays.asList("nmake", "-f", "\"" + file.getPath() + "\"", " %*"); 24 | if (shellCommand == null) return null; 25 | 26 | if (buildTarget.buildConfiguration != null) shellCommand =BuildUtils.appendOptions(shellCommand, buildTarget.buildConfiguration); 27 | if (buildTarget.buildAction != null && !BuildTarget.DEFAULT_BUILD_ACTION.equals(buildTarget.buildAction)) { 28 | shellCommand = BuildUtils.appendOptions(shellCommand, buildTarget.buildAction); 29 | } 30 | return shellCommand; 31 | } 32 | 33 | @NotNull 34 | public String getBuildTitle(BuildTarget target) { 35 | return "NMake"; 36 | } 37 | 38 | private static Pattern targetPattern = Pattern.compile("^(\\w+) \\:"); 39 | 40 | public @Nullable String[] getAvailableBuildActions() { 41 | return BuildUtils.getTargetsFromMakeFile(file, targetPattern); 42 | } 43 | 44 | public @Nullable Filter getOutputFormatFilter() { 45 | return new MakeFormatFilter(file, project); 46 | } 47 | 48 | public void afterProcessStarted() {} 49 | public void afterProcessFinished() {} 50 | 51 | private static class MakeFormatFilter extends BasicFormatFilter { 52 | public MakeFormatFilter(VirtualFile file, Project project) { 53 | super(file, project, "^([^\\(]+)\\(([0-9]+)\\) \\: (?:warning|error|fatal error)"); 54 | } 55 | } 56 | 57 | public String[] getAvailableConfigurations() { 58 | return new String[] { 59 | DEBUG_CONFIGURATION_NAME, RELEASE_CONFIGURATION_NAME 60 | }; 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /src/com/advancedtools/cpp/c_file_obj.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nicity/CppTools/ce6ba79a20827023d023f51e002222f5f128cab3/src/com/advancedtools/cpp/c_file_obj.gif -------------------------------------------------------------------------------- /src/com/advancedtools/cpp/commands/BlockingStringCommand.java: -------------------------------------------------------------------------------- 1 | // Copyright 2006-2012 AdvancedTools. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. 2 | package com.advancedtools.cpp.commands; 3 | 4 | import com.advancedtools.cpp.communicator.BlockingCommand; 5 | 6 | /** 7 | * @author maxim 8 | */ 9 | public class BlockingStringCommand extends BlockingCommand { 10 | private String myCommandText; 11 | private String myCommandResult; 12 | 13 | public BlockingStringCommand(String commandText) { myCommandText = commandText; } 14 | 15 | public void commandOutputString(String str) { 16 | if (myCommandResult == null) myCommandResult = str; 17 | else myCommandResult += str; 18 | } 19 | 20 | public String getCommand() { return myCommandText; } 21 | 22 | public String getCommandResult() { 23 | return myCommandResult; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/com/advancedtools/cpp/commands/ChangedCommand.java: -------------------------------------------------------------------------------- 1 | // Copyright 2006-2012 AdvancedTools. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. 2 | package com.advancedtools.cpp.commands; 3 | 4 | import com.advancedtools.cpp.communicator.BuildingCommandHelper; 5 | import com.advancedtools.cpp.communicator.CommunicatorCommand; 6 | import com.intellij.openapi.util.SystemInfo; 7 | 8 | /** 9 | * @author maxim 10 | */ 11 | public class ChangedCommand extends CommunicatorCommand { 12 | private final int start; 13 | private final int end; 14 | private final String fileName; 15 | private final String change; 16 | private final long modificationStamp; 17 | 18 | public ChangedCommand(String _fileName, String _change, int _start, int _end, long _modificationStamp) { 19 | if (SystemInfo.isWindows && _change.indexOf('\n') != -1) { 20 | _change = _change.replaceAll("\n", "\r\n"); 21 | } 22 | change = _change; 23 | fileName = BuildingCommandHelper.fixVirtualFileName(_fileName); 24 | start = _start; 25 | end = _end; 26 | modificationStamp = _modificationStamp; 27 | } 28 | 29 | public boolean isCancellable() { 30 | return false; 31 | } 32 | 33 | public void doExecute() {} 34 | public void commandOutputString(String str) {} 35 | 36 | public String getCommand() { 37 | return "changed -n " + modificationStamp + " " + BuildingCommandHelper.quote(fileName) + " " + BuildingCommandHelper.quote(change) + " " + start + " " + end; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/com/advancedtools/cpp/commands/CompletionCommand.java: -------------------------------------------------------------------------------- 1 | // Copyright 2006-2012 AdvancedTools. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. 2 | package com.advancedtools.cpp.commands; 3 | 4 | import com.advancedtools.cpp.communicator.BlockingCommand; 5 | import com.advancedtools.cpp.communicator.BuildingCommandHelper; 6 | import com.advancedtools.cpp.communicator.Communicator; 7 | 8 | import java.util.LinkedList; 9 | import java.util.List; 10 | 11 | /** 12 | * @author maxim 13 | * Date: 02.06.2006 14 | * Time: 19:01:11 15 | */ 16 | public class CompletionCommand extends BlockingCommand { 17 | protected final String filePath; 18 | protected final long offset; 19 | private List variants; 20 | 21 | public CompletionCommand(String _filePath, int _offset) { 22 | filePath = BuildingCommandHelper.fixVirtualFileName(_filePath); 23 | offset = _offset; 24 | } 25 | 26 | public void commandOutputString(String str) { 27 | if (!str.startsWith("NUM")) { 28 | final int i = str.indexOf(Communicator.DELIMITER); 29 | final int i2 = str.indexOf(Communicator.DELIMITER, i + 2); 30 | 31 | if (i2 == -1) return; 32 | 33 | if (variants == null) variants = new LinkedList(); 34 | variants.add(str); 35 | } 36 | } 37 | 38 | public String getCommand() { 39 | return "complete " + BuildingCommandHelper.quote(filePath) + " " + offset; 40 | } 41 | 42 | public List getVariants() { 43 | return variants; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/com/advancedtools/cpp/commands/EnumerateSymbolsCommand.java: -------------------------------------------------------------------------------- 1 | // Copyright 2006-2012 AdvancedTools. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. 2 | package com.advancedtools.cpp.commands; 3 | 4 | import com.advancedtools.cpp.communicator.BlockingCommand; 5 | import com.advancedtools.cpp.communicator.BuildingCommandHelper; 6 | import org.jetbrains.annotations.NonNls; 7 | 8 | import java.io.File; 9 | import java.util.HashSet; 10 | import java.util.Set; 11 | 12 | public class EnumerateSymbolsCommand extends BlockingCommand { 13 | private final String prefix; 14 | private final FindSymbolsCommand.TargetTypes myType; 15 | private final Set symbols = new HashSet(5); 16 | private int totalCount; 17 | 18 | public EnumerateSymbolsCommand(String _prefix, FindSymbolsCommand.TargetTypes type) { 19 | prefix = _prefix; 20 | myType = type; 21 | setDoInfiniteBlockingWithCancelledCheck(true); 22 | } 23 | 24 | public EnumerateSymbolsCommand(FindSymbolsCommand.TargetTypes type) { 25 | this("", type); 26 | } 27 | 28 | public void commandOutputString(String str) { 29 | if (myType == FindSymbolsCommand.TargetTypes.CONSTANTS) str = str.substring(1,str.length() - 1); 30 | else if (myType == FindSymbolsCommand.TargetTypes.FILES) str = str.substring(str.lastIndexOf(File.separatorChar) + 1); 31 | symbols.add(str); 32 | ++totalCount; 33 | } 34 | 35 | public String getCommand() { 36 | final String s = BuildingCommandHelper.quote(prefix); 37 | StringBuilder builder = new StringBuilder(); 38 | @NonNls String commandName = null; 39 | 40 | switch(myType) { 41 | case SYMBOLS: commandName = "enumerate-symbols"; break; 42 | case TYPES: commandName = "enumerate-types"; break; 43 | case CONSTANTS: commandName = "enumerate-strings"; break; 44 | case MACROS: commandName = "enumerate-macros"; break; 45 | case FILES: commandName = "enumerate-files"; break; 46 | } 47 | 48 | assert commandName != null; 49 | 50 | builder.append(commandName + " " + s); 51 | 52 | return builder.toString(); 53 | } 54 | 55 | public Set getNames() { 56 | if (symbols.size() != this.totalCount) { 57 | int a = 1; 58 | } 59 | return symbols; 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /src/com/advancedtools/cpp/commands/FindSymbolsCommand.java: -------------------------------------------------------------------------------- 1 | // Copyright 2006-2012 AdvancedTools. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. 2 | package com.advancedtools.cpp.commands; 3 | 4 | import com.advancedtools.cpp.communicator.BuildingCommandHelper; 5 | import org.jetbrains.annotations.NonNls; 6 | 7 | public class FindSymbolsCommand extends FindUsagesCommand { 8 | public enum TargetTypes { 9 | SYMBOLS, TYPES, MACROS, CONSTANTS, FILES 10 | } 11 | 12 | private final String prefix; 13 | private final TargetTypes myTargetType; 14 | 15 | public FindSymbolsCommand(String _prefix, TargetTypes targetType) { 16 | super("",0); 17 | 18 | prefix = _prefix; 19 | myTargetType = targetType; 20 | setDoInfiniteBlockingWithCancelledCheck(true); 21 | } 22 | 23 | public String getCommand() { 24 | final String s = BuildingCommandHelper.quote(prefix); 25 | StringBuilder builder = new StringBuilder(); 26 | @NonNls String command = null; 27 | 28 | switch(myTargetType) { 29 | case MACROS: command = "exact-find-macros"; break; 30 | case TYPES: command = "exact-find-types"; break; 31 | case SYMBOLS: command = "exact-find-names"; break; 32 | case CONSTANTS: command = "find-strings"; break; 33 | case FILES: command = "find-files"; break; 34 | } 35 | 36 | assert command != null; 37 | builder.append(command + " " + s); 38 | 39 | return builder.toString(); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/com/advancedtools/cpp/commands/ImplementSomethingCommand.java: -------------------------------------------------------------------------------- 1 | // Copyright 2006-2012 AdvancedTools. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. 2 | package com.advancedtools.cpp.commands; 3 | 4 | import com.advancedtools.cpp.communicator.CommunicatorCommand; 5 | import com.advancedtools.cpp.communicator.BuildingCommandHelper; 6 | import com.intellij.openapi.editor.Editor; 7 | 8 | /** 9 | * @author maxim 10 | * Date: 06.03.2006 11 | * Time: 0:48:32 12 | */ 13 | public class ImplementSomethingCommand extends CommunicatorCommand { 14 | private final String fileName; 15 | private final Editor editor; 16 | private final int start; 17 | private String myText; 18 | 19 | public ImplementSomethingCommand(String _fileName, Editor _editor) { 20 | _fileName = BuildingCommandHelper.fixVirtualFileName(_fileName); 21 | fileName = _fileName; 22 | 23 | editor = _editor; 24 | start = editor.getCaretModel().getOffset(); 25 | } 26 | 27 | public boolean doInvokeInDispatchThread() { 28 | return true; 29 | } 30 | 31 | public void doExecute() { 32 | 33 | } 34 | 35 | public void commandOutputString(String str) { 36 | myText = str; 37 | } 38 | 39 | public String getCommand() { 40 | final String quotedFileName = BuildingCommandHelper.quote(fileName); 41 | return "implements " + quotedFileName + " " + start; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/com/advancedtools/cpp/commands/NavigationCommand.java: -------------------------------------------------------------------------------- 1 | // Copyright 2006-2012 AdvancedTools. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. 2 | package com.advancedtools.cpp.commands; 3 | 4 | import com.advancedtools.cpp.communicator.BuildingCommandHelper; 5 | import com.intellij.openapi.project.Project; 6 | import com.intellij.openapi.vfs.VirtualFile; 7 | import com.intellij.psi.PsiFile; 8 | import org.jetbrains.annotations.NonNls; 9 | 10 | public class NavigationCommand extends FindUsagesCommand { 11 | protected final Project project; 12 | 13 | protected NavigationCommand(Project _project, String _filePath, int _offset) { 14 | super(_filePath, _offset); 15 | project = _project; 16 | } 17 | 18 | public NavigationCommand(PsiFile file, int _offset) { 19 | this(file.getProject(), getPath(file), _offset); 20 | } 21 | 22 | private static String getPath(PsiFile file) { 23 | VirtualFile virtualFile = file.getVirtualFile(); 24 | 25 | if (virtualFile == null && file.getOriginalFile() != null) { 26 | virtualFile = file.getOriginalFile().getVirtualFile(); 27 | } 28 | return virtualFile != null ? virtualFile.getPath():""; 29 | } 30 | 31 | public String getCommand() { 32 | return getCommandText() + " " + BuildingCommandHelper.quote(filePath) + " " + offset; 33 | } 34 | 35 | protected @NonNls String getCommandText() { 36 | return "goto-def"; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/com/advancedtools/cpp/commands/SelectWordCommand.java: -------------------------------------------------------------------------------- 1 | // Copyright 2006-2012 AdvancedTools. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. 2 | package com.advancedtools.cpp.commands; 3 | 4 | import com.advancedtools.cpp.communicator.BlockingCommand; 5 | import com.advancedtools.cpp.communicator.BuildingCommandHelper; 6 | import com.advancedtools.cpp.communicator.Communicator; 7 | import com.intellij.openapi.editor.Editor; 8 | 9 | /** 10 | * @author maxim 11 | * Date: 06.03.2006 12 | * Time: 0:48:32 13 | */ 14 | public class SelectWordCommand extends BlockingCommand { 15 | private final String fileName; 16 | private final int start, end; 17 | private int mySelectionStart = -1; 18 | private int mySelectionEnd = -1; 19 | 20 | public SelectWordCommand(String _fileName, Editor _editor) { 21 | _fileName = BuildingCommandHelper.fixVirtualFileName(_fileName); 22 | fileName = _fileName; 23 | 24 | start = _editor.getSelectionModel().getSelectionStart(); 25 | end = _editor.getSelectionModel().getSelectionEnd(); 26 | } 27 | 28 | public void commandOutputString(String str) { 29 | if (str.startsWith("AT:|")) { 30 | int offset = str.indexOf(Communicator.DELIMITER, 4) + 1; 31 | 32 | mySelectionStart = Integer.parseInt(str.substring(4, offset - 1)); 33 | mySelectionEnd = Integer.parseInt(str.substring(offset)); 34 | } 35 | } 36 | 37 | public String getCommand() { 38 | final String quotedFileName = BuildingCommandHelper.quote(fileName); 39 | return "select " + quotedFileName + " " + start + " " + end; 40 | } 41 | 42 | 43 | public boolean hasReadyResult() { 44 | return super.hasReadyResult() && mySelectionEnd != -1; 45 | } 46 | 47 | public int getSelectionStart() { 48 | return mySelectionStart; 49 | } 50 | 51 | public int getSelectionEnd() { 52 | return mySelectionEnd; 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/com/advancedtools/cpp/commands/StringCommand.java: -------------------------------------------------------------------------------- 1 | // Copyright 2006-2012 AdvancedTools. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. 2 | package com.advancedtools.cpp.commands; 3 | 4 | import com.advancedtools.cpp.communicator.CommunicatorCommand; 5 | 6 | /** 7 | * @author maxim 8 | * Date: 05.03.2006 9 | * Time: 13:32:58 10 | */ 11 | public class StringCommand extends CommunicatorCommand { 12 | private String myCommandText; 13 | 14 | public StringCommand(String commandText) { myCommandText = commandText; } 15 | 16 | public void doExecute() {} 17 | public void commandOutputString(String str) {} 18 | public String getCommand() { return myCommandText; } 19 | } 20 | -------------------------------------------------------------------------------- /src/com/advancedtools/cpp/communicator/CommunicatorCommand.java: -------------------------------------------------------------------------------- 1 | // Copyright 2006-2012 AdvancedTools. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. 2 | package com.advancedtools.cpp.communicator; 3 | 4 | import com.intellij.openapi.project.Project; 5 | 6 | /** 7 | * @author maxim 8 | */ 9 | public abstract class CommunicatorCommand { 10 | private int restartTimestamp; 11 | 12 | public boolean isCancellable() { 13 | return true; 14 | } 15 | 16 | public abstract void doExecute(); 17 | public abstract void commandOutputString(String str); 18 | 19 | public void commandFinishedString(String str) {} 20 | 21 | public abstract String getCommand(); 22 | 23 | public boolean doInvokeInDispatchThread() { 24 | return false; 25 | } 26 | 27 | public void doExecuteOnCancel() {} 28 | 29 | public void post(Project project) { 30 | if (project.isDisposed()) { 31 | return; 32 | } 33 | Communicator.getInstance(project).sendCommand(this); 34 | } 35 | 36 | public boolean acceptsEmptyResult() { 37 | return false; 38 | } 39 | 40 | public void setRestartTimestamp(int restartTimestamp) { 41 | this.restartTimestamp = restartTimestamp; 42 | } 43 | 44 | public int getRestartTimestamp() { 45 | return restartTimestamp; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/com/advancedtools/cpp/communicator/LoadingCppProjectDialog.form: -------------------------------------------------------------------------------- 1 | 2 |
3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 |
37 | -------------------------------------------------------------------------------- /src/com/advancedtools/cpp/communicator/LoadingCppProjectDialog.java: -------------------------------------------------------------------------------- 1 | // Copyright 2006-2012 AdvancedTools. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. 2 | package com.advancedtools.cpp.communicator; 3 | 4 | import com.intellij.openapi.ui.DialogWrapper; 5 | import com.intellij.openapi.project.Project; 6 | import com.advancedtools.cpp.CppBundle; 7 | 8 | import javax.swing.*; 9 | 10 | import org.jetbrains.annotations.Nullable; 11 | 12 | /** 13 | * @author maxim 14 | */ 15 | public class LoadingCppProjectDialog extends DialogWrapper { 16 | private JComboBox comboBox1; 17 | private JPanel panel; 18 | 19 | protected LoadingCppProjectDialog(Project project, String[] files) { 20 | super(project, false); 21 | setTitle(CppBundle.message("loading.cpp.project.dialog.title")); 22 | comboBox1.setModel(new DefaultComboBoxModel(files)); 23 | if (files.length > 0) comboBox1.setSelectedItem(files[0]); 24 | init(); 25 | } 26 | 27 | @Nullable 28 | protected JComponent createCenterPanel() { 29 | return panel; 30 | } 31 | 32 | public String getSelectedProjectFile() { 33 | return (String) comboBox1.getSelectedItem(); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/com/advancedtools/cpp/communicator/WarnAboutFilesOutOfSourceRootsDialog.form: -------------------------------------------------------------------------------- 1 | 2 |
3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 |
35 | -------------------------------------------------------------------------------- /src/com/advancedtools/cpp/communicator/WarnAboutFilesOutOfSourceRootsDialog.java: -------------------------------------------------------------------------------- 1 | // Copyright 2006-2012 AdvancedTools. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. 2 | package com.advancedtools.cpp.communicator; 3 | 4 | import com.intellij.openapi.ui.DialogWrapper; 5 | import com.intellij.openapi.project.Project; 6 | import com.advancedtools.cpp.CppBundle; 7 | 8 | import javax.swing.*; 9 | 10 | import org.jetbrains.annotations.Nullable; 11 | 12 | /** 13 | * @author maxim 14 | */ 15 | public class WarnAboutFilesOutOfSourceRootsDialog extends DialogWrapper { 16 | private JPanel panel; 17 | 18 | public WarnAboutFilesOutOfSourceRootsDialog(Project project) { 19 | super(project, false); 20 | setTitle(CppBundle.message("c.c.file.outside.of.source.roots.dialog.title")); 21 | init(); 22 | } 23 | 24 | @Nullable 25 | protected JComponent createCenterPanel() { 26 | return panel; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/com/advancedtools/cpp/completion/CppCompletionConfidence.java: -------------------------------------------------------------------------------- 1 | // Copyright 2006-2012 AdvancedTools. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. 2 | package com.advancedtools.cpp.completion; 3 | 4 | import com.intellij.codeInsight.completion.CompletionConfidence; 5 | import com.intellij.codeInsight.completion.CompletionParameters; 6 | import com.intellij.psi.PsiElement; 7 | import com.intellij.psi.PsiFile; 8 | import com.intellij.util.ThreeState; 9 | import org.jetbrains.annotations.NotNull; 10 | import org.jetbrains.annotations.Nullable; 11 | 12 | public class CppCompletionConfidence extends CompletionConfidence { 13 | @NotNull 14 | @Override 15 | public ThreeState shouldFocusLookup(@NotNull CompletionParameters completionParameters) { 16 | return ThreeState.NO; 17 | } 18 | 19 | @NotNull 20 | @Override 21 | public ThreeState shouldSkipAutopopup(@Nullable PsiElement contextElement, @NotNull PsiFile psiFile, int offset) { 22 | return ThreeState.YES; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/com/advancedtools/cpp/completion/CppCompletionContributor.java: -------------------------------------------------------------------------------- 1 | // Copyright 2006-2012 AdvancedTools. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. 2 | package com.advancedtools.cpp.completion; 3 | 4 | import com.advancedtools.cpp.utils.LM; 5 | import com.intellij.codeInsight.completion.CompletionParameters; 6 | import com.intellij.codeInsight.completion.DefaultCompletionContributor; 7 | import org.jetbrains.annotations.NotNull; 8 | 9 | /** 10 | * @author maximm 11 | * Date: 2/3/12 12 | * Time: 1:23 PM 13 | */ 14 | public class CppCompletionContributor extends DefaultCompletionContributor { 15 | @Override 16 | public String advertise(@NotNull CompletionParameters parameters) { 17 | return !LM.isRegistered()? "license owners have no advertising":super.advertise(parameters); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/com/advancedtools/cpp/debugger/CppBaseDebugRunner.java: -------------------------------------------------------------------------------- 1 | // Copyright 2006-2012 AdvancedTools. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. 2 | package com.advancedtools.cpp.debugger; 3 | 4 | import com.advancedtools.cpp.run.BaseCppConfiguration; 5 | import com.intellij.execution.ExecutionException; 6 | import com.intellij.execution.configurations.RunProfile; 7 | import com.intellij.execution.configurations.RunProfileState; 8 | import com.intellij.execution.executors.DefaultDebugExecutor; 9 | import com.intellij.execution.runners.ExecutionEnvironment; 10 | import com.intellij.execution.runners.GenericProgramRunner; 11 | import com.intellij.execution.ui.RunContentDescriptor; 12 | import com.intellij.openapi.fileEditor.FileDocumentManager; 13 | import com.intellij.openapi.project.Project; 14 | import com.intellij.xdebugger.XDebugProcess; 15 | import com.intellij.xdebugger.XDebugProcessStarter; 16 | import com.intellij.xdebugger.XDebugSession; 17 | import com.intellij.xdebugger.XDebuggerManager; 18 | import org.jetbrains.annotations.NotNull; 19 | import org.jetbrains.annotations.Nullable; 20 | 21 | /** 22 | * @author maxim 23 | * Date: 28.03.2009 24 | * Time: 19:35:05 25 | */ 26 | public abstract class CppBaseDebugRunner extends GenericProgramRunner { 27 | @Nullable 28 | @Override 29 | protected RunContentDescriptor doExecute(Project project, RunProfileState runProfileState, RunContentDescriptor runContentDescriptor, ExecutionEnvironment env) throws ExecutionException { 30 | FileDocumentManager.getInstance().saveAllDocuments(); 31 | 32 | final RunProfile runProfile = env.getRunProfile(); 33 | 34 | final XDebugSession debugSession = 35 | XDebuggerManager.getInstance(project).startSession(this, env, runContentDescriptor, new XDebugProcessStarter() { 36 | @NotNull 37 | public XDebugProcess start(@NotNull final XDebugSession session) { 38 | return new CppDebugProcess(session, CppBaseDebugRunner.this, (BaseCppConfiguration)runProfile); 39 | } 40 | }); 41 | 42 | return debugSession.getRunContentDescriptor(); 43 | } 44 | 45 | public boolean canRun(@NotNull final String executorId, @NotNull final RunProfile profile) { 46 | return DefaultDebugExecutor.EXECUTOR_ID.equals(executorId) && 47 | profile instanceof BaseCppConfiguration && 48 | isSuitableConfiguration((BaseCppConfiguration)profile) 49 | ; 50 | } 51 | 52 | protected abstract boolean isSuitableConfiguration(BaseCppConfiguration configuration); 53 | 54 | 55 | public abstract @Nullable String getWorkingDirectory(T runConfiguration); 56 | 57 | public abstract String getStartupCommandText(T runConfiguration); 58 | 59 | public abstract String getQuitCommandText(T runConfiguration); 60 | 61 | public abstract String getRunCommandText(T configuration, CppDebugProcess cppDebugProcess); 62 | } -------------------------------------------------------------------------------- /src/com/advancedtools/cpp/debugger/CppBreakpointType.java: -------------------------------------------------------------------------------- 1 | // Copyright 2006-2012 AdvancedTools. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. 2 | package com.advancedtools.cpp.debugger; 3 | 4 | import com.intellij.xdebugger.breakpoints.XBreakpointProperties; 5 | import com.intellij.xdebugger.breakpoints.XLineBreakpointType; 6 | import com.intellij.openapi.vfs.VirtualFile; 7 | import com.intellij.openapi.project.Project; 8 | import com.advancedtools.cpp.CppSupportLoader; 9 | import com.advancedtools.cpp.CppBundle; 10 | import org.jetbrains.annotations.NotNull; 11 | 12 | /** 13 | * @author maxim 14 | * Date: 28.03.2009 15 | * Time: 20:49:33 16 | */ 17 | public class CppBreakpointType extends XLineBreakpointType { 18 | public CppBreakpointType() { 19 | super("Cpp", CppBundle.message("cpp.breakpoints")); 20 | } 21 | 22 | public XBreakpointProperties createBreakpointProperties(@NotNull VirtualFile file, int line) { 23 | return null; 24 | } 25 | 26 | @Override 27 | public boolean canPutAt(@NotNull VirtualFile file, int line, @NotNull Project project) { 28 | return file.getFileType() == CppSupportLoader.CPP_FILETYPE; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/com/advancedtools/cpp/debugger/CppDebuggerConstants.java: -------------------------------------------------------------------------------- 1 | // Copyright 2006-2012 AdvancedTools. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. 2 | package com.advancedtools.cpp.debugger; 3 | 4 | import com.intellij.openapi.util.SystemInfo; 5 | 6 | /** 7 | * @author maxim 8 | * Date: 05.04.2009 9 | * Time: 0:04:51 10 | */ 11 | public class CppDebuggerConstants { 12 | public static final boolean gdbCanNotRedirectOutputOfDebuggedCommand = SystemInfo.isWindows; 13 | } 14 | -------------------------------------------------------------------------------- /src/com/advancedtools/cpp/debugger/CppSuspendContext.java: -------------------------------------------------------------------------------- 1 | // Copyright 2006-2012 AdvancedTools. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. 2 | package com.advancedtools.cpp.debugger; 3 | 4 | import com.advancedtools.cpp.debugger.commands.CppDebuggerContext; 5 | import com.advancedtools.cpp.debugger.commands.DebuggerCommand; 6 | import com.intellij.xdebugger.frame.XExecutionStack; 7 | import com.intellij.xdebugger.frame.XSuspendContext; 8 | 9 | import java.util.ArrayList; 10 | import java.util.List; 11 | 12 | /** 13 | * User: maxim 14 | * Date: 30.03.2009 15 | * Time: 0:53:59 16 | */ 17 | public class CppSuspendContext extends XSuspendContext { 18 | private CppThreadStackInfo myActiveThreadStack; 19 | private CppThreadStackInfo[] myThreadStacks; 20 | private final CppDebuggerContext myContext; 21 | 22 | public CppSuspendContext(final CppStackFrame stackFrame, final CppDebuggerContext context) { 23 | myContext = context; 24 | 25 | final List threads = new ArrayList(); 26 | 27 | myContext.sendAndProcessOneCommand(new DebuggerCommand("info threads") { 28 | @Override 29 | protected void processToken(String token, CppDebuggerContext context) { 30 | if (token.indexOf("thread") != -1) { 31 | CppThreadStackInfo info; 32 | // "* "?6 thread 3020.0x890 0x7c90e514 in ntdll!LdrAccessResource () from C:\WINDOWS\system32\ntdll.dll 33 | boolean activeThread = token.charAt(0) == '*'; 34 | int startOffset = activeThread ? 2 : 0; 35 | int threadIdEnd = token.indexOf(' ', startOffset); 36 | int startOfFunPos = token.indexOf(' ', token.indexOf(' ', threadIdEnd + 1) + 1); 37 | int threadNo = Integer.parseInt(token.substring(startOffset, threadIdEnd)); 38 | String displayName = token.substring(startOffset, startOfFunPos); 39 | 40 | if (activeThread) { 41 | info = new CppThreadStackInfo(CppSuspendContext.this, stackFrame, context, displayName, threadNo); 42 | myActiveThreadStack = info; 43 | } else { 44 | CppStackFrame cppStackFrame = CppStackFrame.parseStackFrame("#0"+token.substring(startOfFunPos + 1), null, context); 45 | info = new CppThreadStackInfo(CppSuspendContext.this, cppStackFrame, context, displayName, threadNo); 46 | } 47 | threads.add(info); 48 | return; 49 | } 50 | super.processToken(token, context); 51 | } 52 | }); 53 | 54 | myThreadStacks = threads.toArray(new CppThreadStackInfo[threads.size()]); 55 | } 56 | 57 | @Override 58 | public XExecutionStack getActiveExecutionStack() { 59 | return myActiveThreadStack; 60 | } 61 | 62 | @Override 63 | public XExecutionStack[] getExecutionStacks() { 64 | return myThreadStacks; 65 | } 66 | 67 | public void setActiveExecutionStack(CppThreadStackInfo threadStackInfo) { 68 | myActiveThreadStack = threadStackInfo; 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /src/com/advancedtools/cpp/debugger/CppThreadStackInfo.java: -------------------------------------------------------------------------------- 1 | // Copyright 2006-2012 AdvancedTools. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. 2 | package com.advancedtools.cpp.debugger; 3 | 4 | import com.intellij.xdebugger.frame.XExecutionStack; 5 | import com.intellij.xdebugger.frame.XStackFrame; 6 | import com.advancedtools.cpp.debugger.commands.CppDebuggerContext; 7 | import com.advancedtools.cpp.debugger.commands.DebuggerCommand; 8 | 9 | import java.util.List; 10 | import java.util.ArrayList; 11 | import java.io.IOException; 12 | 13 | /** 14 | * User: maxim 15 | * Date: 22.08.2009 16 | * Time: 19:08:11 17 | */ 18 | class CppThreadStackInfo extends XExecutionStack { 19 | private final CppSuspendContext suspendContext; 20 | private final XStackFrame stackFrame; 21 | private final CppDebuggerContext context; 22 | private final int threadNo; 23 | 24 | CppThreadStackInfo(CppSuspendContext _suspendContext, CppStackFrame stackFrame, 25 | CppDebuggerContext context, String displayName, int _threadNo) { 26 | super(displayName); 27 | 28 | suspendContext = _suspendContext; 29 | stackFrame.setThreadStackInfo(this); 30 | this.stackFrame = stackFrame; 31 | this.context = context; 32 | threadNo = _threadNo; 33 | } 34 | 35 | @Override 36 | public XStackFrame getTopFrame() { 37 | return stackFrame; 38 | } 39 | 40 | @Override 41 | public void computeStackFrames(final int i, final XStackFrameContainer xStackFrameContainer) { 42 | switchToTargetThread(this); 43 | context.sendCommand(new DebuggerCommand("bt") { 44 | final List frames = new ArrayList(); 45 | int count = 0; 46 | @Override 47 | protected void processToken(String token, CppDebuggerContext context) { 48 | ++count; 49 | if (count == i) return; 50 | CppStackFrame stackFrame = CppStackFrame.parseStackFrame(token, CppThreadStackInfo.this, context); 51 | if (stackFrame != null) frames.add(stackFrame); 52 | } 53 | 54 | @Override 55 | public void readResponse(CppDebuggerContext context) throws IOException { 56 | super.readResponse(context); 57 | xStackFrameContainer.addStackFrames(frames, true); 58 | } 59 | }); 60 | } 61 | 62 | public static void switchToTargetThread(CppThreadStackInfo threadStackInfo) { 63 | if (!threadStackInfo.isActive()) { 64 | threadStackInfo.context.sendCommand(new DebuggerCommand("thread " + threadStackInfo.threadNo)); 65 | threadStackInfo.suspendContext.setActiveExecutionStack(threadStackInfo); 66 | } 67 | } 68 | 69 | boolean isActive() { 70 | return suspendContext.getActiveExecutionStack() == this; 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /src/com/advancedtools/cpp/debugger/commands/AddBreakpointCommand.java: -------------------------------------------------------------------------------- 1 | // Copyright 2006-2012 AdvancedTools. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. 2 | package com.advancedtools.cpp.debugger.commands; 3 | 4 | import com.intellij.xdebugger.breakpoints.XBreakpointProperties; 5 | import com.intellij.xdebugger.breakpoints.XLineBreakpoint; 6 | import com.intellij.xdebugger.XSourcePosition; 7 | import com.advancedtools.cpp.debugger.CppBreakpointManager; 8 | 9 | /** 10 | * @author maxim 11 | * Date: 29.03.2009 12 | * Time: 17:28:14 13 | */ 14 | public class AddBreakpointCommand extends DebuggerCommand { 15 | private final XLineBreakpoint myBreakpoint; 16 | 17 | public AddBreakpointCommand(XLineBreakpoint breakpoint) { 18 | super("break " + fileName(breakpoint) + ":" + (breakpoint.getLine() + 1)); 19 | myBreakpoint = breakpoint; 20 | } 21 | 22 | private static String fileName(XLineBreakpoint breakpoint) { 23 | XSourcePosition sourcePosition = breakpoint.getSourcePosition(); 24 | 25 | return sourcePosition != null ? sourcePosition.getFile().getName():"unknown.cpp"; 26 | } 27 | 28 | protected boolean processResponse(String s, CppDebuggerContext context) { 29 | String marker = CppBreakpointManager.BREAKPOINT_MARKER; 30 | if (s.startsWith(marker)) { // TODO: setting breakpoint can cause several ones to appear 31 | int breakpointId = Integer.parseInt(s.substring(marker.length(), s.indexOf(' ', marker.length()))); 32 | context.getBreakpointManager().registerBreakpoint(myBreakpoint, breakpointId); 33 | } 34 | return super.processResponse(s, context); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/com/advancedtools/cpp/debugger/commands/ContinueCommand.java: -------------------------------------------------------------------------------- 1 | // Copyright 2006-2012 AdvancedTools. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. 2 | package com.advancedtools.cpp.debugger.commands; 3 | 4 | import java.io.IOException; 5 | 6 | /** 7 | * @author maxim 8 | * Date: 29.03.2009 9 | * Time: 17:28:47 10 | */ 11 | public class ContinueCommand extends DebuggerCommand { 12 | public ContinueCommand() { 13 | super("continue"); 14 | } 15 | 16 | @Override 17 | public void readResponse(CppDebuggerContext context) throws IOException { 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/com/advancedtools/cpp/debugger/commands/CppDebuggerContext.java: -------------------------------------------------------------------------------- 1 | // Copyright 2006-2012 AdvancedTools. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. 2 | package com.advancedtools.cpp.debugger.commands; 3 | 4 | import com.advancedtools.cpp.debugger.CppBreakpointManager; 5 | import com.intellij.xdebugger.XDebugSession; 6 | import com.intellij.execution.process.ProcessHandler; 7 | import com.intellij.execution.ui.ConsoleViewContentType; 8 | 9 | import java.io.InputStream; 10 | import java.io.InputStreamReader; 11 | import java.io.OutputStream; 12 | import java.io.IOException; 13 | 14 | /** 15 | * User: maxim 16 | * Date: 29.03.2009 17 | * Time: 17:24:00 18 | */ 19 | public interface CppDebuggerContext { 20 | OutputStream getOutputStream(); 21 | 22 | InputStream getInputStream(); 23 | 24 | InputStreamReader getInputReader(); 25 | 26 | CppBreakpointManager getBreakpointManager(); 27 | 28 | void scheduleOutputReading(); 29 | 30 | void sendCommand(DebuggerCommand command); 31 | void sendAndProcessOneCommand(DebuggerCommand command); 32 | 33 | XDebugSession getSession(); 34 | 35 | ProcessHandler getProcessHandler(); 36 | 37 | String readLine(boolean b) throws IOException; 38 | 39 | void printToConsole(String s, ConsoleViewContentType contentType); 40 | } 41 | -------------------------------------------------------------------------------- /src/com/advancedtools/cpp/debugger/commands/DebuggerCommand.java: -------------------------------------------------------------------------------- 1 | // Copyright 2006-2012 AdvancedTools. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. 2 | package com.advancedtools.cpp.debugger.commands; 3 | 4 | import com.advancedtools.cpp.debugger.CppStackFrame; 5 | import com.advancedtools.cpp.debugger.CppSuspendContext; 6 | import com.intellij.execution.ui.ConsoleViewContentType; 7 | 8 | import java.io.IOException; 9 | import java.io.OutputStream; 10 | import java.util.StringTokenizer; 11 | 12 | /** 13 | * User: maxim 14 | * Date: 29.03.2009 15 | * Time: 17:23:22 16 | */ 17 | public class DebuggerCommand { 18 | private String command; 19 | 20 | public DebuggerCommand(String _command) { 21 | command = _command; 22 | } 23 | 24 | public String getCommandText() { 25 | return command; 26 | } 27 | 28 | public void post(CppDebuggerContext context) throws IOException { 29 | OutputStream outputStream = context.getOutputStream(); 30 | String text = getCommandText(); 31 | System.out.println("in:"+text); 32 | outputStream.write((text + "\n").getBytes()); 33 | outputStream.flush(); 34 | } 35 | 36 | public void readResponse(CppDebuggerContext context) throws IOException { 37 | while(true) { 38 | String s = context.readLine(shouldReadTillMarker()); 39 | System.out.println("out:"+s); 40 | if (!processResponse(s, context)) return; 41 | } 42 | } 43 | 44 | protected boolean shouldReadTillMarker() { 45 | return true; 46 | } 47 | 48 | protected boolean processResponse(String s, CppDebuggerContext context) { 49 | if (s == null) return false; 50 | StringTokenizer tokenizer = new StringTokenizer(s, "\r\n"); 51 | while(tokenizer.hasMoreElements()) { 52 | final String token = tokenizer.nextToken().trim(); 53 | if (token.length() == 0) continue; 54 | 55 | processToken(token, context); 56 | } 57 | return false; 58 | } 59 | 60 | protected void processToken(String token, CppDebuggerContext context) { 61 | if(context.getBreakpointManager().processResponseLine(token, context)) return; 62 | 63 | final char c = token.charAt(0); 64 | if (Character.isDigit(c) && !context.getSession().isPaused()) { 65 | context.sendCommand(new DebuggerCommand("bt 1")); 66 | } else if (c == '#' && token.startsWith("#0")) { 67 | final CppStackFrame stackFrame = CppStackFrame.parseStackFrame(token, null, context); 68 | 69 | context.getSession().positionReached( 70 | new CppSuspendContext(stackFrame, context) 71 | ); 72 | } else if (token.indexOf("Program exited") != -1) { 73 | context.printToConsole(token, ConsoleViewContentType.SYSTEM_OUTPUT); 74 | if (!context.getSession().isStopped()) { 75 | context.getProcessHandler().detachProcess(); 76 | } 77 | } else if (token.indexOf("Program received signal") != -1) { 78 | context.printToConsole(token, ConsoleViewContentType.SYSTEM_OUTPUT); 79 | } 80 | } 81 | 82 | } 83 | -------------------------------------------------------------------------------- /src/com/advancedtools/cpp/debugger/commands/QuitCommand.java: -------------------------------------------------------------------------------- 1 | // Copyright 2006-2012 AdvancedTools. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. 2 | package com.advancedtools.cpp.debugger.commands; 3 | 4 | import com.advancedtools.cpp.debugger.CppBaseDebugRunner; 5 | import com.advancedtools.cpp.run.BaseCppConfiguration; 6 | 7 | /** 8 | * @author maxim 9 | * Date: 29.03.2009 10 | * Time: 20:26:29 11 | */ 12 | public class QuitCommand extends DebuggerCommand { 13 | private CppBaseDebugRunner myDebugRunner; 14 | private BaseCppConfiguration myRunConfiguration; 15 | 16 | public QuitCommand(CppBaseDebugRunner debugRunner, BaseCppConfiguration runConfiguration) { 17 | super(""); 18 | myDebugRunner = debugRunner; 19 | myRunConfiguration = runConfiguration; 20 | } 21 | 22 | @Override 23 | public String getCommandText() { 24 | return myDebugRunner.getQuitCommandText(myRunConfiguration); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/com/advancedtools/cpp/debugger/commands/ReadOutputCommand.java: -------------------------------------------------------------------------------- 1 | // Copyright 2006-2012 AdvancedTools. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. 2 | package com.advancedtools.cpp.debugger.commands; 3 | 4 | import java.io.IOException; 5 | 6 | /** 7 | * @author maxim 8 | * Date: 29.03.2009 9 | * Time: 17:27:21 10 | */ 11 | public class ReadOutputCommand extends DebuggerCommand { 12 | public ReadOutputCommand() { 13 | super(""); 14 | } 15 | 16 | @Override 17 | public void post(CppDebuggerContext context) { 18 | } 19 | 20 | protected boolean shouldReadTillMarker() { 21 | return false; 22 | } 23 | 24 | @Override 25 | public void readResponse(CppDebuggerContext context) throws IOException { 26 | if (context.getInputStream().available() == 0) { 27 | context.scheduleOutputReading(); 28 | return; 29 | } 30 | super.readResponse(context); 31 | } 32 | 33 | @Override 34 | protected boolean processResponse(String s, CppDebuggerContext context) { 35 | context.scheduleOutputReading(); 36 | return super.processResponse(s, context); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/com/advancedtools/cpp/debugger/commands/RemoveBreakpointCommand.java: -------------------------------------------------------------------------------- 1 | // Copyright 2006-2012 AdvancedTools. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. 2 | package com.advancedtools.cpp.debugger.commands; 3 | 4 | import com.advancedtools.cpp.debugger.commands.DebuggerCommand; 5 | import com.advancedtools.cpp.debugger.commands.CppDebuggerContext; 6 | import com.intellij.xdebugger.breakpoints.XBreakpointProperties; 7 | import com.intellij.xdebugger.breakpoints.XLineBreakpoint; 8 | 9 | import java.io.IOException; 10 | 11 | /** 12 | * @author maxim 13 | * Date: 30.03.2009 14 | * Time: 1:23:02 15 | */ 16 | public class RemoveBreakpointCommand extends DebuggerCommand { 17 | private XLineBreakpoint myBreakpoint; 18 | 19 | public RemoveBreakpointCommand(XLineBreakpoint breakpoint, int index) { 20 | super("delete "+index); 21 | myBreakpoint = breakpoint; 22 | } 23 | 24 | @Override 25 | public void readResponse(CppDebuggerContext context) throws IOException { 26 | super.readResponse(context); 27 | context.getBreakpointManager().unregisterBreakpoint(myBreakpoint); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/com/advancedtools/cpp/debugger/commands/StartupCommand.java: -------------------------------------------------------------------------------- 1 | // Copyright 2006-2012 AdvancedTools. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. 2 | package com.advancedtools.cpp.debugger.commands; 3 | 4 | import com.advancedtools.cpp.debugger.CppBaseDebugRunner; 5 | import com.advancedtools.cpp.run.BaseCppConfiguration; 6 | 7 | /** 8 | * @author maxim 9 | * Date: 29.03.2009 10 | * Time: 17:27:21 11 | */ 12 | public class StartupCommand extends DebuggerCommand { 13 | private CppBaseDebugRunner myDebugRunner; 14 | private BaseCppConfiguration myRunConfiguration; 15 | 16 | public StartupCommand(CppBaseDebugRunner debugRunner, BaseCppConfiguration runConfiguration) { 17 | super(""); 18 | myDebugRunner = debugRunner; 19 | myRunConfiguration = runConfiguration; 20 | } 21 | 22 | @Override 23 | public void post(CppDebuggerContext context) { 24 | String myExecutableParameters = myDebugRunner.getStartupCommandText(myRunConfiguration); 25 | context.sendCommand(new TextDebuggerCommand(myExecutableParameters)); 26 | context.sendCommand(new DebuggerCommand("set breakpoint pending on")); 27 | context.sendCommand(new DebuggerCommand("set confirm off")); 28 | } 29 | 30 | protected boolean processResponse(String s, CppDebuggerContext context) { 31 | return super.processResponse(s, context); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/com/advancedtools/cpp/debugger/commands/TextDebuggerCommand.java: -------------------------------------------------------------------------------- 1 | // Copyright 2006-2012 AdvancedTools. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. 2 | package com.advancedtools.cpp.debugger.commands; 3 | 4 | /** 5 | * @author maxim 6 | * Date: Apr 5, 2009 7 | * Time: 12:57:16 PM 8 | */ 9 | public class TextDebuggerCommand extends DebuggerCommand { 10 | private int expectedResponseCount = 1; 11 | private int responseCount; 12 | 13 | public TextDebuggerCommand(String executableParameters) { 14 | super(executableParameters); 15 | 16 | int ptr = -1; 17 | while((ptr = executableParameters.indexOf('\n', ptr + 1)) != -1) { 18 | ++expectedResponseCount; 19 | } 20 | } 21 | 22 | @Override 23 | protected boolean processResponse(String s, CppDebuggerContext context) { 24 | super.processResponse(s, context); 25 | ++responseCount; 26 | return responseCount != expectedResponseCount; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/com/advancedtools/cpp/debugger/remote/CppRemoteDebugConfigurationType.java: -------------------------------------------------------------------------------- 1 | // Copyright 2006-2012 AdvancedTools. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. 2 | package com.advancedtools.cpp.debugger.remote; 3 | 4 | import com.advancedtools.cpp.CppSupportLoader; 5 | import com.intellij.execution.configurations.ConfigurationFactory; 6 | import com.intellij.execution.configurations.RunConfiguration; 7 | import com.intellij.execution.configurations.ConfigurationType; 8 | import com.intellij.openapi.project.Project; 9 | import com.advancedtools.cpp.sdk.CppSdkType; 10 | 11 | import javax.swing.*; 12 | 13 | import org.jetbrains.annotations.NotNull; 14 | 15 | /** 16 | * @author maxim 17 | * Date: 28.03.2009 18 | * Time: 20:09:12 19 | */ 20 | public class CppRemoteDebugConfigurationType implements ConfigurationType { 21 | private final ConfigurationFactory myFactory; 22 | 23 | public CppRemoteDebugConfigurationType() { 24 | myFactory = new ConfigurationFactory(this) { 25 | public RunConfiguration createTemplateConfiguration(Project project) { 26 | return new CppRemoteDebugConfiguration(project, this, ""); 27 | } 28 | }; 29 | } 30 | 31 | public String getDisplayName() { 32 | return "Cpp Remote Debug"; 33 | } 34 | 35 | public String getConfigurationTypeDescription() { 36 | return "Cpp Remote Debug"; 37 | } 38 | 39 | public Icon getIcon() { 40 | return CppSupportLoader.ourSdkIcon; 41 | } 42 | 43 | public ConfigurationFactory[] getConfigurationFactories() { 44 | return new ConfigurationFactory[] {myFactory}; 45 | } 46 | 47 | @NotNull 48 | public String getId() { 49 | return "CppRemoteDebugConfigurationType"; 50 | } 51 | } -------------------------------------------------------------------------------- /src/com/advancedtools/cpp/debugger/remote/CppRemoteDebugParameters.java: -------------------------------------------------------------------------------- 1 | // Copyright 2006-2012 AdvancedTools. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. 2 | package com.advancedtools.cpp.debugger.remote; 3 | 4 | import com.advancedtools.cpp.run.BaseCppRunnerParameters; 5 | 6 | /** 7 | * @author maxim 8 | * Date: Apr 5, 2009 9 | * Time: 12:04:09 PM 10 | */ 11 | public class CppRemoteDebugParameters extends BaseCppRunnerParameters { 12 | private String host; 13 | private String port; 14 | private String pid; 15 | 16 | public String getHost() { 17 | return host; 18 | } 19 | 20 | public void setHost(String host) { 21 | this.host = host; 22 | } 23 | 24 | public String getPort() { 25 | return port; 26 | } 27 | 28 | public void setPort(String port) { 29 | this.port = port; 30 | } 31 | 32 | public String getPid() { 33 | return pid; 34 | } 35 | 36 | public void setPid(String pid) { 37 | this.pid = pid; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/com/advancedtools/cpp/debugger/remote/CppRemoteDebugRunner.java: -------------------------------------------------------------------------------- 1 | // Copyright 2006-2012 AdvancedTools. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. 2 | package com.advancedtools.cpp.debugger.remote; 3 | 4 | import com.advancedtools.cpp.debugger.CppBaseDebugRunner; 5 | import com.advancedtools.cpp.debugger.CppDebugProcess; 6 | import com.advancedtools.cpp.run.BaseCppConfiguration; 7 | import org.jetbrains.annotations.NotNull; 8 | 9 | /** 10 | * @author maxim 11 | * Date: Apr 5, 2009 12 | * Time: 11:13:29 AM 13 | */ 14 | public class CppRemoteDebugRunner extends CppBaseDebugRunner { 15 | @NotNull 16 | public String getRunnerId() { 17 | return "CppRemoteDebugRunner"; 18 | } 19 | 20 | protected boolean isSuitableConfiguration(BaseCppConfiguration configuration) { 21 | return configuration instanceof CppRemoteDebugConfiguration; 22 | } 23 | 24 | public String getWorkingDirectory(CppRemoteDebugConfiguration runConfiguration) { 25 | return null; 26 | } 27 | 28 | public String getStartupCommandText(CppRemoteDebugConfiguration runConfiguration) { 29 | CppRemoteDebugParameters debugParameters = runConfiguration.getRunnerParameters(); 30 | if (debugParameters.getPid() != null) { 31 | return "attach " + debugParameters.getPid(); 32 | } 33 | return "target remote "+ debugParameters.getHost() + ":" + debugParameters.getPort(); 34 | } 35 | 36 | @Override 37 | public String getQuitCommandText(CppRemoteDebugConfiguration runConfiguration) { 38 | return "continue\ndetach\nquit\ny"; // TODO: gdb forks process and may be we need to close copy 39 | } 40 | 41 | public String getRunCommandText(CppRemoteDebugConfiguration configuration, CppDebugProcess cppRemoteDebugConfigurationCppDebugProcess) { 42 | return "run"; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/com/advancedtools/cpp/debugger/remote/CppRemoteDebugSettingEditor.java: -------------------------------------------------------------------------------- 1 | // Copyright 2006-2012 AdvancedTools. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. 2 | package com.advancedtools.cpp.debugger.remote; 3 | 4 | import com.advancedtools.cpp.run.BaseCppRunSettingsEditor; 5 | import com.intellij.ui.ComboboxWithBrowseButton; 6 | import com.intellij.ui.TextFieldWithStoredHistory; 7 | import com.intellij.openapi.project.Project; 8 | import com.intellij.openapi.options.ConfigurationException; 9 | import org.jetbrains.annotations.NotNull; 10 | 11 | import javax.swing.*; 12 | 13 | /** 14 | * @author maxim 15 | * Date: Apr 5, 2009 16 | * Time: 12:06:02 PM 17 | */ 18 | class CppRemoteDebugSettingEditor extends BaseCppRunSettingsEditor { 19 | private JPanel myPanel; 20 | private ComboboxWithBrowseButton myExecutableName; 21 | private TextFieldWithStoredHistory myHost; 22 | private TextFieldWithStoredHistory myPort; 23 | private TextFieldWithStoredHistory myPid; 24 | 25 | CppRemoteDebugSettingEditor(Project project) { 26 | setupCommonUI(project); 27 | } 28 | 29 | protected ComboboxWithBrowseButton getExecutableName() { 30 | return myExecutableName; 31 | } 32 | 33 | @NotNull 34 | protected JComponent createEditor() { 35 | return myPanel; 36 | } 37 | 38 | protected void disposeEditor() { 39 | myPanel = null; 40 | myExecutableName = null; 41 | myHost = null; 42 | myPort = null; 43 | myPid = null; 44 | } 45 | 46 | @Override 47 | protected void resetEditorFrom(CppRemoteDebugConfiguration s) { 48 | super.resetEditorFrom(s); 49 | 50 | CppRemoteDebugParameters runnerParameters = s.getRunnerParameters(); 51 | myHost.setText(runnerParameters != null && runnerParameters.getHost() != null ? runnerParameters.getHost():""); 52 | myPort.setText(runnerParameters != null && runnerParameters.getPort() != null ? runnerParameters.getPort():""); 53 | myPid.setText(runnerParameters != null && runnerParameters.getPid() != null ? runnerParameters.getPid():""); 54 | } 55 | 56 | @Override 57 | protected void applyEditorTo(CppRemoteDebugConfiguration s) throws ConfigurationException { 58 | super.applyEditorTo(s); 59 | 60 | CppRemoteDebugParameters runnerParameters = s.getRunnerParameters(); 61 | runnerParameters.setPort(myPort.getText()); 62 | runnerParameters.setHost(myHost.getText()); 63 | runnerParameters.setPid(myPid.getText()); 64 | } 65 | 66 | private void createUIComponents() { 67 | myHost = new TextFieldWithStoredHistory("cpp.remote.debug.host"); 68 | myPort = new TextFieldWithStoredHistory("cpp.remote.debug.port"); 69 | myPid = new TextFieldWithStoredHistory("cpp.remote.debug.pid"); 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /src/com/advancedtools/cpp/facade/CppCodeFragment.java: -------------------------------------------------------------------------------- 1 | // Copyright 2006-2012 AdvancedTools. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. 2 | package com.advancedtools.cpp.facade; 3 | 4 | import com.advancedtools.cpp.CppParserDefinition; 5 | import com.advancedtools.cpp.psi.ICppCodeFragment; 6 | import com.intellij.psi.FileViewProvider; 7 | import com.intellij.psi.SingleRootFileViewProvider; 8 | import com.intellij.psi.impl.PsiManagerEx; 9 | import com.intellij.psi.impl.file.impl.FileManager; 10 | import com.intellij.psi.impl.source.tree.FileElement; 11 | import com.intellij.psi.search.GlobalSearchScope; 12 | import com.intellij.testFramework.LightVirtualFile; 13 | import org.jetbrains.annotations.NotNull; 14 | 15 | /** 16 | * @author maxim 17 | * Date: 2/2/12 18 | * Time: 7:49 PM 19 | */ 20 | public class CppCodeFragment extends CppParserDefinition.CppFile implements ICppCodeFragment { 21 | private GlobalSearchScope myResolveScope; 22 | private boolean myPhysical = true; 23 | private SingleRootFileViewProvider myViewProvider; 24 | 25 | public CppCodeFragment(@NotNull FileViewProvider fileViewProvider) { 26 | super(fileViewProvider); 27 | ((SingleRootFileViewProvider)fileViewProvider).forceCachedPsi(this); 28 | } 29 | 30 | protected CppCodeFragment clone() { 31 | final CppCodeFragment clone = (CppCodeFragment)cloneImpl((FileElement)calcTreeElement().clone()); 32 | clone.myPhysical = false; 33 | clone.myOriginalFile = this; 34 | FileManager fileManager = ((PsiManagerEx)getManager()).getFileManager(); 35 | SingleRootFileViewProvider cloneViewProvider = (SingleRootFileViewProvider)fileManager.createFileViewProvider(new LightVirtualFile(getName(), getLanguage(), getText()), false); 36 | cloneViewProvider.forceCachedPsi(clone); 37 | clone.myViewProvider = cloneViewProvider; 38 | return clone; 39 | } 40 | 41 | @NotNull 42 | public FileViewProvider getViewProvider() { 43 | if(myViewProvider != null) return myViewProvider; 44 | return super.getViewProvider(); 45 | } 46 | 47 | public void forceResolveScope(GlobalSearchScope globalSearchScope) { 48 | myResolveScope = globalSearchScope; 49 | } 50 | 51 | public GlobalSearchScope getForcedResolveScope() { 52 | return myResolveScope; 53 | } 54 | 55 | @Override 56 | public boolean isPhysical() { 57 | return myPhysical; 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/com/advancedtools/cpp/facade/CppDocumentationProvider.java: -------------------------------------------------------------------------------- 1 | // Copyright 2006-2012 AdvancedTools. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. 2 | package com.advancedtools.cpp.facade; 3 | 4 | import com.advancedtools.cpp.CppSupportLoader; 5 | import com.intellij.lang.documentation.DocumentationProvider; 6 | import com.intellij.psi.PsiElement; 7 | import com.intellij.psi.PsiManager; 8 | 9 | import java.util.Collections; 10 | 11 | /** 12 | * @author maxim 13 | * Date: 2/3/12 14 | * Time: 1:40 PM 15 | */ 16 | public class CppDocumentationProvider implements DocumentationProvider { 17 | public String getQuickNavigateInfo(PsiElement psiElement, PsiElement psiElement1) { 18 | return CppSupportLoader.getQuickDoc(psiElement); 19 | } 20 | 21 | public java.util.List getUrlFor(PsiElement psiElement, PsiElement psiElement1) { 22 | return Collections.emptyList(); 23 | } 24 | 25 | public String generateDoc(PsiElement psiElement, PsiElement psiElement1) { 26 | return null; 27 | } 28 | 29 | public PsiElement getDocumentationElementForLookupItem(PsiManager psiManager, Object o, PsiElement psiElement) { 30 | return null; 31 | } 32 | 33 | public PsiElement getDocumentationElementForLink(PsiManager psiManager, String s, PsiElement psiElement) { 34 | return null; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/com/advancedtools/cpp/facade/CppGotoTargetRendererProvider.java: -------------------------------------------------------------------------------- 1 | // Copyright 2006-2012 AdvancedTools. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. 2 | package com.advancedtools.cpp.facade; 3 | 4 | import com.advancedtools.cpp.CppSupportLoader; 5 | import com.advancedtools.cpp.usages.OurUsage; 6 | import com.intellij.codeInsight.navigation.GotoTargetHandler; 7 | import com.intellij.codeInsight.navigation.GotoTargetRendererProvider; 8 | import com.intellij.ide.util.DefaultPsiElementCellRenderer; 9 | import com.intellij.ide.util.PsiElementListCellRenderer; 10 | import com.intellij.psi.PsiElement; 11 | import org.jetbrains.annotations.Nullable; 12 | 13 | /** 14 | * @author maxim 15 | * Date: 2/3/12 16 | * Time: 1:56 PM 17 | */ 18 | public class CppGotoTargetRendererProvider implements GotoTargetRendererProvider { 19 | protected PsiElementListCellRenderer getRendererImpl(PsiElement psiElement) { 20 | if (psiElement.getLanguage() != CppSupportLoader.CPP_LANGUAGE) return null; 21 | return new DefaultPsiElementCellRenderer() { 22 | @Override 23 | public String getElementText(PsiElement psiElement) { 24 | OurUsage usage = psiElement.getUserData(CppSupportLoader.ourUsageKey); 25 | if (usage != null) { 26 | String text = usage.getContextText(); 27 | if (text != null) return text; 28 | } 29 | return super.getElementText(psiElement); 30 | } 31 | 32 | @Override 33 | public String getContainerText(PsiElement psiElement, String s) { 34 | OurUsage usage = psiElement.getUserData(CppSupportLoader.ourUsageKey); 35 | if (usage != null) { 36 | return " in " + usage.fileUsage.getFileLocaton(); 37 | } 38 | return super.getContainerText(psiElement, s); 39 | } 40 | }; 41 | } 42 | 43 | public PsiElementListCellRenderer getRenderer(PsiElement psiElement) { 44 | return getRendererImpl(psiElement); 45 | } 46 | 47 | @Nullable 48 | public PsiElementListCellRenderer getRenderer(PsiElement psiElement, GotoTargetHandler.GotoData gotoData) { 49 | return getRenderer(psiElement); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/com/advancedtools/cpp/facade/ExtendedPlatformServices.java: -------------------------------------------------------------------------------- 1 | // Copyright 2006-2012 AdvancedTools. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. 2 | package com.advancedtools.cpp.facade; 3 | 4 | import com.advancedtools.cpp.CppSupportLoader; 5 | import com.intellij.openapi.compiler.CompilerManager; 6 | import com.intellij.openapi.project.Project; 7 | 8 | /** 9 | * @author maxim 10 | * Date: 2/24/12 11 | * Time: 11:47 AM 12 | */ 13 | public class ExtendedPlatformServices { 14 | 15 | public static void registerCompilerStuff(Project project) { 16 | CompilerManager.getInstance(project).addCompilableFileType(CppSupportLoader.CPP_FILETYPE); 17 | CompilerManager.getInstance(project).addCompiler(new CppCompiler()); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/com/advancedtools/cpp/facade/GotoSuperActionHandler.java: -------------------------------------------------------------------------------- 1 | // Copyright 2006-2012 AdvancedTools. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. 2 | package com.advancedtools.cpp.facade; 3 | 4 | import com.intellij.lang.LanguageCodeInsightActionHandler; 5 | import com.intellij.openapi.editor.Editor; 6 | import com.intellij.openapi.project.Project; 7 | import com.intellij.psi.PsiFile; 8 | import com.advancedtools.cpp.commands.NavigationCommand; 9 | import com.advancedtools.cpp.utils.NavigationUtils; 10 | import org.jetbrains.annotations.NonNls; 11 | 12 | /** 13 | * @author maxim 14 | * Date: Dec 24, 2008 15 | * Time: 9:06:02 PM 16 | */ 17 | public class GotoSuperActionHandler implements LanguageCodeInsightActionHandler { 18 | public boolean isValidFor(Editor editor, PsiFile file) { 19 | return true; 20 | } 21 | 22 | public void invoke(Project project, Editor editor, PsiFile file) { 23 | new NavigationCommand(file, editor.getCaretModel().getOffset()) { 24 | @NonNls 25 | @Override 26 | protected String getCommandText() { 27 | return "find-immediate-parents"; 28 | } 29 | 30 | public boolean doInvokeInDispatchThread() { 31 | return true; 32 | } 33 | 34 | public void doExecute() { 35 | super.doExecute(); 36 | NavigationUtils.navigate(project, usagesList); 37 | } 38 | }.post(project); 39 | } 40 | 41 | public boolean startInWriteAction() { 42 | return false; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/com/advancedtools/cpp/facade/LanguageAwareStructureViewFactory.java: -------------------------------------------------------------------------------- 1 | // Copyright 2006-2012 AdvancedTools. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. 2 | package com.advancedtools.cpp.facade; 3 | 4 | import com.advancedtools.cpp.LanguageFeatureAware; 5 | import com.intellij.ide.structureView.StructureViewBuilder; 6 | import com.intellij.lang.PsiStructureViewFactory; 7 | import com.intellij.psi.PsiFile; 8 | 9 | /** 10 | * @author maxim 11 | * Date: 2/3/12 12 | * Time: 1:38 PM 13 | */ 14 | public class LanguageAwareStructureViewFactory implements PsiStructureViewFactory { 15 | public StructureViewBuilder getStructureViewBuilder(PsiFile psiFile) { 16 | return ((LanguageFeatureAware)psiFile.getLanguage()).getStructureViewBuilder(psiFile); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/com/advancedtools/cpp/facade/LanguageAwareSyntaxHighlighterFactory.java: -------------------------------------------------------------------------------- 1 | // Copyright 2006-2012 AdvancedTools. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. 2 | package com.advancedtools.cpp.facade; 3 | 4 | import com.advancedtools.cpp.LanguageFeatureAware; 5 | import com.intellij.lang.Language; 6 | import com.intellij.openapi.fileTypes.*; 7 | import com.intellij.openapi.project.Project; 8 | import com.intellij.openapi.vfs.VirtualFile; 9 | import org.jetbrains.annotations.NotNull; 10 | 11 | /** 12 | * @author maxim 13 | * Date: 2/3/12 14 | * Time: 1:53 PM 15 | */ 16 | public class LanguageAwareSyntaxHighlighterFactory extends SyntaxHighlighterFactory { 17 | 18 | @NotNull 19 | public SyntaxHighlighter getSyntaxHighlighter(Project project, VirtualFile virtualFile) { 20 | if (virtualFile != null) { 21 | FileType fileType = virtualFile.getFileType(); 22 | if (fileType instanceof LanguageFileType) { 23 | Language language = ((LanguageFileType) fileType).getLanguage(); 24 | if (language instanceof LanguageFeatureAware) { 25 | return ((LanguageFeatureAware) language).getSyntaxHighlighter(project, virtualFile); 26 | } 27 | } 28 | } 29 | 30 | return new PlainSyntaxHighlighter(); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/com/advancedtools/cpp/hilighting/AnalyzeProcessor.java: -------------------------------------------------------------------------------- 1 | // Copyright 2006-2012 AdvancedTools. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. 2 | package com.advancedtools.cpp.hilighting; 3 | 4 | /** 5 | * User: maxim 6 | * Date: 17.06.2008 7 | * Time: 21:29:21 8 | */ 9 | public interface AnalyzeProcessor { 10 | String getAnalizedFileName(); 11 | void startedAnalyzedFileName(String fileName); 12 | 13 | enum MessageType { Error, Warning, Intention, Info } 14 | 15 | void addMessage(MessageType type, int start, int end, String message, Fix ... fixes); 16 | } 17 | -------------------------------------------------------------------------------- /src/com/advancedtools/cpp/hilighting/CppOverridenHighlightingPassFactory.java: -------------------------------------------------------------------------------- 1 | // Copyright 2006-2012 AdvancedTools. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. 2 | package com.advancedtools.cpp.hilighting; 3 | 4 | import com.intellij.codeHighlighting.Pass; 5 | import com.intellij.codeHighlighting.TextEditorHighlightingPass; 6 | import com.intellij.codeHighlighting.TextEditorHighlightingPassRegistrar; 7 | import com.intellij.openapi.editor.Editor; 8 | import com.intellij.openapi.project.Project; 9 | import com.intellij.openapi.util.Key; 10 | import com.intellij.psi.PsiFile; 11 | import org.jetbrains.annotations.NonNls; 12 | import org.jetbrains.annotations.NotNull; 13 | 14 | /** 15 | * @author maxim 16 | */ 17 | public class CppOverridenHighlightingPassFactory extends CppHighlightingPassFactoryBase { 18 | public CppOverridenHighlightingPassFactory(Project _project) { 19 | super(_project); 20 | } 21 | 22 | protected void register(TextEditorHighlightingPassRegistrar instance) { 23 | instance.registerTextEditorHighlightingPass( 24 | this, 25 | TextEditorHighlightingPassRegistrar.BEFORE, 26 | Pass.LOCAL_INSPECTIONS 27 | ); 28 | } 29 | 30 | protected TextEditorHighlightingPass doCreatePass(Editor editor, PsiFile psiFile, HighlightCommand command) { 31 | return new OverridenHighlightingPass(editor, psiFile,command); 32 | } 33 | 34 | @NonNls 35 | @NotNull 36 | public String getComponentName() { 37 | return "Cpp.OverridenHighlightingHandler"; 38 | } 39 | 40 | static class OverridenHighlightingPass extends HighlightingPassBase { 41 | private static Key updateMarkKey = Key.create("override.update.mark"); 42 | 43 | public OverridenHighlightingPass(Editor editor, PsiFile psiFile, HighlightCommand command) { 44 | super(editor, psiFile, command); 45 | } 46 | 47 | protected void await() { 48 | command.awaitOverriden(editor.getProject()); 49 | } 50 | 51 | protected Key getUpdateMarkKey() { 52 | return updateMarkKey; 53 | } 54 | 55 | protected void addMarkers() { 56 | command.addOverridenRangeMarkers(editor); 57 | } 58 | 59 | public int getPassId() { 60 | return 2082001; 61 | } 62 | } 63 | 64 | } -------------------------------------------------------------------------------- /src/com/advancedtools/cpp/hilighting/CppSimpleEditorHighlightingPassFactory.java: -------------------------------------------------------------------------------- 1 | // Copyright 2006-2012 AdvancedTools. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. 2 | package com.advancedtools.cpp.hilighting; 3 | 4 | import com.intellij.codeHighlighting.TextEditorHighlightingPass; 5 | import com.intellij.codeHighlighting.TextEditorHighlightingPassRegistrar; 6 | import com.intellij.openapi.editor.Editor; 7 | import com.intellij.openapi.project.Project; 8 | import com.intellij.openapi.util.Key; 9 | import com.intellij.psi.PsiFile; 10 | import com.intellij.psi.PsiManager; 11 | import org.jetbrains.annotations.NonNls; 12 | import org.jetbrains.annotations.NotNull; 13 | 14 | /** 15 | * @author maxim 16 | */ 17 | public class CppSimpleEditorHighlightingPassFactory extends CppHighlightingPassFactoryBase { 18 | public CppSimpleEditorHighlightingPassFactory(Project _project) { 19 | super(_project); 20 | } 21 | 22 | protected void register(TextEditorHighlightingPassRegistrar instance) { 23 | instance.registerTextEditorHighlightingPass( 24 | this, 25 | TextEditorHighlightingPassRegistrar.FIRST, 26 | 0xff 27 | ); 28 | } 29 | 30 | protected TextEditorHighlightingPass doCreatePass(Editor editor, PsiFile psiFile, HighlightCommand command) { 31 | return new SimpleHighlightingPass(editor, psiFile, command); 32 | } 33 | 34 | @NonNls 35 | @NotNull 36 | public String getComponentName() { 37 | return "Cpp.HighlightingHandler"; 38 | } 39 | 40 | static class SimpleHighlightingPass extends HighlightingPassBase { 41 | private static Key updateMarkKey = Key.create("simple.update.mark"); 42 | 43 | public SimpleHighlightingPass(Editor editor, PsiFile psiFile, HighlightCommand command) { 44 | super(editor, psiFile, command); 45 | } 46 | 47 | protected void await() { 48 | command.awaitHighlighting(editor.getProject()); 49 | } 50 | 51 | protected Key getUpdateMarkKey() { 52 | return updateMarkKey; 53 | } 54 | 55 | protected void addMarkers() { 56 | command.addRangeMarkers(editor); 57 | } 58 | 59 | public int getPassId() { 60 | return 13101977; 61 | } 62 | } 63 | } -------------------------------------------------------------------------------- /src/com/advancedtools/cpp/include_obj.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nicity/CppTools/ce6ba79a20827023d023f51e002222f5f128cab3/src/com/advancedtools/cpp/include_obj.gif -------------------------------------------------------------------------------- /src/com/advancedtools/cpp/inspections/BaseCppInspection.java: -------------------------------------------------------------------------------- 1 | // Copyright 2006-2012 AdvancedTools. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. 2 | package com.advancedtools.cpp.inspections; 3 | 4 | import com.advancedtools.cpp.CppBundle; 5 | import com.intellij.codeInspection.LocalInspectionTool; 6 | import com.intellij.codeInspection.ProblemDescriptor; 7 | import org.jetbrains.annotations.Nls; 8 | import org.jetbrains.annotations.NotNull; 9 | 10 | /** 11 | * @author maxim 12 | */ 13 | public abstract class BaseCppInspection extends LocalInspectionTool { 14 | protected static final ProblemDescriptor[] EMPTY = new ProblemDescriptor[0]; 15 | 16 | @Nls 17 | @NotNull 18 | public String getGroupDisplayName() { 19 | return CppBundle.message("cpp.inspections.group.name"); 20 | } 21 | 22 | @Override 23 | public boolean isEnabledByDefault() { 24 | return true; 25 | } 26 | } -------------------------------------------------------------------------------- /src/com/advancedtools/cpp/inspections/CppInspectionsHighlightingHandler.java: -------------------------------------------------------------------------------- 1 | // Copyright 2006-2012 AdvancedTools. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. 2 | package com.advancedtools.cpp.inspections; 3 | 4 | import com.advancedtools.cpp.CppSupportLoader; 5 | import com.advancedtools.cpp.facade.EnvironmentFacade; 6 | import com.intellij.codeInspection.InspectionToolProvider; 7 | import com.intellij.openapi.components.ApplicationComponent; 8 | import org.jetbrains.annotations.NonNls; 9 | import org.jetbrains.annotations.NotNull; 10 | 11 | /** 12 | * @author maxim 13 | */ 14 | public class CppInspectionsHighlightingHandler implements InspectionToolProvider, ApplicationComponent { 15 | @NonNls 16 | @NotNull 17 | public String getComponentName() { 18 | return "Cpp.InspectionsHighlightingHandler"; 19 | } 20 | 21 | public void initComponent() { 22 | CppSupportLoader.doRegisterExtensionPoint("com.intellij.inspectionToolProvider", this, null); 23 | } 24 | 25 | public void disposeComponent() { 26 | } 27 | 28 | public Class[] getInspectionClasses() { 29 | if (EnvironmentFacade.isJavaIde()) { 30 | return new Class[] { 31 | UnusedCppSymbolInspection.class, 32 | NativeJavaMethodsInspection.class, 33 | JNIImplementationsInspection.class 34 | }; 35 | } else { 36 | return new Class[] { UnusedCppSymbolInspection.class }; 37 | } 38 | } 39 | } -------------------------------------------------------------------------------- /src/com/advancedtools/cpp/inspections/JNIFunction2JavaMethodBinding.java: -------------------------------------------------------------------------------- 1 | // Copyright 2006-2012 AdvancedTools. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. 2 | package com.advancedtools.cpp.inspections; 3 | 4 | import com.advancedtools.cpp.facade.EnvironmentFacade; 5 | import com.intellij.openapi.project.Project; 6 | import com.intellij.psi.JavaPsiFacade; 7 | import com.intellij.psi.PsiClass; 8 | import com.intellij.psi.PsiMethod; 9 | import com.intellij.psi.PsiManager; 10 | import com.intellij.psi.search.GlobalSearchScope; 11 | 12 | /** 13 | * @author maxim 14 | */ 15 | public class JNIFunction2JavaMethodBinding { 16 | public static final String JAVA_NATIVE_PREFIX = "Java_"; 17 | private final PsiMethod method; 18 | private final PsiClass clazz; 19 | 20 | public JNIFunction2JavaMethodBinding(String jniFunctionName, PsiManager psiManager) { 21 | int lastUnderscoreIndex = jniFunctionName.lastIndexOf('_'); 22 | String className = jniFunctionName.substring(0, lastUnderscoreIndex).replace('_','.').substring(JAVA_NATIVE_PREFIX.length()); 23 | String methodName = jniFunctionName.substring(lastUnderscoreIndex + 1); 24 | Project project = psiManager.getProject(); 25 | clazz = JavaPsiFacade.getInstance(project).findClass(className, GlobalSearchScope.projectScope(project)); 26 | PsiMethod m = null; 27 | 28 | if (clazz != null) { 29 | PsiMethod[] psiMethods = clazz.findMethodsByName(methodName, false); 30 | if (psiMethods.length > 0) { 31 | m = psiMethods[0]; 32 | } 33 | } 34 | 35 | method = m; 36 | } 37 | 38 | public PsiMethod getMethod() { 39 | return method; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/com/advancedtools/cpp/inspections/NativeMethod2JNIFunctionBinding.java: -------------------------------------------------------------------------------- 1 | // Copyright 2006-2012 AdvancedTools. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. 2 | package com.advancedtools.cpp.inspections; 3 | 4 | import com.intellij.psi.PsiMethod; 5 | import com.intellij.psi.PsiClass; 6 | import com.intellij.psi.PsiManager; 7 | import com.advancedtools.cpp.commands.FindSymbolsCommand; 8 | import com.advancedtools.cpp.usages.FileUsageList; 9 | import org.jetbrains.annotations.NotNull; 10 | 11 | /** 12 | * @author maxim 13 | */ 14 | public class NativeMethod2JNIFunctionBinding { 15 | private final FileUsageList usagesList; 16 | 17 | public NativeMethod2JNIFunctionBinding(@NotNull PsiMethod method) { 18 | final StringBuilder b = new StringBuilder(); 19 | b.append(JNIFunction2JavaMethodBinding.JAVA_NATIVE_PREFIX) 20 | .append(method.getContainingClass().getQualifiedName().replace('.','_')) 21 | .append("_").append(method.getName()); 22 | final FindSymbolsCommand myNavigationCommand = new FindSymbolsCommand(b.toString(), FindSymbolsCommand.TargetTypes.SYMBOLS); 23 | myNavigationCommand.post(method.getProject()); 24 | usagesList = myNavigationCommand.getUsagesList(); 25 | } 26 | 27 | public FileUsageList getUsagesList() { 28 | return usagesList; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/com/advancedtools/cpp/inspections/UnusedCppSymbolInspection.java: -------------------------------------------------------------------------------- 1 | // Copyright 2006-2012 AdvancedTools. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. 2 | package com.advancedtools.cpp.inspections; 3 | 4 | import com.advancedtools.cpp.CppBundle; 5 | import com.advancedtools.cpp.CppSupportLoader; 6 | import com.advancedtools.cpp.hilighting.HighlightCommand; 7 | import com.advancedtools.cpp.hilighting.HighlightUtils; 8 | import com.intellij.codeInspection.InspectionManager; 9 | import com.intellij.codeInspection.ProblemDescriptor; 10 | import com.intellij.psi.PsiFile; 11 | import org.jetbrains.annotations.Nls; 12 | import org.jetbrains.annotations.NonNls; 13 | import org.jetbrains.annotations.NotNull; 14 | import org.jetbrains.annotations.Nullable; 15 | 16 | /** 17 | * @author maxim 18 | */ 19 | public class UnusedCppSymbolInspection extends BaseCppInspection { 20 | @Nls 21 | @NotNull 22 | public String getDisplayName() { 23 | return CppBundle.message("unused.cpp.symbol.inspection.name"); 24 | } 25 | 26 | @NonNls 27 | @NotNull 28 | public String getShortName() { 29 | return "UnusedCppSymbol"; 30 | } 31 | 32 | @Override 33 | @Nullable 34 | public ProblemDescriptor[] checkFile(@NotNull PsiFile file, @NotNull InspectionManager manager, boolean isOnTheFly) { 35 | if (file.getFileType() != CppSupportLoader.CPP_FILETYPE) return EMPTY; 36 | if (HighlightUtils.debug) { 37 | HighlightUtils.trace(file, null, "Inspections about to start:"); 38 | } 39 | 40 | final HighlightCommand command = HighlightUtils.getUpToDateHighlightCommand(file, file.getProject()); 41 | 42 | if (command.isUpToDate()) command.awaitInspections(file.getProject()); 43 | 44 | if (HighlightUtils.debug) { 45 | HighlightUtils.trace(file, null, "Adding inspection errors:"); 46 | } 47 | final ProblemDescriptor[] problemDescriptors = command.addInspectionErrors(manager); 48 | // System.out.println("Finished inspections--:" + getClass() + "," + (System.currentTimeMillis() - command.started)); 49 | return problemDescriptors; 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/com/advancedtools/cpp/makefile.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nicity/CppTools/ce6ba79a20827023d023f51e002222f5f128cab3/src/com/advancedtools/cpp/makefile.gif -------------------------------------------------------------------------------- /src/com/advancedtools/cpp/makefile/MakefileCommenter.java: -------------------------------------------------------------------------------- 1 | // Copyright 2006-2012 AdvancedTools. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. 2 | package com.advancedtools.cpp.makefile; 3 | 4 | import com.intellij.lang.Commenter; 5 | import org.jetbrains.annotations.Nullable; 6 | 7 | /** 8 | * @author maxim 9 | * Date: 2/3/12 10 | * Time: 1:30 PM 11 | */ 12 | public class MakefileCommenter implements Commenter { 13 | @Nullable 14 | public String getLineCommentPrefix() { 15 | return "#"; 16 | } 17 | 18 | @Nullable 19 | public String getBlockCommentPrefix() { 20 | return null; 21 | } 22 | 23 | @Nullable 24 | public String getBlockCommentSuffix() { 25 | return null; 26 | } 27 | 28 | public String getCommentedBlockCommentPrefix() { 29 | return null; 30 | } 31 | 32 | public String getCommentedBlockCommentSuffix() { 33 | return null; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/com/advancedtools/cpp/makefile/MakefileElementType.java: -------------------------------------------------------------------------------- 1 | // Copyright 2006-2012 AdvancedTools. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. 2 | package com.advancedtools.cpp.makefile; 3 | 4 | import com.advancedtools.cpp.CppSupportLoader; 5 | import com.intellij.psi.tree.IElementType; 6 | import org.jetbrains.annotations.NonNls; 7 | 8 | /** 9 | * @author maxim 10 | * Date: 21.09.2006 11 | * Time: 5:29:48 12 | */ 13 | public class MakefileElementType extends IElementType { 14 | public MakefileElementType(@NonNls String s) { 15 | super(s, CppSupportLoader.MAKE_FILETYPE.getLanguage()); 16 | } 17 | } -------------------------------------------------------------------------------- /src/com/advancedtools/cpp/makefile/MakefileFindUsagesProvider.java: -------------------------------------------------------------------------------- 1 | // Copyright 2006-2012 AdvancedTools. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. 2 | package com.advancedtools.cpp.makefile; 3 | 4 | import com.intellij.lang.cacheBuilder.DefaultWordsScanner; 5 | import com.intellij.lang.cacheBuilder.WordsScanner; 6 | import com.intellij.lang.findUsages.FindUsagesProvider; 7 | import com.intellij.lexer.FlexAdapter; 8 | import com.intellij.psi.PsiElement; 9 | import com.intellij.psi.tree.IElementType; 10 | import com.intellij.psi.tree.TokenSet; 11 | import org.jetbrains.annotations.NotNull; 12 | 13 | /** 14 | * @author maxim 15 | * Date: 2/3/12 16 | * Time: 1:34 PM 17 | */ 18 | public class MakefileFindUsagesProvider implements FindUsagesProvider { 19 | public WordsScanner getWordsScanner() { 20 | return new DefaultWordsScanner( 21 | new FlexAdapter(new _MakefileLexer(true)), 22 | TokenSet.create(MakefileTokenTypes.IDENTIFIER, MakefileTokenTypes.TARGET_IDENTIFIER, 23 | MakefileTokenTypes.VAR_DEFINITION, MakefileTokenTypes.VAR_REFERENCE), 24 | MakefileTokenTypes.COMMENTS, 25 | MakefileTokenTypes.LITERALS 26 | ); 27 | } 28 | 29 | public boolean canFindUsagesFor(@NotNull PsiElement psiElement) { 30 | return MakefileIdentifierReference.isSelfReferenceType(MakefileIdentifierReference.type(psiElement)); 31 | } 32 | 33 | public String getHelpId(@NotNull PsiElement psiElement) { 34 | return null; 35 | } 36 | 37 | @NotNull 38 | public String getType(@NotNull PsiElement psiElement) { 39 | IElementType iElementType = MakefileIdentifierReference.type(psiElement); 40 | if(iElementType == MakefileTokenTypes.VAR_DEFINITION) return "definition"; 41 | if(iElementType == MakefileTokenTypes.TARGET_IDENTIFIER) return "target"; 42 | return "should not happen type"; 43 | } 44 | 45 | @NotNull 46 | public String getDescriptiveName(@NotNull PsiElement psiElement) { 47 | return psiElement.getText(); 48 | } 49 | 50 | @NotNull 51 | public String getNodeText(@NotNull PsiElement psiElement, boolean b) { 52 | return getDescriptiveName(psiElement); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/com/advancedtools/cpp/makefile/MakefileLexer.java: -------------------------------------------------------------------------------- 1 | // Copyright 2006-2012 AdvancedTools. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. 2 | package com.advancedtools.cpp.makefile; 3 | 4 | import com.intellij.lexer.FlexAdapter; 5 | import com.intellij.lexer.MergingLexerAdapter; 6 | import com.intellij.psi.tree.TokenSet; 7 | 8 | /** 9 | * @author maxim 10 | */ 11 | class MakefileLexer extends MergingLexerAdapter { 12 | private static final TokenSet tokenSet = TokenSet.create(MakefileTokenTypes.TEMPLATE_DATA, MakefileTokenTypes.WHITE_SPACE); 13 | 14 | public MakefileLexer(boolean highlighting) { 15 | super(new FlexAdapter(new _MakefileLexer(highlighting)), tokenSet); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/com/advancedtools/cpp/makefile/MakefileNamedElement.java: -------------------------------------------------------------------------------- 1 | // Copyright 2006-2012 AdvancedTools. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. 2 | package com.advancedtools.cpp.makefile; 3 | 4 | import com.intellij.lang.ASTNode; 5 | import com.intellij.psi.PsiElement; 6 | import com.intellij.psi.PsiNamedElement; 7 | import com.intellij.psi.PsiReference; 8 | import com.intellij.psi.tree.TokenSet; 9 | import com.intellij.util.IncorrectOperationException; 10 | import org.jetbrains.annotations.NonNls; 11 | import org.jetbrains.annotations.NotNull; 12 | 13 | /** 14 | * User: maxim 15 | * Date: 01.04.2010 16 | * Time: 0:05:51 17 | */ 18 | public class MakefileNamedElement extends MakefilePsiElement implements PsiNamedElement { 19 | private static TokenSet ourSet = TokenSet.create(MakefileTokenTypes.TARGET_IDENTIFIER, MakefileTokenTypes.VAR_DEFINITION); 20 | 21 | public MakefileNamedElement(@org.jetbrains.annotations.NotNull ASTNode astNode) { 22 | super(astNode); 23 | } 24 | 25 | @NotNull 26 | @Override 27 | public PsiReference[] getReferences() { 28 | return new PsiReference[] { new MakefileIdentifierReference(this) }; 29 | } 30 | 31 | public PsiElement setName(@NonNls String s) throws IncorrectOperationException { 32 | throw new IncorrectOperationException("not supported"); 33 | } 34 | 35 | @Override 36 | public String getName() { 37 | PsiElement psiElement = findNameElement(); 38 | return psiElement != null ? psiElement.getText():null; 39 | } 40 | 41 | PsiElement findNameElement() { 42 | ASTNode child = getNode().findChildByType(ourSet); 43 | return child != null ? child.getPsi() : null; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/com/advancedtools/cpp/makefile/MakefilePsiElement.java: -------------------------------------------------------------------------------- 1 | // Copyright 2006-2012 AdvancedTools. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. 2 | package com.advancedtools.cpp.makefile; 3 | 4 | import com.intellij.extapi.psi.ASTWrapperPsiElement; 5 | import com.intellij.lang.ASTNode; 6 | import com.intellij.psi.PsiReference; 7 | import org.jetbrains.annotations.NotNull; 8 | 9 | /** 10 | * User: maxim 11 | * Date: 01.04.2010 12 | * Time: 0:09:05 13 | */ 14 | public class MakefilePsiElement extends ASTWrapperPsiElement { 15 | public MakefilePsiElement(ASTNode astNode) { 16 | super(astNode); 17 | } 18 | 19 | public String toString() { 20 | return "Composite:" + getNode().getElementType(); 21 | } 22 | 23 | @NotNull 24 | @Override 25 | public PsiReference[] getReferences() { 26 | if (MakefileParserDefinition.MakefileParser.shouldProduceComposite(getNode().getElementType())) 27 | return new PsiReference[] {new MakefileIdentifierReference(this) }; 28 | return super.getReferences(); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/com/advancedtools/cpp/makefile/MakefileSyntaxHighlighter.java: -------------------------------------------------------------------------------- 1 | // Copyright 2006-2012 AdvancedTools. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. 2 | package com.advancedtools.cpp.makefile; 3 | 4 | import com.intellij.lexer.Lexer; 5 | import com.intellij.openapi.editor.SyntaxHighlighterColors; 6 | import com.intellij.openapi.editor.colors.TextAttributesKey; 7 | import com.intellij.openapi.fileTypes.SyntaxHighlighterBase; 8 | import com.intellij.psi.tree.IElementType; 9 | import org.jetbrains.annotations.NotNull; 10 | 11 | import java.util.HashMap; 12 | import java.util.Map; 13 | 14 | /** 15 | * @author maxim 16 | */ 17 | class MakefileSyntaxHighlighter extends SyntaxHighlighterBase { 18 | private static Map keys1; 19 | private static Map keys2; 20 | 21 | public static final TextAttributesKey Makefile_KEYWORD = TextAttributesKey.createTextAttributesKey( 22 | "Makefile.KEYWORD", 23 | SyntaxHighlighterColors.KEYWORD.getDefaultAttributes() 24 | ); 25 | 26 | static final TextAttributesKey Makefile_LINE_COMMENT = TextAttributesKey.createTextAttributesKey( 27 | "Makefile.LINE_COMMENT", 28 | SyntaxHighlighterColors.LINE_COMMENT.getDefaultAttributes() 29 | ); 30 | 31 | static final TextAttributesKey Makefile_TEMPLATE_DATA = TextAttributesKey.createTextAttributesKey( 32 | "Makefile.TEMPLATE_DATA", 33 | SyntaxHighlighterColors.NUMBER.getDefaultAttributes() 34 | ); 35 | 36 | static final TextAttributesKey Makefile_TARGET = TextAttributesKey.createTextAttributesKey( 37 | "Makefile.TARGET", 38 | SyntaxHighlighterColors.DOC_COMMENT_TAG.getDefaultAttributes() 39 | ); 40 | 41 | static final TextAttributesKey Makefile_DEFINITION = TextAttributesKey.createTextAttributesKey( 42 | "Makefile.DEFINITION", 43 | SyntaxHighlighterColors.DOC_COMMENT_MARKUP.getDefaultAttributes() 44 | ); 45 | 46 | static { 47 | keys1 = new HashMap(); 48 | keys2 = new HashMap(); 49 | 50 | fillMap(keys1, MakefileTokenTypes.KEYWORDS, Makefile_KEYWORD); 51 | keys1.put(MakefileTokenTypes.END_OF_LINE_COMMENT, Makefile_LINE_COMMENT); 52 | keys1.put(MakefileTokenTypes.TEMPLATE_DATA, Makefile_TEMPLATE_DATA); 53 | keys1.put(MakefileTokenTypes.TARGET_IDENTIFIER_PART, Makefile_TARGET); 54 | keys1.put(MakefileTokenTypes.VAR_DEFINITION, Makefile_DEFINITION); 55 | } 56 | 57 | @NotNull 58 | public Lexer getHighlightingLexer() { 59 | return new MakefileLexer(true); 60 | } 61 | 62 | @NotNull 63 | public TextAttributesKey[] getTokenHighlights(IElementType tokenType) { 64 | return pack(keys1.get(tokenType), keys2.get(tokenType)); 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /src/com/advancedtools/cpp/navigation/CppFileContributor.java: -------------------------------------------------------------------------------- 1 | // Copyright 2006-2012 AdvancedTools. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. 2 | package com.advancedtools.cpp.navigation; 3 | 4 | import com.advancedtools.cpp.CppSupportLoader; 5 | import com.advancedtools.cpp.commands.EnumerateSymbolsCommand; 6 | import com.advancedtools.cpp.commands.FindSymbolsCommand; 7 | import com.advancedtools.cpp.communicator.Communicator; 8 | import com.advancedtools.cpp.usages.FileUsage; 9 | import com.advancedtools.cpp.usages.OurUsage; 10 | import com.advancedtools.cpp.utils.NavigationUtils; 11 | import com.intellij.navigation.ChooseByNameContributor; 12 | import com.intellij.navigation.ItemPresentation; 13 | import com.intellij.navigation.NavigationItem; 14 | import com.intellij.openapi.editor.colors.TextAttributesKey; 15 | import com.intellij.openapi.project.Project; 16 | import com.intellij.openapi.vcs.FileStatus; 17 | import com.intellij.openapi.vcs.FileStatusManager; 18 | import com.intellij.openapi.vfs.VirtualFile; 19 | import com.intellij.psi.PsiManager; 20 | import com.intellij.util.ArrayUtil; 21 | import org.jetbrains.annotations.Nullable; 22 | 23 | import javax.swing.*; 24 | import java.util.Collections; 25 | import java.util.HashMap; 26 | import java.util.Map; 27 | import java.util.Set; 28 | 29 | /** 30 | * @author maxim 31 | */ 32 | public class CppFileContributor extends BaseCppSymbolContributor { 33 | public CppFileContributor() { 34 | super(FindSymbolsCommand.TargetTypes.FILES); 35 | } 36 | 37 | @Override 38 | protected NavigationItem createNavigatationItem(OurUsage u, String string, FileUsage fu, Project project) { 39 | VirtualFile virtualFile = fu.findVirtualFile(); 40 | if (virtualFile == null) { 41 | new Throwable("Unsupported file path:" + fu.fileName).printStackTrace(); 42 | return null; 43 | } 44 | return PsiManager.getInstance(project).findFile(virtualFile); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/com/advancedtools/cpp/navigation/CppTypeContributor.java: -------------------------------------------------------------------------------- 1 | // Copyright 2006-2012 AdvancedTools. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. 2 | package com.advancedtools.cpp.navigation; 3 | 4 | import com.advancedtools.cpp.commands.FindSymbolsCommand; 5 | 6 | /** 7 | * @author maxim 8 | */ 9 | public class CppTypeContributor extends CppSymbolContributor { 10 | public CppTypeContributor() { 11 | super(FindSymbolsCommand.TargetTypes.TYPES); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/com/advancedtools/cpp/psi/CppElementVisitor.java: -------------------------------------------------------------------------------- 1 | // Copyright 2006-2012 AdvancedTools. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. 2 | package com.advancedtools.cpp.psi; 3 | 4 | import com.intellij.psi.PsiElementVisitor; 5 | 6 | /** 7 | * @author maxim 8 | */ 9 | public abstract class CppElementVisitor extends PsiElementVisitor { 10 | public void visitCppElement(CppElement element) { 11 | visitElement(element); 12 | } 13 | 14 | public void visitCppKeyword(CppKeyword keyword) { 15 | visitElement(keyword); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/com/advancedtools/cpp/psi/CppFile.java: -------------------------------------------------------------------------------- 1 | // Copyright 2006-2012 AdvancedTools. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. 2 | package com.advancedtools.cpp.psi; 3 | 4 | import com.intellij.psi.PsiFile; 5 | 6 | /** 7 | * @author maxim 8 | */ 9 | public interface CppFile extends PsiFile, ICppElement { 10 | } 11 | -------------------------------------------------------------------------------- /src/com/advancedtools/cpp/psi/CppKeyword.java: -------------------------------------------------------------------------------- 1 | // Copyright 2006-2012 AdvancedTools. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. 2 | package com.advancedtools.cpp.psi; 3 | 4 | import com.intellij.extapi.psi.ASTWrapperPsiElement; 5 | import com.intellij.lang.ASTNode; 6 | import com.intellij.lang.Language; 7 | import com.intellij.psi.PsiReference; 8 | import com.intellij.psi.PsiElementVisitor; 9 | import com.intellij.psi.PsiElement; 10 | import com.intellij.psi.tree.IElementType; 11 | import com.intellij.util.IncorrectOperationException; 12 | import com.advancedtools.cpp.CppSupportLoader; 13 | import com.advancedtools.cpp.CppTokenTypes; 14 | import org.jetbrains.annotations.NotNull; 15 | import org.jetbrains.annotations.NonNls; 16 | 17 | /** 18 | * @author maxim 19 | */ 20 | public class CppKeyword extends ASTWrapperPsiElement implements ICppElement { 21 | public CppKeyword(ASTNode node) { 22 | super(node); 23 | } 24 | 25 | @NotNull 26 | public PsiReference[] getReferences() { 27 | IElementType elementType = getNode().getElementType(); 28 | if (elementType == CppTokenTypes.OPERATOR_KEYWORD) { 29 | return new PsiReference[] {new MyPsiPolyVariantReference(this)}; 30 | } 31 | return PsiReference.EMPTY_ARRAY; 32 | } 33 | 34 | 35 | public PsiReference getReference() { 36 | final PsiReference[] references = getReferences(); 37 | if (references.length > 0) return references[0]; 38 | return null; 39 | } 40 | 41 | @NotNull 42 | public Language getLanguage() { 43 | return CppSupportLoader.CPP_FILETYPE.getLanguage(); 44 | } 45 | 46 | public String toString() { 47 | return "CppKeyword:"+getNode().getElementType(); 48 | } 49 | 50 | public void accept(@NotNull PsiElementVisitor psiElementVisitor) { 51 | if (psiElementVisitor instanceof CppElementVisitor) { 52 | ((CppElementVisitor)psiElementVisitor).visitCppKeyword(this); 53 | } else { 54 | psiElementVisitor.visitElement(this); 55 | } 56 | } 57 | 58 | public PsiElement setName(@NonNls String s) throws IncorrectOperationException { 59 | throw new IncorrectOperationException(); 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /src/com/advancedtools/cpp/psi/ICppCodeFragment.java: -------------------------------------------------------------------------------- 1 | // Copyright 2006-2012 AdvancedTools. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. 2 | package com.advancedtools.cpp.psi; 3 | 4 | import com.intellij.psi.PsiCodeFragment; 5 | 6 | /** 7 | * User: maxim 8 | * Date: 06.03.2010 9 | * Time: 23:11:12 10 | */ 11 | public interface ICppCodeFragment extends CppFile, PsiCodeFragment { 12 | } 13 | -------------------------------------------------------------------------------- /src/com/advancedtools/cpp/psi/ICppElement.java: -------------------------------------------------------------------------------- 1 | // Copyright 2006-2012 AdvancedTools. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. 2 | package com.advancedtools.cpp.psi; 3 | 4 | import com.intellij.psi.PsiElement; 5 | import com.intellij.psi.PsiNamedElement; 6 | import com.intellij.navigation.NavigationItem; 7 | 8 | /** 9 | * @author maxim 10 | * Date: Jan 15, 2007 11 | * Time: 10:09:16 PM 12 | */ 13 | public interface ICppElement extends PsiElement, NavigationItem, PsiNamedElement { 14 | } 15 | -------------------------------------------------------------------------------- /src/com/advancedtools/cpp/psi/PsiElementResolveResult.java: -------------------------------------------------------------------------------- 1 | // Copyright 2006-2012 AdvancedTools. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. 2 | package com.advancedtools.cpp.psi; 3 | 4 | import com.intellij.psi.PsiElement; 5 | import com.intellij.psi.ResolveResult; 6 | import org.jetbrains.annotations.Nullable; 7 | 8 | /** 9 | * User: maxim 10 | * Date: 31.03.2010 11 | * Time: 16:09:57 12 | */ 13 | public class PsiElementResolveResult implements ResolveResult { 14 | private final PsiElement psiElement; 15 | 16 | public PsiElementResolveResult(PsiElement psiElement) { 17 | this.psiElement = psiElement; 18 | } 19 | 20 | @Nullable 21 | public PsiElement getElement() { 22 | return psiElement; 23 | } 24 | 25 | public boolean isValidResult() { 26 | return true; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/com/advancedtools/cpp/refactoring/CppInlineHandler.java: -------------------------------------------------------------------------------- 1 | // Copyright 2006-2012 AdvancedTools. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. 2 | package com.advancedtools.cpp.refactoring; 3 | 4 | import com.intellij.lang.refactoring.InlineHandler; 5 | import com.intellij.openapi.editor.Editor; 6 | import com.intellij.psi.PsiElement; 7 | import com.intellij.psi.PsiReference; 8 | import com.intellij.usageView.UsageInfo; 9 | import com.intellij.util.containers.MultiMap; 10 | import org.jetbrains.annotations.Nullable; 11 | 12 | /** 13 | * @author maxim 14 | * Date: 2/3/12 15 | * Time: 1:20 PM 16 | */ 17 | public class CppInlineHandler implements InlineHandler { 18 | 19 | @Nullable 20 | public Settings prepareInlineElement(PsiElement psiElement, Editor editor, boolean b) { 21 | return new Settings() { 22 | public boolean isOnlyOneReferenceToInline() { 23 | return true; 24 | } 25 | }; 26 | } 27 | 28 | public void removeDefinition(PsiElement psiElement, Settings settings) { 29 | // non relevant 30 | } 31 | 32 | public void removeDefinition(PsiElement psiElement) { 33 | // non relevant 34 | } 35 | 36 | public Inliner createInliner(PsiElement psiElement, Settings settings) { 37 | return new Inliner() { 38 | 39 | public MultiMap getConflicts(PsiReference psiReference, PsiElement psiElement) { 40 | return null; 41 | } 42 | 43 | public void inlineUsage(UsageInfo usageInfo, PsiElement psiElement) { 44 | final CppRefactoringSupportProvider.InlineCommand command = new CppRefactoringSupportProvider.InlineCommand(psiElement.getTextOffset(), psiElement.getContainingFile()); 45 | command.post(psiElement.getProject()); 46 | if (command.isFailedOrCancelled()) return; 47 | command.execute(); 48 | } 49 | }; 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/com/advancedtools/cpp/refactoring/ExtractFunctionDialog.form: -------------------------------------------------------------------------------- 1 | 2 |
3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 |
36 | -------------------------------------------------------------------------------- /src/com/advancedtools/cpp/refactoring/ExtractFunctionDialog.java: -------------------------------------------------------------------------------- 1 | // Copyright 2006-2012 AdvancedTools. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. 2 | package com.advancedtools.cpp.refactoring; 3 | 4 | import com.advancedtools.cpp.CppSupportLoader; 5 | import com.intellij.ide.DataManager; 6 | import com.intellij.openapi.actionSystem.DataConstants; 7 | import com.intellij.openapi.project.Project; 8 | import com.intellij.openapi.ui.DialogWrapper; 9 | import com.intellij.refactoring.ui.NameSuggestionsField; 10 | import org.jetbrains.annotations.Nullable; 11 | 12 | import javax.swing.*; 13 | 14 | /** 15 | * @author maxim 16 | * Date: 11.06.2008 17 | * Time: 1:04:40 18 | */ 19 | class ExtractFunctionDialog extends DialogWrapper { 20 | private JPanel myPanel; 21 | private NameSuggestionsField functionMethodNameTextField; 22 | 23 | protected ExtractFunctionDialog(final Project project) { 24 | super(project, true); 25 | setTitle("Extract Function / Method"); 26 | 27 | IntroduceVariableDialog.setupNameValidation(project, functionMethodNameTextField, getOKAction()); 28 | 29 | init(); 30 | } 31 | 32 | @Nullable 33 | protected JComponent createCenterPanel() { 34 | return myPanel; 35 | } 36 | 37 | public String getFunctionName() { 38 | return functionMethodNameTextField.getEnteredName(); 39 | } 40 | 41 | public JComponent getPreferredFocusedComponent() { 42 | return functionMethodNameTextField.getFocusableComponent(); 43 | } 44 | 45 | private void createUIComponents() { 46 | functionMethodNameTextField = new NameSuggestionsField( 47 | new String[] {"fun"}, 48 | (Project) DataManager.getInstance().getDataContext().getData(DataConstants.PROJECT), 49 | CppSupportLoader.CPP_FILETYPE 50 | ); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/com/advancedtools/cpp/refactoring/IntroduceVariableDialog.form: -------------------------------------------------------------------------------- 1 | 2 |
3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 |
54 | -------------------------------------------------------------------------------- /src/com/advancedtools/cpp/run/BaseCppRunSettingsEditor.java: -------------------------------------------------------------------------------- 1 | // Copyright 2006-2012 AdvancedTools. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. 2 | package com.advancedtools.cpp.run; 3 | 4 | import com.intellij.openapi.options.SettingsEditor; 5 | import com.intellij.openapi.options.ConfigurationException; 6 | import com.intellij.openapi.project.Project; 7 | import com.intellij.openapi.fileChooser.FileChooserDescriptor; 8 | import com.intellij.openapi.vfs.VirtualFile; 9 | import com.intellij.openapi.ui.TextComponentAccessor; 10 | import com.intellij.openapi.ui.TextFieldWithBrowseButton; 11 | import com.intellij.ui.ComboboxWithBrowseButton; 12 | import com.advancedtools.cpp.run.CppRunConfiguration; 13 | import com.advancedtools.cpp.run.CppRunnerParameters; 14 | import org.jetbrains.annotations.NotNull; 15 | 16 | import javax.swing.*; 17 | 18 | /** 19 | * @author maxim 20 | * Date: 28.03.2009 21 | * Time: 22:18:19 22 | */ 23 | public abstract class BaseCppRunSettingsEditor extends SettingsEditor { 24 | 25 | private static final String CHOOSE_EXECUTABLE_TITLE = "Choose Executable"; 26 | 27 | protected void setupCommonUI(Project project) { 28 | ComboboxWithBrowseButton myExecutableName = getExecutableName(); 29 | myExecutableName.getComboBox().setEditable(true); 30 | myExecutableName.addBrowseFolderListener( 31 | CHOOSE_EXECUTABLE_TITLE, 32 | CHOOSE_EXECUTABLE_TITLE, 33 | project, 34 | new FileChooserDescriptor(true, false, false, false, false, false) { 35 | @Override 36 | public boolean isFileSelectable(VirtualFile file) { 37 | return super.isFileSelectable(file); 38 | } 39 | }, 40 | TextComponentAccessor.STRING_COMBOBOX_WHOLE_TEXT 41 | ); 42 | } 43 | 44 | protected abstract @NotNull ComboboxWithBrowseButton getExecutableName(); 45 | 46 | protected void resetEditorFrom(T s) { 47 | BaseCppRunnerParameters runnerParameters = s.getRunnerParameters(); 48 | getExecutableName().getComboBox().getEditor().setItem(runnerParameters != null ? runnerParameters.getExecutableName():""); 49 | } 50 | 51 | protected void applyEditorTo(T s) throws ConfigurationException { 52 | BaseCppRunnerParameters runnerParameters = s.getRunnerParameters(); 53 | if (runnerParameters == null) { 54 | runnerParameters = s.createRunnerParameters(); 55 | } 56 | runnerParameters.setExecutableName((String)getExecutableName().getComboBox().getEditor().getItem()); 57 | 58 | s.setRunnerParameters(runnerParameters); 59 | } 60 | } -------------------------------------------------------------------------------- /src/com/advancedtools/cpp/run/BaseCppRunnerParameters.java: -------------------------------------------------------------------------------- 1 | // Copyright 2006-2012 AdvancedTools. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. 2 | package com.advancedtools.cpp.run; 3 | 4 | /** 5 | * @author maxim 6 | * Date: 28.03.2009 7 | * Time: 20:14:54 8 | */ 9 | public class BaseCppRunnerParameters { 10 | private String executableName; 11 | 12 | public String getExecutableName() { 13 | return executableName; 14 | } 15 | 16 | public void setExecutableName(String executableName) { 17 | this.executableName = executableName; 18 | } 19 | } -------------------------------------------------------------------------------- /src/com/advancedtools/cpp/run/CppRunConfigurationType.java: -------------------------------------------------------------------------------- 1 | // Copyright 2006-2012 AdvancedTools. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. 2 | package com.advancedtools.cpp.run; 3 | 4 | import com.intellij.execution.*; 5 | import com.intellij.execution.configurations.ConfigurationFactory; 6 | import com.intellij.execution.configurations.ConfigurationType; 7 | import com.intellij.execution.configurations.RunConfiguration; 8 | import com.intellij.openapi.project.Project; 9 | import com.intellij.openapi.vfs.VirtualFile; 10 | import com.intellij.psi.PsiFile; 11 | import com.advancedtools.cpp.sdk.CppSdkType; 12 | import com.advancedtools.cpp.CppSupportLoader; 13 | 14 | import javax.swing.*; 15 | 16 | import org.jetbrains.annotations.Nullable; 17 | import org.jetbrains.annotations.NotNull; 18 | 19 | /** 20 | * @author maxim 21 | * Date: 28.03.2009 22 | * Time: 20:09:12 23 | */ 24 | public class CppRunConfigurationType implements ConfigurationType { 25 | private final ConfigurationFactory myFactory; 26 | 27 | public CppRunConfigurationType() { 28 | myFactory = new ConfigurationFactory(this) { 29 | public RunConfiguration createTemplateConfiguration(Project project) { 30 | return new CppRunConfiguration(project, this, ""); 31 | } 32 | }; 33 | } 34 | 35 | public String getDisplayName() { 36 | return "Cpp"; 37 | } 38 | 39 | public String getConfigurationTypeDescription() { 40 | return "Cpp Run"; 41 | } 42 | 43 | public Icon getIcon() { 44 | return CppSupportLoader.ourSdkIcon; // TODO 45 | } 46 | 47 | public ConfigurationFactory[] getConfigurationFactories() { 48 | return new ConfigurationFactory[] {myFactory}; 49 | } 50 | 51 | @NotNull 52 | public String getId() { 53 | return "CppRunConfigurationType"; 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/com/advancedtools/cpp/run/CppRunSettingsEditor.java: -------------------------------------------------------------------------------- 1 | // Copyright 2006-2012 AdvancedTools. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. 2 | package com.advancedtools.cpp.run; 3 | 4 | import com.intellij.openapi.options.ConfigurationException; 5 | import com.intellij.openapi.project.Project; 6 | import com.intellij.openapi.fileChooser.FileChooserDescriptor; 7 | import com.intellij.openapi.ui.TextComponentAccessor; 8 | import com.intellij.openapi.ui.TextFieldWithBrowseButton; 9 | import com.intellij.ui.ComboboxWithBrowseButton; 10 | import com.advancedtools.cpp.run.CppRunConfiguration; 11 | import com.advancedtools.cpp.run.CppRunnerParameters; 12 | import org.jetbrains.annotations.NotNull; 13 | 14 | import javax.swing.*; 15 | 16 | /** 17 | * @author maxim 18 | * Date: 28.03.2009 19 | * Time: 22:18:19 20 | */ 21 | public class CppRunSettingsEditor extends BaseCppRunSettingsEditor { 22 | private JPanel myPanel; 23 | private ComboboxWithBrowseButton myExecutableName; 24 | private JComboBox myExecutableParameters; 25 | private TextFieldWithBrowseButton workingDirectoryTextField; 26 | private static final String CHOOSE_WORKING_DIRECTORY_TITLE = "Choose working directory"; 27 | 28 | public CppRunSettingsEditor(Project project) { 29 | setupCommonUI(project); 30 | workingDirectoryTextField.addBrowseFolderListener( 31 | CHOOSE_WORKING_DIRECTORY_TITLE, 32 | CHOOSE_WORKING_DIRECTORY_TITLE, 33 | project, 34 | new FileChooserDescriptor(false, true, false, false, false, false), 35 | TextComponentAccessor.TEXT_FIELD_WHOLE_TEXT 36 | ); 37 | } 38 | 39 | protected void resetEditorFrom(CppRunConfiguration s) { 40 | super.resetEditorFrom(s); 41 | CppRunnerParameters runnerParameters = s.getRunnerParameters(); 42 | myExecutableParameters.getEditor().setItem(runnerParameters != null ? runnerParameters.getExecutableParameters() : ""); 43 | workingDirectoryTextField.setText(runnerParameters != null ? runnerParameters.getWorkingDir() : ""); 44 | } 45 | 46 | protected void applyEditorTo(CppRunConfiguration s) throws ConfigurationException { 47 | super.applyEditorTo(s); 48 | CppRunnerParameters runnerParameters = s.getRunnerParameters(); 49 | runnerParameters.setExecutableParameters((String) myExecutableParameters.getEditor().getItem()); 50 | runnerParameters.setWorkingDir(workingDirectoryTextField.getText()); 51 | } 52 | 53 | @NotNull 54 | protected JComponent createEditor() { 55 | return myPanel; 56 | } 57 | 58 | protected void disposeEditor() { 59 | myPanel = null; 60 | myExecutableName = null; 61 | workingDirectoryTextField = null; 62 | myExecutableParameters = null; 63 | } 64 | 65 | protected ComboboxWithBrowseButton getExecutableName() { 66 | return myExecutableName; 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /src/com/advancedtools/cpp/run/CppRunner.java: -------------------------------------------------------------------------------- 1 | // Copyright 2006-2012 AdvancedTools. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. 2 | package com.advancedtools.cpp.run; 3 | 4 | import com.intellij.execution.runners.GenericProgramRunner; 5 | import com.intellij.execution.runners.ExecutionEnvironment; 6 | import com.intellij.execution.runners.RunContentBuilder; 7 | import com.intellij.execution.Executor; 8 | import com.intellij.execution.ExecutionException; 9 | import com.intellij.execution.ExecutionResult; 10 | import com.intellij.execution.executors.DefaultRunExecutor; 11 | import com.intellij.execution.configurations.*; 12 | import com.intellij.execution.ui.RunContentDescriptor; 13 | import com.intellij.openapi.project.Project; 14 | import com.intellij.openapi.fileEditor.FileDocumentManager; 15 | import org.jetbrains.annotations.NotNull; 16 | import org.jetbrains.annotations.Nullable; 17 | 18 | /** 19 | * @author maxim 20 | * Date: 28.03.2009 21 | * Time: 19:35:05 22 | */ 23 | public class CppRunner extends GenericProgramRunner { 24 | @Nullable 25 | @Override 26 | protected RunContentDescriptor doExecute(Project project, RunProfileState runProfileState, RunContentDescriptor runContentDescriptor, ExecutionEnvironment executionEnvironment) throws ExecutionException { 27 | FileDocumentManager.getInstance().saveAllDocuments(); 28 | Executor executor = executionEnvironment.getExecutor(); 29 | 30 | ExecutionResult executionResult = runProfileState.execute(executor, this); 31 | if (executionResult == null) return null; 32 | final RunContentBuilder contentBuilder = new RunContentBuilder(executionResult, executionEnvironment); 33 | onProcessStarted(executionEnvironment.getRunnerSettings(), executionResult); 34 | 35 | return contentBuilder.showRunContent(runContentDescriptor); 36 | } 37 | 38 | public boolean canRun(@NotNull final String executorId, @NotNull final RunProfile profile) { 39 | return DefaultRunExecutor.EXECUTOR_ID.equals(executorId) && profile instanceof CppRunConfiguration; 40 | } 41 | 42 | @NotNull 43 | public String getRunnerId() { 44 | return "CppRunner"; 45 | } 46 | } -------------------------------------------------------------------------------- /src/com/advancedtools/cpp/run/CppRunnerParameters.java: -------------------------------------------------------------------------------- 1 | // Copyright 2006-2012 AdvancedTools. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. 2 | package com.advancedtools.cpp.run; 3 | 4 | /** 5 | * @author maxim 6 | * Date: 28.03.2009 7 | * Time: 20:14:54 8 | */ 9 | public class CppRunnerParameters extends BaseCppRunnerParameters { 10 | private String executableParameters; 11 | private String workingDir; 12 | 13 | public String getExecutableParameters() { 14 | return executableParameters; 15 | } 16 | 17 | public void setExecutableParameters(String executableParameters) { 18 | this.executableParameters = executableParameters; 19 | } 20 | 21 | public String getWorkingDir() { 22 | return workingDir; 23 | } 24 | 25 | public void setWorkingDir(String launchingPath) { 26 | this.workingDir = launchingPath; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/com/advancedtools/cpp/sdk/BuildFileType.java: -------------------------------------------------------------------------------- 1 | // Copyright 2006-2012 AdvancedTools. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. 2 | package com.advancedtools.cpp.sdk; 3 | 4 | /** 5 | * User: maxim 6 | * Date: 09.07.2008 7 | * Time: 9:53:48 8 | */ 9 | public enum BuildFileType { 10 | MAKEFILE, MSVC 11 | } 12 | -------------------------------------------------------------------------------- /src/com/advancedtools/cpp/sdk/ChooseCppSdk.form: -------------------------------------------------------------------------------- 1 | 2 |
3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 |
34 | -------------------------------------------------------------------------------- /src/com/advancedtools/cpp/sdk/CppModuleConfigurationEditorProvider.java: -------------------------------------------------------------------------------- 1 | // Copyright 2006-2012 AdvancedTools. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. 2 | package com.advancedtools.cpp.sdk; 3 | 4 | import com.intellij.openapi.module.ModuleComponent; 5 | import com.intellij.openapi.module.ModuleConfigurationEditor; 6 | import com.intellij.openapi.module.Module; 7 | import com.intellij.openapi.module.ModuleType; 8 | import com.intellij.openapi.roots.ModifiableRootModel; 9 | import com.intellij.openapi.roots.ui.configuration.ModuleConfigurationEditorProvider; 10 | import com.intellij.openapi.roots.ui.configuration.ModuleConfigurationState; 11 | import com.intellij.openapi.roots.ui.configuration.DefaultModuleConfigurationEditorFactory; 12 | import org.jetbrains.annotations.NonNls; 13 | import org.jetbrains.annotations.NotNull; 14 | 15 | /** 16 | * @author maxim 17 | */ 18 | public class CppModuleConfigurationEditorProvider implements ModuleConfigurationEditorProvider, ModuleComponent { 19 | public ModuleConfigurationEditor[] createEditors(ModuleConfigurationState state) { 20 | final Module module = state.getRootModel().getModule(); 21 | if (ModuleType.get(module) != CppModuleType.getInstance()) return new ModuleConfigurationEditor[0]; 22 | 23 | ModifiableRootModel rootModel = state.getRootModel(); 24 | 25 | DefaultModuleConfigurationEditorFactory defaultModuleConfigurationEditorFactory = DefaultModuleConfigurationEditorFactory.getInstance(); 26 | return new ModuleConfigurationEditor[] { 27 | defaultModuleConfigurationEditorFactory.createModuleContentRootsEditor(state), 28 | defaultModuleConfigurationEditorFactory.createClasspathEditor(state), 29 | }; 30 | } 31 | 32 | public void projectOpened() { 33 | } 34 | 35 | public void projectClosed() { 36 | } 37 | 38 | public void moduleAdded() { 39 | } 40 | 41 | @NonNls 42 | @NotNull 43 | public String getComponentName() { 44 | return "CppSupport.ModuleEditorProvider"; 45 | } 46 | 47 | public void initComponent() { 48 | } 49 | 50 | public void disposeComponent() { 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/com/advancedtools/cpp/sdk/CppModuleType.java: -------------------------------------------------------------------------------- 1 | // Copyright 2006-2012 AdvancedTools. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. 2 | package com.advancedtools.cpp.sdk; 3 | 4 | import com.advancedtools.cpp.CppBundle; 5 | import com.advancedtools.cpp.CppSupportLoader; 6 | import com.intellij.ide.util.projectWizard.ModuleWizardStep; 7 | import com.intellij.ide.util.projectWizard.ProjectWizardStepFactory; 8 | import com.intellij.ide.util.projectWizard.WizardContext; 9 | import com.intellij.openapi.application.ApplicationManager; 10 | import com.intellij.openapi.components.ApplicationComponent; 11 | import com.intellij.openapi.module.ModuleType; 12 | import com.intellij.openapi.module.ModuleTypeManager; 13 | import com.intellij.openapi.projectRoots.Sdk; 14 | import com.intellij.openapi.roots.ui.configuration.ModulesProvider; 15 | import org.jetbrains.annotations.NonNls; 16 | import org.jetbrains.annotations.NotNull; 17 | 18 | import javax.swing.*; 19 | import java.util.List; 20 | 21 | /** 22 | * @author maxim 23 | */ 24 | public class CppModuleType extends ModuleType implements ApplicationComponent { 25 | public CppModuleType() { 26 | super("C++"); 27 | } 28 | 29 | public CppModuleBuilder createModuleBuilder() { 30 | return new CppModuleBuilder(); 31 | } 32 | 33 | public String getName() { 34 | return CppBundle.message("c.cpp.module"); 35 | } 36 | 37 | public ModuleWizardStep[] createWizardSteps(WizardContext wizardContext, CppModuleBuilder cppModuleBuilder, ModulesProvider modulesProvider) { 38 | final List list = CppSdkType.getInstance().getCppSdks(); 39 | final ModuleWizardStep sourceModuleWizardStep = ProjectWizardStepFactory.getInstance().createSourcePathsStep(wizardContext, cppModuleBuilder, null, null); 40 | final ModuleWizardStep createSampleCode = new CreateEntryCodeStep(cppModuleBuilder); 41 | 42 | if (list.size() == 0) { 43 | return new ModuleWizardStep[] { new ChooseCppSdkStep(cppModuleBuilder, wizardContext),sourceModuleWizardStep, createSampleCode }; 44 | } 45 | return new ModuleWizardStep[] { sourceModuleWizardStep, createSampleCode }; 46 | } 47 | 48 | public String getDescription() { 49 | return CppBundle.message("c.cpp.module.description"); 50 | } 51 | 52 | public Icon getBigIcon() { 53 | return CppSupportLoader.ourBigModuleIcon; 54 | } 55 | 56 | public Icon getNodeIcon(boolean isOpened) { 57 | return CppSupportLoader.ourModuleIcon; 58 | } 59 | 60 | @NonNls 61 | @NotNull 62 | public String getComponentName() { 63 | return "CppTools.ModuleType"; 64 | } 65 | 66 | public void initComponent() { 67 | ModuleTypeManager.getInstance().registerModuleType(this); 68 | } 69 | 70 | public void disposeComponent() { 71 | } 72 | 73 | public static CppModuleType getInstance() { 74 | return ApplicationManager.getApplication().getComponent(CppModuleType.class); 75 | } 76 | 77 | } 78 | -------------------------------------------------------------------------------- /src/com/advancedtools/cpp/sdk/CreateEntryCodeStep.form: -------------------------------------------------------------------------------- 1 | 2 |
3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 |
49 | -------------------------------------------------------------------------------- /src/com/advancedtools/cpp/sdk/CreateEntryCodeStep.java: -------------------------------------------------------------------------------- 1 | // Copyright 2006-2012 AdvancedTools. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. 2 | package com.advancedtools.cpp.sdk; 3 | 4 | import com.intellij.ide.util.projectWizard.ModuleWizardStep; 5 | 6 | import javax.swing.*; 7 | import java.awt.event.ItemListener; 8 | import java.awt.event.ItemEvent; 9 | 10 | /** 11 | * @author maxim 12 | * Date: 09.07.2008 13 | * Time: 9:52:24 14 | */ 15 | class CreateEntryCodeStep extends ModuleWizardStep { 16 | private CppModuleBuilder myModelBuilder; 17 | private JPanel myPanel; 18 | private JComboBox addEntryType; 19 | private JComboBox buildFileType; 20 | private JCheckBox myAddEntryPointSwitch; 21 | private JCheckBox myAddBuildFileSwitch; 22 | 23 | CreateEntryCodeStep(CppModuleBuilder moduleBuilder) { 24 | myModelBuilder = moduleBuilder; 25 | 26 | myAddBuildFileSwitch.addItemListener(new ItemListener() { 27 | public void itemStateChanged(ItemEvent e) { 28 | buildFileType.setEnabled(myAddBuildFileSwitch.isSelected()); 29 | } 30 | }); 31 | buildFileType.setModel(new DefaultComboBoxModel(BuildFileType.values())); 32 | 33 | myAddEntryPointSwitch.addItemListener(new ItemListener() { 34 | public void itemStateChanged(ItemEvent e) { 35 | addEntryType.setEnabled(myAddEntryPointSwitch.isSelected()); 36 | } 37 | }); 38 | addEntryType.setModel(new DefaultComboBoxModel(EntryPointType.values())); 39 | } 40 | 41 | public JComponent getComponent() { 42 | return myPanel; 43 | } 44 | 45 | public void updateDataModel() { 46 | if (myAddBuildFileSwitch.isSelected()) { 47 | myModelBuilder.setBuildFileType((BuildFileType) buildFileType.getSelectedItem()); 48 | } 49 | if (myAddEntryPointSwitch.isSelected()) { 50 | myModelBuilder.setEntryPointType((EntryPointType) addEntryType.getSelectedItem()); 51 | } 52 | } 53 | 54 | } 55 | -------------------------------------------------------------------------------- /src/com/advancedtools/cpp/sdk/EntryPointType.java: -------------------------------------------------------------------------------- 1 | // Copyright 2006-2012 AdvancedTools. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. 2 | package com.advancedtools.cpp.sdk; 3 | 4 | /** 5 | * User: maxim 6 | * Date: 09.07.2008 7 | * Time: 9:53:48 8 | */ 9 | public enum EntryPointType { 10 | CSTYLE, CPPSTYLE 11 | } -------------------------------------------------------------------------------- /src/com/advancedtools/cpp/settings/IncludeFilesListEditor.java: -------------------------------------------------------------------------------- 1 | // Copyright 2006-2012 AdvancedTools. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. 2 | package com.advancedtools.cpp.settings; 3 | 4 | import org.jetbrains.annotations.NotNull; 5 | import com.intellij.openapi.vfs.VirtualFile; 6 | import com.intellij.openapi.fileChooser.FileChooserDescriptor; 7 | import com.advancedtools.cpp.communicator.Communicator; 8 | import com.advancedtools.cpp.settings.AbstractFileListEditor; 9 | 10 | /** 11 | * @author maxim 12 | */ 13 | public class IncludeFilesListEditor extends AbstractFileListEditor { 14 | public IncludeFilesListEditor(String title, @NotNull String pathesList) { 15 | super(title, pathesList); 16 | 17 | init(); 18 | } 19 | 20 | protected FileChooserDescriptor configureFileChooserDescriptor() { 21 | return new FileChooserDescriptor(true, false, false, false, false, false) { 22 | public boolean isFileSelectable(VirtualFile virtualFile) { 23 | return Communicator.isHeaderFile(virtualFile); 24 | } 25 | }; 26 | } 27 | 28 | protected boolean isValidFile(Object value) { 29 | final VirtualFile byPath = getFile(value); 30 | return byPath != null && Communicator.isHeaderFile(byPath); 31 | } 32 | 33 | protected String getChooseTitle() { 34 | return "Choose Include File"; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/com/advancedtools/cpp/settings/IncludePathesListEditor.java: -------------------------------------------------------------------------------- 1 | // Copyright 2006-2012 AdvancedTools. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. 2 | package com.advancedtools.cpp.settings; 3 | 4 | import org.jetbrains.annotations.NotNull; 5 | import com.intellij.openapi.vfs.VirtualFile; 6 | import com.intellij.openapi.fileChooser.FileChooserDescriptor; 7 | import com.advancedtools.cpp.settings.AbstractFileListEditor; 8 | 9 | /** 10 | * @author maxim 11 | */ 12 | public class IncludePathesListEditor extends AbstractFileListEditor { 13 | public IncludePathesListEditor(String title, @NotNull String pathesList) { 14 | super(title, pathesList); 15 | 16 | init(); 17 | } 18 | 19 | protected FileChooserDescriptor configureFileChooserDescriptor() { 20 | return new FileChooserDescriptor(false, true, false, false, false, false) { 21 | public boolean isFileSelectable(VirtualFile virtualFile) { 22 | return virtualFile.isDirectory(); 23 | } 24 | }; 25 | } 26 | 27 | protected boolean isValidFile(Object value) { 28 | VirtualFile byPath = getFile(value); 29 | return byPath != null && byPath.isDirectory(); 30 | } 31 | 32 | protected String getChooseTitle() { 33 | return "Choose Include Path"; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/com/advancedtools/cpp/settings/MacrosListEditor.java: -------------------------------------------------------------------------------- 1 | // Copyright 2006-2012 AdvancedTools. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. 2 | package com.advancedtools.cpp.settings; 3 | 4 | import org.jetbrains.annotations.NotNull; 5 | 6 | import javax.swing.table.DefaultTableModel; 7 | import javax.swing.table.TableModel; 8 | 9 | import com.advancedtools.cpp.settings.StringListEditor; 10 | 11 | /** 12 | * @author maxim 13 | */ 14 | public class MacrosListEditor extends StringListEditor { 15 | public MacrosListEditor(String title, @NotNull String pathesList) { 16 | super(title, pathesList); 17 | 18 | editButton.setVisible(false); 19 | 20 | init(); 21 | } 22 | 23 | protected void insertRowWithDefaultValues(int i) { 24 | ((DefaultTableModel) stringListTable.getModel()).insertRow(i, new Object[]{"", ""}); 25 | } 26 | 27 | protected void swapRows(int i, int i1) { 28 | String s = (String) stringListTable.getValueAt(i, 0); 29 | String s2 = (String) stringListTable.getValueAt(i, 1); 30 | stringListTable.setValueAt(stringListTable.getValueAt(i1, 0), i, 0); 31 | stringListTable.setValueAt(stringListTable.getValueAt(i1, 1), i, 1); 32 | stringListTable.setValueAt(s, i1, 0); 33 | stringListTable.setValueAt(s2, i1, 1); 34 | } 35 | 36 | protected Object[] getColumnNames() { 37 | return new Object[] { "define", "value" }; 38 | } 39 | 40 | protected String[][] buildResultArrayForGivenElementsCount(int i) { 41 | return new String[i][2]; 42 | } 43 | 44 | protected void addResultToArray(String[][] result, int i, String s) { 45 | int index = s.indexOf(' '); 46 | result[i] = new String[] {s.substring(0, index != -1 ? index:s.length()),index != -1 ? s.substring(index + 1):""}; 47 | } 48 | 49 | protected Object getStringAtIndex(TableModel tableModel, int i) { 50 | String name = (String) tableModel.getValueAt(i, 0); 51 | String value = (String) tableModel.getValueAt(i, 1); 52 | if (name.length() == 0) return null; 53 | if (value.length() == 0) return name; 54 | return name + " " + value; 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/com/advancedtools/cpp/settings/ValidatingFilePathCellRenderer.java: -------------------------------------------------------------------------------- 1 | // Copyright 2006-2012 AdvancedTools. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. 2 | package com.advancedtools.cpp.settings; 3 | 4 | import javax.swing.table.DefaultTableCellRenderer; 5 | import javax.swing.*; 6 | import java.awt.*; 7 | 8 | /** 9 | * @author maxim 10 | * Date: 31.05.2009 11 | * Time: 15:40:50 12 | */ 13 | public class ValidatingFilePathCellRenderer extends DefaultTableCellRenderer { 14 | public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { 15 | boolean validDir = isValidDir(value); 16 | setForeground(validDir ? Color.black : Color.red); 17 | return super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column); 18 | } 19 | 20 | protected boolean isValidDir(Object value) { 21 | return AbstractFileListEditor.getFile(value) != null; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/com/advancedtools/cpp/usages/FileUsage.java: -------------------------------------------------------------------------------- 1 | // Copyright 2006-2012 AdvancedTools. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. 2 | package com.advancedtools.cpp.usages; 3 | 4 | import com.intellij.openapi.vfs.VirtualFile; 5 | import com.intellij.openapi.vfs.LocalFileSystem; 6 | 7 | import java.util.List; 8 | import java.util.ArrayList; 9 | import java.io.File; 10 | 11 | /** 12 | * @author maxim 13 | * Date: 02.06.2006 14 | * Time: 18:39:09 15 | */ 16 | public class FileUsage { 17 | public final String fileName; 18 | private VirtualFile vfile; 19 | public final List usageList = new ArrayList(); 20 | 21 | public FileUsage(String _fileName) { 22 | fileName = _fileName; 23 | } 24 | 25 | public VirtualFile findVirtualFile() { 26 | if (vfile == null) { 27 | vfile = LocalFileSystem.getInstance().findFileByPath(fileName.replace(File.separatorChar,'/')); 28 | } 29 | return vfile; 30 | } 31 | 32 | public String getFileLocaton() { 33 | VirtualFile file = findVirtualFile(); 34 | return formatFile(file); 35 | } 36 | 37 | public static String formatFile(VirtualFile file) { 38 | return file.getName() + " ( " + file.getParent().getPath() + " )"; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/com/advancedtools/cpp/usages/FileUsageList.java: -------------------------------------------------------------------------------- 1 | // Copyright 2006-2012 AdvancedTools. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. 2 | package com.advancedtools.cpp.usages; 3 | 4 | import com.advancedtools.cpp.usages.FileUsage; 5 | 6 | import java.util.List; 7 | import java.util.ArrayList; 8 | 9 | /** 10 | * @author maxim 11 | * Date: 02.06.2006 12 | * Time: 18:38:55 13 | */ 14 | public class FileUsageList { 15 | public final List files = new ArrayList(); 16 | } 17 | -------------------------------------------------------------------------------- /src/com/advancedtools/cpp/usages/OurUsage.java: -------------------------------------------------------------------------------- 1 | // Copyright 2006-2012 AdvancedTools. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. 2 | package com.advancedtools.cpp.usages; 3 | 4 | /** 5 | * @author maxim 6 | * Date: 02.06.2006 7 | * Time: 18:38:16 8 | */ 9 | public class OurUsage { 10 | public final int start, end; 11 | public String text; 12 | public String context; 13 | public int line; 14 | public int endColumn; 15 | public int startColumn; 16 | public final FileUsage fileUsage; 17 | 18 | public OurUsage(int _start, int _end, FileUsage _fileUsage) { 19 | start = _start; 20 | end = _end; 21 | fileUsage = _fileUsage; 22 | } 23 | 24 | public int getStart() { 25 | return start; 26 | } 27 | 28 | public String getText() { 29 | if (text != null) { 30 | return text.substring(startColumn, endColumn); 31 | } 32 | return "!null!"; 33 | } 34 | 35 | public String getContextText() { 36 | return context != null ? context:getText(); 37 | } 38 | 39 | public int getEnd() { 40 | return end; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/com/advancedtools/cpp/utils/About.form: -------------------------------------------------------------------------------- 1 | 2 |
3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | -------------------------------------------------------------------------------- /src/com/advancedtools/cpp/utils/IconableGutterNavigator.java: -------------------------------------------------------------------------------- 1 | // Copyright 2006-2012 AdvancedTools. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. 2 | package com.advancedtools.cpp.utils; 3 | 4 | import com.intellij.openapi.editor.markup.GutterIconRenderer; 5 | import com.intellij.openapi.actionSystem.AnAction; 6 | import com.intellij.openapi.actionSystem.AnActionEvent; 7 | import com.intellij.openapi.actionSystem.DataConstants; 8 | import com.intellij.openapi.project.Project; 9 | 10 | import javax.swing.*; 11 | 12 | import org.jetbrains.annotations.NotNull; 13 | import org.jetbrains.annotations.Nullable; 14 | 15 | /** 16 | * @author maxim 17 | */ 18 | abstract public class IconableGutterNavigator extends GutterIconRenderer { 19 | private AnAction myAction; 20 | private final Icon myIcon; 21 | private final String myTooltip; 22 | 23 | public IconableGutterNavigator(Icon icon, String tooltip) { 24 | myIcon = icon; 25 | myTooltip = tooltip != null ? tooltip:null; 26 | } 27 | 28 | @NotNull 29 | public Icon getIcon() { 30 | return myIcon; 31 | } 32 | 33 | public boolean isNavigateAction() { 34 | return true; 35 | } 36 | 37 | @Override 38 | public boolean equals(Object o) { 39 | if (!(o instanceof IconableGutterNavigator)) return false; 40 | return myTooltip.equals(((IconableGutterNavigator)o).myTooltip); 41 | } 42 | 43 | @Override 44 | public int hashCode() { 45 | return myTooltip.hashCode(); 46 | } 47 | 48 | @Nullable 49 | public String getTooltipText() { 50 | return myTooltip; 51 | } 52 | 53 | @Nullable 54 | public AnAction getClickAction() { 55 | if (myAction == null) { 56 | myAction = new AnAction() { 57 | public void actionPerformed(AnActionEvent anActionEvent) { 58 | final Project project = (Project) anActionEvent.getDataContext().getData(DataConstants.PROJECT); 59 | doNavigate(project); 60 | } 61 | }; 62 | } 63 | return myAction; 64 | } 65 | 66 | protected abstract void doNavigate(Project project); 67 | } 68 | -------------------------------------------------------------------------------- /src/com/advancedtools/cpp/utils/StringTokenizerIterable.java: -------------------------------------------------------------------------------- 1 | package com.advancedtools.cpp.utils; 2 | 3 | import java.util.Iterator; 4 | import java.util.StringTokenizer; 5 | import java.io.File; 6 | 7 | /** 8 | * User: maxim 9 | * Date: 31.05.2009 10 | * Time: 15:01:36 11 | */ 12 | public class StringTokenizerIterable implements Iterable { 13 | private StringTokenizer tokenizer; 14 | public StringTokenizerIterable(String additionalIncludeDirs, String separator) { 15 | tokenizer = new StringTokenizer(additionalIncludeDirs, separator); 16 | } 17 | 18 | public Iterator iterator() { 19 | return new Iterator() { 20 | public boolean hasNext() { 21 | return tokenizer.hasMoreElements(); 22 | } 23 | 24 | public String next() { 25 | return tokenizer.nextToken().replace(File.separatorChar, '/'); 26 | } 27 | 28 | public void remove() { 29 | throw new UnsupportedOperationException(); 30 | } 31 | }; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/com/advancedtools/cpp/utils/TemplateUtils.java: -------------------------------------------------------------------------------- 1 | // Copyright 2006-2012 AdvancedTools. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. 2 | package com.advancedtools.cpp.utils; 3 | 4 | import com.advancedtools.cpp.sdk.CppModuleBuilder; 5 | import com.intellij.ide.fileTemplates.FileTemplate; 6 | import com.intellij.ide.fileTemplates.FileTemplateManager; 7 | import com.intellij.openapi.util.io.FileUtil; 8 | import com.intellij.openapi.vfs.VirtualFile; 9 | 10 | import java.io.IOException; 11 | import java.io.OutputStream; 12 | import java.io.StringBufferInputStream; 13 | import java.util.Properties; 14 | 15 | /** 16 | * @author maxim 17 | */ 18 | public class TemplateUtils { 19 | public static final String MAKEFILE_TEMPLATE_NAME = "Makefile"; 20 | public static final String C_MAIN_TEMPLATE_NAME = "C_Main"; 21 | public static final String CPP_MAIN_TEMPLATE_NAME = "Cpp_Main"; 22 | 23 | public static String getTemplateText(String fileName, String ... additionalParameters) throws IOException { 24 | Properties properties = FileTemplateManager.getInstance().getDefaultProperties(); 25 | 26 | if (additionalParameters != null) { 27 | for(int i = 0; i < additionalParameters.length; ++i) { 28 | String paramName = additionalParameters[i]; 29 | if (i + 1 < additionalParameters.length) { 30 | ++i; 31 | properties.put(paramName, additionalParameters[i]); 32 | } 33 | } 34 | } 35 | final FileTemplate fileTemplate = FileTemplateManager.getInstance().getTemplate(fileName); 36 | assert fileTemplate != null; 37 | String text = fileTemplate.getText(properties); 38 | return text; 39 | } 40 | 41 | public static void createOrResetFileContent(VirtualFile sourcePathDir, String fileName, StringBufferInputStream inputStream) throws IOException { 42 | VirtualFile child = sourcePathDir.findChild(fileName); 43 | if (child == null) child = sourcePathDir.createChildData(CppModuleBuilder.class, fileName); 44 | OutputStream outputStream = child.getOutputStream(CppModuleBuilder.class); 45 | 46 | FileUtil.copy(inputStream, outputStream); 47 | outputStream.flush(); 48 | outputStream.close(); 49 | } 50 | 51 | public static void createOrResetFileContentFromTemplate(VirtualFile sourcePathDir, String fileName, 52 | String templateFileName, String ... additionalParameters) { 53 | try { 54 | createOrResetFileContent(sourcePathDir, fileName, new StringBufferInputStream(getTemplateText(templateFileName, additionalParameters))); 55 | } catch (IOException ex) { 56 | ex.printStackTrace(); 57 | } 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/fileTemplates/C_Main.c.ft: -------------------------------------------------------------------------------- 1 | \#include 2 | int main(int argc, const char* argv[]) { 3 | printf("Hello, World"); 4 | return 0; 5 | } -------------------------------------------------------------------------------- /src/fileTemplates/Cpp_Main.cpp.ft: -------------------------------------------------------------------------------- 1 | \#include 2 | \#include 3 | using namespace std; 4 | 5 | int main(int argc, const char* argv[]) { 6 | std::cout << "Hello, World" << endl; 7 | return 0; 8 | } -------------------------------------------------------------------------------- /src/fileTemplates/Makefile.empty.ft: -------------------------------------------------------------------------------- 1 | COMPILER=G++ 2 | 3 | # todo: object files into output path, processing c / c++ files in the same time (?), nested directories for source files (?) 4 | C = ${Extension} 5 | OUTPUT_PATH = ${OutputPath} 6 | SOURCE_PATH = ${SourcePath} 7 | EXE = $(OUTPUT_PATH)${Executable} 8 | 9 | ifeq ($(COMPILER), G++) 10 | ifeq ($(OS),Windows_NT) 11 | OBJ = obj 12 | else 13 | OBJ = o 14 | endif 15 | COPT = -O2 16 | CCMD = g++ 17 | OBJFLAG = -o 18 | EXEFLAG = -o 19 | # INCLUDES = -I../.includes 20 | INCLUDES = 21 | # LIBS = -lgc 22 | LIBS = 23 | # LIBPATH = -L../gc/.libs 24 | LIBPATH = 25 | CPPFLAGS = $(COPT) -g $(INCLUDES) 26 | LDFLAGS = $(LIBPATH) -g $(LIBS) 27 | DEP = dep 28 | else 29 | OBJ = obj 30 | COPT = /O2 31 | CCMD = cl 32 | OBJFLAG = /Fo 33 | EXEFLAG = /Fe 34 | # INCLUDES = /I..\\.includes 35 | INCLUDES = 36 | # LIBS = ..\\.libs\\libgc.lib 37 | LIBS = 38 | CPPFLAGS = $(COPT) /DEBUG $(INCLUDES) 39 | LDFLAGS = /DEBUG 40 | endif 41 | 42 | OBJS := $(patsubst %.$(C),%.$(OBJ),$(wildcard $(SOURCE_PATH)*.$(C))) 43 | 44 | %.$(OBJ):%.$(C) 45 | @echo Compiling $(basename $<)... 46 | $(CCMD) -c $(CPPFLAGS) $(CXXFLAGS) $< $(OBJFLAG)$@ 47 | 48 | all: $(OBJS) 49 | @echo Linking... 50 | $(CCMD) $(LDFLAGS) $^ $(LIBS) $(EXEFLAG) $(EXE) 51 | 52 | clean: 53 | rm -rf $(SOURCE_PATH)*.$(OBJ) $(EXE) 54 | 55 | rebuild: clean all 56 | #rebuild is not entirely correct -------------------------------------------------------------------------------- /src/inspectionDescriptions/JNIImplementations.html: -------------------------------------------------------------------------------- 1 | Provides gutter icons that link JNI function implementations with Java method declarations. -------------------------------------------------------------------------------- /src/inspectionDescriptions/NativeJavaMethods.html: -------------------------------------------------------------------------------- 1 | Provides gutter icons that link java native method declarations with native code implementations -------------------------------------------------------------------------------- /src/inspectionDescriptions/UnusedCppSymbol.html: -------------------------------------------------------------------------------- 1 | Checks for cpp identifiers not used or used once. -------------------------------------------------------------------------------- /testData/makefile_parsing/CheckRefResolve.mk: -------------------------------------------------------------------------------- 1 | WAF=python tools/waf-light --jobs=1 2 | 3 | all: 4 | @$(WAF) build 5 | -------------------------------------------------------------------------------- /testData/makefile_parsing/CheckRefResolve2.mk: -------------------------------------------------------------------------------- 1 | all: all 2 | 3 | -------------------------------------------------------------------------------- /testData/makefile_parsing/CheckRefResolve3.mk: -------------------------------------------------------------------------------- 1 | PP = exe 2 | $(PP).xxx: 3 | all: $(PP).xxx .cf-modules cfcat -------------------------------------------------------------------------------- /testData/makefile_parsing/CompleteTargetRef.mk: -------------------------------------------------------------------------------- 1 | WAF=python tools/waf-light --jobs=1 2 | 3 | all: al 4 | -------------------------------------------------------------------------------- /testData/makefile_parsing/CompleteTargetRef_after.mk: -------------------------------------------------------------------------------- 1 | WAF=python tools/waf-light --jobs=1 2 | 3 | all: all 4 | -------------------------------------------------------------------------------- /testData/makefile_parsing/CompleteVar.mk: -------------------------------------------------------------------------------- 1 | WAF=python tools/waf-light --jobs=1 2 | 3 | install: 4 | @$(W 5 | -------------------------------------------------------------------------------- /testData/makefile_parsing/CompleteVar_after.mk: -------------------------------------------------------------------------------- 1 | WAF=python tools/waf-light --jobs=1 2 | 3 | install: 4 | @$(WAF 5 | -------------------------------------------------------------------------------- /testData/makefile_parsing/Makefile2.mk: -------------------------------------------------------------------------------- 1 | WAF=python tools/waf-light --jobs=1 2 | 3 | all: 4 | @$(WAF) build 5 | 6 | all-debug: 7 | @$(WAF) -v build 8 | 9 | all-progress: 10 | @$(WAF) -p build 11 | 12 | install: 13 | @$(WAF) install 14 | 15 | uninstall: 16 | @$(WAF) uninstall 17 | 18 | test: all 19 | python tools/test.py --mode=release simple 20 | 21 | test-all: all 22 | python tools/test.py --mode=debug,release 23 | 24 | test-release: all 25 | python tools/test.py --mode=release 26 | 27 | test-debug: all 28 | python tools/test.py --mode=debug 29 | 30 | test-simple: all 31 | python tools/test.py simple 32 | 33 | test-pummel: all 34 | python tools/test.py pummel 35 | 36 | test-internet: all 37 | python tools/test.py internet 38 | 39 | benchmark: all 40 | build/default/node benchmark/run.js 41 | 42 | doc: doc/node.1 doc/api.html doc/index.html doc/changelog.html 43 | 44 | doc/api.html: doc/api.txt 45 | asciidoc --unsafe \ 46 | -a theme=pipe \ 47 | -a toc \ 48 | -a toclevels=1 \ 49 | -a linkcss \ 50 | -o doc/api.html doc/api.txt 51 | 52 | doc/changelog.html: ChangeLog 53 | echo 'Node.js ChangeLog

Node.js ChangeLog

' > doc/changelog.html
54 | 	cat ChangeLog >> doc/changelog.html
55 | 	echo '
' >> doc/changelog.html 56 | 57 | doc/api.xml: doc/api.txt 58 | asciidoc -b docbook -d manpage -o doc/api.xml doc/api.txt 59 | 60 | doc/node.1: doc/api.xml 61 | xsltproc --output doc/node.1 --nonet doc/manpage.xsl doc/api.xml 62 | 63 | website-upload: doc 64 | scp doc/* ryan@nodejs.org:~/tinyclouds/node/ 65 | 66 | docclean: 67 | @-rm -f doc/node.1 doc/api.xml doc/api.html doc/changelog.html 68 | 69 | clean: 70 | @$(WAF) clean 71 | @-find tools/ -name "*.pyc" -delete 72 | 73 | distclean: clean docclean 74 | @-rm -rf build/ 75 | 76 | check: 77 | @tools/waf-light check 78 | 79 | VERSION=$(shell git describe) 80 | TARNAME=node-$(VERSION) 81 | 82 | dist: doc/node.1 doc/api.html 83 | git archive --prefix=$(TARNAME)/ HEAD > $(TARNAME).tar 84 | mkdir -p $(TARNAME)/doc 85 | cp doc/node.1 $(TARNAME)/doc/node.1 86 | cp doc/api.html $(TARNAME)/doc/api.html 87 | tar rf $(TARNAME).tar \ 88 | $(TARNAME)/doc/node.1 \ 89 | $(TARNAME)/doc/api.html 90 | rm -r $(TARNAME) 91 | gzip -f -9 $(TARNAME).tar 92 | 93 | .PHONY: benchmark clean docclean dist distclean check uninstall install all test test-all website-upload 94 | -------------------------------------------------------------------------------- /testData/parsing/ParseWithMacrosDef.cpp: -------------------------------------------------------------------------------- 1 | void main () { 2 | 3 | #define C() \ 4 | do \ 5 | { \ 6 | int z = 0; \ 7 | if (z) { \ 8 | } \ 9 | z = z * 2; \ 10 | } \ 11 | while (false) 12 | 13 | for(;;) { 14 | if (1) { 15 | C (); 16 | } 17 | } 18 | C (); 19 | } -------------------------------------------------------------------------------- /testData/parsing/ParseWithNs.cpp: -------------------------------------------------------------------------------- 1 | namespace Mode 2 | { 3 | class Mode_error: public Msg 4 | { 5 | public: 6 | typedef Mode_error const * R; 7 | Str::C const msg; 8 | Mode_error ( Str::C const _msg, Text::Seg const text); 9 | Mode_error (Msg::Kind const kind, Str::C const _msg, Text::Seg const text); 10 | virtual void out (Str::Buf<> & out, Text::Seg const text) const; 11 | }; 12 | 13 | class Error; 14 | class Unknown; 15 | class Based; 16 | # define DefHash(Type,Init) class Type; 17 | # include "mode.tab.inc" 18 | # undef DefHash 19 | 20 | template 21 | M const * hash__clone (Allocate::T & store, M const * const src) 22 | { return POOL_NEW (store, M) (*src); } 23 | 24 | extern Function const * hash__clone (Allocate::T & store, Function const * const src); 25 | 26 | # include "mode.tab.h" 27 | 28 | class FunctionRequired: public Msg 29 | { 30 | public: 31 | FunctionRequired (Text::Seg const _text); 32 | virtual void out (Str::Buf<> & out, Text::Seg const text) const; 33 | }; 34 | } 35 | 36 | // comment \ 37 | continues -------------------------------------------------------------------------------- /testData/parsing/SimpleParse.cpp: -------------------------------------------------------------------------------- 1 | #include "A.h" 2 | /************************************************************************** 3 | * Start cleaning up * 4 | **************************************************************************/ 5 | void main() { 6 | warn(1,1,1,1); 7 | warn(1,1,1,1); 8 | a->*bbb(aaa[1]); 9 | if (true) { 10 | cout << errr << flush; 11 | } 12 | warn(1,1,1,1); 13 | } 14 | 15 | static STLInfo g_stlinfo[] = 16 | { 17 | // className baseClass1 baseClass2 templType1 templName1 templType2 templName2 virtInheritance // iterators 18 | { "overflow_error", "runtime_error", 0, 0, 0, 0, 0, FALSE, FALSE }, 19 | { "underflow_error", "runtime_error", 0, 0, 0, 0, 0, FALSE, FALSE }, 20 | { 0, 0, 0, 0, 0, 0, 0, FALSE, FALSE } 21 | }; 22 | 23 | # if (! defined (malloc) && ! defined (YYINCLUDED_STDLIB_H) \ 24 | && (defined (__STDC__) || defined (__cplusplus))) 25 | void *malloc (YYSIZE_T); /* INFRINGES ON USER NAME SPACE */ 26 | # elif (! defined (malloc) && ! defined (YYINCLUDED_STDLIB_H) \ 27 | && (defined (__STDC__) || defined (__cplusplus))) 28 | void *malloc (size_t); /* INFRINGES ON USER NAME SPACE */ 29 | # endif 30 | 31 | static void main(const char* p) { 32 | int a = 1; 33 | } 34 | 35 | void aaa(); 36 | void bbb() {}; 37 | 38 | #ifdef HAS_SIGNALS 39 | static void stopGen(int) 40 | { 41 | exit(1); 42 | } 43 | #endif 44 | 45 | # \ 46 | 47 | # define W(name,default) \ 48 | if (Str::eq (real_name, #name)) \ 49 | project -> options -> warnings.name = state; \ 50 | else 51 | WARNINGS_LIST 52 | # undef W 53 | 54 | class A { 55 | A &operator=(const A &); 56 | A &operator ==(const A &); 57 | ~A(); 58 | }; 59 | -------------------------------------------------------------------------------- /testSrc/tests/CppParsingTest.java: -------------------------------------------------------------------------------- 1 | package tests; 2 | 3 | import com.intellij.codeInsight.TargetElementUtil; 4 | import com.intellij.psi.PsiElement; 5 | import com.intellij.psi.PsiReference; 6 | import com.intellij.psi.impl.source.resolve.reference.impl.PsiMultiReference; 7 | 8 | /** 9 | * @author maxim 10 | */ 11 | public class CppParsingTest extends BaseCppTestCase { 12 | 13 | protected String getTestDataPath() { 14 | return "testData/parsing"; 15 | } 16 | 17 | public void test() throws Throwable { 18 | doParseTest("SimpleParse"); 19 | String docContent = myFixture.getEditor().getDocument().getCharsSequence().toString(); 20 | String marker = "warn"; 21 | 22 | PsiReference psiReference = myFixture.getFile().findReferenceAt(docContent.indexOf(marker) + marker.length()); 23 | assertNotNull(psiReference); 24 | assertTrue(!(psiReference instanceof PsiMultiReference)); 25 | 26 | marker = "operator =="; 27 | int offset = docContent.indexOf(marker) + marker.length() - 1; 28 | psiReference = myFixture.getFile().findReferenceAt(offset); 29 | assertNotNull(psiReference); 30 | assertTrue(!(psiReference instanceof PsiMultiReference)); 31 | 32 | PsiElement psiElement = TargetElementUtil.getInstance().findTargetElement(myFixture.getEditor(), TargetElementUtil.REFERENCED_ELEMENT_ACCEPTED | 33 | TargetElementUtil.ELEMENT_NAME_ACCEPTED, offset); 34 | 35 | assertNotNull(psiElement); 36 | 37 | marker = "operator="; 38 | offset = docContent.indexOf(marker) + marker.length() - 1; 39 | psiReference = myFixture.getFile().findReferenceAt(offset); 40 | assertNotNull(psiReference); 41 | assertTrue(!(psiReference instanceof PsiMultiReference)); 42 | psiElement = TargetElementUtil.getInstance().findTargetElement(myFixture.getEditor(), TargetElementUtil.REFERENCED_ELEMENT_ACCEPTED | 43 | TargetElementUtil.ELEMENT_NAME_ACCEPTED, offset); 44 | assertNotNull(psiElement); 45 | } 46 | 47 | public void testParseWithMacrosDef() throws Throwable { 48 | doParseTest(getTestName()); 49 | } 50 | 51 | public void testParseWithNs() throws Throwable { 52 | doParseTest(getTestName()); 53 | } 54 | 55 | private void doParseTest(String fileName) throws Throwable { 56 | super.doParseTest(fileName, "cpp"); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /testSrc/tests/HighlightCommandTest.java: -------------------------------------------------------------------------------- 1 | package tests; 2 | 3 | import com.advancedtools.cpp.hilighting.AnalyzeProcessor; 4 | import com.advancedtools.cpp.hilighting.Fix; 5 | import com.advancedtools.cpp.hilighting.HighlightCommand; 6 | import gnu.trove.TIntObjectHashMap; 7 | import junit.framework.TestCase; 8 | 9 | import java.util.ArrayList; 10 | import java.util.List; 11 | 12 | /** 13 | * Created by IntelliJ IDEA. 14 | * User: Maxim 15 | * Date: 16.08.2010 16 | * Time: 12:18:44 17 | */ 18 | public class HighlightCommandTest extends TestCase { 19 | static class MessageInfo { 20 | final int start; 21 | final int end; 22 | final AnalyzeProcessor.MessageType type; 23 | final Fix[] fixes; 24 | final String text; 25 | 26 | public MessageInfo(int start, int end, String text, AnalyzeProcessor.MessageType type, Fix[] fixes) { 27 | this.start = start; 28 | this.end = end; 29 | this.text = text; 30 | this.type = type; 31 | this.fixes = fixes; 32 | } 33 | } 34 | public void test() { 35 | HighlightCommand.initErrorsDataInTest("16|SEMANTIC|Undefined identifier `%0'|1", "112|MODE|void function cannot return value|0"); 36 | final List messages = new ArrayList(2); 37 | HighlightCommand.processErrorInfoFromString("27483|27486|16|res|112|fix:24|fix:27", new AnalyzeProcessor() { 38 | public String getAnalizedFileName() { 39 | return "foo.cpp"; 40 | } 41 | 42 | public void startedAnalyzedFileName(String fileName) {} 43 | 44 | public void addMessage(MessageType type, int start, int end, String message, Fix... fixes) { 45 | messages.add(new MessageInfo(start, end, message, type, fixes)); 46 | } 47 | }); 48 | 49 | assertEquals(2, messages.size()); 50 | MessageInfo messageInfo = messages.get(0); 51 | assertEquals(messageInfo.start, 27483); 52 | assertEquals(messageInfo.end, 27486); 53 | assertEquals(messageInfo.text, "Undefined identifier `res'"); 54 | assertEquals(messageInfo.type, AnalyzeProcessor.MessageType.Error); 55 | assertEquals(2, messageInfo.fixes.length); 56 | 57 | messageInfo = messages.get(1); 58 | assertEquals(messageInfo.start, 27483); 59 | assertEquals(messageInfo.end, 27486); 60 | assertEquals(messageInfo.text, "void function cannot return value"); 61 | assertEquals(messageInfo.type, AnalyzeProcessor.MessageType.Error); 62 | assertEquals(0, messageInfo.fixes.length); 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /testSrc/tests/MakefileParsingTest.java: -------------------------------------------------------------------------------- 1 | package tests; 2 | 3 | import com.intellij.psi.PsiElement; 4 | import com.intellij.psi.PsiReference; 5 | import com.intellij.psi.ResolveResult; 6 | import com.intellij.psi.impl.source.resolve.reference.impl.PsiMultiReference; 7 | 8 | /** 9 | * @author maxim 10 | */ 11 | public class MakefileParsingTest extends BaseCppTestCase { 12 | protected String getTestDataPath() { 13 | return "testData/makefile_parsing"; 14 | } 15 | 16 | public void testMakefile1() throws Throwable { 17 | doParseTest(getTestName(),"mk"); 18 | } 19 | 20 | public void testMakefile2() throws Throwable { 21 | doParseTest(getTestName(),"mk"); 22 | } 23 | 24 | public void testMakefile3() throws Throwable { 25 | doParseTest(getTestName(),"mk"); 26 | } 27 | 28 | public void testCheckRefResolve() throws Throwable { 29 | refTest(); 30 | } 31 | 32 | private void refTest() throws Throwable { 33 | myFixture.testHighlighting(getTestName() + ".mk"); 34 | PsiReference psiReference = myFixture.getFile().findReferenceAt(myFixture.getEditor().getCaretModel().getOffset()); 35 | assertNotNull(psiReference); 36 | PsiElement psiElement = psiReference.resolve(); 37 | assertNotNull(psiElement); 38 | } 39 | 40 | public void testCheckRefResolve2() throws Throwable { 41 | refTest(); 42 | } 43 | 44 | public void testCheckRefResolve3() throws Throwable { 45 | myFixture.testHighlighting(getTestName() + ".mk"); 46 | PsiReference psiReference = myFixture.getFile().findReferenceAt(myFixture.getEditor().getCaretModel().getOffset()); 47 | assertTrue(psiReference instanceof PsiMultiReference); 48 | ResolveResult[] resolveResults = ((PsiMultiReference) psiReference).multiResolve(false); 49 | assertEquals(2, resolveResults.length); 50 | 51 | assertNotNull(resolveResults[0].getElement()); 52 | assertNotNull(resolveResults[1].getElement()); 53 | 54 | // TODO 55 | //assertEquals(2, ReferencesSearch.search(resolveResults[0].getElement()).findAll().size()); 56 | //assertEquals(2, ReferencesSearch.search(resolveResults[1].getElement()).findAll().size()); 57 | } 58 | 59 | public void testCompleteTargetRef() throws Throwable { 60 | myFixture.testCompletion(getTestName() + ".mk", getTestName() + "_after.mk"); 61 | } 62 | 63 | public void testCompleteVar() throws Throwable { 64 | myFixture.testCompletion(getTestName() + ".mk", getTestName() + "_after.mk"); 65 | } 66 | } --------------------------------------------------------------------------------