PageRenderTime 43ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/projects/netbeans-7.3/php.refactoring/src/org/netbeans/modules/refactoring/php/delete/PhpDeleteRefactoringPlugin.java

https://gitlab.com/essere.lab.public/qualitas.class-corpus
Java | 165 lines | 103 code | 17 blank | 45 comment | 7 complexity | 06df572e5a124d86dddd48eb98121793 MD5 | raw file
  1. /*
  2. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
  3. *
  4. * Copyright 2010 Oracle and/or its affiliates. All rights reserved.
  5. *
  6. * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
  7. * Other names may be trademarks of their respective owners.
  8. *
  9. * The contents of this file are subject to the terms of either the GNU
  10. * General Public License Version 2 only ("GPL") or the Common
  11. * Development and Distribution License("CDDL") (collectively, the
  12. * "License"). You may not use this file except in compliance with the
  13. * License. You can obtain a copy of the License at
  14. * http://www.netbeans.org/cddl-gplv2.html
  15. * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
  16. * specific language governing permissions and limitations under the
  17. * License. When distributing the software, include this License Header
  18. * Notice in each file and include the License file at
  19. * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this
  20. * particular file as subject to the "Classpath" exception as provided
  21. * by Oracle in the GPL Version 2 section of the License file that
  22. * accompanied this code. If applicable, add the following below the
  23. * License Header, with the fields enclosed by brackets [] replaced by
  24. * your own identifying information:
  25. * "Portions Copyrighted [year] [name of copyright owner]"
  26. *
  27. * If you wish your version of this file to be governed by only the CDDL
  28. * or only the GPL Version 2, indicate your decision by adding
  29. * "[Contributor] elects to include this software in this distribution
  30. * under the [CDDL or GPL Version 2] license." If you do not indicate a
  31. * single choice of license, a recipient has the option to distribute
  32. * your version of this file under either the CDDL, the GPL Version 2 or
  33. * to extend the choice of license to its licensees as provided above.
  34. * However, if you add GPL Version 2 code and therefore, elected the GPL
  35. * Version 2 license, then the option applies only if the new code is
  36. * made subject to such option by the copyright holder.
  37. *
  38. * Contributor(s):
  39. *
  40. * Portions Copyrighted 2010 Sun Microsystems, Inc.
  41. */
  42. package org.netbeans.modules.refactoring.php.delete;
  43. import java.util.Collections;
  44. import java.util.Set;
  45. import javax.swing.Action;
  46. import org.netbeans.modules.php.editor.api.ElementQuery.Index;
  47. import org.netbeans.modules.php.editor.model.ModelElement;
  48. import org.netbeans.modules.refactoring.api.AbstractRefactoring;
  49. import org.netbeans.modules.refactoring.api.Problem;
  50. import org.netbeans.modules.refactoring.api.ProblemDetails;
  51. import org.netbeans.modules.refactoring.api.RefactoringElement;
  52. import org.netbeans.modules.refactoring.api.RefactoringSession;
  53. import org.netbeans.modules.refactoring.api.SafeDeleteRefactoring;
  54. import org.netbeans.modules.refactoring.api.WhereUsedQuery;
  55. import org.netbeans.modules.refactoring.php.findusages.WhereUsedQueryUI;
  56. import org.netbeans.modules.refactoring.php.findusages.WhereUsedSupport;
  57. import org.netbeans.modules.refactoring.spi.ProblemDetailsFactory;
  58. import org.netbeans.modules.refactoring.spi.ProblemDetailsImplementation;
  59. import org.netbeans.modules.refactoring.spi.ProgressProviderAdapter;
  60. import org.netbeans.modules.refactoring.spi.RefactoringElementsBag;
  61. import org.netbeans.modules.refactoring.spi.RefactoringPlugin;
  62. import org.netbeans.modules.refactoring.spi.ui.RefactoringUI;
  63. import org.netbeans.modules.refactoring.spi.ui.UI;
  64. import org.openide.filesystems.FileObject;
  65. import org.openide.util.Cancellable;
  66. import org.openide.util.NbBundle;
  67. import org.openide.util.lookup.Lookups;
  68. /**
  69. *
  70. * @author Radek Matous
  71. */
  72. public class PhpDeleteRefactoringPlugin extends ProgressProviderAdapter implements RefactoringPlugin {
  73. private final SafeDeleteRefactoring refactoring;
  74. private final SafeDeleteSupport safeDeleteSupport;
  75. private WhereUsedQuery[] whereUsedQueries;
  76. public PhpDeleteRefactoringPlugin(SafeDeleteRefactoring refactoring) {
  77. this.refactoring = refactoring;
  78. safeDeleteSupport = this.refactoring.getRefactoringSource().lookup(SafeDeleteSupport.class);
  79. }
  80. public SafeDeleteRefactoring getRefactoring() {
  81. return refactoring;
  82. }
  83. @Override
  84. public Problem preCheck() {
  85. return null;
  86. }
  87. @Override
  88. public Problem fastCheckParameters() {
  89. return null;
  90. }
  91. @Override
  92. public void cancelRequest() {
  93. }
  94. @Override
  95. public Problem checkParameters() {
  96. Set<ModelElement> visibleElements = safeDeleteSupport.getVisibleElements();
  97. whereUsedQueries = new WhereUsedQuery[visibleElements.size()];
  98. Index idx = safeDeleteSupport.getIdx();
  99. int position = 0;
  100. for (ModelElement modelElement : visibleElements) {
  101. WhereUsedSupport support = WhereUsedSupport.getInstance(Collections.singleton(modelElement), idx, modelElement.getFileObject(), modelElement.getOffset());
  102. whereUsedQueries[position++] = new WhereUsedQuery(Lookups.singleton(support));
  103. }
  104. return null;
  105. }
  106. @Override
  107. public Problem prepare(RefactoringElementsBag refactoringElements) {
  108. RefactoringSession inner = RefactoringSession.create("delete"); // NOI18N
  109. FileObject file = safeDeleteSupport.getFile();
  110. fireProgressListenerStart(AbstractRefactoring.PARAMETERS_CHECK, whereUsedQueries.length + 1);
  111. for (int i = 0; i < whereUsedQueries.length; ++i) {
  112. final WhereUsedQuery whereUsedQuery = whereUsedQueries[i];
  113. whereUsedQuery.prepare(inner);
  114. fireProgressListenerStep();
  115. for (RefactoringElement refacElem : inner.getRefactoringElements()) {
  116. if (file != refacElem.getParentFile()) {
  117. WhereUsedSupport support = whereUsedQuery.getRefactoringSource().lookup(WhereUsedSupport.class);
  118. final ProblemDetailsImplemen problemDetailsImplemen = new ProblemDetailsImplemen(new WhereUsedQueryUI(support), inner);
  119. final ProblemDetails problemDetails = ProblemDetailsFactory.createProblemDetails(problemDetailsImplemen);
  120. Problem problem = new Problem(false, NbBundle.getMessage(PhpDeleteRefactoringPlugin.class, "ERR_ReferencesFound"), problemDetails);
  121. if (problem != null) {
  122. fireProgressListenerStop();
  123. return problem;
  124. }
  125. }
  126. }
  127. }
  128. fireProgressListenerStep();
  129. return null;
  130. }
  131. private static class ProblemDetailsImplemen implements ProblemDetailsImplementation {
  132. private RefactoringUI ui;
  133. private RefactoringSession rs;
  134. public ProblemDetailsImplemen(RefactoringUI ui, RefactoringSession rs) {
  135. this.ui = ui;
  136. this.rs = rs;
  137. }
  138. @Override
  139. public void showDetails(Action callback, Cancellable parent) {
  140. parent.cancel();
  141. UI.openRefactoringUI(ui, rs, callback);
  142. }
  143. @Override
  144. public String getDetailsHint() {
  145. return NbBundle.getMessage(PhpDeleteRefactoringPlugin.class, "LBL_ShowUsages");//NOI18N
  146. }
  147. }
  148. }