org.eclipse.wst.jsdt.core.JavaScriptCore Java Examples

The following examples show how to use org.eclipse.wst.jsdt.core.JavaScriptCore. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: HybridProjectCreator.java    From thym with Eclipse Public License 1.0 6 votes vote down vote up
private void addNature(IProject project, IProgressMonitor monitor) throws CoreException {
    IProjectDescription description = project.getDescription();
    String[] oldNatures = description.getNatureIds();
    List<String> natureList =  new ArrayList<String>();
    natureList.addAll(Arrays.asList(oldNatures));
    
    if( !project.hasNature(HybridAppNature.NATURE_ID ) ){
        natureList.add(HybridAppNature.NATURE_ID);
    }
    
    if( !project.hasNature( JavaScriptCore.NATURE_ID )){
        natureList.add(JavaScriptCore.NATURE_ID);
    }
    
    description.setNatureIds(natureList.toArray(new String[natureList.size()]));
    project.setDescription(description, monitor);
    
}
 
Example #2
Source File: HybridProjectCreator.java    From thym with Eclipse Public License 1.0 6 votes vote down vote up
private void setUpJavaScriptProject(IProject project,
        IProgressMonitor monitor) throws JavaScriptModelException {
    IJavaScriptProject javascriptProject = JavaScriptCore.create(project);
    IIncludePathEntry[] entries = javascriptProject.getRawIncludepath();
    List<IIncludePathEntry> entryList = new ArrayList<IIncludePathEntry>();
    
    //remove all source entries && existing cordova libs
    for (IIncludePathEntry aEntry : entries) {
        if(!(IIncludePathEntry.CPE_SOURCE == aEntry.getEntryKind()) &&
        		!aEntry.getPath().segment(0).equals(CordovaLibraryJsContainerInitializer.CONTAINER_ID)){
        	entryList.add(aEntry);
        }
    }
    
    //add cordova.js lib
    IIncludePathEntry cordovaLibEntry = JavaScriptCore.newContainerEntry(new Path(CordovaLibraryJsContainerInitializer.CONTAINER_ID));
    entryList.add(cordovaLibEntry);
    
    // add www
    IIncludePathEntry wwwSrcEntry = JavaScriptCore.newSourceEntry(project.getFolder("www").getFullPath());
    entryList.add(wwwSrcEntry);
    
    javascriptProject.setRawIncludepath(entryList.toArray(new IIncludePathEntry[entryList.size()]), monitor);
}
 
Example #3
Source File: HybridProjectConvertTest.java    From thym with Eclipse Public License 1.0 6 votes vote down vote up
@Test
public void testJavaScriptProjectSetup() throws CoreException{
    IProject theProject = getTheProject();
    addRequiredResources(theProject);
    HybridProjectCreator creator = new HybridProjectCreator();
    creator.convertProject(theProject, new NullProgressMonitor());
    IJavaScriptProject javascriptProject = JavaScriptCore.create(theProject);
    IIncludePathEntry[] entries = javascriptProject.getRawIncludepath();
    List<IIncludePathEntry> entryList = new ArrayList<IIncludePathEntry>(Arrays.asList(entries));
    
    boolean foundWWW = false;
    for (IIncludePathEntry aEntry : entryList) {
        if(IIncludePathEntry.CPE_SOURCE == aEntry.getEntryKind() && 
                aEntry.getPath().lastSegment().equals(PlatformConstants.DIR_WWW)){
            foundWWW = true;
        }
    }
    
    assertTrue("www is not configured to be a JavaScript source directory", foundWWW);
    
}
 
Example #4
Source File: JavaScriptLightWeightEditor.java    From typescript.java with MIT License 6 votes vote down vote up
@Override
public void createPartControl(Composite parent) {

	super.createPartControl(parent);

	// do not even install projection support until folding is actually
	// enabled
	if (isFoldingEnabled()) {
		installProjectionSupport();
	}

	IPreferenceStore preferenceStore = getPreferenceStore();
	boolean closeBrackets = preferenceStore.getBoolean(CLOSE_BRACKETS);
	boolean closeStrings = preferenceStore.getBoolean(CLOSE_STRINGS);
	boolean closeAngularBrackets = JavaScriptCore.VERSION_1_5
			.compareTo(preferenceStore.getString(JavaScriptCore.COMPILER_SOURCE)) <= 0;

	fBracketInserter.setCloseBracketsEnabled(closeBrackets);
	fBracketInserter.setCloseStringsEnabled(closeStrings);
	fBracketInserter.setCloseAngularBracketsEnabled(closeAngularBrackets);

	ISourceViewer sourceViewer = getSourceViewer();
	if (sourceViewer instanceof ITextViewerExtension)
		((ITextViewerExtension) sourceViewer).prependVerifyKeyListener(fBracketInserter);
}
 
Example #5
Source File: HybridProjectCreatorTest.java    From thym with Eclipse Public License 1.0 6 votes vote down vote up
@Test
public void testJavaScriptProjectSetup() throws CoreException{
    IProject theProject = getTheProject();
    IJavaScriptProject javascriptProject = JavaScriptCore.create(theProject);
    IIncludePathEntry[] entries = javascriptProject.getRawIncludepath();
    List<IIncludePathEntry> entryList = new ArrayList<IIncludePathEntry>(Arrays.asList(entries));
    
    boolean foundWWW = false;
    for (IIncludePathEntry aEntry : entryList) {
        if(IIncludePathEntry.CPE_SOURCE == aEntry.getEntryKind() && 
                aEntry.getPath().lastSegment().equals(PlatformConstants.DIR_WWW)){
            foundWWW = true;
        }
    }
    
    assertTrue("www is not configured to be a JavaScript source directory", foundWWW);
    
}
 
Example #6
Source File: TypeScriptMergeViewer.java    From typescript.java with MIT License 5 votes vote down vote up
private ChainedPreferenceStore createChainedPreferenceStore(IIDETypeScriptProject project) {
	ArrayList<IPreferenceStore> stores = new ArrayList<>(4);
	if (project != null) {
		stores.add(new EclipsePreferencesAdapter(new ProjectScope(project.getProject()),
				TypeScriptCorePlugin.PLUGIN_ID));
		stores.add(new EclipsePreferencesAdapter(new ProjectScope(project.getProject()),
				TypeScriptUIPlugin.PLUGIN_ID));
	}
	stores.add(JavaScriptPlugin.getDefault().getPreferenceStore());
	stores.add(new PreferencesAdapter(JavaScriptCore.getPlugin().getPluginPreferences()));
	stores.add(new PreferencesAdapter(JSDTTypeScriptUIPlugin.getDefault().getPluginPreferences()));
	stores.add(EditorsUI.getPreferenceStore());
	return new ChainedPreferenceStore(stores.toArray(new IPreferenceStore[stores.size()]));
}
 
Example #7
Source File: JavascriptASTExtractor.java    From codemining-core with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Get the AST of a file. It is assumed that a JavaScriptUnit will be
 * returned. An heuristic is used to set the path variables.
 * 
 * @param file
 * @return the compilation unit of the file
 * @throws IOException
 */
public final JavaScriptUnit getAST(final File file) throws IOException {
	final String sourceFile = FileUtils.readFileToString(file);
	final ASTParser parser = ASTParser.newParser(AST.JLS3);
	parser.setKind(ASTParser.K_COMPILATION_UNIT);

	final Map<String, String> options = new Hashtable<String, String>();
	options.put(JavaScriptCore.COMPILER_CODEGEN_TARGET_PLATFORM,
			JavaScriptCore.VERSION_1_7);
	options.put(JavaScriptCore.COMPILER_SOURCE, JavaScriptCore.VERSION_1_7);
	if (useJavadocs) {
		options.put(JavaScriptCore.COMPILER_DOC_COMMENT_SUPPORT,
				JavaScriptCore.ENABLED);
	}
	parser.setCompilerOptions(options);
	parser.setSource(sourceFile.toCharArray()); // set source
	parser.setResolveBindings(useBindings);
	parser.setBindingsRecovery(useBindings);

	parser.setStatementsRecovery(true);

	parser.setUnitName(file.getAbsolutePath());

	// FIXME Need file's project loaded into Eclipse to get bindings
	// which is only possible automatically if this were an Eclipse plugin
	// cf. https://bugs.eclipse.org/bugs/show_bug.cgi?id=206391
	// final IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
	// final IProject project = root.getProject(projectName);
	// parser.setProject(JavaScriptCore.create(project));

	final JavaScriptUnit compilationUnit = (JavaScriptUnit) parser
			.createAST(null);

	return compilationUnit;
}
 
Example #8
Source File: CordovaLibraryJsContainerInitializer.java    From thym with Eclipse Public License 1.0 5 votes vote down vote up
private IIncludePathEntry getCordovaJsIncludePathEntry(){
	try {
		IPath cordovaJSRuntimePath = getLibraryRuntimeFolder().append(PlatformConstants.FILE_JS_CORDOVA);
		File cordovaJS = cordovaJSRuntimePath.toFile();
		if (!cordovaJS.exists()) {
			HybridProject prj = HybridProject.getHybridProject(project.getProject());
			
			HybridMobileEngine[] activeEngines = prj.getEngineManager().getEngines();
			if(activeEngines == null || activeEngines.length <1){
				return null;
			}
			HybridMobileLibraryResolver resolver = activeEngines[0].getResolver();
			if(resolver != null){
				String templateCordovaJS = resolver.getTemplateFile(PlatformConstants.FILE_JS_CORDOVA);
			
				File jsFile = new File(project.getProject().getFile(new Path("platforms/"+templateCordovaJS.toString())).getRawLocation().toOSString());
			
				if(jsFile.exists()){
					org.eclipse.thym.core.internal.util.FileUtils.fileCopy(
							org.eclipse.thym.core.internal.util.FileUtils.toURL(jsFile),
							org.eclipse.thym.core.internal.util.FileUtils.toURL(cordovaJS));

				}
			}
		}
		return JavaScriptCore.newLibraryEntry(cordovaJSRuntimePath.makeAbsolute(),null, null);
		
	} catch (IOException e) {
		HybridCore.log(IStatus.ERROR, "Error creating the cordova JS runtime libraries", e);
	}
	return null;
}
 
Example #9
Source File: HybridProjectConvertTest.java    From thym with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void testNature() throws CoreException{
    IProject project = getTheProject();
    addRequiredResources(project);
    HybridProjectCreator creator = new HybridProjectCreator();
    creator.convertProject(project, new NullProgressMonitor());
    assertTrue("Missing Hybrid project nature id",project.hasNature(HybridAppNature.NATURE_ID));
    assertTrue("Missing JavaScript project nature id", project.hasNature(JavaScriptCore.NATURE_ID));
    HybridProject hp = HybridProject.getHybridProject(project);
    assertNotNull("Can not retrieve HybridProject instance", hp);
}
 
Example #10
Source File: TestProject.java    From thym with Eclipse Public License 1.0 5 votes vote down vote up
private IStatus isProjectValid() throws CoreException{
	IProject project = getProject();
	if( !project.hasNature(HybridAppNature.NATURE_ID ) ){
		return error("project does not have hybrid application nature");
	}
	if( !project.hasNature( JavaScriptCore.NATURE_ID )){
		return error("project does not have javascript nature");
	}
	for (int i = 0; i < COMMON_PATHS.length; i++) {
		IResource resource = project.findMember(COMMON_PATHS[i]);
		if(resource == null || !resource.exists()){
			error("Project is missing "+ COMMON_PATHS[i] );
		}
	}
	Document doc;
	try {
		doc = loadConfigXML();
	} catch (Exception e) {
		return error("error parsing config.xml");
	}
	String id = doc.getDocumentElement().getAttribute("id");
	if( !appId.equals(id)){
		error("wrong application id");
	}
	NodeList nodes = doc.getDocumentElement().getElementsByTagName("name");
	if(nodes.getLength()< 1){
		return error("Application name is not updated"); 
	}
	String name = nodes.item(0).getTextContent();
	if( !appName.equals(name)){
		return error("Wrong application name");
	}
	
	
	return Status.OK_STATUS;
}
 
Example #11
Source File: JavascriptASTExtractor.java    From tassal with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Get the AST of a file. It is assumed that a JavaScriptUnit will be
 * returned. An heuristic is used to set the path variables.
 * 
 * @param file
 * @return the compilation unit of the file
 * @throws IOException
 */
public final JavaScriptUnit getAST(final File file) throws IOException {
	final String sourceFile = FileUtils.readFileToString(file);
	final ASTParser parser = ASTParser.newParser(AST.JLS3);
	parser.setKind(ASTParser.K_COMPILATION_UNIT);

	final Map<String, String> options = new Hashtable<String, String>();
	options.put(JavaScriptCore.COMPILER_CODEGEN_TARGET_PLATFORM,
			JavaScriptCore.VERSION_1_7);
	options.put(JavaScriptCore.COMPILER_SOURCE, JavaScriptCore.VERSION_1_7);
	if (useJavadocs) {
		options.put(JavaScriptCore.COMPILER_DOC_COMMENT_SUPPORT,
				JavaScriptCore.ENABLED);
	}
	parser.setCompilerOptions(options);
	parser.setSource(sourceFile.toCharArray()); // set source
	parser.setResolveBindings(useBindings);
	parser.setBindingsRecovery(useBindings);

	parser.setStatementsRecovery(true);

	parser.setUnitName(file.getAbsolutePath());

	// FIXME Need file's project loaded into Eclipse to get bindings
	// which is only possible automatically if this were an Eclipse plugin
	// cf. https://bugs.eclipse.org/bugs/show_bug.cgi?id=206391
	// final IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
	// final IProject project = root.getProject(projectName);
	// parser.setProject(JavaScriptCore.create(project));

	final JavaScriptUnit compilationUnit = (JavaScriptUnit) parser
			.createAST(null);

	return compilationUnit;
}
 
Example #12
Source File: JsniFormattingUtil.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Same as format(IDocument, Map, String[]), except the formatting options
 * are taken from the given project.
 * 
 */
public static TextEdit format(IDocument document, IJavaProject project,
    String[] originalJsniMethods) {
  @SuppressWarnings("unchecked")
  // safe by IJavaScriptProject.getOptions spec
  Map<String, String> jsOptions = JavaScriptCore.create(project.getProject()).getOptions(true);
  @SuppressWarnings("unchecked")
  // safe by IJavaScriptProject.getOptions spec
  Map<String, String> jOptions = project.getOptions(true);
  return format(document, jOptions, jsOptions, originalJsniMethods);
}
 
Example #13
Source File: JavascriptASTExtractor.java    From api-mining with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Get the AST of a file. It is assumed that a JavaScriptUnit will be
 * returned. An heuristic is used to set the path variables.
 * 
 * @param file
 * @return the compilation unit of the file
 * @throws IOException
 */
public final JavaScriptUnit getAST(final File file) throws IOException {
	final String sourceFile = FileUtils.readFileToString(file);
	final ASTParser parser = ASTParser.newParser(AST.JLS3);
	parser.setKind(ASTParser.K_COMPILATION_UNIT);

	final Map<String, String> options = new Hashtable<String, String>();
	options.put(JavaScriptCore.COMPILER_CODEGEN_TARGET_PLATFORM,
			JavaScriptCore.VERSION_1_7);
	options.put(JavaScriptCore.COMPILER_SOURCE, JavaScriptCore.VERSION_1_7);
	if (useJavadocs) {
		options.put(JavaScriptCore.COMPILER_DOC_COMMENT_SUPPORT,
				JavaScriptCore.ENABLED);
	}
	parser.setCompilerOptions(options);
	parser.setSource(sourceFile.toCharArray()); // set source
	parser.setResolveBindings(useBindings);
	parser.setBindingsRecovery(useBindings);

	parser.setStatementsRecovery(true);

	parser.setUnitName(file.getAbsolutePath());

	// FIXME Need file's project loaded into Eclipse to get bindings
	// which is only possible automatically if this were an Eclipse plugin
	// cf. https://bugs.eclipse.org/bugs/show_bug.cgi?id=206391
	// final IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
	// final IProject project = root.getProject(projectName);
	// parser.setProject(JavaScriptCore.create(project));

	final JavaScriptUnit compilationUnit = (JavaScriptUnit) parser
			.createAST(null);

	return compilationUnit;
}
 
Example #14
Source File: JavaScriptLightWeightEditor.java    From typescript.java with MIT License 5 votes vote down vote up
@Override
protected void configureSourceViewerDecorationSupport(SourceViewerDecorationSupport support) {
	fBracketMatcher.setSourceVersion(getPreferenceStore().getString(JavaScriptCore.COMPILER_SOURCE));
	support.setCharacterPairMatcher(fBracketMatcher);
	support.setMatchingCharacterPainterPreferenceKeys(MATCHING_BRACKETS, MATCHING_BRACKETS_COLOR);
	super.configureSourceViewerDecorationSupport(support);
}
 
Example #15
Source File: JavascriptASTExtractor.java    From api-mining with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Return an ASTNode given the content
 * 
 * @param content
 * @return
 */
public final ASTNode getASTNode(final char[] content,
		final ParseType parseType) {
	final ASTParser parser = ASTParser.newParser(AST.JLS3);
	final int astKind;
	switch (parseType) {
	case CLASS_BODY:
	case METHOD:
		astKind = ASTParser.K_CLASS_BODY_DECLARATIONS;
		break;
	case COMPILATION_UNIT:
		astKind = ASTParser.K_COMPILATION_UNIT;
		break;
	case EXPRESSION:
		astKind = ASTParser.K_EXPRESSION;
		break;
	case STATEMENTS:
		astKind = ASTParser.K_STATEMENTS;
		break;
	default:
		astKind = ASTParser.K_COMPILATION_UNIT;
	}
	parser.setKind(astKind);

	final Map<String, String> options = new Hashtable<String, String>();
	options.put(JavaScriptCore.COMPILER_CODEGEN_TARGET_PLATFORM,
			JavaScriptCore.VERSION_1_7);
	options.put(JavaScriptCore.COMPILER_SOURCE, JavaScriptCore.VERSION_1_7);
	if (useJavadocs) {
		options.put(JavaScriptCore.COMPILER_DOC_COMMENT_SUPPORT,
				JavaScriptCore.ENABLED);
	}
	parser.setCompilerOptions(options);
	parser.setSource(content); // set source
	parser.setResolveBindings(useBindings);
	parser.setBindingsRecovery(useBindings);

	parser.setStatementsRecovery(true);

	if (parseType != ParseType.METHOD) {
		return parser.createAST(null);
	} else {
		final ASTNode cu = parser.createAST(null);
		return getFirstFunctionDeclaration(cu);
	}
}
 
Example #16
Source File: JavascriptASTExtractor.java    From tassal with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
/**
 * Return an ASTNode given the content
 * 
 * @param content
 * @return
 */
public final ASTNode getASTNode(final char[] content,
		final ParseType parseType) {
	final ASTParser parser = ASTParser.newParser(AST.JLS3);
	final int astKind;
	switch (parseType) {
	case CLASS_BODY:
	case METHOD:
		astKind = ASTParser.K_CLASS_BODY_DECLARATIONS;
		break;
	case COMPILATION_UNIT:
		astKind = ASTParser.K_COMPILATION_UNIT;
		break;
	case EXPRESSION:
		astKind = ASTParser.K_EXPRESSION;
		break;
	case STATEMENTS:
		astKind = ASTParser.K_STATEMENTS;
		break;
	default:
		astKind = ASTParser.K_COMPILATION_UNIT;
	}
	parser.setKind(astKind);

	final Map<String, String> options = new Hashtable<String, String>();
	options.put(JavaScriptCore.COMPILER_CODEGEN_TARGET_PLATFORM,
			JavaScriptCore.VERSION_1_7);
	options.put(JavaScriptCore.COMPILER_SOURCE, JavaScriptCore.VERSION_1_7);
	if (useJavadocs) {
		options.put(JavaScriptCore.COMPILER_DOC_COMMENT_SUPPORT,
				JavaScriptCore.ENABLED);
	}
	parser.setCompilerOptions(options);
	parser.setSource(content); // set source
	parser.setResolveBindings(useBindings);
	parser.setBindingsRecovery(useBindings);

	parser.setStatementsRecovery(true);

	if (parseType != ParseType.METHOD) {
		return parser.createAST(null);
	} else {
		final ASTNode cu = parser.createAST(null);
		return getFirstFunctionDeclaration(cu);
	}
}
 
Example #17
Source File: JavaScriptLightWeightEditor.java    From typescript.java with MIT License 4 votes vote down vote up
@Override
protected void handlePreferenceStoreChanged(PropertyChangeEvent event) {

	String property = event.getProperty();

	if (AbstractDecoratedTextEditorPreferenceConstants.EDITOR_TAB_WIDTH.equals(property)) {
		/*
		 * Ignore tab setting since we rely on the formatter preferences. We
		 * do this outside the try-finally block to avoid that
		 * EDITOR_TAB_WIDTH is handled by the sub-class
		 * (AbstractDecoratedTextEditor).
		 */
		return;
	}

	try {
		ISourceViewer sourceViewer = getSourceViewer();
		if (sourceViewer == null)
			return;

		if (JavaScriptCore.COMPILER_SOURCE.equals(property)) {
			if (event.getNewValue() instanceof String)
				fBracketMatcher.setSourceVersion((String) event.getNewValue());
			// fall through as others are interested in source change as
			// well.
		}

		((JavaScriptSourceViewerConfiguration) getSourceViewerConfiguration()).handlePropertyChangeEvent(event);

		if (PreferenceConstants.EDITOR_FOLDING_PROVIDER.equals(property)) {
			if (sourceViewer instanceof ProjectionViewer) {
				ProjectionViewer pv = (ProjectionViewer) sourceViewer;
				// install projection support if it has not even been
				// installed yet
				if (isFoldingEnabled() && (fProjectionSupport == null)) {
					installProjectionSupport();
				}
				if (pv.isProjectionMode() != isFoldingEnabled()) {
					if (pv.canDoOperation(ProjectionViewer.TOGGLE)) {
						pv.doOperation(ProjectionViewer.TOGGLE);
					}
				}
			}
			return;
		}
	} finally {
		super.handlePreferenceStoreChanged(event);
	}
}
 
Example #18
Source File: JavaScriptLightWeightEditor.java    From typescript.java with MIT License 4 votes vote down vote up
protected void addPreferenceStores(List stores, IEditorInput input) {
	stores.add(JavaScriptPlugin.getDefault().getPreferenceStore());
	stores.add(new PreferencesAdapter(JavaScriptCore.getPlugin().getPluginPreferences()));
	stores.add(new PreferencesAdapter(JSDTTypeScriptUIPlugin.getDefault().getPluginPreferences()));
	stores.add(EditorsUI.getPreferenceStore());
}
 
Example #19
Source File: TypeScriptIndenter.java    From typescript.java with MIT License 4 votes vote down vote up
private boolean hasGenerics() {
	return JavaScriptCore.VERSION_1_5.compareTo(getCoreFormatterOption(JavaScriptCore.COMPILER_SOURCE)) <= 0;
}
 
Example #20
Source File: CordovaLibraryJsContainerInitializer.java    From thym with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public void initialize(IPath containerPath, IJavaScriptProject project)
		throws CoreException {
	CordovaLibraryJsContainerInitializer scopeContainer = new CordovaLibraryJsContainerInitializer(project);
	JavaScriptCore.setJsGlobalScopeContainer(containerPath, new IJavaScriptProject[] { project }, new IJsGlobalScopeContainer[] {scopeContainer} , null);
}
 
Example #21
Source File: TypeScriptIndenter.java    From typescript.java with MIT License 4 votes vote down vote up
CorePrefs(ITypeScriptFile project) {
	fProject = project;
	if (isStandalone()) {
		prefUseTabs = true;
		prefTabSize = 4;
		prefIndentationSize = 4;
		prefArrayDimensionsDeepIndent = true;
		prefContinuationIndent = 2;
		prefBlockIndent = 1;
		prefArrayIndent = prefContinuationIndent;
		prefArrayDeepIndent = true;
		prefTernaryDeepAlign = false;
		prefTernaryIndent = prefContinuationIndent;
		prefCaseIndent = 0;
		prefAssignmentIndent = prefBlockIndent;
		prefCaseBlockIndent = prefBlockIndent;
		prefIndentBracesForBlocks = false;
		prefSimpleIndent = (prefIndentBracesForBlocks && prefBlockIndent == 0) ? 1 : prefBlockIndent;
		prefBracketIndent = prefBlockIndent;
		prefMethodDeclDeepIndent = true;
		prefMethodDeclIndent = 1;
		prefMethodCallDeepIndent = false;
		prefMethodCallIndent = 1;
		prefParenthesisDeepIndent = false;
		prefParenthesisIndent = prefContinuationIndent;
		prefMethodBodyIndent = 1;
		prefTypeIndent = 1;
		prefIndentBracesForArrays = false;
		prefIndentBracesForMethods = false;
		prefIndentBracesForTypes = false;
		prefHasGenerics = false;
		prefTabChar = JavaScriptCore.TAB;
	} else {
		prefUseTabs = prefUseTabs();
		prefTabSize = prefTabSize();
		prefIndentationSize = prefIndentationSize();
		prefArrayDimensionsDeepIndent = prefArrayDimensionsDeepIndent();
		prefContinuationIndent = prefContinuationIndent();
		prefBlockIndent = prefBlockIndent();
		prefArrayIndent = prefArrayIndent();
		prefArrayDeepIndent = prefArrayDeepIndent();
		prefTernaryDeepAlign = prefTernaryDeepAlign();
		prefTernaryIndent = prefTernaryIndent();
		prefCaseIndent = prefCaseIndent();
		prefAssignmentIndent = prefAssignmentIndent();
		prefCaseBlockIndent = prefCaseBlockIndent();
		prefIndentBracesForBlocks = prefIndentBracesForBlocks();
		prefSimpleIndent = prefSimpleIndent();
		prefBracketIndent = prefBracketIndent();
		prefMethodDeclDeepIndent = prefMethodDeclDeepIndent();
		prefMethodDeclIndent = prefMethodDeclIndent();
		prefMethodCallDeepIndent = prefMethodCallDeepIndent();
		prefMethodCallIndent = prefMethodCallIndent();
		prefParenthesisDeepIndent = prefParenthesisDeepIndent();
		prefParenthesisIndent = prefParenthesisIndent();
		prefMethodBodyIndent = prefMethodBodyIndent();
		prefTypeIndent = prefTypeIndent();
		prefIndentBracesForArrays = prefIndentBracesForArrays();
		prefIndentBracesForMethods = prefIndentBracesForMethods();
		prefIndentBracesForTypes = prefIndentBracesForTypes();
		prefHasGenerics = hasGenerics();
		prefTabChar = getCoreFormatterOption(DefaultCodeFormatterConstants.FORMATTER_TAB_CHAR);
	}
}
 
Example #22
Source File: JSDTTypeScriptUIPlugin.java    From typescript.java with MIT License 4 votes vote down vote up
public synchronized TypeScriptTextTools getJavaTextTools() {
	if (fJavaTextTools == null)
		fJavaTextTools = new TypeScriptTextTools(getPreferenceStore(),
				JavaScriptCore.getPlugin().getPluginPreferences());
	return fJavaTextTools;
}
 
Example #23
Source File: JavascriptASTExtractor.java    From codemining-core with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
/**
 * Return an ASTNode given the content
 * 
 * @param content
 * @return
 */
public final ASTNode getASTNode(final char[] content,
		final ParseType parseType) {
	final ASTParser parser = ASTParser.newParser(AST.JLS3);
	final int astKind;
	switch (parseType) {
	case CLASS_BODY:
	case METHOD:
		astKind = ASTParser.K_CLASS_BODY_DECLARATIONS;
		break;
	case COMPILATION_UNIT:
		astKind = ASTParser.K_COMPILATION_UNIT;
		break;
	case EXPRESSION:
		astKind = ASTParser.K_EXPRESSION;
		break;
	case STATEMENTS:
		astKind = ASTParser.K_STATEMENTS;
		break;
	default:
		astKind = ASTParser.K_COMPILATION_UNIT;
	}
	parser.setKind(astKind);

	final Map<String, String> options = new Hashtable<String, String>();
	options.put(JavaScriptCore.COMPILER_CODEGEN_TARGET_PLATFORM,
			JavaScriptCore.VERSION_1_7);
	options.put(JavaScriptCore.COMPILER_SOURCE, JavaScriptCore.VERSION_1_7);
	if (useJavadocs) {
		options.put(JavaScriptCore.COMPILER_DOC_COMMENT_SUPPORT,
				JavaScriptCore.ENABLED);
	}
	parser.setCompilerOptions(options);
	parser.setSource(content); // set source
	parser.setResolveBindings(useBindings);
	parser.setBindingsRecovery(useBindings);

	parser.setStatementsRecovery(true);

	if (parseType != ParseType.METHOD) {
		return parser.createAST(null);
	} else {
		final ASTNode cu = parser.createAST(null);
		return getFirstFunctionDeclaration(cu);
	}
}
 
Example #24
Source File: TypeScriptAutoIndentStrategy.java    From typescript.java with MIT License 2 votes vote down vote up
/**
 * Returns the possibly <code>project</code>-specific core preference defined under
 * <code>key</code>.
 *
 * @param project the project to get the preference from, or <code>null</code> to get the global
 *            preference
 * @param key the key of the preference
 * @return the value of the preference
 * @since 3.5
 */
private static String getCoreOption(IJavaScriptProject project, String key) {
	if (project == null)
		return JavaScriptCore.getOption(key);
	return project.getOption(key, true);
}
 
Example #25
Source File: TypeScriptIndenter.java    From typescript.java with MIT License 2 votes vote down vote up
/**
 * Returns the possibly project-specific core preference defined under
 * <code>key</code>.
 *
 * @param key
 *            the key of the preference
 * @return the value of the preference
 * 
 */
private String getCoreFormatterOption(String key) {
	// if (fProject == null)
	return JavaScriptCore.getOption(key);
	// return fProject.getOption(key, true);
}
 
Example #26
Source File: TypeScriptIndenter.java    From typescript.java with MIT License 2 votes vote down vote up
/**
 * Returns <code>true</code> if the class is used outside the workbench,
 * <code>false</code> in normal mode
 *
 * @return <code>true</code> if the plug-ins are not available
 */
private boolean isStandalone() {
	return JavaScriptCore.getPlugin() == null;
}