Codota Logo
CorrectPackageDeclarationProposal
Code IndexAdd Codota to your IDE (free)

How to use
CorrectPackageDeclarationProposal
in
org.eclipse.jdt.internal.ui.text.correction.proposals

Best Java code snippets using org.eclipse.jdt.internal.ui.text.correction.proposals.CorrectPackageDeclarationProposal (Showing top 6 results out of 315)

  • Add the Codota plugin to your IDE and get smart completions
private void myMethod () {
Point p =
  • Codota Iconnew Point(x, y)
  • Codota Iconnew Point()
  • Codota IconMouseEvent e;e.getPoint()
  • Smart code suggestions by Codota
}
origin: org.eclipse.jdt/org.eclipse.jdt.ui

public static void getWrongPackageDeclNameProposals(IInvocationContext context, IProblemLocation problem, Collection<ICommandAccess> proposals) throws CoreException {
  ICompilationUnit cu= context.getCompilationUnit();
  boolean isLinked= cu.getResource().isLinked();
  // correct package declaration
  int relevance= cu.getPackageDeclarations().length == 0 ? IProposalRelevance.MISSING_PACKAGE_DECLARATION : IProposalRelevance.CORRECT_PACKAGE_DECLARATION; // bug 38357
  if (CorrectPackageDeclarationProposal.isValidProposal(cu)) {		
    proposals.add(new CorrectPackageDeclarationProposal(cu, problem, relevance));
  }
  // move to package
  IPackageDeclaration[] packDecls= cu.getPackageDeclarations();
  String newPackName= packDecls.length > 0 ? packDecls[0].getElementName() : ""; //$NON-NLS-1$
  IPackageFragmentRoot root= JavaModelUtil.getPackageFragmentRoot(cu);
  IPackageFragment newPack= root.getPackageFragment(newPackName);
  ICompilationUnit newCU= newPack.getCompilationUnit(cu.getElementName());
  if (!newCU.exists() && !isLinked) {
    String label;
    if (newPack.isDefaultPackage()) {
      label= Messages.format(CorrectionMessages.ReorgCorrectionsSubProcessor_movecu_default_description, BasicElementLabels.getFileName(cu));
    } else {
      String packageLabel= JavaElementLabels.getElementLabel(newPack, JavaElementLabels.ALL_DEFAULT);
      label= Messages.format(CorrectionMessages.ReorgCorrectionsSubProcessor_movecu_description, new Object[] { BasicElementLabels.getFileName(cu), packageLabel });
    }
    CompositeChange composite= new CompositeChange(label);
    composite.add(new CreatePackageChange(newPack));
    composite.add(new MoveCompilationUnitChange(cu, newPack));
    proposals.add(new ChangeCorrectionProposal(label, composite, IProposalRelevance.MOVE_CU_TO_PACKAGE, JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_MOVE)));
  }
}
origin: org.eclipse.scout.sdk.deps/org.eclipse.jdt.ui

  @Override
  public String getName() {
    ICompilationUnit cu= getCompilationUnit();
    IPackageFragment parentPack= (IPackageFragment) cu.getParent();
    try {
      IPackageDeclaration[] decls= cu.getPackageDeclarations();
      if (parentPack.isDefaultPackage() && decls.length > 0) {
        return Messages.format(CorrectionMessages.CorrectPackageDeclarationProposal_remove_description, BasicElementLabels.getJavaElementName(decls[0].getElementName()));
      }
      if (!parentPack.isDefaultPackage() && decls.length == 0) {
        return (Messages.format(CorrectionMessages.CorrectPackageDeclarationProposal_add_description,  JavaElementLabels.getElementLabel(parentPack, JavaElementLabels.ALL_DEFAULT)));
      }
    } catch(JavaModelException e) {
      JavaPlugin.log(e);
    }
    return (Messages.format(CorrectionMessages.CorrectPackageDeclarationProposal_change_description, JavaElementLabels.getElementLabel(parentPack, JavaElementLabels.ALL_DEFAULT)));
  }
}
origin: org.eclipse.scout.sdk.deps/org.eclipse.jdt.ui

public static void getWrongPackageDeclNameProposals(IInvocationContext context, IProblemLocation problem, Collection<ICommandAccess> proposals) throws CoreException {
  ICompilationUnit cu= context.getCompilationUnit();
  boolean isLinked= cu.getResource().isLinked();
  // correct package declaration
  int relevance= cu.getPackageDeclarations().length == 0 ? IProposalRelevance.MISSING_PACKAGE_DECLARATION : IProposalRelevance.CORRECT_PACKAGE_DECLARATION; // bug 38357
  proposals.add(new CorrectPackageDeclarationProposal(cu, problem, relevance));
  // move to package
  IPackageDeclaration[] packDecls= cu.getPackageDeclarations();
  String newPackName= packDecls.length > 0 ? packDecls[0].getElementName() : ""; //$NON-NLS-1$
  IPackageFragmentRoot root= JavaModelUtil.getPackageFragmentRoot(cu);
  IPackageFragment newPack= root.getPackageFragment(newPackName);
  ICompilationUnit newCU= newPack.getCompilationUnit(cu.getElementName());
  if (!newCU.exists() && !isLinked) {
    String label;
    if (newPack.isDefaultPackage()) {
      label= Messages.format(CorrectionMessages.ReorgCorrectionsSubProcessor_movecu_default_description, BasicElementLabels.getFileName(cu));
    } else {
      String packageLabel= JavaElementLabels.getElementLabel(newPack, JavaElementLabels.ALL_DEFAULT);
      label= Messages.format(CorrectionMessages.ReorgCorrectionsSubProcessor_movecu_description, new Object[] { BasicElementLabels.getFileName(cu), packageLabel });
    }
    CompositeChange composite= new CompositeChange(label);
    composite.add(new CreatePackageChange(newPack));
    composite.add(new MoveCompilationUnitChange(cu, newPack));
    proposals.add(new ChangeCorrectionProposal(label, composite, IProposalRelevance.MOVE_CU_TO_PACKAGE, JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_MOVE)));
  }
}
origin: org.eclipse.jdt/org.eclipse.jdt.ui

@Override
public String getName() {
  ICompilationUnit cu= getCompilationUnit();
  IPackageFragment parentPack= (IPackageFragment) cu.getParent();
  try {
    IPackageDeclaration[] decls= cu.getPackageDeclarations();
    if (parentPack.isDefaultPackage() && decls.length > 0) {
      return Messages.format(CorrectionMessages.CorrectPackageDeclarationProposal_remove_description, BasicElementLabels.getJavaElementName(decls[0].getElementName()));
    }
    if (!parentPack.isDefaultPackage() && decls.length == 0) {
      return (Messages.format(CorrectionMessages.CorrectPackageDeclarationProposal_add_description,  JavaElementLabels.getElementLabel(parentPack, JavaElementLabels.ALL_DEFAULT)));
    }
  } catch(JavaModelException e) {
    JavaPlugin.log(e);
  }
  return (Messages.format(CorrectionMessages.CorrectPackageDeclarationProposal_change_description, JavaElementLabels.getElementLabel(parentPack, JavaElementLabels.ALL_DEFAULT)));
}

origin: org.eclipse.jdt/org.eclipse.jdt.ui

@Override
protected void addEdits(IDocument doc, TextEdit root) throws CoreException {
  super.addEdits(doc, root);
  ICompilationUnit cu= getCompilationUnit();
  IPackageFragment parentPack= (IPackageFragment) cu.getParent();
  IPackageDeclaration[] decls= cu.getPackageDeclarations();
  if (parentPack.isDefaultPackage() && decls.length > 0) {
    for (int i= 0; i < decls.length; i++) {
      ISourceRange range= decls[i].getSourceRange();
      root.addChild(new DeleteEdit(range.getOffset(), range.getLength()));
    }
    return;
  }
  if (!parentPack.isDefaultPackage() && decls.length == 0) {
    String lineDelim= StubUtility.getLineDelimiterUsed(cu);
    String str= "package " + parentPack.getElementName() + ';' + lineDelim + lineDelim; //$NON-NLS-1$
    root.addChild(new InsertEdit(0, str));
    return;
  }
  root.addChild(new ReplaceEdit(fLocation.getOffset(), fLocation.getLength(), parentPack.getElementName()));
}
origin: org.eclipse.scout.sdk.deps/org.eclipse.jdt.ui

@Override
protected void addEdits(IDocument doc, TextEdit root) throws CoreException {
  super.addEdits(doc, root);
  ICompilationUnit cu= getCompilationUnit();
  IPackageFragment parentPack= (IPackageFragment) cu.getParent();
  IPackageDeclaration[] decls= cu.getPackageDeclarations();
  if (parentPack.isDefaultPackage() && decls.length > 0) {
    for (int i= 0; i < decls.length; i++) {
      ISourceRange range= decls[i].getSourceRange();
      root.addChild(new DeleteEdit(range.getOffset(), range.getLength()));
    }
    return;
  }
  if (!parentPack.isDefaultPackage() && decls.length == 0) {
    String lineDelim= StubUtility.getLineDelimiterUsed(cu);
    String str= "package " + parentPack.getElementName() + ';' + lineDelim + lineDelim; //$NON-NLS-1$
    root.addChild(new InsertEdit(0, str));
    return;
  }
  root.addChild(new ReplaceEdit(fLocation.getOffset(), fLocation.getLength(), parentPack.getElementName()));
}
org.eclipse.jdt.internal.ui.text.correction.proposalsCorrectPackageDeclarationProposal

Most used methods

  • <init>
  • getCompilationUnit
  • isValidProposal

Popular in Java

  • Making http requests using okhttp
  • onCreateOptionsMenu (Activity)
  • notifyDataSetChanged (ArrayAdapter)
  • getSupportFragmentManager (FragmentActivity)
    Return the FragmentManager for interacting with fragments associated with this activity.
  • SocketException (java.net)
    This SocketException may be thrown during socket creation or setting options, and is the superclass
  • UUID (java.util)
    UUID is an immutable representation of a 128-bit universally unique identifier (UUID). There are mul
  • Vector (java.util)
    The Vector class implements a growable array of objects. Like an array, it contains components that
  • Notification (javax.management)
  • Project (org.apache.tools.ant)
    Central representation of an Ant project. This class defines an Ant project with all of its targets,
  • Option (scala)
Codota Logo
  • Products

    Search for Java codeSearch for JavaScript codeEnterprise
  • IDE Plugins

    IntelliJ IDEAWebStormAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimAtomGoLandRubyMineEmacsJupyter
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogCodota Academy Plugin user guide Terms of usePrivacy policyJava Code IndexJavascript Code Index
Get Codota for your IDE now