1 19 package org.netbeans.api.retouche.source; 20 21 import java.io.IOException ; 22 import java.util.ArrayList ; 23 import java.util.List ; 24 import javax.swing.text.Document ; 25 import org.netbeans.api.gsf.Error; 26 import org.netbeans.api.gsf.Index; 27 import org.netbeans.api.gsf.ParserResult; 28 import org.netbeans.api.gsf.PositionManager; 29 import org.netbeans.api.retouche.source.CompilationUnitTree; 30 import org.netbeans.api.retouche.source.ParserTaskImpl; 31 import org.netbeans.modules.gsf.Language; 32 import org.netbeans.modules.retouche.source.parsing.SourceFileObject; 33 import org.openide.ErrorManager; 34 import org.openide.cookies.EditorCookie; 35 import org.openide.filesystems.FileObject; 36 import org.openide.loaders.DataObject; 37 import org.netbeans.api.gsf.annotations.CheckForNull; 38 import org.netbeans.api.gsf.annotations.NonNull; 39 import org.netbeans.api.gsf.annotations.Nullable; 40 41 42 53 public class CompilationInfo extends org.netbeans.api.gsf.CompilationInfo { 54 private Phase phase = Phase.MODIFIED; 55 private CompilationUnitTree compilationUnit; 56 private ParserTaskImpl javacTask; 57 final SourceFileObject jfo; 58 final Source javaSource; 59 boolean needsRestart; 60 private Language language; 61 62 CompilationInfo() throws IOException { 63 super(null); 64 this.javaSource = null; 65 this.jfo = null; 66 this.javacTask = null; 67 } 68 69 CompilationInfo(final Source javaSource, final FileObject fo, final ParserTaskImpl javacTask) 70 throws IOException { 71 super(fo); 72 assert javaSource != null; 73 this.javaSource = javaSource; 74 75 if (fo.isValid() && !fo.isVirtual()) { 77 this.jfo = new SourceFileObject(fo, true); 78 } else { 79 this.jfo = null; 80 } 81 82 this.javacTask = javacTask; 83 } 84 85 87 93 public Phase getPhase() { 94 return this.phase; 95 } 96 97 102 @CheckForNull 103 public CompilationUnitTree getCompilationUnit() { 104 if (this.jfo == null) { 105 throw new IllegalStateException (); 106 } 107 108 return this.compilationUnit; 109 } 110 111 117 public String getText() { 118 if (this.jfo == null) { 119 throw new IllegalStateException (); 120 } 121 122 try { 123 return this.jfo.getCharContent(false).toString(); 124 } catch (IOException ioe) { 125 ErrorManager.getDefault().notify(ioe); 127 128 return null; 129 } 130 } 131 132 public Source getSource() { 133 return javaSource; 134 } 135 136 public ClasspathInfo getClasspathInfo() { 137 return javaSource.getClasspathInfo(); 138 } 139 140 @Override 141 public Index getIndex() { 142 return getClasspathInfo().getClassIndex(); 143 } 144 145 void setPhase(final Phase phase) { 146 assert phase != null; 147 this.phase = phase; 148 } 149 150 void setCompilationUnit(final CompilationUnitTree compilationUnit) { 151 assert compilationUnit != null; 152 this.compilationUnit = compilationUnit; 153 } 154 155 synchronized ParserTaskImpl getParserTask() { 156 if (javacTask == null) { 157 javacTask = 158 javaSource.createParserTask( 159 this); 160 } 161 162 return javacTask; 163 } 164 165 public Language getLanguage() { 166 return language; 167 } 168 169 public void setLanguage(Language language) { 170 this.language = language; 171 } 172 } 173 | Popular Tags |