blob: 419e91c11c308b4b8c0b366e1fa2b54673458608 [file] [log] [blame]
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.netbeans.modules.languages.antlr.v3;
import org.netbeans.api.lexer.Language;
import org.netbeans.core.spi.multiview.MultiViewElement;
import org.netbeans.core.spi.multiview.text.MultiViewEditorElement;
import org.netbeans.modules.csl.api.DeclarationFinder;
import org.netbeans.modules.csl.api.OccurrencesFinder;
import org.netbeans.modules.csl.api.StructureScanner;
import org.netbeans.modules.csl.spi.DefaultLanguageConfig;
import org.netbeans.modules.csl.spi.LanguageRegistration;
import org.netbeans.modules.languages.antlr.AntlrDeclarationFinder;
import org.netbeans.modules.languages.antlr.AntlrOccurancesFinder;
import org.netbeans.modules.languages.antlr.AntlrParser;
import org.netbeans.modules.languages.antlr.AntlrParserResult;
import org.netbeans.modules.languages.antlr.AntlrStructureScanner;
import org.netbeans.modules.languages.antlr.AntlrTokenId;
import org.netbeans.modules.parsing.api.Snapshot;
import org.netbeans.modules.parsing.spi.Parser;
import org.netbeans.spi.lexer.Lexer;
import org.netbeans.spi.lexer.LexerRestartInfo;
import org.openide.awt.ActionID;
import org.openide.awt.ActionReference;
import org.openide.awt.ActionReferences;
import org.openide.filesystems.MIMEResolver;
import org.openide.util.Lookup;
import org.openide.util.NbBundle;
import org.openide.windows.TopComponent;
/**
*
* @author lkishalmi
*/
@NbBundle.Messages(
"ANTLRv3Resolver=ANTLR v3 Grammar"
)
@MIMEResolver.ExtensionRegistration(displayName = "#ANTLRv3Resolver",
extension = "g",
mimeType = Antlr3Language.MIME_TYPE,
position = 286
)
@ActionReferences({
@ActionReference(
path = "Loaders/text/x-antlr3/Actions",
id = @ActionID(category = "System", id = "org.openide.actions.OpenAction"),
position = 100,
separatorAfter = 200
),
@ActionReference(
path = "Loaders/text/x-antlr3/Actions",
id = @ActionID(category = "Edit", id = "org.openide.actions.CutAction"),
position = 300
),
@ActionReference(
path = "Loaders/text/x-antlr3/Actions",
id = @ActionID(category = "Edit", id = "org.openide.actions.CopyAction"),
position = 400
),
@ActionReference(
path = "Loaders/text/x-antlr3/Actions",
id = @ActionID(category = "Edit", id = "org.openide.actions.PasteAction"),
position = 500,
separatorAfter = 600
),
@ActionReference(
path = "Loaders/text/x-antlr3/Actions",
id = @ActionID(category = "Edit", id = "org.openide.actions.DeleteAction"),
position = 700
),
@ActionReference(
path = "Loaders/text/x-antlr3/Actions",
id = @ActionID(category = "System", id = "org.openide.actions.RenameAction"),
position = 800,
separatorAfter = 900
),
@ActionReference(
path = "Loaders/text/x-antlr3/Actions",
id = @ActionID(category = "System", id = "org.openide.actions.SaveAsTemplateAction"),
position = 1000,
separatorAfter = 1100
),
@ActionReference(
path = "Loaders/text/x-antlr3/Actions",
id = @ActionID(category = "System", id = "org.openide.actions.FileSystemAction"),
position = 1200,
separatorAfter = 1300
),
@ActionReference(
path = "Loaders/text/x-antlr3/Actions",
id = @ActionID(category = "System", id = "org.openide.actions.ToolsAction"),
position = 1400
),
@ActionReference(
path = "Loaders/text/x-antlr3/Actions",
id = @ActionID(category = "System", id = "org.openide.actions.PropertiesAction"),
position = 1500
),
@ActionReference(
path = "Editors/text/x-antlr3/Popup",
id = @ActionID(category = "Refactoring", id = "org.netbeans.modules.refactoring.api.ui.WhereUsedAction"),
position = 1600
),
})
@LanguageRegistration(mimeType = Antlr3Language.MIME_TYPE, useMultiview = true)
public final class Antlr3Language extends DefaultLanguageConfig {
public static final String MIME_TYPE = "text/x-antlr3";
@Override
public Language getLexerLanguage() {
return language;
}
@Override
public String getDisplayName() {
return Bundle.ANTLRv3Resolver();
}
@Override
public String getPreferredExtension() {
return "g";
}
@Override
public Parser getParser() {
return new AntlrParser() {
@Override
protected AntlrParserResult<?> createParserResult(Snapshot snapshot) {
return new Antlr3ParserResult(snapshot);
}
};
}
@Override
public String getLineCommentPrefix() {
return "//"; // NOI18N
}
@Override
public DeclarationFinder getDeclarationFinder() {
return new AntlrDeclarationFinder();
}
@Override
public StructureScanner getStructureScanner() {
return new AntlrStructureScanner();
}
@Override
public boolean hasStructureScanner() {
return true;
}
@Override
public OccurrencesFinder getOccurrencesFinder() {
return new AntlrOccurancesFinder();
}
@Override
public boolean hasOccurrencesFinder() {
return true;
}
private static final Language<AntlrTokenId> language
= new AntlrTokenId.AntlrLanguageHierarchy() {
@Override
protected String mimeType() {
return Antlr3Language.MIME_TYPE;
}
@Override
protected Lexer<AntlrTokenId> createLexer(LexerRestartInfo<AntlrTokenId> info) {
return new Antlr3Lexer(info);
}
}.language();
@NbBundle.Messages("Source=&Source")
@MultiViewElement.Registration(
displayName = "#Source",
persistenceType = TopComponent.PERSISTENCE_ONLY_OPENED,
mimeType = Antlr3Language.MIME_TYPE,
preferredID = "antlr3.source",
position = 100
)
public static MultiViewEditorElement createMultiViewEditorElement(Lookup context) {
return new MultiViewEditorElement(context);
}
}