org.netbeans.modules.csl.api.InstantRenameAction Maven / Gradle / Ivy
The newest version!
/*
* 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.csl.api;
import java.awt.event.ActionEvent;
import java.io.IOException;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.atomic.AtomicInteger;
import javax.swing.Action;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
import javax.swing.text.BadLocationException;
import javax.swing.text.Document;
import javax.swing.text.JTextComponent;
import org.netbeans.modules.parsing.api.Embedding;
import org.netbeans.modules.parsing.api.Source;
import org.netbeans.modules.parsing.api.UserTask;
import org.netbeans.modules.parsing.spi.ParseException;
import org.netbeans.editor.BaseAction;
import org.netbeans.editor.Utilities;
import org.netbeans.modules.csl.core.Language;
import org.netbeans.modules.csl.core.LanguageRegistry;
import org.netbeans.modules.csl.editor.InstantRenamePerformer;
import org.netbeans.modules.csl.spi.ParserResult;
import org.netbeans.modules.parsing.api.ParserManager;
import org.netbeans.modules.parsing.api.ResultIterator;
import org.netbeans.modules.parsing.api.indexing.IndexingManager;
import org.netbeans.modules.parsing.spi.Parser;
import org.netbeans.modules.parsing.spi.Parser.Result;
import org.netbeans.modules.refactoring.api.ui.RefactoringActionsFactory;
import org.openide.ErrorManager;
import org.openide.cookies.EditorCookie;
import org.openide.nodes.Node;
import org.openide.util.Lookup;
import org.openide.util.NbBundle;
import org.openide.util.lookup.AbstractLookup;
import org.openide.util.lookup.InstanceContent;
/**
* This file is originally from Retouche, the Java Support
* infrastructure in NetBeans. I have modified the file as little
* as possible to make merging Retouche fixes back as simple as
* possible.
*
*
* @author Jan Lahoda
* @author Tor Norbye
* @deprecated use {@link CslActions#createInstantRenameAction() } instead.
*/
@Deprecated
public class InstantRenameAction extends BaseAction {
/** Creates a new instance of InstantRenameAction */
public InstantRenameAction() {
super("in-place-refactoring", MAGIC_POSITION_RESET | UNDO_MERGE_RESET); //NOI18N
}
public @Override void actionPerformed(ActionEvent evt, final JTextComponent target) {
try {
final int caret = target.getCaretPosition();
final String ident = Utilities.getIdentifier(Utilities.getDocument(target), caret);
if (ident == null) {
Utilities.setStatusBoldText(target, NbBundle.getMessage(InstantRenameAction.class, "InstantRenameDenied"));
return;
}
if (IndexingManager.getDefault().isIndexing()) {
Utilities.setStatusBoldText(target, NbBundle.getMessage(InstantRenameAction.class, "scanning-in-progress"));
return;
}
Source js = Source.create(target.getDocument());
if (js == null) {
return;
}
final Set[] changePoints = new Set[1];
final AtomicInteger changed = new AtomicInteger(0);
DocumentListener dl = new DocumentListener() {
@Override
public void insertUpdate(DocumentEvent e) {
changed.compareAndSet(0, 1);
}
@Override
public void removeUpdate(DocumentEvent e) {
changed.compareAndSet(0, 1);
}
@Override
public void changedUpdate(DocumentEvent e) {
// ignore attr changes
}
};
target.getDocument().addDocumentListener(dl);
final InstantRenamer[] renamer = new InstantRenamer[1];
try {
do {
changed.set(0);
ParserManager.parse (
Collections.
© 2015 - 2025 Weber Informatics LLC | Privacy Policy